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)) #print 'BYE received in the Ringing state, going to the Disconnected state' if req.countHFs('also') > 0: also = req.getHFBody('also').getUrl().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
def recvRequest(self, req): if req.getMethod() == 'INVITE': self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(491, 'Request Pending')) return None elif req.getMethod() == 'BYE': self.ua.sendUasResponse(487, 'Request Terminated') self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(200, 'OK')) #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')) return None self.ua.sendUasResponse(487, 'Request Terminated') self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(202, 'Accepted')) also = req.getHFBody('refer-to').getUrl().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
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').getUrl().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
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)
def cancel(self, rtime, req): req = self.ua.genRequest('BYE') self.ua.lCSeq += 1 self.ua.global_config['_sip_tm'].newTransaction(req) 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)
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)
def recvRequest(self, req): if req.getMethod() == 'INVITE': self.ua.global_config['_sip_tm'].sendResponse(req.genResponse(491, 'Request Pending')) 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')) #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
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
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
def recvResponse(self, resp): body = resp.getBody() code, reason = resp.getSCode() scode = (code, reason, body) if code < 200: self.ua.equeue.append( CCEventRing(scode, rtime=resp.rtime, origin=self.ua.origin)) return None if code >= 200 and code < 300: event = CCEventConnect(scode, rtime=resp.rtime, origin=self.ua.origin) 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 (UaStateConnected, ) else: self.ua.rSDP = body.getCopy() else: self.ua.rSDP = None self.ua.equeue.append(event) return (UaStateConnected, ) if code in (301, 302) and resp.countHFs('contact') > 0: scode = (code, reason, body, resp.getHFBody('contact').getUrl().getCopy()) self.ua.equeue.append( CCEventRedirect(scode, rtime=resp.rtime, origin=self.ua.origin)) elif code in (408, 481): # If the response for a request within a dialog is a 481 # (Call/Transaction Does Not Exist) or a 408 (Request Timeout), the UAC # SHOULD terminate the dialog. A UAC SHOULD also terminate a dialog if # no response at all is received for the request (the client # transaction would inform the TU about the timeout.) event = CCEventDisconnect(rtime=resp.rtime, origin=self.ua.origin) try: event.reason = resp.getHFBody('reason') except: pass self.ua.equeue.append(event) self.ua.cancelCreditTimer() self.ua.disconnect_ts = resp.rtime return (UaStateDisconnected, self.ua.disc_cbs, resp.rtime, self.ua.origin) else: event = CCEventFail(scode, rtime=resp.rtime, origin=self.ua.origin) try: event.reason = resp.getHFBody('reason') except: pass self.ua.equeue.append(event) return (UaStateConnected, )
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)) #print 'BYE received in the Ringing state, going to the Disconnected state' if req.countHFs('also') > 0: also = req.getHFBody('also').getUrl().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
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').getUrl().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').getUrl().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
def disconnect(self, rtime=None): if rtime == None: rtime = time() self.equeue.append(CCEventDisconnect(rtime=rtime)) self.recvEvent(CCEventDisconnect(rtime=rtime))