send files to gc peer. Fixes #7171

This commit is contained in:
Jefry Lagrange 2012-06-16 18:41:33 -04:00
parent cfb49bb4ec
commit ccb53c7c08
5 changed files with 47 additions and 7 deletions

View File

@ -1722,8 +1722,9 @@ class ChatControl(ChatControlBase):
self._video_button.set_sensitive(self.video_available)
# Send file
if (self.contact.supports(NS_FILE) or self.contact.supports(NS_JINGLE_FILE_TRANSFER)) and (self.type_id == 'chat' or \
self.gc_contact.resource):
if (self.contact.supports(NS_FILE) or \
self.contact.supports(NS_JINGLE_FILE_TRANSFER)) or \
self.type_id == 'chat' or self.gc_contact.resource:
self._send_file_button.set_sensitive(True)
self._send_file_button.set_tooltip_text('')
else:

View File

@ -28,10 +28,13 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
from common import caps_cache
from common.account import Account
import common.gajim
try:
from common import caps_cache
from common.account import Account
import common.gajim
except ImportError, e:
if __name__ != "__main__":
raise ImportError(e)
class XMPPEntity(object):
"""
@ -411,6 +414,9 @@ class LegacyContactsAPI:
def get_gc_contact(self, account, room_jid, nick):
return self._accounts[account].gc_contacts.get_gc_contact(room_jid, nick)
def is_gc_contact(self, account, jid):
return self._accounts[account].gc_contacts.is_gc_contact(jid)
def get_nb_role_total_gc_contacts(self, account, room_jid, role):
return self._accounts[account].gc_contacts.get_nb_role_total_gc_contacts(room_jid, role)
@ -564,6 +570,21 @@ class GC_Contacts():
return None
return self._rooms[room_jid][nick]
def is_gc_contact(self, jid):
"""
>>> gc = GC_Contacts()
>>> gc._rooms = {'gajim@conference.gajim.org' : {'test' : True}}
>>> gc.is_gc_contact('gajim@conference.gajim.org/test')
True
>>> gc.is_gc_contact('test@jabbim.com')
False
"""
jid = jid.split('/')
if len(jid) != 2:
return False
gcc = self.get_gc_contact(jid[0], jid[1])
return gcc != None
def get_nb_role_total_gc_contacts(self, room_jid, role):
"""
Return the number of group chat contacts for the given role and the total
@ -827,3 +848,8 @@ class MetacontactManager():
"""
family.sort(cmp=self._compare_metacontacts)
return family[-1]
if __name__ == "__main__":
import doctest
doctest.testmod()

View File

@ -145,6 +145,10 @@ class ConnectionJingle(object):
logger.info("start file transfer with file: %s" % file_props)
contact = gajim.contacts.get_contact_with_highest_priority(self.name,
gajim.get_jid_without_resource(jid))
if gajim.contacts.is_gc_contact(self.name,jid):
gcc = jid.split('/')
if len(gcc) == 2:
contact = gajim.contacts.get_gc_contact(self.name, gcc[0], gcc[1])
if contact is None:
return
use_security = contact.supports(xmpp.NS_JINGLE_XTLS)

View File

@ -19,6 +19,7 @@
Handles Jingle File Transfer (XEP 0234)
"""
import hashlib
import gajim
import xmpp
from jingle_content import contents, JingleContent
@ -97,7 +98,13 @@ class JingleFileTransfer(JingleContent):
self.session = session
self.media = 'file'
self.nominated_cand = {}
if gajim.contacts.is_gc_contact(session.connection.name,
session.peerjid):
roomjid = session.peerjid.split('/')[0]
dstaddr = hashlib.sha1('%s%s%s' % (self.file_props['sid'],
session.ourjid,
roomjid)).hexdigest()
self.file_props['dstaddr'] = dstaddr
self.state = STATE_NOT_STARTED
self.states = {STATE_INITIALIZED : StateInitialized(self),
STATE_CAND_SENT : StateCandSent(self),

View File

@ -132,6 +132,8 @@ class JingleTransportSocks5(JingleTransport):
transport = xmpp.Node('transport')
transport.setNamespace(xmpp.NS_JINGLE_BYTESTREAM)
transport.setAttr('sid', self.sid)
if 'dstaddr' in self.file_props:
transport.setAttr('dstaddr', self.file_props['dstaddr'])
return transport
def parse_transport_stanza(self, transport):