Esempio n. 1
0
 def recvRequest(self, req):
     if req.getMethod() == 'BYE':
         self.ua.sendUasResponse(487, 'Request Terminated')
         self.ua.global_config['_sip_tm'].sendResponse(
             req.genResponse(200, 'OK', server=self.ua.local_ua),
             lossemul=self.ua.uas_lossemul)
         #print 'BYE received in the Ringing state, going to the Disconnected state'
         if req.countHFs('also') > 0:
             also = req.getHFBody('also').getCopy()
         else:
             also = None
         event = CCEventDisconnect(also,
                                   rtime=req.rtime,
                                   origin=self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         if self.ua.expire_timer != None:
             self.ua.expire_timer.cancel()
             self.ua.expire_timer = None
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime,
                 self.ua.origin)
     return None
Esempio n. 2
0
 def recvRequest(self, req):
     if req.getMethod() == 'INVITE':
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(491, \
           'Request Pending', server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
         return None
     elif req.getMethod() == 'BYE':
         self.ua.sendUasResponse(487, 'Request Terminated')
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(200, 'OK', \
           server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
         #print 'BYE received in the Updating state, going to the Disconnected state'
         event = CCEventDisconnect(rtime = req.rtime, origin = self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         self.ua.cancelCreditTimer()
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime, self.ua.origin)
     elif req.getMethod() == 'REFER':
         if req.countHFs('refer-to') == 0:
             self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(400, 'Bad Request',
               server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
             return None
         self.ua.sendUasResponse(487, 'Request Terminated')
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(202, 'Accepted', \
           server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
         also = req.getHFBody('refer-to').getCopy()
         self.ua.equeue.append(CCEventDisconnect(also, rtime = req.rtime, origin = self.ua.origin))
         self.ua.cancelCreditTimer()
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime, self.ua.origin)
     #print 'wrong request %s in the state Updating' % req.getMethod()
     return None
Esempio n. 3
0
 def cancel(self, rtime, req):
     self.ua.disconnect_ts = rtime
     self.ua.changeState((UaStateDisconnected, self.ua.disc_cbs, rtime, self.ua.origin))
     event = CCEventDisconnect(rtime = rtime, origin = self.ua.origin)
     if req != None:
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
     self.ua.emitEvent(event)
Esempio n. 4
0
 def cancel(self, rtime, req):
     self.ua.disconnect_ts = rtime
     self.ua.changeState(
         (UaStateDisconnected, self.ua.disc_cbs, rtime, self.ua.origin))
     event = CCEventDisconnect(rtime=rtime, origin=self.ua.origin)
     if req != None:
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
     self.ua.emitEvent(event)
Esempio n. 5
0
 def cancel(self, rtime, req):
     req = self.ua.genRequest('BYE')
     self.ua.lCSeq += 1
     self.ua.global_config['_sip_tm'].newTransaction(req, \
       laddress = self.ua.source_address, compact = self.ua.compact_sip)
     self.ua.cancelCreditTimer()
     self.ua.disconnect_ts = rtime
     self.ua.changeState((UaStateDisconnected, self.ua.disc_cbs, rtime, self.ua.origin))
     event = CCEventDisconnect(rtime = rtime, origin = self.ua.origin)
     if req != None:
         try:
             event.reason = req.getHFBody('reason')     
         except:
             pass
     self.ua.emitEvent(event)
Esempio n. 6
0
 def cancel(self, rtime, req):
     req = self.ua.genRequest('BYE')
     self.ua.lCSeq += 1
     self.ua.global_config['_sip_tm'].newTransaction(req, \
       laddress = self.ua.source_address, compact = self.ua.compact_sip)
     self.ua.cancelCreditTimer()
     self.ua.disconnect_ts = rtime
     self.ua.changeState(
         (UaStateDisconnected, self.ua.disc_cbs, rtime, self.ua.origin))
     event = CCEventDisconnect(rtime=rtime, origin=self.ua.origin)
     if req != None:
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
     self.ua.emitEvent(event)
Esempio n. 7
0
 def recvRequest(self, req):
     if req.getMethod() == 'INVITE':
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(491, 'Request Pending', server = self.ua.local_ua))
         return None
     elif req.getMethod() == 'BYE':
         self.ua.global_config['_sip_tm'].cancelTransaction(self.ua.tr)
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(200, 'OK', server = self.ua.local_ua))
         #print 'BYE received in the Updating state, going to the Disconnected state'
         event = CCEventDisconnect(rtime = req.rtime, origin = self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         self.ua.cancelCreditTimer()
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime, self.ua.origin)
     #print 'wrong request %s in the state Updating' % req.getMethod()
     return None
Esempio n. 8
0
 def recvRequest(self, req):
     if req.getMethod() == 'INVITE':
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(491, \
           'Request Pending', server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
         return None
     elif req.getMethod() == 'BYE':
         self.ua.sendUasResponse(487, 'Request Terminated')
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(200, 'OK', \
           server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
         #print 'BYE received in the Updating state, going to the Disconnected state'
         event = CCEventDisconnect(rtime=req.rtime, origin=self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         self.ua.cancelCreditTimer()
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime,
                 self.ua.origin)
     elif req.getMethod() == 'REFER':
         if req.countHFs('refer-to') == 0:
             self.ua.global_config['_sip_tm'].sendResponse(
                 req.genResponse(400,
                                 'Bad Request',
                                 server=self.ua.local_ua),
                 lossemul=self.ua.uas_lossemul)
             return None
         self.ua.sendUasResponse(487, 'Request Terminated')
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(202, 'Accepted', \
           server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
         also = req.getHFBody('refer-to').getCopy()
         self.ua.equeue.append(
             CCEventDisconnect(also, rtime=req.rtime,
                               origin=self.ua.origin))
         self.ua.cancelCreditTimer()
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime,
                 self.ua.origin)
     #print 'wrong request %s in the state Updating' % req.getMethod()
     return None
Esempio n. 9
0
 def updateFailed(self, event):
     self.ua.equeue.append(event)
     req = self.ua.genRequest('BYE', reason=event.reason)
     self.ua.lCSeq += 1
     self.ua.global_config['_sip_tm'].newTransaction(req, \
       laddress = self.ua.source_address, compact = self.ua.compact_sip)
     self.ua.cancelCreditTimer()
     self.ua.disconnect_ts = event.rtime
     self.ua.equeue.append(CCEventDisconnect(rtime = event.rtime, \
       origin = self.ua.origin))
     return (UaStateDisconnected, self.ua.disc_cbs, event.rtime, \
       event.origin)
Esempio n. 10
0
 def recvEvent(self, event, ua):
     if ua == self.uaA:
         if self.uaO == None:
             if not isinstance(event, CCEventTry):
                 # Some weird event received
                 self.uaA.recvEvent(CCEventDisconnect())
                 return
             self.uaO = UA(self.global_config, event_cb=self.recvEvent, \
                           nh_address=self.global_config['nh_addr'])
         self.uaO.recvEvent(event)
     else:
         self.uaA.recvEvent(event)
Esempio n. 11
0
 def recvRequest(self, req):
     if req.getMethod() == 'BYE':
         self.ua.sendUasResponse(487, 'Request Terminated')
         self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(200, 'OK',
           server = self.ua.local_ua), lossemul = self.ua.uas_lossemul)
         #print 'BYE received in the Ringing state, going to the Disconnected state'
         if req.countHFs('also') > 0:
             also = req.getHFBody('also').getCopy()
         else:
             also = None
         event = CCEventDisconnect(also, rtime = req.rtime, origin = self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         if self.ua.expire_timer != None:
             self.ua.expire_timer.cancel()
             self.ua.expire_timer = None
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime, self.ua.origin)
     return None
Esempio n. 12
0
 def recvRequest(self, req):
     if req.getMethod() == 'INVITE':
         self.ua.global_config['_sip_tm'].sendResponse(
             req.genResponse(491,
                             'Request Pending',
                             server=self.ua.local_ua))
         return None
     elif req.getMethod() == 'BYE':
         self.ua.global_config['_sip_tm'].cancelTransaction(self.ua.tr)
         self.ua.global_config['_sip_tm'].sendResponse(
             req.genResponse(200, 'OK', server=self.ua.local_ua))
         #print 'BYE received in the Updating state, going to the Disconnected state'
         event = CCEventDisconnect(rtime=req.rtime, origin=self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         self.ua.cancelCreditTimer()
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime,
                 self.ua.origin)
     #print 'wrong request %s in the state Updating' % req.getMethod()
     return None
Esempio n. 13
0
 def recvEvent(self, event, ua):
     if ua == self.uaA:
         if self.uaO == None and self._invite_event == None:
             if not isinstance(event, CCEventTry) or self._number != None:
                 # Some weird event received
                 self.uaA.recvEvent(CCEventDisconnect())
                 return
             self.cId, cGUID, self.cli, self.cld, body, auth, caller_name = event.getData(
             )
             self._invite_event = event
             self.global_config['_sip_logger'].write(
                 'recvEvent %s==>%s|%s' % (self.id, self.cli, self.cld))
             self.time_invite = int(round(time.time() * 1000))
             self.addRequest((self.cli, self.cld, '0', 'invite'))
         elif self.uaO != None:
             self.uaO.recvEvent(event)
     else:
         self.uaA.recvEvent(event)
Esempio n. 14
0
 def recvRequest(self, req):
     if req.getMethod() == 'REFER':
         if req.countHFs('refer-to') == 0:
             self.ua.global_config['_sip_tm'].sendResponse(
                 req.genResponse(400,
                                 'Bad Request',
                                 server=self.ua.local_ua))
             return None
         self.ua.global_config['_sip_tm'].sendResponse(
             req.genResponse(202, 'Accepted', server=self.ua.local_ua))
         also = req.getHFBody('refer-to').getCopy()
         self.ua.equeue.append(
             CCEventDisconnect(also, rtime=req.rtime,
                               origin=self.ua.origin))
         self.ua.recvEvent(
             CCEventDisconnect(rtime=req.rtime, origin=self.ua.origin))
         return None
     if req.getMethod() == 'INVITE':
         self.ua.uasResp = req.genResponse(100,
                                           'Trying',
                                           server=self.ua.local_ua)
         self.ua.global_config['_sip_tm'].sendResponse(self.ua.uasResp)
         body = req.getBody()
         if body == None:
             # Some brain-damaged stacks use body-less re-INVITE as a means
             # for putting session on hold. Quick and dirty hack to make this
             # scenario working.
             body = self.ua.rSDP.getCopy()
             body.parse()
             for sect in body.content.sections:
                 sect.c_header.addr = '0.0.0.0'
         elif str(self.ua.rSDP) == str(body):
             self.ua.global_config['_sip_tm'].sendResponse(
                 req.genResponse(200,
                                 'OK',
                                 self.ua.lSDP,
                                 server=self.ua.local_ua))
             return None
         event = CCEventUpdate(body, rtime=req.rtime, origin=self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         try:
             event.max_forwards = req.getHFBody('max-forwards').getNum()
         except:
             pass
         if body != None:
             if self.ua.on_remote_sdp_change != None:
                 self.ua.on_remote_sdp_change(
                     body,
                     lambda x: self.ua.delayed_remote_sdp_update(event, x))
                 return (UasStateUpdating, )
             else:
                 self.ua.rSDP = body.getCopy()
         else:
             self.ua.rSDP = None
         self.ua.equeue.append(event)
         return (UasStateUpdating, )
     if req.getMethod() == 'BYE':
         self.ua.global_config['_sip_tm'].sendResponse(
             req.genResponse(200, 'OK', server=self.ua.local_ua))
         #print 'BYE received in the Connected state, going to the Disconnected state'
         if req.countHFs('also') > 0:
             also = req.getHFBody('also').getCopy()
         else:
             also = None
         event = CCEventDisconnect(also,
                                   rtime=req.rtime,
                                   origin=self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         self.ua.cancelCreditTimer()
         self.ua.disconnect_ts = req.rtime
         return (UaStateDisconnected, self.ua.disc_cbs, req.rtime,
                 self.ua.origin)
     if req.getMethod() == 'INFO':
         self.ua.global_config['_sip_tm'].sendResponse(
             req.genResponse(200, 'OK', server=self.ua.local_ua))
         event = CCEventInfo(req.getBody(),
                             rtime=req.rtime,
                             origin=self.ua.origin)
         try:
             event.reason = req.getHFBody('reason')
         except:
             pass
         self.ua.equeue.append(event)
         return None
     if req.getMethod() == 'OPTIONS':
         self.ua.global_config['_sip_tm'].sendResponse(
             req.genResponse(200, 'OK', server=self.ua.local_ua))
         return None
     #print 'wrong request %s in the state Connected' % req.getMethod()
     return None
Esempio n. 15
0
 def recvEvent(self, event, ua):
     if ua == self.uaA:
         if self.state == CCStateIdle:
             if not isinstance(event, CCEventTry):
                 # Some weird event received
                 self.uaA.recvEvent(CCEventDisconnect(rtime=event.rtime))
                 return
             self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name = event.getData(
             )
             self.cGUID = cGUID.hexForm()
             if self.cld == None:
                 self.uaA.recvEvent(
                     CCEventFail((500, 'Internal Server Error (1)'),
                                 rtime=event.rtime))
                 self.state = CCStateDead
                 return
             if body != None and '_allowed_pts' in self.global_config:
                 try:
                     body.parse()
                 except:
                     self.uaA.recvEvent(
                         CCEventFail((400, 'Malformed SDP Body'),
                                     rtime=event.rtime))
                     self.state = CCStateDead
                     return
                 allowed_pts = self.global_config['_allowed_pts']
                 mbody = body.content.sections[0].m_header
                 if mbody.transport.lower() == 'rtp/avp':
                     old_len = len(mbody.formats)
                     mbody.formats = [
                         x for x in mbody.formats if x in allowed_pts
                     ]
                     if len(mbody.formats) == 0:
                         self.uaA.recvEvent(
                             CCEventFail((488, 'Not Acceptable Here')))
                         self.state = CCStateDead
                         return
                     if old_len > len(mbody.formats):
                         body.content.sections[0].optimize_a()
             if self.cld.startswith('nat-'):
                 self.cld = self.cld[4:]
                 if body != None:
                     body.content += 'a=nated:yes\r\n'
                 event.data = (self.cId, cGUID, self.cli, self.cld, body,
                               auth, self.caller_name)
             if 'static_tr_in' in self.global_config:
                 self.cld = re_replace(self.global_config['static_tr_in'],
                                       self.cld)
                 event.data = (self.cId, cGUID, self.cli, self.cld, body,
                               auth, self.caller_name)
             if '_rtp_proxy_clients' in self.global_config:
                 self.rtp_proxy_session = Rtp_proxy_session(self.global_config, call_id = self.cId, \
                   notify_socket = self.global_config['b2bua_socket'], \
                   notify_tag = quote('r %s' % str(self.id)))
                 self.rtp_proxy_session.callee.raddress = (self.remote_ip,
                                                           5060)
                 self.rtp_proxy_session.insert_nortpp = True
             self.eTry = event
             self.state = CCStateWaitRoute
             if not self.global_config['auth_enable']:
                 self.username = self.remote_ip
                 self.rDone(((), 0))
             elif auth == None or auth.username == None or len(
                     auth.username) == 0:
                 self.username = self.remote_ip
                 self.auth_proc = self.global_config['_radius_client'].do_auth(self.remote_ip, self.cli, self.cld, self.cGUID, \
                   self.cId, self.remote_ip, self.rDone)
             else:
                 self.username = auth.username
                 self.auth_proc = self.global_config[
                     '_radius_client'].do_auth(auth.username, self.cli,
                                               self.cld, self.cGUID,
                                               self.cId, self.remote_ip,
                                               self.rDone, auth.realm,
                                               auth.nonce, auth.uri,
                                               auth.response)
             return
         if self.state not in (CCStateARComplete, CCStateConnected,
                               CCStateDisconnecting) or self.uaO == None:
             return
         self.uaO.recvEvent(event)
     else:
         if (isinstance(event, CCEventFail) or isinstance(event, CCEventDisconnect)) and self.state == CCStateARComplete and \
           (isinstance(self.uaA.state, UasStateTrying) or isinstance(self.uaA.state, UasStateRinging)) and len(self.routes) > 0:
             if isinstance(event, CCEventFail):
                 code = event.getData()[0]
             else:
                 code = None
             if code == None or code not in self.huntstop_scodes:
                 self.placeOriginate(self.routes.pop(0))
                 return
         self.uaA.recvEvent(event)
Esempio n. 16
0
 def disconnect(self, ua):
     if self.disconnect_done:
         return
     event = CCEventDisconnect(origin='switch')
     ua.recvEvent(event)
Esempio n. 17
0
 def disconnect(self, ua):
     event = CCEventDisconnect(origin='switch')
     ua.recvEvent(event)
Esempio n. 18
0
File: UA.py Progetto: twmobius/b2bua
 def disconnect(self, rtime=None):
     if rtime == None:
         rtime = MonoTime()
     self.equeue.append(CCEventDisconnect(rtime=rtime))
     self.recvEvent(CCEventDisconnect(rtime=rtime))