~ubuntu-branches/ubuntu/precise/papyon/precise

« back to all changes in this revision

Viewing changes to papyon/sip/core.py

  • Committer: Ken VanDine
  • Date: 2010-09-14 20:39:57 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: ken.vandine@canonical.com-20100914203957-1hriss4zo8rr11hr
Tags: 0.5.1-0ubuntu1
releasing version 0.5.1-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from papyon.sip.transaction import SIPTransactionLayer
26
26
from papyon.sip.transport import SIPTunneledTransport
27
27
from papyon.util.decorator import rw_property
 
28
from papyon.util.timer import Timer
28
29
 
29
30
import gobject
30
31
import logging
34
35
 
35
36
logger = logging.getLogger('papyon.sip.core')
36
37
 
37
 
class SIPCore(gobject.GObject):
 
38
class SIPCore(gobject.GObject, Timer):
38
39
    """ The set of processing functions required at a UAS and a UAC that
39
40
        resides above the transaction and transport layers.
40
41
        
66
67
 
67
68
    def __init__(self, client):
68
69
        gobject.GObject.__init__(self)
 
70
        Timer.__init__(self)
 
71
 
69
72
        self._client = client
70
73
        self._transport = SIPTunneledTransport(client._protocol)
71
74
        self._transaction_layer = SIPTransactionLayer(self._transport)
92
95
            return self._transport.send(message)
93
96
        return self._transaction_layer.send(message)
94
97
 
95
 
    def answer(self, request, status, extra_headers={}):
 
98
    def answer(self, request, status, tag=None, extra_headers={}, content=None):
96
99
        """Create response with given status and send to transaction layer."""
97
 
        response = self.create_response(request, status)
 
100
        response = self.create_response(request, status, tag=tag)
98
101
        for (name, value) in extra_headers:
99
102
            response.add_header(name, value)
 
103
        if content is not None:
 
104
            response.set_content(content)
100
105
        return self.send(response)
101
106
 
102
107
    # Public API -------------------------------------------------------------
113
118
 
114
119
    def cancel(self, canceled_request):
115
120
        request = self._create_cancel_request(canceled_request)
116
 
        self.start_timeout("cancel", 64 * T1, canceled_request)
 
121
        self.start_timeout("cancel", int(64 * T1), canceled_request)
117
122
        self.send(request)
118
123
        return request
119
124
 
121
126
 
122
127
    def establish_UAS_dialog(self, request, status):
123
128
        # 12.1.1 UAS behavior (Creation of a Dialog)
124
 
        response = self.create_response(request, status)
125
 
        self_tag = response.to.tag
 
129
        self_tag = self._generate_tag()
 
130
        response = self.create_response(request, status, tag=self_tag)
126
131
        response.clone_headers("Record-Route", request)
127
132
        #response.add_header("Contact", SIPContact(None, self.self_uri, None))
128
133
        request.transaction.send(response)
141
146
    def _create_dialog(self, request, response, mode):
142
147
        dialog = SIPDialog(self, request, response, mode)
143
148
        key = (dialog.call_id, dialog.local_tag, dialog.remote_tag)
 
149
        logger.info("Create dialog id=%s, local_tag=%s, remote_tag=%s" % key)
144
150
        handle = dialog.connect("disposed", self._on_dialog_disposed)
145
151
        self._dialogs[key] = dialog
146
152
        self._dialog_handles[dialog] = handle
194
200
        request.add_header("CSeq", SIPCSeq(cseq, code))
195
201
        return request
196
202
 
197
 
    def create_response(self, request, status):
 
203
    def create_response(self, request, status, tag=None):
198
204
        """ Create a response outside of a dialog """
199
205
        # 8.2.6 Generating the Response (UAS Behavior)
200
206
        response = SIPResponse(status)
215
221
 
216
222
        # Add To tag if missing
217
223
        if not response.to.tag:
218
 
            response.to.tag = self._generate_tag()
 
224
            if tag is None:
 
225
                tag = self._generate_tag()
 
226
            response.to.tag = tag
219
227
 
220
228
        return response
221
229