<s> from sippy . UA import UA <EOL> from sippy . CCEvents import CCEventDisconnect , CCEventTry <EOL> from sippy . UaStateDead import UaStateDead <EOL> from sippy . SipConf import SipConf <EOL> from sippy . SipLogger import SipLogger <EOL> from sippy . SipTransactionManager import SipTransactionManager <EOL> from sippy . StatefulProxy import StatefulProxy <EOL> from twisted . internet import reactor <EOL> import getopt , os , sys <EOL> class CallController ( object ) : <EOL> global_config = None <EOL> uaA = None <EOL> uaO = None <EOL> nh_addr = None <EOL> def __init__ ( self , global_config ) : <EOL> self . global_config = global_config <EOL> self . uaA = UA ( self . global_config , self . recvEvent ) <EOL> self . uaO = None <EOL> def recvEvent ( self , event , ua ) : <EOL> if ua == self . uaA : <EOL> if self . uaO == None : <EOL> if not isinstance ( event , CCEventTry ) : <EOL> self . uaA . recvEvent ( CCEventDisconnect ( ) ) <EOL> return <EOL> self . uaO = UA ( self . global_config , event_cb = self . recvEvent , nh_address = self . global_config [ '<STR_LIT>' ] ) <EOL> self . uaO . recvEvent ( event ) <EOL> else : <EOL> self . uaA . recvEvent ( event ) <EOL> class CallMap ( object ) : <EOL> global_config = None <EOL> proxy = None <EOL> def __init__ ( self , global_config ) : <EOL> self . global_config = global_config <EOL> self . proxy = StatefulProxy ( global_config , self . global_config [ '<STR_LIT>' ] ) <EOL> def recvRequest ( self , req ) : <EOL> if req . getHFBody ( '<STR_LIT:to>' ) . getTag ( ) != None : <EOL> return ( req . genResponse ( <NUM_LIT> , '<STR_LIT>' ) , None , None ) <EOL> if req . getMethod ( ) == '<STR_LIT>' : <EOL> cc = CallController ( self . global_config ) <EOL> return cc . uaA . recvRequest ( req ) <EOL> if req . getMethod ( ) == '<STR_LIT>' : <EOL> return self . proxy . recvRequest ( req ) <EOL> if req . getMethod ( ) in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return ( req . genResponse ( <NUM_LIT:200> , '<STR_LIT:OK>' ) , None , None ) <EOL> return ( req . genResponse ( <NUM_LIT> , '<STR_LIT>' ) , None , None ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' ) <EOL> except getopt . GetoptError : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> laddr = None <EOL> lport = None <EOL> global_config = { '<STR_LIT>' : [ '<STR_LIT>' , <NUM_LIT> ] } <EOL> foreground = False <EOL> for o , a in opts : <EOL> if o == '<STR_LIT>' : <EOL> foreground = True <EOL> continue <EOL> if o == '<STR_LIT>' : <EOL> laddr = a <EOL> continue <EOL> if o == '<STR_LIT>' : <EOL> lport = int ( a ) <EOL> continue <EOL> if o == '<STR_LIT>' : <EOL> if a . startswith ( '<STR_LIT:[>' ) : <EOL> parts = a . split ( '<STR_LIT:]>' , <NUM_LIT:1> ) <EOL> global_config [ '<STR_LIT>' ] = [ parts [ <NUM_LIT:0> ] + '<STR_LIT:]>' , <NUM_LIT> ] <EOL> parts = parts [ <NUM_LIT:1> ] . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> else : <EOL> parts = a . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> global_config [ '<STR_LIT>' ] = [ parts [ <NUM_LIT:0> ] , <NUM_LIT> ] <EOL> if len ( parts ) == <NUM_LIT:2> : <EOL> global_config [ '<STR_LIT>' ] [ <NUM_LIT:1> ] = int ( parts [ <NUM_LIT:1> ] ) <EOL> continue <EOL> global_config [ '<STR_LIT>' ] = tuple ( global_config [ '<STR_LIT>' ] ) <EOL> if not foreground : <EOL> if os . fork ( ) != <NUM_LIT:0> : <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> os . setsid ( ) <EOL> if os . fork ( ) != <NUM_LIT:0> : <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> os . chdir ( '<STR_LIT:/>' ) <EOL> fd = os . open ( '<STR_LIT>' , os . O_RDONLY ) <EOL> os . dup2 ( fd , sys . __stdin__ . fileno ( ) ) <EOL> os . close ( fd ) <EOL> fd = os . open ( '<STR_LIT>' , os . O_WRONLY | os . O_CREAT | os . O_APPEND ) <EOL> os . dup2 ( fd , sys . __stdout__ . fileno ( ) ) <EOL> os . dup2 ( fd , sys . __stderr__ . fileno ( ) ) <EOL> os . close ( fd ) <EOL> SipConf . my_uaname = '<STR_LIT>' <EOL> SipConf . allow_formats = ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:100> , <NUM_LIT> ) <EOL> global_config [ '<STR_LIT>' ] = SipConf . my_address <EOL> global_config [ '<STR_LIT>' ] = SipConf . my_port <EOL> if laddr != None : <EOL> global_config [ '<STR_LIT>' ] = laddr <EOL> if lport != None : <EOL> global_config [ '<STR_LIT>' ] = lport <EOL> global_config [ '<STR_LIT>' ] = SipLogger ( '<STR_LIT>' ) <EOL> cmap = CallMap ( global_config ) <EOL> global_config [ '<STR_LIT>' ] = SipTransactionManager ( global_config , cmap . recvRequest ) <EOL> reactor . run ( installSignalHandlers = True ) </s>
