Skip to content

Commit

Permalink
Merge branch 'verbose_logging_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
twonds committed Feb 27, 2009
2 parents 1720afd + 4c57490 commit 304f173
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
_trial_temp
twistd.log
twistd.pid
dropin.cache
*.~*
41 changes: 27 additions & 14 deletions punjab/httpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,13 @@ def render_POST(self, request):
self.hp._reset()

if getattr(body_tag, 'name', '') != "body":
log.msg('Client sent bad POST data')
if self.service.v:
log.msg('Client sent bad POST data')
self.send_http_error(400, request)
return server.NOT_DONE_YET
except domish.ParserError:
log.msg('ERROR: Xml Parse Error')
log.err()
self.hp._reset()
self.send_http_error(400, request)
return server.NOT_DONE_YET
Expand All @@ -350,12 +352,14 @@ def render_POST(self, request):
# sid is an existing session
if body_tag.getAttribute('rid'):
request.rid = body_tag['rid']
log.msg(request.rid)
if self.service.v:
log.msg(request.rid)

s, d = self.service.parseBody(body_tag, xmpp_elements)
d.addCallback(self.return_httpb, s, request)
elif body_tag.hasAttribute('sid'):
log.msg("no sid is found but the body element has a 'sid' attribute")
if self.service.v:
log.msg("no sid is found but the body element has a 'sid' attribute")
# This is an error, no sid is found but the body element has a 'sid' attribute
self.send_http_error(404, request)
return server.NOT_DONE_YET
Expand Down Expand Up @@ -486,8 +490,9 @@ def send_http_error(self, code, request, condition = 'undefined-condition', typ

if children:
b.children += children

log.msg('HTTPB Error %d' %(int(code),))

if self.service.v:
log.msg('HTTPB Error %d' %(int(code),))

if int(code) != 400 and int(code) != 404 and int(code) != 403:
if data != '':
Expand All @@ -498,7 +503,8 @@ def send_http_error(self, code, request, condition = 'undefined-condition', typ
t['xmlns'] = 'urn:ietf:params:xml:ns:xmpp-streams'

bxml = b.toXml().encode(charset, 'replace')
log.msg('HTTPB Return Error: ' + str(code) + ' -> ' + bxml)
if self.service.v:
log.msg('HTTPB Return Error: ' + str(code) + ' -> ' + bxml)
request.setHeader("content-type", "text/xml")
request.setHeader("content-length", len(bxml))
request.write(bxml)
Expand Down Expand Up @@ -546,7 +552,8 @@ def startSession(self, body, xmpp_elements):

# look for rid
if not body.hasAttribute('rid') or body['rid']=='':
log.msg('start session called but we had a rid')
if self.v:
log.msg('start session called but we had a rid')
return None, defer.fail(error.NotFound)

# look for to
Expand Down Expand Up @@ -578,14 +585,16 @@ def parseBody(self, body, xmpp_elements):
if body.hasAttribute('sid'):
sid = str(body['sid'])
else:
log.msg('Session ID not found')
if self.v:
log.msg('Session ID not found')
return None, defer.fail(error.NotFound)

if self.inSession(body):
s = self.sessions[sid]
s.touch() # any connection should be a renew on wait
else:
log.msg('session does not exist?')
if self.v:
log.msg('session does not exist?')
return None, defer.fail(error.NotFound)
## XXX this seems to break xmpp:restart='true' --vargas
## (cf. http://www.xmpp.org/extensions/xep-0206.html#preconditions-sasl [Example 10])
Expand All @@ -609,7 +618,8 @@ def parseBody(self, body, xmpp_elements):
if key == s.key:
s.key = next_key
else:
log.msg('Error in key')
if self.v:
log.msg('Error in key')
return s, defer.fail(error.NotFound)
else:
log.err()
Expand All @@ -627,10 +637,12 @@ def parseBody(self, body, xmpp_elements):
# implements issue 32 and returns the data returned on a dropped connection
return s, defer.succeed(s.cache_data[int(body['rid'])])
if abs(int(body['rid']) - int(s.rid)) > s.window:
log.msg('This rid is invalid %s %s ' % (str(body['rid']), str(s.rid),))
if self.v:
log.msg('This rid is invalid %s %s ' % (str(body['rid']), str(s.rid),))
return s, defer.fail(error.NotFound)
else:
log.msg('There is no rid on this request')
if self.v:
log.msg('There is no rid on this request')
return s, defer.fail(error.NotFound)

return s, self._parse(s, body, xmpp_elements)
Expand All @@ -643,8 +655,9 @@ def parseBody(self, body, xmpp_elements):

def onExpire(self, session_id):
""" preform actions based on when the jabber connection expires """
log.msg('expire (%s)' % (str(session_id),))
log.msg(len(self.sessions.keys()))
if self.v:
log.msg('expire (%s)' % (str(session_id),))
log.msg(len(self.sessions.keys()))

def _parse(self, session, body_tag, xmpp_elements):
# increment the request counter
Expand Down
1 change: 0 additions & 1 deletion punjab/jabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def associateWithStream(self, xs):


def _reset(self):
log.msg('\n\n======================= reset ====================\n\n')
# need this to be in xmlstream
self.xmlstream.stream = domish.elementStream()
self.xmlstream.stream.DocumentStartEvent = self.xmlstream.onDocumentStart
Expand Down
1 change: 1 addition & 0 deletions punjab/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __init__(self, pint, sid, attrs):

self.cache_data = {}
self.verbose = self.pint.v
self.noisy = self.verbose

self.version = attrs.get('version', 0.0)

Expand Down

0 comments on commit 304f173

Please sign in to comment.