<s> from UaStateGeneric import UaStateGeneric <EOL> from CCEvents import CCEventRing , CCEventConnect , CCEventFail , CCEventRedirect , CCEventDisconnect , CCEventPreConnect <EOL> from SipContact import SipContact <EOL> from SipAddress import SipAddress <EOL> class UasStateRinging ( UaStateGeneric ) : <EOL> sname = '<STR_LIT>' <EOL> rseq = None <EOL> def recvEvent ( self , event ) : <EOL> if isinstance ( event , CCEventRing ) : <EOL> scode = event . getData ( ) <EOL> if scode == None : <EOL> code , reason , body = ( <NUM_LIT> , '<STR_LIT>' , None ) <EOL> else : <EOL> code , reason , body = scode <EOL> if code == <NUM_LIT:100> : <EOL> return None <EOL> if body != None and self . ua . on_local_sdp_change != None and body . needs_update : <EOL> self . ua . on_local_sdp_change ( body , lambda x : self . ua . recvEvent ( event ) ) <EOL> return None <EOL> self . ua . lSDP = body <EOL> if self . ua . p1xx_ts == None : <EOL> self . ua . p1xx_ts = event . rtime <EOL> self . ua . sendUasResponse ( code , reason , body ) <EOL> for ring_cb in self . ua . ring_cbs : <EOL> ring_cb ( self . ua , event . rtime , event . origin , code ) <EOL> return None <EOL> elif isinstance ( event , CCEventConnect ) or isinstance ( event , CCEventPreConnect ) : <EOL> code , reason , body = event . getData ( ) <EOL> if body != None and self . ua . on_local_sdp_change != None and body . needs_update : <EOL> self . ua . on_local_sdp_change ( body , lambda x : self . ua . recvEvent ( event ) ) <EOL> return None <EOL> if event . extra_headers != None : <EOL> extra_headers = tuple ( event . extra_headers ) <EOL> else : <EOL> extra_headers = None <EOL> self . ua . lSDP = body <EOL> if isinstance ( event , CCEventConnect ) : <EOL> self . ua . sendUasResponse ( code , reason , body , self . ua . lContact , ack_wait = False , extra_headers = extra_headers ) <EOL> if self . ua . expire_timer != None : <EOL> self . ua . expire_timer . cancel ( ) <EOL> self . ua . expire_timer = None <EOL> self . ua . startCreditTimer ( event . rtime ) <EOL> self . ua . connect_ts = event . rtime <EOL> return ( UaStateConnected , self . ua . conn_cbs , event . rtime , event . origin ) <EOL> else : <EOL> self . ua . sendUasResponse ( code , reason , body , self . ua . lContact , ack_wait = True , extra_headers = extra_headers ) <EOL> return ( UaStateConnected , ) <EOL> elif isinstance ( event , CCEventRedirect ) : <EOL> scode = event . getData ( ) <EOL> if scode == None : <EOL> scode = ( <NUM_LIT> , '<STR_LIT>' , None , None ) <EOL> self . ua . sendUasResponse ( scode [ <NUM_LIT:0> ] , scode [ <NUM_LIT:1> ] , scode [ <NUM_LIT:2> ] , SipContact ( address = SipAddress ( url = scode [ <NUM_LIT:3> ] ) ) ) <EOL> if self . ua . expire_timer != None : <EOL> self . ua . expire_timer . cancel ( ) <EOL> self . ua . expire_timer = None <EOL> self . ua . disconnect_ts = event . rtime <EOL> return ( UaStateFailed , self . ua . fail_cbs , event . rtime , event . origin , scode [ <NUM_LIT:0> ] ) <EOL> elif isinstance ( event , CCEventFail ) : <EOL> scode = event . getData ( ) <EOL> if scode == None : <EOL> scode = ( <NUM_LIT> , '<STR_LIT>' ) <EOL> if event . extra_headers != None : <EOL> extra_headers = tuple ( event . extra_headers ) <EOL> else : <EOL> extra_headers = None <EOL> self . ua . sendUasResponse ( scode [ <NUM_LIT:0> ] , scode [ <NUM_LIT:1> ] , reason_rfc3326 = event . reason , extra_headers = extra_headers ) <EOL> if self . ua . expire_timer != None : <EOL> self . ua . expire_timer . cancel ( ) <EOL> self . ua . expire_timer = None <EOL> self . ua . disconnect_ts = event . rtime <EOL> return ( UaStateFailed , self . ua . fail_cbs , event . rtime , event . origin , scode [ <NUM_LIT:0> ] ) <EOL> elif isinstance ( event , CCEventDisconnect ) : <EOL> self . ua . sendUasResponse ( <NUM_LIT> , '<STR_LIT>' , reason_rfc3326 = event . reason ) <EOL> if self . ua . expire_timer != None : <EOL> self . ua . expire_timer . cancel ( ) <EOL> self . ua . expire_timer = None <EOL> self . ua . disconnect_ts = event . rtime <EOL> return ( UaStateDisconnected , self . ua . disc_cbs , event . rtime , event . origin , self . ua . last_scode ) <EOL> return None <EOL> def recvRequest ( self , req ) : <EOL> if req . getMethod ( ) == '<STR_LIT>' : <EOL> self . ua . sendUasResponse ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . ua . global_config [ '<STR_LIT>' ] . sendResponse ( req . genResponse ( <NUM_LIT:200> , '<STR_LIT:OK>' , server = self . ua . local_ua ) ) <EOL> if req . countHFs ( '<STR_LIT>' ) > <NUM_LIT:0> : <EOL> also = req . getHFBody ( '<STR_LIT>' ) . getUrl ( ) . getCopy ( ) <EOL> else : <EOL> also = None <EOL> event = CCEventDisconnect ( also , rtime = req . rtime , origin = self . ua . origin ) <EOL> try : <EOL> event . reason = req . getHFBody ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> self . ua . equeue . append ( event ) <EOL> if self . ua . expire_timer != None : <EOL> self . ua . expire_timer . cancel ( ) <EOL> self . ua . expire_timer = None <EOL> self . ua . disconnect_ts = req . rtime <EOL> return ( UaStateDisconnected , self . ua . disc_cbs , req . rtime , self . ua . origin ) <EOL> return None <EOL> def cancel ( self , rtime , req ) : <EOL> self . ua . disconnect_ts = rtime <EOL> self . ua . changeState ( ( UaStateDisconnected , self . ua . disc_cbs , rtime , self . ua . origin ) ) <EOL> event = CCEventDisconnect ( rtime = rtime , origin = self . ua . origin ) <EOL> if req != None : <EOL> try : <EOL> event . reason = req . getHFBody ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> self . ua . emitEvent ( event ) <EOL> if not globals ( ) . has_key ( '<STR_LIT>' ) : <EOL> from UaStateFailed import UaStateFailed <EOL> if not globals ( ) . has_key ( '<STR_LIT>' ) : <EOL> from UaStateConnected import UaStateConnected <EOL> if not globals ( ) . has_key ( '<STR_LIT>' ) : <EOL> from UaStateDisconnected import UaStateDisconnected <EOL> if not globals ( ) . has_key ( '<STR_LIT>' ) : <EOL> from UasStateTrying import UasStateTrying </s>
