changeset 61f42e72a6fc in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=61f42e72a6fc
description: send files to gc peer. Fixes #7171

diffstat:

 src/chat_control.py            |   5 +++--
 src/common/contacts.py         |  34 ++++++++++++++++++++++++++++++----
 src/common/jingle.py           |   4 ++++
 src/common/jingle_ft.py        |   9 ++++++++-
 src/common/jingle_transport.py |   2 ++
 5 files changed, 47 insertions(+), 7 deletions(-)

diffs (129 lines):

diff -r 8c3223cea458 -r 61f42e72a6fc src/chat_control.py
--- a/src/chat_control.py       Wed Jun 13 17:17:45 2012 +0400
+++ b/src/chat_control.py       Sat Jun 16 18:41:33 2012 -0400
@@ -1722,8 +1722,9 @@
         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:
diff -r 8c3223cea458 -r 61f42e72a6fc src/common/contacts.py
--- a/src/common/contacts.py    Wed Jun 13 17:17:45 2012 +0400
+++ b/src/common/contacts.py    Sat Jun 16 18:41:33 2012 -0400
@@ -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 @@
     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 @@
             return None
         return self._rooms[room_jid][nick]
 
+    def is_gc_contact(self, jid):
+        """
+        >>> gc = GC_Contacts()
+        >>> gc._rooms = {'[email protected]' : {'test' : True}}
+        >>> gc.is_gc_contact('[email protected]/test')
+        True
+        >>> gc.is_gc_contact('[email protected]')
+        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 @@
         """
         family.sort(cmp=self._compare_metacontacts)
         return family[-1]
+
+
+if __name__ == "__main__":
+    import doctest
+    doctest.testmod()
diff -r 8c3223cea458 -r 61f42e72a6fc src/common/jingle.py
--- a/src/common/jingle.py      Wed Jun 13 17:17:45 2012 +0400
+++ b/src/common/jingle.py      Sat Jun 16 18:41:33 2012 -0400
@@ -145,6 +145,10 @@
         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)
diff -r 8c3223cea458 -r 61f42e72a6fc src/common/jingle_ft.py
--- a/src/common/jingle_ft.py   Wed Jun 13 17:17:45 2012 +0400
+++ b/src/common/jingle_ft.py   Sat Jun 16 18:41:33 2012 -0400
@@ -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 @@
         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),
diff -r 8c3223cea458 -r 61f42e72a6fc src/common/jingle_transport.py
--- a/src/common/jingle_transport.py    Wed Jun 13 17:17:45 2012 +0400
+++ b/src/common/jingle_transport.py    Sat Jun 16 18:41:33 2012 -0400
@@ -132,6 +132,8 @@
             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):
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to