# 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
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


class UacStateUpdating(UaStateGeneric):
    sname = 'Updating(UAC)'
    triedauth = False
    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'

# 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

#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


class UacStateUpdating(UaStateGeneric):
    sname = 'Updating(UAC)'
    triedauth = False
    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)