comparison sat_pubsub/gateway.py @ 274:6641ea7990ee

Fix checking for malformed XMPP URI in DeleteResource.
author Ralph Meijer <ralphm@ik.nu>
date Mon, 07 Oct 2013 12:14:54 +0200
parents 6ba0d6def7f5
children 9c74cd2635f6
comparison
equal deleted inserted replaced
273:6ba0d6def7f5 274:6641ea7990ee
236 236
237 def trapNotFound(failure): 237 def trapNotFound(failure):
238 failure.trap(error.NodeNotFound) 238 failure.trap(error.NodeNotFound)
239 raise Error(http.NOT_FOUND, "Node not found") 239 raise Error(http.NOT_FOUND, "Node not found")
240 240
241 def trapXMPPURIParseError(failure):
242 failure.trap(XMPPURIParseError)
243 raise Error(http.BAD_REQUEST,
244 "Malformed XMPP URI: %s" % failure.value)
245
246 if not request.args.get('uri'): 241 if not request.args.get('uri'):
247 raise Error(http.BAD_REQUEST, "No URI given") 242 raise Error(http.BAD_REQUEST, "No URI given")
248 243
249 jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0]) 244 try:
245 jid, nodeIdentifier = getServiceAndNode(request.args['uri'][0])
246 except XMPPURIParseError, e:
247 raise Error(http.BAD_REQUEST, "Malformed XMPP URI: %s" % e)
248
250 249
251 data = request.content.read() 250 data = request.content.read()
252 if data: 251 if data:
253 params = simplejson.loads(data) 252 params = simplejson.loads(data)
254 redirectURI = params.get('redirect_uri', None) 253 redirectURI = params.get('redirect_uri', None)
257 256
258 d = self.backend.deleteNode(nodeIdentifier, self.owner, 257 d = self.backend.deleteNode(nodeIdentifier, self.owner,
259 redirectURI) 258 redirectURI)
260 d.addCallback(toResponse) 259 d.addCallback(toResponse)
261 d.addErrback(trapNotFound) 260 d.addErrback(trapNotFound)
262 d.addErrback(trapXMPPURIParseError)
263 return d 261 return d
264 262
265 263
266 264
267 class PublishResource(resource.Resource): 265 class PublishResource(resource.Resource):