Ejemplo n.º 1
0
    def generateRequest(self, method):
        #RFC 3261 12.2.1.1
        r = Request(method, self.remoteAddress[1])

        if self.routeSet:
            r.headers['route'] = [
                formatAddress(route) for route in self.routeSet
            ]
            if 'lr' not in self.routeSet[0][1].other:
                r.headers['route'].append(formatAddress(("", r.uri, {})))
                r.uri = parseAddress(r.headers['route'].pop())[1]

        r.addHeader('to', formatAddress(self.remoteAddress))
        r.addHeader('from', formatAddress(self.localAddress))
        r.addHeader('cseq', "%s %s" % (self.localCSeq, method))
        self.localCSeq += 1
        r.addHeader('call-id', self.msg.headers['call-id'][0])
        r.addHeader('contact', formatAddress(self.contactURI))
        r.addHeader('content-length', 0)
        return r
Ejemplo n.º 2
0
    def generateRequest(self, method):
        #RFC 3261 12.2.1.1
        r = Request(method, self.remoteAddress[1])

        if self.routeSet:
            r.headers['route'] = [formatAddress(route) for route in self.routeSet]
            if 'lr' not in self.routeSet[0][1].other:
                r.headers['route'].append(formatAddress(("", r.uri, {})))
                r.uri = parseAddress(r.headers['route'].pop())[1]

        r.addHeader('to', formatAddress(self.remoteAddress))
        r.addHeader('from', formatAddress(self.localAddress))
        r.addHeader('cseq', "%s %s" % (self.localCSeq, method))
        self.localCSeq += 1
        r.addHeader('call-id', self.msg.headers['call-id'][0])
        r.addHeader('contact', formatAddress(self.contactURI))
        r.addHeader('content-length', 0)
        return r
Ejemplo n.º 3
0
    def _generateInvite(self, contacturi, fromName, uri, noSDP):
        #RFC 3261 8.1.1
        #RFC 3261 13.2.1
        invite = Request("INVITE", uri)
        invite.addHeader("to", formatAddress(uri))
        invite.addHeader(
            "from",
            formatAddress((fromName, URL(contacturi.host,
                                         contacturi.username), {
                                             'tag': self.genTag()
                                         })))
        invite.addHeader(
            "call-id", "%s@%s" %
            (md5.md5(str(random.random())).hexdigest(), contacturi.host))
        invite.addHeader("cseq", "%s INVITE" % self.localCSeq)
        invite.addHeader("user-agent", "Divmod Sine")
        if noSDP:
            invite.headers["content-length"] = ["0"]
        else:
            invite.addHeader("content-type", "application/sdp")
        #XXX maybe rip off IP discovered in SDP phase?
        invite.addHeader("contact", formatAddress(contacturi))

        def fillSDP(_):
            def consultSDP(sdpobj):
                sdp = sdpobj.show()
                self.sessionDescription = sdp
                invite.body = sdp
                invite.headers['content-length'] = [str(len(sdp))]
                invite.creationFinished()

            return defer.maybeDeferred(self.rtp.getSDP, self,
                                       None).addCallback(consultSDP)

        def finish(_):
            self.msg = invite
            toAddress, fromAddress = self._finishInit()
            self.localAddress = fromAddress
            self.remoteAddress = toAddress
            return self

        d = self.rtp.createRTPSocket(self, contacturi.host)

        def gotCookie(c):
            self.cookie = c

        d.addCallback(gotCookie)
        if noSDP:
            invite.creationFinished()
            return d.addCallback(finish)
        else:
            return d.addCallback(fillSDP).addCallback(finish)
Ejemplo n.º 4
0
    def _generateInvite(self, contacturi, fromName, uri, noSDP):
        #RFC 3261 8.1.1
        #RFC 3261 13.2.1
        invite = Request("INVITE", uri)
        invite.addHeader("to", formatAddress(uri))
        invite.addHeader("from", formatAddress((fromName, URL(contacturi.host, contacturi.username), {'tag': self.genTag()})))
        invite.addHeader("call-id",
                         "%s@%s" % (hashlib.md5(str(random.random())).hexdigest(),
                                    contacturi.host))
        invite.addHeader("cseq", "%s INVITE" % self.localCSeq)
        invite.addHeader("user-agent", "Divmod Sine")
        if noSDP:
            invite.headers["content-length"] =  ["0"]
        else:
            invite.addHeader("content-type", "application/sdp")
        #XXX maybe rip off IP discovered in SDP phase?
        invite.addHeader("contact", formatAddress(contacturi))
        def fillSDP(_):
            def consultSDP(sdpobj):
                sdp = sdpobj.show()
                self.sessionDescription = sdp
                invite.body = sdp
                invite.headers['content-length'] = [str(len(sdp))]
                invite.creationFinished()
            return defer.maybeDeferred(self.rtp.getSDP, self, None).addCallback(consultSDP)

        def finish(_):
            self.msg = invite
            toAddress,fromAddress = self._finishInit()
            self.localAddress = fromAddress
            self.remoteAddress = toAddress
            return self

        d = self.rtp.createRTPSocket(self, contacturi.host)
        def gotCookie(c):
            self.cookie = c
        d.addCallback(gotCookie)
        if noSDP:
            invite.creationFinished()
            return d.addCallback(finish)
        else:
            return d.addCallback(fillSDP).addCallback(finish)