def onREGISTER(self, ua, request, stack): # incoming registration if request.To.value.uri != request.From.value.uri: ua.sendResponse(400, 'Third-party registration not supported') return auth = self.authorize(request) # validate user's password. if auth == 200: saved = yield self.save(msg=request, uri=str(request.To.value.uri).lower()) if _debug: print 'saved=', saved if not saved: ua.sendResponse(500, 'Internal server error') else: response = ua.createResponse(200, 'OK') locations = yield self.locate(str(request.To.value.uri)) for h in map(lambda x: Header(str(x), 'Contact'), locations): response.insert(h, append=True) response.Expires = request.Expires if request.Expires else Header( '3600', 'Expires') ua.sendResponse(response) elif auth == 404: # not found ua.sendResponse(404, 'Not found') else: response = ua.createResponse(401, 'Unauthorized') response.insert(Header( createAuthenticate(realm='localhost', domain=str(request.uri), stale=('FALSE' if auth == 401 else 'TRUE')), 'WWW-Authenticate'), append=True) ua.sendResponse(response)
def onREGISTER(self, ua, request, stack): # incoming registration print "reeeeeeeeeeeeeeeeeeeeegisteeeeeeer" if request.To.value.uri != request.From.value.uri: ua.sendResponse(400, 'Third-party registration not supported') return auth = self.authorize(request) # validate user's password. if auth == 200: saved = yield self.save(msg=request, uri=str(request.To.value.uri).lower()) if _debug: print 'saved=', saved if not saved: ua.sendResponse(500, 'Internal server error') else: response = ua.createResponse(200, 'OK'); locations = yield self.locate(str(request.To.value.uri)) for h in map(lambda x: Header(str(x), 'Contact'), locations): response.insert(h, append=True) response.Expires = request.Expires if request.Expires else Header('3600', 'Expires') ua.sendResponse(response) elif auth == 404: # not found ua.sendResponse(404, 'Not found') else: response = ua.createResponse(401, 'Unauthorized') response.insert(Header(createAuthenticate(realm='localhost', domain=str(request.uri), stale=('FALSE' if auth==401 else 'TRUE')), 'WWW-Authenticate'), append=True) ua.sendResponse(response)
def challenge(self, realm): response = self.ua.createResponse(401, 'Unauthorized') response.insert(Header( createAuthenticate(realm=realm, domain=str(self.uri), stale='FALSE'), 'WWW-Authenticate'), append=True) self.ua.sendResponse(response)
def challenge(self, realm): response = self.ua.createResponse(401, 'Unauthorized') response.insert(Header(createAuthenticate(realm=realm, domain=str(self.uri), stale=('FALSE' if auth==401 else 'TRUE')), 'WWW-Authenticate'), append=True) self.ua.sendResponse(response)