# Path: sippy/UaStateGeneric.py
# class UaStateGeneric(object):
#     sname = 'Generic'
#     ua = None
#     connected = False
#     dead = False
# 
#     def __init__(self, ua):
#         self.ua = ua
# 
#     def recvRequest(self, req):
#         return None
# 
#     def recvResponse(self, resp, tr):
#         return None
# 
#     def recvEvent(self, event):
#         return None
# 
#     def cancel(self, rtime, req):
#         return None
# 
#     def onStateChange(self, newstate):
#         pass
# 
#     def __str__(self):
#         return self.sname
# 
# Path: sippy/CCEvents.py
# class CCEventDisconnect(CCEventGeneric):
#     name = 'CCEventDisconnect'
#     pass
# 
# class CCEventRing(CCEventGeneric):
#     name = 'CCEventRing'
#     pass
# 
# class CCEventConnect(CCEventGeneric):
#     name = 'CCEventConnect'
#     pass
# 
# class CCEventFail(CCEventGeneric):
#     name = 'CCEventFail'
#     challenges = None
#     warning = None
# 
#     def getCopy(self):
#         cself = CCEventGeneric.getCopy(self)
#         if self.challenges != None:
#             cself.challenges = [x.getCopy() for x in self.challenges]
#         return cself
# 
#     def setWarning(self, eistr):
#         self.warning = SipHeader(body = SipWarning(text = eistr))
# 
# class CCEventRedirect(CCEventGeneric):
#     name = 'CCEventRedirect'
#     pass


from sippy.UaStateGeneric import UaStateGeneric
from sippy.CCEvents import CCEventDisconnect, CCEventRing, CCEventConnect, CCEventFail, CCEventRedirect
    from sippy.UaStateConnected import UaStateConnected
    from sippy.UaStateDisconnected import UaStateDisconnected
    connected = True

    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 recvResponse(self, resp, tr):
        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:

# Path: sippy/UaStateGeneric.py
# class UaStateGeneric(object):
#     sname = 'Generic'
#     ua = None
#     connected = False
#     dead = False
# 
#     def __init__(self, ua):
#         self.ua = ua
# 
#     def recvRequest(self, req):
#         return None
# 
#     def recvResponse(self, resp, tr):
#         return None
# 
#     def recvEvent(self, event):
#         return None
# 
#     def cancel(self, rtime, req):
#         return None
# 
#     def onStateChange(self, newstate):
#         pass
# 
#     def __str__(self):
#         return self.sname
# 
# Path: sippy/CCEvents.py
# class CCEventDisconnect(CCEventGeneric):
#     name = 'CCEventDisconnect'
#     pass
# 
# class CCEventRing(CCEventGeneric):
#     name = 'CCEventRing'
#     pass
# 
# class CCEventConnect(CCEventGeneric):
#     name = 'CCEventConnect'
#     pass
# 
# class CCEventFail(CCEventGeneric):
#     name = 'CCEventFail'
#     challenges = None
#     warning = None
# 
#     def getCopy(self):
#         cself = CCEventGeneric.getCopy(self)
#         if self.challenges != None:
#             cself.challenges = [x.getCopy() for x in self.challenges]
#         return cself
# 
#     def setWarning(self, eistr):
#         self.warning = SipHeader(body = SipWarning(text = eistr))
# 
# class CCEventRedirect(CCEventGeneric):
#     name = 'CCEventRedirect'
#     pass


# Path: sippy/UacStateUpdating.py
from sippy.UaStateGeneric import UaStateGeneric
from sippy.CCEvents import CCEventDisconnect, CCEventRing, CCEventConnect, CCEventFail, CCEventRedirect
    from sippy.UaStateConnected import UaStateConnected
    from sippy.UaStateDisconnected import UaStateDisconnected

    connected = True

    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 recvResponse(self, resp, tr):
        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)