Handle malformed timestamps (which would cause an unhandled exception and hork the connection)
and XEP-82 (dashes in timestamps).
This commit is contained in:
parent
6ca2d76cba
commit
270c956db3
|
@ -24,7 +24,7 @@ import socket
|
|||
import sys
|
||||
|
||||
from time import (altzone, daylight, gmtime, localtime, mktime, strftime,
|
||||
strptime, time as time_time, timezone, tzname)
|
||||
time as time_time, timezone, tzname)
|
||||
from calendar import timegm
|
||||
|
||||
import socks5
|
||||
|
@ -1424,7 +1424,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
mtype = msg.getType()
|
||||
subject = msg.getSubject() # if not there, it's None
|
||||
tim = msg.getTimestamp()
|
||||
tim = strptime(tim, '%Y%m%dT%H:%M:%S')
|
||||
tim = helpers.datetime_tuple(tim)
|
||||
tim = localtime(timegm(tim))
|
||||
frm = helpers.get_full_jid_from_iq(msg)
|
||||
jid = helpers.get_jid_from_iq(msg)
|
||||
|
@ -1614,7 +1614,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
|||
elif namespace == common.xmpp.NS_DELAY:
|
||||
# XEP-0091
|
||||
tim = prs.getTimestamp()
|
||||
tim = strptime(tim, '%Y%m%dT%H:%M:%S')
|
||||
tim = helpers.datetime_tuple(tim)
|
||||
timestamp = localtime(timegm(tim))
|
||||
elif namespace == 'http://delx.cjb.net/protocol/roster-subsync':
|
||||
# see http://trac.gajim.org/ticket/326
|
||||
|
|
|
@ -970,3 +970,15 @@ def get_avatar_path(prefix):
|
|||
if os.path.exists(file_):
|
||||
return file_
|
||||
return None
|
||||
|
||||
def datetime_tuple(timestamp):
|
||||
'''Converts timestamp using strptime and the format: %Y%m%dT%H:%M:%S
|
||||
Because of various datetime formats are used the following exceptions
|
||||
are handled:
|
||||
- Optional milliseconds appened to the string are removed
|
||||
- XEP-082 datetime strings have all '-' cahrs removed to meet
|
||||
the above format.'''
|
||||
timestamp = timestamp.split('.')[0]
|
||||
timestamp = timestamp.replace('-', '')
|
||||
from time import strptime
|
||||
return strptime(timestamp, '%Y%m%dT%H:%M:%S')
|
||||
|
|
|
@ -640,7 +640,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionBytestream):
|
|||
mtype = msg.getType()
|
||||
subject = msg.getSubject() # if not there, it's None
|
||||
tim = msg.getTimestamp()
|
||||
tim = time.strptime(tim, '%Y%m%dT%H:%M:%S')
|
||||
tim = helpers.datetime_tuple(tim)
|
||||
tim = time.localtime(timegm(tim))
|
||||
frm = msg.getFrom()
|
||||
if frm == None:
|
||||
|
|
Loading…
Reference in New Issue