def __init__( self, proxyAuthentication = False ):
		super( AuthenticationAdapter, self ).__init__()
		self.log = Logger().get_instance( self.__class__.__name__ )

		"""
		Authentication-Info 2xx -  o - o o o
		Authorization       R   o  o o o o o	(challenge response)
		Proxy-Authenticate  407 ar - m - m m m	(challenge request)
		Proxy-Authenticate  401 ar - o o o o o	(challenge request)
		Proxy-Authorization R   dr o o - o o o	(challenge response)
		WWW-Authenticate    401 ar - m - m m m	(challenge request)
		WWW-Authenticate    407 ar - o - o o o	(challenge request)
		"""
		self.proxyAuthentication = proxyAuthentication
		if self.proxyAuthentication:
			self.statusCode = 407
			self.challengeRequestHeader = 'Proxy-Authenticate'
			self.challengeResponseHeader = 'Proxy-Authorization'
		else:
			self.statusCode = 401
			self.challengeRequestHeader = 'WWW-Authenticate'
			self.challengeResponseHeader = 'Authorization'

		self.authentication = None
		obj = importExtension( 'simple_authentication' )
		if obj:
			self.authentication = obj()
Beispiel #2
0
	def __new__( cls, name, parent, event ):
		if event.id == 'RxRequest':
			prefix = 'uas_dialog'
		elif event.id == 'RxResponse':
			prefix = 'uac_dialog'
		elif event.id == 'TxRequest':
			prefix = 'uac_dialog'
		elif event.id == 'TxResponse':
			prefix = 'uas_dialog'

		obj = importExtension( prefix + '_' + event.message.method )
		if not obj:
			obj = importExtension( prefix )

		if obj:
			return obj( prefix + '-' + str(name), parent, event )

		raise SipException( 'Cannot create ' + prefix + ' for ' + str(event) + '.' )
Beispiel #3
0
	def __new__( cls, event ):
		if cls == Binding:
			obj = importExtension( event.transport + '_binding' )

			if obj:
				return obj( event )

			raise Exception( 'Cannot create binding, ' + str(event.transport) + '.' )
		else:
			# Just build the object.
			return type.__new__( cls, event )
Beispiel #4
0
	def __new__( cls, headers, body ):
		if cls == Body:
			contentType = headers['Content-Type']
			name = contentType.fullType + '_body'
			obj = importExtension( name, 'mercury.body' )

			if obj:
				return obj( headers, body )

			raise SipException( 'Cannot create body, ' + contentType.fullType + '.' )
		else:
			# Just build the object.
			return object.__new__( cls, headers, body )
Beispiel #5
0
    def __new__(cls, value=None):
        if not value:
            raise SipException("Failed to parse empty protocol of URI.")

        value = value.strip()
        if containsWhitespace(value):
            raise SipException("Whitespace present in URI, " + str(value) + ".")

        n = value.find(":")
        if n < 0:
            raise SipException("Failed to parse protocol of URI, " + str(value) + ".")

        protocol = value[:n]

        # print protocol.capitalize() + '-Uri'
        obj = importExtension(protocol.capitalize() + "-Uri", "mercury.uri")
        if obj:
            return obj(value)

        raise SipException("Cannot create URI, " + str(value) + ".")