Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/protocols/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyc


[XMc@s`dZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
mZddlm
Z
ddlmZddlmZddlmZmZmZdd	lmZddlZdd
lmZmZddlmZdZi	d
d6dd6dd6dd6dd6dd6dd6dd6dd6ZiZ x$ej!D]\Z"Z#e"e e#<qZW["[#i5dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6dUdV6dWdX6dYdZ6d[d\6d]d^6d_d`6dadb6dcdd6dedf6dgdh6didj6dkdl6dmdn6dodp6dqdr6dsdt6dudv6dwdx6dydz6d{d|6d}d~6dd6dd6dd6dd6dCd6Z$idd6dd6dd6Z%dZ&dZ'dZ(e
edddde(Z(dZ)e
edddde)Z)e*Z+de*fdYZ,dZ-dddYZ.dddZ0dZ1ddddZ2de3fdYZ4de4fdYZ5dddYZ6de6fdYZ7de6fdYZ8dej9fdYZ:dej;fdYZ<defdYZ=dddYZ>defdYZ?defdYZ@de<fdYZAdefdYZBdddYZCdefdYZDdddYZEdeAfdYZFdddYZGdS(sSession Initialization Protocol.

Documented in RFC 2543.
[Superceded by 3261]


This module contains a deprecated implementation of HTTP Digest authentication.
See L{twisted.cred.credentials} and L{twisted.cred._digest} for its new home.
iN(t
implementst	Interface(tlogtutil(t
deprecated(tVersion(tmd5(tprotocoltdefertreactor(tcred(tUsernameHashedPasswordtUsernamePassword(tbasicitiscall-idtmtcontacttescontent-encodingtlscontent-lengthtcscontent-typetftfromtstsubjectttttotvtviatTryingidtRingingisCall Is Being ForwardeditQueuedisSession ProgressitOKisMultiple Choicesi,sMoved Permanentlyi-sMoved Temporarilyi.s	See Otheri/s	Use Proxyi1sAlternative Servicei|sBad RequestitUnauthorizedisPayment Requiredit	Forbiddenis	Not FoundisMethod Not AllowedisNot AcceptableisProxy Authentication RequiredisRequest TimeoutitConflictitGoneisLength RequiredisRequest Entity Too LargeisRequest-URI Too LargeisUnsupported Media TypeisUnsupported URI Schemeis
Bad ExtensionisExtension RequiredisInterval Too BriefisTemporarily UnavailableisCall/Transaction Does Not Existis
Loop Detectedis
Too Many HopsisAddress Incompleteit	Ambiguousis	Busy HereisRequest TerminatedisNot Acceptable HereisRequest PendingitUndecipherableisInternal Server ErrorisNot ImplementedisBad GatewayisService UnavailableisServer Time-outisSIP Version not supportedisMessage Too LargeisBusy EverywhereiXtDeclinei[sDoes not exist anywherei\i^tCSeqtcseqsCall-IDsWWW-Authenticateswww-authenticatecCs/djg|jdD]}|j^qS(sA Capitalize a string, making sure to treat - as a word seperator t-(tjointsplitt
capitalize(Rtx((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytdashCapitalize{scCs3|d|dkodknr/|dd!S|S(Niit"i((R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytunqs$cCst}|j||jd|j||jd|j||j}|dkrt}|j||jd|j||jd|j||j}n|jdS(Nt:smd5-sessthex(Rtupdatetdigesttencode(tpszAlgtpszUserNametpszRealmtpszPasswordtpszNoncet	pszCNonceRtHA1((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt
DigestCalcHA1s 	




	




tTwistedi	icCs.t}|j||jd|j||dkrY|jd|j|n|jjd}	t}|j||jd|j||jd|r|r|j||jd|j||jd|j||jdn|j|	|jjd}
|
S(NR1sauth-intR2(RR3R4R5(R<R:t
pszNonceCountR;tpszQopt	pszMethodtpszDigestUrit
pszHEntityRtHA2thash((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytDigestCalcResponses.
	



	









tViac	BsYeZdZeddededddZdZdZ	e
ee	ZdZRS(s
    A L{Via} is a SIP Via header, representing a segment of the path taken by
    the request.

    See RFC 3261, sections 8.1.1.7, 18.2.2, and 20.42.

    @ivar transport: Network protocol used for this leg. (Probably either "TCP"
    or "UDP".)
    @type transport: C{str}
    @ivar branch: Unique identifier for this request.
    @type branch: C{str}
    @ivar host: Hostname or IP for this leg.
    @type host: C{str}
    @ivar port: Port used for this leg.
    @type port C{int}, or None.
    @ivar rportRequested: Whether to request RFC 3581 client processing or not.
    @type rportRequested: C{bool}
    @ivar rportValue: Servers wishing to honor requests for RFC 3581 processing
    should set this parameter to the source port the request was received
    from.
    @type rportValue: C{int}, or None.

    @ivar ttl: Time-to-live for requests on multicast paths.
    @type ttl: C{int}, or None.
    @ivar maddr: The destination multicast address, if any.
    @type maddr: C{str}, or None.
    @ivar hidden: Obsolete in SIP 2.0.
    @type hidden: C{bool}
    @ivar otherParams: Any other parameters in the header.
    @type otherParams: C{dict}
    tUDPc
Ks||_||_||_||_||_||_|tkrmtjdt	ddd|_t|_nT|dkrd|_t|_n3|t
krd|_t|_n||_t|_||_|	|_|
|_dS(s(
        Set parameters of this Via header. All arguments correspond to
        attributes of the same name.

        To maintain compatibility with old SIP
        code, the 'rport' argument is used to determine the values of
        C{rportRequested} and C{rportValue}. If None, C{rportRequested} is set
        to True. (The deprecated method for doing this is to pass True.) If an
        integer, C{rportValue} is set to the given value.

        Any arguments not explicitly named here are collected into the
        C{otherParams} dict.
        s+rport=True is deprecated since Twisted 9.0.t
stackleveliN(t	transportthosttporttttlthiddentreceivedtTruetwarningstwarntDeprecationWarningtNonet
rportValuetrportRequestedt_absenttFalsetbranchtmaddrtotherParams(tselfRKRLRJRMRNROtrportRYRZtkw((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt__init__s0													cCs1|jtkrtS|jdk	r)|jSdSdS(sG
        Returns the rport value expected by the old SIP code.
        N(RVRPRURT(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt	_getrports
cCs||_t|_dS(s
        L{Base._fixupNAT} sets C{rport} directly, so this method sets
        C{rportValue} based on that.

        @param newRPort: The new rport value.
        @type newRPort: C{int}
        N(RURXRV(R\tnewRPort((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt	_setrport!s	cCsd|j|j|jf}|jr2|d7}nx@dD]8}t||}|dk	r9|d||f7}q9q9W|jr|d7}n&|jdk	r|d	|jf7}n|j	j
}|jxE|D]=\}}|dkr|d
|7}q|d||f7}qW|S(
sI
        Serialize this header for use in a request or response.
        sSIP/2.0/%s %s:%ss;hiddenRMRYRZROs;%s=%ss;rports	;rport=%st;(sttlsbranchsmaddrsreceivedN(RJRKRLRNtgetattrRTRVRUR]R[titemstsort(R\RtntvaluetetctkR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyttoString/s$	

	

N(
t__name__t
__module__t__doc__tPORTRTRXRWR_R`RbtpropertyR]Rk(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRGs	*		cCs|jd}|d|d}}|jdd\}}|j}i}|jd\}}}	|dks~|dkrtd|n|	|d	<d
|kr|jd
\}
}t||d<|
|d<n
||d<x|D]}|jjdd}t|dkr+|dd
}}
n|\}}
|dkrSt|d<qn|jdd}t|dkr|dd}}n'|\}}|dkrt|}n|||<qWt|S(sa
    Parse a Via header.

    @return: The parsed version of this header.
    @rtype: L{Via}
    Rciit t/tSIPs2.0swrong protocol or version: %rRJR1RLRKtRNt=R]RMN(srportsttl(R+tstript
ValueErrortinttlenRPRTRG(RhtpartstsenttparamstprotocolinfotbytresulttpnametpversionRJRKRLtptcommenttname((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytparseViaHeaderIs<




tURLcBsSeZdZddddddddddddZdZdZdZRS(s
A SIP URL.c

Cs||_||_||_||_||_||_||_|
|_||_|	|_	|dkrrg|_n	||_|dkri|_n	||_dS(N(
tusernameRKtpasswordRLRJtusertypetmethodttagRMRZRTtothertheaders(
R\RKRRRLRJRRRMRZRRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_ws 											cCsg}|j}|d|jdkre||j|jdkrX|d|jn|dn||j|jdkr|d|jn|jdkr|d|jnx@dD]8}t||}|dkr|d||fqqWx|jD]}|d|qW|j	r|d
|dj
g|j	jD]1\}}dtj
|ppt||f^qIndj
|S(Nssip:s:%st@s:%ds;user=%sRJRMRZRRs;%s=%ss;%st?t&s%s=%sRt(s	transportsttlsmaddrsmethodstag(tappendRRTRRKRLRRdRRR*RetspecialCasestgetR.(R\RtwRgRth((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRks.	




	
WcCs
|jS(N(Rk(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt__str__scCs&d|j|j|j|j|jfS(Ns<URL %s:%s@%s:%r/%s>(RRRKRLRJ(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt__repr__sN(RlRmRnRTR_RkRR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRts				cCsi}|jds,td|d n|djd}|d|d}}|jdd}t|dkr|\}}	|jd	d}
t|
dkr|
d|d
<q|
d|d
<|
d|d<n
|d}	|	jd	d}t|dkr|d|d<n"|d|d<t|d|d
<|dkrR||d<n|dkrk||d
<nxA|D]9}||dkrd|kri|d<}
|jdd\}}x9|jdD]%}|jd\}}||
|<qWn|jdd}t|dkr9|jdgj|qrn|\}}|dkr^||d<qr|dkr|dkrt|}n|||<qr|jdgj|qrWt|S(sTReturn string into URL object.

    URIs are of of form 'sip:user@example.com'.
    ssip:sunsupported scheme: iRciiRiR1RRRKRLiRRRRuRtuserRRJRMRZRRN(s	transportsttlsmaddrsmethodstag(	t
startswithRwR+RyRxRTt
setdefaultRR(turlRKRLtdRzt
userdomainR|tudpartstuserpassthostporttuppartsthppartsRRRtheaderRjRtnvRRh((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytparseURLsV





cCs(d|_d|_d|_i|_dS(s Clean a URL from a Request line.N(RTRJRZRMR(R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytcleanRequestURLs			cCs`|j}|jdr:dt|d|d|ifSi}|jdd\}}|j}|jdr|d}n|jdr|d }n|jd	d\}}t|d|d|}|j}|r&xE|jd
D]1}|sqn|jd\}	}
|
||	<qWn|rSd|_i|_d|_d|_	n|||fS(
sReturn (name, uri, params) for From/To/Contact header.

    @param clean: remove unnecessary info, usually for From and To headers.
    ssip:RtRKRLt<iR/it>RcRuN(
RvRRR+tendswithRTRMRRJRZ(taddressRKRLtcleanR|RRtparamstringRRjR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytparseAddresss2

			tSIPErrorcBseZddZRS(cCsI|dkrt|}ntj|d||f||_||_dS(NsSIP error (%d): %s(RTtstatusCodest	ExceptionR_tcodetphrase(R\RR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_
s

	N(RlRmRTR_(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRstRegistrationErrorcBseZdZRS(sRegistration was not possible.(RlRmRn(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRstMessagecBsJeZdZdZdZdZdZdZdZ	dZ
RS(sA SIP message.cCs%tj|_d|_d|_dS(NRti(RtOrderedDictRtbodytfinished(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_s	cCs\|j}tj||}|dkr<t||_n|jj|gj|dS(Nscontent-length(tlowertlongHeadersRRxtlengthRRR(R\RRh((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt	addHeader#s
cCs|j|7_dS(N(R(R\tdata((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytbodyDataReceived*scCs@|jdkr3|jt|jkr3tdnd|_dS(Nswrong body lengthi(RRTRyRRwR(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytcreationFinished-s'cCsd|j}xW|jjD]F\}}x7|D]/}|dtj|pWt||f7}q3Wq W|d7}||j7}|S(Ns%s
s%s: %s
s
(t_getHeaderLineRReRRR.R(R\RRgtvsR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRk2s
1

cCs
tdS(N(tNotImplementedError(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR;sN(RlRmRnRTRR_RRRRkR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs						tRequestcBs,eZdZddZdZdZRS(sA Request for a URIsSIP/2.0cCsQtj|||_t|tr1||_nt||_t|jdS(N(RR_Rt
isinstanceRturiRR(R\RRtversion((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_Cs
	cCs#dt||j|jjfS(Ns<SIP Request %d:%s %s>(tidRRRk(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRLscCsd|j|jjfS(Ns
%s %s SIP/2.0(RRRk(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyROs(RlRmRnR_RR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR?s		tResponsecBs/eZdZdddZdZdZRS(sA Response to a URI RequestsSIP/2.0cCs<tj|||_|dkr/t|}n||_dS(N(RR_RRTRR(R\RRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_Vs

	
cCsdt||jfS(Ns<SIP Response %d:%s>(RR(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR]scCsd|j|jfS(Ns
SIP/2.0 %s %s(RR(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR`sN(RlRmRnRTR_RR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRSs	tMessagesParsercBseZdZdZdZdZdZdZdZddZ	dZ
d	Zd
ZdZ
dZd
ZddZdZRS(sA SIP messages parser.

    Expects dataReceived, dataDone repeatedly,
    in that order. Shouldn't be connected to actual transport.
    sSIP/2.0it	firstlineicCs||_|jdS(N(tmessageReceivedtreset(R\tmessageReceivedCallback((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_rs	RtcCs5d|_d|_d|_d|_|j|dS(NRi(tstateRTRtbodyReceivedtmessagetsetLineMode(R\t
remainingData((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRvs
				cCsd|_|jdS(Ntinvalid(Rt
setRawMode(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytinvalidMessage}s	cCs|j|jdkrdS|jdkr:|jdS|jdkrV|jn(|j|jkru|jn	tddS(NRRsthis should never happen(tclearLineBufferRRRRTtmessageDoneRtRuntimeError(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytdataDones



cCs9ytjj||Wntj|jnXdS(N(R
tLineReceivertdataReceivedRterrR(R\R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs

cCs
tdS(s Expected to create self.message.N(R(R\tline((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pythandleFirstLinescCs|jdS(N(R(R\R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytlineLengthExceededscCs|jdkr$x,|jds0|jdr=|d}qW|sHdSy|jdd\}}}Wntk
r|jdSX|dkr|jryt|}Wntk
r|jdSXt|||_n8|dkr	|j	r	t
|||_n|jdSd|_dS|jdks9t|ry|jd	d\}}Wntk
ry|jdSX|jj||j
|jd
kryt|j
|_Wqtk
r|jdSXqn0d|_|jdkr	|jdS|jdS(
NRs
s
iRqisSIP/2.0RR1scontent-lengthRi(RRR+RwRtacceptResponsesRxRRtacceptRequestsRtAssertionErrorRtlstripRRRR(R\RtatbRRRRh((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytlineReceivedsT!




	



	
cCsC|jdkst|jj|j|j|j|dS(NR(RRRRRR(R\R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs
cCs|jdkst|jdkr(dS|jdkrJ|jj|nt|}|j|j}||kr|jj|| |j||dS|j|7_|jj||j|jkr|jndS(NRR(sbodysinvalid(	RRRRTRRRyRR(R\RtdataLentexpectedLen((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytrawDataReceiveds(RlRmRnRRRRtdebugR_RRRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRds 							4tBasecBskeZdZeZeZdZdZdZdZ	dZ
dZdZdZ
d	ZRS(
s'Base class for SIP clients and servers.cCsg|_t|j|_dS(N(tmessagesRt
addMessagetparser(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_s	cCs|jj|dS(N(RR(R\tmsg((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRscCs|jj||jjx||jD]q}|j|||jrftjd|j|fnt	|t
r|j||q'|j||q'Wg|j(dS(NsReceived %r from %r(
RRRRt	_fixupNATRRRRkRRthandle_requestthandle_response(R\RtaddrR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytdatagramReceiveds
	 cCs|\}}t|jdd}|j|krp||_|j|krV||_n|j|jdd<n;|jtkr||_||_|j|jdd<ndS(NRi(RRRKRORLR]RkRP(R\Rt.2tsrcHosttsrcPortt	senderVia((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR	s				cCsmt|jdd}|jp&|j}|jpA|jpA|j}td|d|}|j||dS(sFDeliver response.

        Destination is based on topmost Via header.RiRKRLN(	RRRORKR]RLRoRtsendMessage(R\tresponseMessagetdestViaRKRLtdestAddr((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytdeliverResponses
cCs>t|}x+dD]#}|jj|g|j|<qW|S(s'Create a response to a request message.RRRscall-idR((sviaRRscall-idR((RRR(R\RtrequesttresponseR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytresponseFromRequest!s
!cCsv|jdkrtdn|jrDtjd|j|fn|jj|j|j|j	pk|j
fdS(sSend a message.

        @param destURL: C{URL}. This should be a *physical* URL, not a logical one.
        @param message: The message to send.
        tudpsonly UDP currently supportedsSending %r to %rN(RN(RJRTRRRRRktwriteRKRLRo(R\tdestURLR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR)s
	 cCs
tdS(szOverride to define behavior for requests received

        @type message: C{Message}
        @type addr: C{tuple}
        N(R(R\RR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR5scCs
tdS(s|Override to define behavior for responses received.

        @type message: C{Message}
        @type addr: C{tuple}
        N(R(R\RR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR=s(RlRmRnRoRXRR_RRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs			
	
				tIContactcBseZdZRS(sA user of a registrar or proxy(RlRmRn(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRFstRegistrationcBseZdZRS(cCs||_||_dS(N(tsecondsToExpiryt
contactURL(R\RR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_Ks	(RlRmR_(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRJst	IRegistrycBs)eZdZdZdZdZRS(s5Allows registration of logical->physical URL mapping.cCsdS(sRegister the physical address of a logical URL.

        @return: Deferred of C{Registration} or failure with RegistrationError.
        N((t	domainURLt
logicalURLtphysicalURL((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytregisterAddressRscCsdS(sUnregister the physical address of a logical URL.

        @return: Deferred of C{Registration} or failure with RegistrationError.
        N((RR	R
((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytunregisterAddressXscCsdS(sGet registration info for logical URL.

        @return: Deferred of C{Registration} object or failure of LookupError.
        N((R	((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytgetRegistrationInfo^s(RlRmRnRRR
(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyROs		tILocatorcBseZdZdZRS(s2Allow looking up physical address for logical URL.cCsdS(sReturn physical URL of server for logical URL of user.

        @param logicalURL: a logical C{URL}.
        @return: Deferred which becomes URL or fails with LookupError.
        N((R	((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt
getAddresshs(RlRmRnR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRestProxycBsqeZdZeZd
Zd
edZdZdZdZ	dZ
dZdZdZ
d	ZRS(s
SIP proxy.cCs/|ptj|_||_tj|dS(sCreate new instance.

        @param host: our hostname/IP as set in Via headers.
        @param port: our port as set in Via headers.
        N(tsockettgetfqdnRKRLRR_(R\RKRL((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_ws	cCstd|jd|jS(s*Return value of Via header for this proxy.RKRL(RGRKRL(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytgetViascstdjd}|dkr1j}ny||}WnXtk
ru}jj|jnRtj	jjdn)X|dk	r|j
fdndS(Nshandle_%s_requesticsjj|jS(N(RRR(R(R\R(s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt<lambda>s(RdRRTthandle_request_defaultRRRRRRt
addErrback(R\RRRRR((R\Rs9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs
cs|\}}fd}j}|j|jdkrQtjddS|jdjd|jt|jdddd\}}}	jj|}
|
j	j
||
jj|dS(	sDefault request handler.

        Default behaviour for OPTIONS and unknown methods for proxies
        is to forward message on to the client.

        Since at the moment we are stateless proxy, thats basically
        everything.
        cs'|j|jdd<j||S(NRi(RkRR(RR(R\(s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt_mungContactHeadersRsDropping looped message.NiRRi(
RRkRRRtinsertRtlocatorRtaddCallbackRRt_cantForwardRequest(R\RRRRRt	viaHeaderRRttagsR((R\s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs		
&cCs8|jt|jdd=|j|jd|dS(NRii(ttraptLookupErrorRRR(R\terrorR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs
cCsmt|jdd}|jp&|j}|jpA|jpA|j}td|d|}|j||dS(sFDeliver response.

        Destination is based on topmost Via header.RiRKRLN(	RRRORKR]RLRoRR(R\RRRKRLR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs
cCs>t|}x+dD]#}|jj|g|j|<qW|S(s'Create a response to a request message.RRRscall-idR((sviastosfromscall-idscseq(RRR(R\RRRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs
!cCst|jdd}|j|jf|j|jfkrLtjddS|jdd=|jds{|j||dS|j|dS(sDefault response handler.Ris&Dropping incorrectly addressed messageN(RRRKRLRRtgotResponseR(R\RRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRs$

cCsdS(s8Called with responses that are addressed at this server.N((R\RR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR!sN(RlRmRnRoRTRR_RRRRRRRR!(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRps
							tIAuthorizercBseZdZdZRS(cCsdS(sGenerate a challenge the client may respond to.

        @type peer: C{tuple}
        @param peer: The client's address

        @rtype: C{str}
        @return: The challenge string
        N((tpeer((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytgetChallengescCsdS(s]Create a credentials object from the given response.

        @type response: C{str}
        N((R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytdecodes(RlRmR$R%(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR"s	
tBasicAuthorizercBs3eZdZeedZdZdZRS(sAuthorizer for insecure Basic (base64-encoded plaintext) authentication.

    This form of authentication is broken and insecure.  Do not use it.
    cCstjddtdddS(sK
        This method exists solely to issue a deprecation warning.
        sEtwisted.protocols.sip.BasicAuthorizer was deprecated in Twisted 9.0.0tcategoryRIiN(RQRRRS(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_scCsdS(N(RT(R\R#((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR$scCsxFtdD],}y|d|jd}Wnq
XPq
Wtd|jdd}t|dkrwt|StddS(NiRutbase64iR1ii(trangeR%RR+RyR(R\RRtcredsR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR%s
(RlRmRnRR"R_R$R%(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR&s

		tDigestedCredentialscBs eZdZdZdZRS(s3Yet Another Simple Digest-MD5 authentication schemecCs8tjddtdd||_||_||_dS(NsItwisted.protocols.sip.DigestedCredentials was deprecated in Twisted 9.0.0R'RIi(RQRRRSRtfieldst
challenges(R\RR,R-((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_s		c	Cs-d}|jjd}|jjd}|jjd}|jjd}|jjd}|jjdd}|jjd	d
}	|jjd}
|
|jkrtS|j|
=|jjdd
\}}|dkrd|}ntt||||||||||	||d}
|
|kS(NtREGISTERRRtnoncetcnoncetnct	algorithmtMD5sqop-optionstauthtopaqueRissip:(	R,RR-RXRR+RTRFR=(R\RRRRR/R0R1talgotqopR5Rtdomaintexpected((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt
checkPassword&s&

(RlRmRnR_R:(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR+s	
tDigestAuthorizercBsEeZdZeedZdZdZdZdZ	RS(icCs&tjddtddi|_dS(NsFtwisted.protocols.sip.DigestAuthorizer was deprecated in Twisted 9.0.0R'RIi(RQRRRStoutstanding(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_Es
cCs?tgtdD]}tjtj^q}d|}|S(Nis%d%d%d(ttupleR)trandomt	randrangetsystmaxint(R\t_R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt
generateNoncePs1
cCsttjtjS(N(tstrR>R?R@RA(R\((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pytgenerateOpaqueUscCsF|j}|j}||j|<djd|d|ddfS(Nt,s
nonce="%s"sopaque="%s"sqop-options="auth"salgorithm="MD5"(RCRER<R*(R\R#Rto((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR$Xs
cCsdj|j}|jd}tgg|D]}|jdd^q1D]*\}}|jt|jf^qM}y|d}Wntk
rtdnXyt|||j	SWntdnXdS(NRqRFRuiRii(
R*t
splitlinesR+tdictRvR0tKeyErrorRR+R<(R\RRzRRjRR4R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR%cs\
(
RlRmtCHALLENGE_LIFETIMERR"R_RCRER$R%(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR;@s
				t
RegisterProxycBseZdZdZdZiZdZdZdZ	dZ
dZdZdZ
dZd	Zd
ZdZdZd
ZRS(sfA proxy that allows registration for a specific domain.

    Unregistered users won't be handled.
    cOsBtj|||i|_d|jkr>t|jd<ndS(NR4(RR_tliveChallengestauthorizersR;(R\targsR^((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_}s	cCs|\}}dS(N((R\RRRKRL((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pythandle_ACK_requests	cCsm|\}}|jdkr1|j|||n8|jjdsV|j|||S|j|||SdS(sWHandle a registration request.

        Currently registration is not proxied.
        t
authorizationN(tportalRTtregisterRthas_keytunauthorizedtlogin(R\RRRKRL((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pythandle_REGISTER_requests	c	Cs|jd|}x|jjD]\}}|j||f}|dkrkd|j|jf}nd|j||jf}|jjdgj	|q"W|j
|dS(Nis
%s realm="%s"s%s %s,realm="%s"swww-authenticate(RRNt	iteritemsR$RTttitleRKRRRR(	R\RRKRLRtschemeR4tchalRh((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRUs cCs|jddjdd}|jj|dj}|ry|j|d}Wn=tk
rlqtj	|j
|jd|qX|jd|j
7_|jj|dtj|j|||j|j|||jtj	n|j
|jd|dS(NRQiiiRi(RR+RTRNRRR%RRRRRRRKRRRVRRt_cbLoginRt_ebLogin(R\RRKRLRzRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRVs 


cCs&|\}}}|j|||dS(N(RS(R\t.1RRKRLRRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR\scCs*|jtjj|j|||dS(N(RR
R tUnauthorizedLoginRU(R\tfailureRRKRL((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR]sc
Cst|jdddd\}}}d}|jjdrR|jdd}n|jjddgddkr|j|||n|dk	rt|d|d	|\}}}|jj|j||}	n|jj	|}	|	j
|j|jd
|fd|fdS(
sAllow all users to registerRiRiRtexpirest0RKRLtcallbackArgsterrbackArgsN(
RRRTRTRt
unregistertregistryRRR
taddCallbackst_cbRegistert_ebRegister(
R\RRKRLRttoURLR|RRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRSs&"!	cCsu|jd|}|jdkrT|jd|jj|jdd|jn|jdd|j|dS(NiRRas%dscontent-lengthRb(RRRTRRkRR(R\tregistrationRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRhscCs|jttdS(N(RRR(R\R R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRisc	Csyt|jdd}Wn*tk
rG|j|jd|nwX|dkr|dkrid}nt|\}}}|jj|j||}|j	|j
|j|j|ndS(NRaiit*(
RxRRwRRRRfRRRt
_cbUnregisterRt
_ebUnregister(	R\RRjRRaRRR|R((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRes
	cCsX|jd|}|jjdgj|jj|jdd|j|dS(NiRRaRb(RRRRRRkRR(R\RkRR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRms%cCsdS(N((R\RkR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRnsN(RlRmRnRTRRRfRNR_RPRWRURVR\R]RSRhRiReRmRn(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRLqs"												tInMemoryRegistrycBsQeZdZeeedZdZdZdZ	dZ
dZRS(s,A simplistic registry for a specific domain.cCs||_i|_dS(N(R8tusers(R\R8((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR_s	cCst|j|jkr%tjtdS|jj|jr]|j|j\}}tj|StjtdSdS(Nsunknown domainsno such user(	RKR8RtfailRRpRTRtsucceed(R\tuserURItdcR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR	s
cCs|j|jkr%tjtdS|jj|jr||j|j\}}tjt	t
|jtj|StjtdSdS(Nsunknown domainsno such user(
RKR8RRqRRpRTRRrRRxtgetTimettime(R\RsRtR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR
s,cCsey|j|\}}Wn!tk
r:tjtdSX|j|j|=tjtd|S(Nsno such useri(RpRJRRqRtcancelRrR(R\RRtR((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt_expireRegistrations


cCs|j|jkr2tjdtjtdS|j|jkrdtjdtjtdS|jj|j	r|j|j	\}}|j
dntjd|j
|j	}tjd|j|jf||f|j|j	<tjtt|jtj|S(Ns(Registration for domain we don't handle.iisRegistered %s at %s(RKR8RRRRqRRpRTRRR	t	callLaterRxRkRrRRxRuRv(R\RR	R
Rttold((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR%s

#cCs|j|jS(N(RxR(R\RR	R
((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyR5s(RlRmRnRRRR_RR
RxRR(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyRos
						
	(((((((HRnRRvR@R>RQtzope.interfaceRRttwisted.pythonRRttwisted.python.deprecateRttwisted.python.versionsRttwisted.python.hashlibRttwisted.internetRRR	ttwistedR
ttwisted.cred.errorttwisted.cred.credentialsRRttwisted.protocolsR
RotshortHeadersRReRjRRRR.R0R=RFtobjectRWRGRRRTRRRRRRRRRRRtDatagramProtocolRRRRRRR"R&R+R;RLRo(((s9/usr/lib/python2.7/dist-packages/twisted/protocols/sip.pyt<module>s<



			!	$!		+86	"	&Wo)'1