jingle IBB and normal IBB are different

This commit is contained in:
Yann Leboulanger 2012-06-14 18:34:07 +02:00
parent 2af1af2011
commit 1fdf6b7e35
3 changed files with 43 additions and 35 deletions

View File

@ -1978,6 +1978,21 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
self.file_props.stream_methods = xmpp.NS_BYTESTREAM self.file_props.stream_methods = xmpp.NS_BYTESTREAM
file_tag = self.jingle_content.getTag('description').getTag( file_tag = self.jingle_content.getTag('description').getTag(
'offer').getTag('file') 'offer').getTag('file')
for child in file_tag.getChildren():
name = child.getName()
val = child.getData()
if val is None:
continue
if name == 'name':
self.file_props.name = val
if name == 'size':
self.file_props.size = val
if name == 'hash':
self.file_props.algo = child.getAttr('algo')
self.file_props.hash_ = val
if name == 'date':
self.file_props.date = val
else: else:
profile = si.getAttr('profile') profile = si.getAttr('profile')
if profile != xmpp.NS_FILE: if profile != xmpp.NS_FILE:
@ -2002,20 +2017,13 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
typ='stream') typ='stream')
raise xmpp.NodeProcessed raise xmpp.NodeProcessed
file_tag = si.getTag('file') file_tag = si.getTag('file')
for child in file_tag.getChildren(): for name, val in file_tag.getAttrs().items():
name = child.getName() if val is None:
val = child.getData() continue
if val is None: if name == 'name':
continue self.file_props.name = val
if name == 'name': if name == 'size':
self.file_props.name = val self.file_props.size = val
if name == 'size':
self.file_props.size = val
if name == 'hash':
self.file_props.algo = child.getAttr('algo')
self.file_props.hash_ = val
if name == 'date':
self.file_props.date = val
file_desc_tag = file_tag.getTag('desc') file_desc_tag = file_tag.getTag('desc')
if file_desc_tag is not None: if file_desc_tag is not None:
self.file_props.desc = file_desc_tag.getData() self.file_props.desc = file_desc_tag.getData()

View File

@ -569,7 +569,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
err.setData(msg) err.setData(msg)
self.connection.send(iq) self.connection.send(iq)
if code == 404: if code == 404:
file_props = FilesProp.getFileProp(self.name, sid) file_props = FilesProp.getFileProp(self.name, sid)
if file_props is not None: if file_props is not None:
self.disconnect_transfer(file_props) self.disconnect_transfer(file_props)
file_props.error = -3 file_props.error = -3
@ -584,7 +584,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
""" """
if not self.connection or self.connected < 2: if not self.connection or self.connected < 2:
return return
file_props = FilesProp.getFileProp(self.connection, proxy['sid']) file_props = FilesProp.getFileProp(self.connection, proxy['sid'])
iq = xmpp.Iq(to=proxy['initiator'], typ='set') iq = xmpp.Iq(to=proxy['initiator'], typ='set')
auth_id = "au_" + proxy['sid'] auth_id = "au_" + proxy['sid']
iq.setID(auth_id) iq.setID(auth_id)
@ -617,7 +617,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
id_ = unicode(iq_obj.getAttr('id')) id_ = unicode(iq_obj.getAttr('id'))
query = iq_obj.getTag('query') query = iq_obj.getTag('query')
sid = unicode(query.getAttr('sid')) sid = unicode(query.getAttr('sid'))
file_props = FilesProp.getFileProp(self.name, sid) file_props = FilesProp.getFileProp(self.name, sid)
streamhosts = [] streamhosts = []
for item in query.getChildren(): for item in query.getChildren():
if item.getName() == 'streamhost': if item.getName() == 'streamhost':
@ -780,14 +780,14 @@ class ConnectionIBBytestream(ConnectionBytestream):
blocksize = stanza.getTagAttr('open', 'block-size') blocksize = stanza.getTagAttr('open', 'block-size')
log.debug('StreamOpenHandler called sid->%s blocksize->%s' % (sid, log.debug('StreamOpenHandler called sid->%s blocksize->%s' % (sid,
blocksize)) blocksize))
file_props = FilesProp.getFileProp(self.name, sid) file_props = FilesProp.getFileProp(self.name, sid)
try: try:
blocksize = int(blocksize) blocksize = int(blocksize)
except: except:
err = xmpp.ERR_BAD_REQUEST err = xmpp.ERR_BAD_REQUEST
if not sid or not blocksize: if not sid or not blocksize:
err = xmpp.ERR_BAD_REQUEST err = xmpp.ERR_BAD_REQUEST
elif not file_props: elif not file_props:
err = xmpp.ERR_UNEXPECTED_REQUEST err = xmpp.ERR_UNEXPECTED_REQUEST
if err: if err:
rep = xmpp.Error(stanza, err) rep = xmpp.Error(stanza, err)
@ -900,8 +900,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
seq = '' seq = ''
data = '' data = ''
err = None err = None
file_props = FilesProp.getFileProp(self.name, sid) file_props = FilesProp.getFileProp(self.name, sid)
if file_props is None: if file_props is None:
err = xmpp.ERR_ITEM_NOT_FOUND err = xmpp.ERR_ITEM_NOT_FOUND
else: else:
if not data: if not data:

View File

@ -167,7 +167,7 @@ NS_HASHES_MD5 = 'urn:xmpp:hash-function-textual-names:md5'
NS_HASHES_SHA1 = 'urn:xmpp:hash-function-textual-names:sha-1' NS_HASHES_SHA1 = 'urn:xmpp:hash-function-textual-names:sha-1'
NS_HASHES_SHA256 = 'urn:xmpp:hash-function-textual-names:sha-256' NS_HASHES_SHA256 = 'urn:xmpp:hash-function-textual-names:sha-256'
NS_HASHES_SHA512 = 'urn:xmpp:hash-function-textual-names:sha-512' NS_HASHES_SHA512 = 'urn:xmpp:hash-function-textual-names:sha-512'
xmpp_stream_error_conditions = ''' xmpp_stream_error_conditions = '''
bad-format -- -- -- The entity has sent XML that cannot be processed. bad-format -- -- -- The entity has sent XML that cannot be processed.
bad-namespace-prefix -- -- -- The entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix. bad-namespace-prefix -- -- -- The entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix.
@ -1037,12 +1037,12 @@ class Iq(Protocol):
attrs={'id': self.getID()}) attrs={'id': self.getID()})
iq.setQuery(self.getQuery().getName()).setNamespace(self.getQueryNS()) iq.setQuery(self.getQuery().getName()).setNamespace(self.getQueryNS())
return iq return iq
class Hashes(Node): class Hashes(Node):
""" """
Hash elements for various XEPs as defined in XEP-300 Hash elements for various XEPs as defined in XEP-300
""" """
""" """
RECOMENDED HASH USE: RECOMENDED HASH USE:
Algorithm Support Algorithm Support
@ -1053,14 +1053,14 @@ class Hashes(Node):
SHA-256 MUST SHA-256 MUST
SHA-512 SHOULD SHA-512 SHOULD
""" """
supported = ('md5', 'sha-1', 'sha-256', 'sha-512') supported = ('md5', 'sha-1', 'sha-256', 'sha-512')
def __init__(self, nsp=NS_HASHES): def __init__(self, nsp=NS_HASHES):
Node.__init__(self, None, {}, [], None, None, False, None) Node.__init__(self, None, {}, [], None, None, False, None)
self.setNamespace(nsp) self.setNamespace(nsp)
self.setName('hash') self.setName('hash')
def calculateHash(self, algo, file_string): def calculateHash(self, algo, file_string):
""" """
Calculate the hash and add it. It is preferable doing it here Calculate the hash and add it. It is preferable doing it here
@ -1078,12 +1078,12 @@ class Hashes(Node):
hl = hashlib.sha256() hl = hashlib.sha256()
elif algo == 'sha-512': elif algo == 'sha-512':
hl = hashlib.sha512() hl = hashlib.sha512()
if hl: if hl:
hl.update(file_string) hl.update(file_string)
hash_ = hl.hexdigest() hash_ = hl.hexdigest()
else: # if it is a file else: # if it is a file
if algo == 'md5': if algo == 'md5':
hl = hashlib.md5() hl = hashlib.md5()
elif algo == 'sha-1': elif algo == 'sha-1':
@ -1092,18 +1092,18 @@ class Hashes(Node):
hl = hashlib.sha256() hl = hashlib.sha256()
elif algo == 'sha-512': elif algo == 'sha-512':
hl = hashlib.sha512() hl = hashlib.sha512()
if hl: if hl:
for line in file_string: for line in file_string:
hl.update(line) hl.update(line)
hash_ = hl.hexdigest() hash_ = hl.hexdigest()
return hash_ return hash_
def addHash(self, hash_, algo): def addHash(self, hash_, algo):
self.setAttr('algo', algo) self.setAttr('algo', algo)
self.setData(hash_) self.setData(hash_)
class Acks(Node): class Acks(Node):
""" """
Acknowledgement elements for Stream Management Acknowledgement elements for Stream Management