Mercurial > pidgin
annotate libpurple/protocols/jabber/ibb.c @ 32031:cd1d9e04c587
Rename the _with_invite functions to their counterparts.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 03 Sep 2011 23:13:11 +0000 |
parents | 7fbb7612e3dd |
children |
rev | line source |
---|---|
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
1 /* |
29884
7fbb7612e3dd
Fix license to refer to GPLv2 in a files...
Marcus Lundblad <ml@update.uu.se>
parents:
29612
diff
changeset
|
2 * purple - Jabber Service Discovery |
7fbb7612e3dd
Fix license to refer to GPLv2 in a files...
Marcus Lundblad <ml@update.uu.se>
parents:
29612
diff
changeset
|
3 * |
28047
8c991e09efcb
Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents:
26803
diff
changeset
|
4 * Purple is the legal property of its developers, whose names are too numerous |
8c991e09efcb
Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents:
26803
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8c991e09efcb
Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents:
26803
diff
changeset
|
6 * source distribution. |
8c991e09efcb
Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents:
26803
diff
changeset
|
7 * |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
11 * (at your option) any later version. |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
12 * |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
29884
7fbb7612e3dd
Fix license to refer to GPLv2 in a files...
Marcus Lundblad <ml@update.uu.se>
parents:
29612
diff
changeset
|
16 * GNU General Public License for more details. |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
17 * |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
28070
7921a53b94b3
Oops, Elliott correctly pointed out this was wrong...
Paul Aurich <paul@darkrain42.org>
parents:
28047
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
29884
7fbb7612e3dd
Fix license to refer to GPLv2 in a files...
Marcus Lundblad <ml@update.uu.se>
parents:
29612
diff
changeset
|
21 * |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
22 */ |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
23 |
25719
dc01f9b0aaa3
Patch from Phil Hannent to fix build on win32,
Marcus Lundblad <ml@update.uu.se>
parents:
25129
diff
changeset
|
24 #include "internal.h" |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
25 #include "ibb.h" |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
26 #include "debug.h" |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
27 #include "xmlnode.h" |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
28 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
29 #define JABBER_IBB_SESSION_DEFAULT_BLOCK_SIZE 4096 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
30 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
31 static GHashTable *jabber_ibb_sessions = NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
32 static GList *open_handlers = NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
33 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
34 JabberIBBSession * |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
35 jabber_ibb_session_create(JabberStream *js, const gchar *sid, const gchar *who, |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
36 gpointer user_data) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
37 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
38 JabberIBBSession *sess = g_new0(JabberIBBSession, 1); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
39 sess->js = js; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
40 if (sid) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
41 sess->sid = g_strdup(sid); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
42 } else { |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
43 sess->sid = jabber_get_next_id(js); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
44 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
45 sess->who = g_strdup(who); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
46 sess->block_size = JABBER_IBB_SESSION_DEFAULT_BLOCK_SIZE; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
47 sess->state = JABBER_IBB_SESSION_NOT_OPENED; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
48 sess->user_data = user_data; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
49 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
50 g_hash_table_insert(jabber_ibb_sessions, sess->sid, sess); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
51 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
52 return sess; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
53 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
54 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
55 JabberIBBSession * |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
56 jabber_ibb_session_create_from_xmlnode(JabberStream *js, const char *from, |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
57 const char *id, xmlnode *open, gpointer user_data) |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
58 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
59 JabberIBBSession *sess = NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
60 const gchar *sid = xmlnode_get_attrib(open, "sid"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
61 const gchar *block_size = xmlnode_get_attrib(open, "block-size"); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
62 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
63 if (!open) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
64 return NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
65 } |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
66 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
67 if (!sid || !block_size) { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
68 purple_debug_error("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
69 "IBB session open tag requires sid and block-size attributes\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
70 g_free(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
71 return NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
72 } |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
73 |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
74 sess = jabber_ibb_session_create(js, sid, from, user_data); |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
75 sess->id = g_strdup(id); |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
76 sess->block_size = atoi(block_size); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
77 /* if we create a session from an incoming <open/> request, it means the |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
78 session is immediatly open... */ |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
79 sess->state = JABBER_IBB_SESSION_OPENED; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
80 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
81 return sess; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
82 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
83 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
84 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
85 jabber_ibb_session_destroy(JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
86 { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
87 purple_debug_info("jabber", "IBB: destroying session %p %s\n", sess, |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
88 sess->sid); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
89 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
90 if (jabber_ibb_session_get_state(sess) == JABBER_IBB_SESSION_OPENED) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
91 jabber_ibb_session_close(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
92 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
93 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
94 if (sess->last_iq_id) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
95 purple_debug_info("jabber", "IBB: removing callback for <iq/> %s\n", |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
96 sess->last_iq_id); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
97 jabber_iq_remove_callback_by_id(jabber_ibb_session_get_js(sess), |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
98 sess->last_iq_id); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
99 g_free(sess->last_iq_id); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
100 sess->last_iq_id = NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
101 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
102 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
103 g_hash_table_remove(jabber_ibb_sessions, sess->sid); |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
104 g_free(sess->id); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
105 g_free(sess->sid); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
106 g_free(sess->who); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
107 g_free(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
108 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
109 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
110 const gchar * |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
111 jabber_ibb_session_get_sid(const JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
112 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
113 return sess->sid; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
114 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
115 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
116 JabberStream * |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
117 jabber_ibb_session_get_js(JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
118 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
119 return sess->js; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
120 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
121 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
122 const gchar * |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
123 jabber_ibb_session_get_who(const JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
124 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
125 return sess->who; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
126 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
127 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
128 guint16 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
129 jabber_ibb_session_get_send_seq(const JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
130 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
131 return sess->send_seq; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
132 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
133 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
134 guint16 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
135 jabber_ibb_session_get_recv_seq(const JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
136 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
137 return sess->recv_seq; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
138 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
139 |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
140 JabberIBBSessionState |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
141 jabber_ibb_session_get_state(const JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
142 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
143 return sess->state; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
144 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
145 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
146 gsize |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
147 jabber_ibb_session_get_block_size(const JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
148 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
149 return sess->block_size; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
150 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
151 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
152 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
153 jabber_ibb_session_set_block_size(JabberIBBSession *sess, gsize size) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
154 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
155 if (jabber_ibb_session_get_state(sess) == JABBER_IBB_SESSION_NOT_OPENED) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
156 sess->block_size = size; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
157 } else { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
158 purple_debug_error("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
159 "Can't set block size on an open IBB session\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
160 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
161 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
162 |
29612
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
163 gsize |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
164 jabber_ibb_session_get_max_data_size(const JabberIBBSession *sess) |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
165 { |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
166 return (gsize) floor((sess->block_size - 2) * (float) 3 / 4); |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
167 } |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
168 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
169 gpointer |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
170 jabber_ibb_session_get_user_data(JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
171 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
172 return sess->user_data; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
173 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
174 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
175 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
176 jabber_ibb_session_set_opened_callback(JabberIBBSession *sess, |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
177 JabberIBBOpenedCallback *cb) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
178 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
179 sess->opened_cb = cb; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
180 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
181 |
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
182 void |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
183 jabber_ibb_session_set_data_sent_callback(JabberIBBSession *sess, |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
184 JabberIBBSentCallback *cb) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
185 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
186 sess->data_sent_cb = cb; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
187 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
188 |
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
189 void |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
190 jabber_ibb_session_set_closed_callback(JabberIBBSession *sess, |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
191 JabberIBBClosedCallback *cb) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
192 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
193 sess->closed_cb = cb; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
194 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
195 |
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
196 void |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
197 jabber_ibb_session_set_data_received_callback(JabberIBBSession *sess, |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
198 JabberIBBDataCallback *cb) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
199 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
200 sess->data_received_cb = cb; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
201 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
202 |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
203 void |
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
204 jabber_ibb_session_set_error_callback(JabberIBBSession *sess, |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
205 JabberIBBErrorCallback *cb) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
206 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
207 sess->error_cb = cb; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
208 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
209 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
210 static void |
26465
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
211 jabber_ibb_session_opened_cb(JabberStream *js, const char *from, |
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
212 JabberIqType type, const char *id, |
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
213 xmlnode *packet, gpointer data) |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
214 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
215 JabberIBBSession *sess = (JabberIBBSession *) data; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
216 |
26465
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
217 if (type == JABBER_IQ_ERROR) { |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
218 sess->state = JABBER_IBB_SESSION_ERROR; |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
219 } else { |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
220 sess->state = JABBER_IBB_SESSION_OPENED; |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
221 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
222 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
223 if (sess->opened_cb) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
224 sess->opened_cb(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
225 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
226 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
227 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
228 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
229 jabber_ibb_session_open(JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
230 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
231 if (jabber_ibb_session_get_state(sess) != JABBER_IBB_SESSION_NOT_OPENED) { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
232 purple_debug_error("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
233 "jabber_ibb_session called on an already open stream\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
234 } else { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
235 JabberIq *set = jabber_iq_new(sess->js, JABBER_IQ_SET); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
236 xmlnode *open = xmlnode_new("open"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
237 gchar block_size[10]; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
238 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
239 xmlnode_set_attrib(set->node, "to", jabber_ibb_session_get_who(sess)); |
28645
7b4ade7c6d8a
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents:
28070
diff
changeset
|
240 xmlnode_set_namespace(open, NS_IBB); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
241 xmlnode_set_attrib(open, "sid", jabber_ibb_session_get_sid(sess)); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
242 g_snprintf(block_size, sizeof(block_size), "%" G_GSIZE_FORMAT, |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
243 jabber_ibb_session_get_block_size(sess)); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
244 xmlnode_set_attrib(open, "block-size", block_size); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
245 xmlnode_insert_child(set->node, open); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
246 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
247 jabber_iq_set_callback(set, jabber_ibb_session_opened_cb, sess); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
248 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
249 jabber_iq_send(set); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
250 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
251 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
252 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
253 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
254 jabber_ibb_session_close(JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
255 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
256 JabberIBBSessionState state = jabber_ibb_session_get_state(sess); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
257 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
258 if (state != JABBER_IBB_SESSION_OPENED && state != JABBER_IBB_SESSION_ERROR) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
259 purple_debug_error("jabber", |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
260 "jabber_ibb_session_close called on a session that has not been" |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
261 "opened\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
262 } else { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
263 JabberIq *set = jabber_iq_new(jabber_ibb_session_get_js(sess), |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
264 JABBER_IQ_SET); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
265 xmlnode *close = xmlnode_new("close"); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
266 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
267 xmlnode_set_attrib(set->node, "to", jabber_ibb_session_get_who(sess)); |
28645
7b4ade7c6d8a
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents:
28070
diff
changeset
|
268 xmlnode_set_namespace(close, NS_IBB); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
269 xmlnode_set_attrib(close, "sid", jabber_ibb_session_get_sid(sess)); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
270 xmlnode_insert_child(set->node, close); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
271 jabber_iq_send(set); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
272 sess->state = JABBER_IBB_SESSION_CLOSED; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
273 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
274 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
275 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
276 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
277 jabber_ibb_session_accept(JabberIBBSession *sess) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
278 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
279 JabberIq *result = jabber_iq_new(jabber_ibb_session_get_js(sess), |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
280 JABBER_IQ_RESULT); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
281 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
282 xmlnode_set_attrib(result->node, "to", jabber_ibb_session_get_who(sess)); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
283 jabber_iq_set_id(result, sess->id); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
284 jabber_iq_send(result); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
285 sess->state = JABBER_IBB_SESSION_OPENED; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
286 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
287 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
288 static void |
26465
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
289 jabber_ibb_session_send_acknowledge_cb(JabberStream *js, const char *from, |
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
290 JabberIqType type, const char *id, |
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
291 xmlnode *packet, gpointer data) |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
292 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
293 JabberIBBSession *sess = (JabberIBBSession *) data; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
294 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
295 if (sess) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
296 /* reset callback */ |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
297 if (sess->last_iq_id) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
298 g_free(sess->last_iq_id); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
299 sess->last_iq_id = NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
300 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
301 |
26465
ae41d8e827e3
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <paul@darkrain42.org>
parents:
25952
diff
changeset
|
302 if (type == JABBER_IQ_ERROR) { |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
303 jabber_ibb_session_close(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
304 sess->state = JABBER_IBB_SESSION_ERROR; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
305 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
306 if (sess->error_cb) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
307 sess->error_cb(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
308 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
309 } else { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
310 if (sess->data_sent_cb) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
311 sess->data_sent_cb(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
312 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
313 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
314 } else { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
315 /* the session has gone away, it was probably cancelled */ |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
316 purple_debug_info("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
317 "got response from send data, but IBB session is no longer active\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
318 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
319 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
320 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
321 void |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
322 jabber_ibb_session_send_data(JabberIBBSession *sess, gconstpointer data, |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
323 gsize size) |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
324 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
325 JabberIBBSessionState state = jabber_ibb_session_get_state(sess); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
326 |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
327 purple_debug_info("jabber", "sending data block of %" G_GSIZE_FORMAT " bytes on IBB stream\n", |
25722
be762644486f
Actually close the assoiciated jsx when closing an IBB session.
Marcus Lundblad <ml@update.uu.se>
parents:
25719
diff
changeset
|
328 size); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
329 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
330 if (state != JABBER_IBB_SESSION_OPENED) { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
331 purple_debug_error("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
332 "trying to send data on a non-open IBB session\n"); |
29612
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
333 } else if (size > jabber_ibb_session_get_max_data_size(sess)) { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
334 purple_debug_error("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
335 "trying to send a too large packet in the IBB session\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
336 } else { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
337 JabberIq *set = jabber_iq_new(jabber_ibb_session_get_js(sess), |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
338 JABBER_IQ_SET); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
339 xmlnode *data_element = xmlnode_new("data"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
340 char *base64 = purple_base64_encode(data, size); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
341 char seq[10]; |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
342 g_snprintf(seq, sizeof(seq), "%u", jabber_ibb_session_get_send_seq(sess)); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
343 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
344 xmlnode_set_attrib(set->node, "to", jabber_ibb_session_get_who(sess)); |
28645
7b4ade7c6d8a
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents:
28070
diff
changeset
|
345 xmlnode_set_namespace(data_element, NS_IBB); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
346 xmlnode_set_attrib(data_element, "sid", jabber_ibb_session_get_sid(sess)); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
347 xmlnode_set_attrib(data_element, "seq", seq); |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
348 xmlnode_insert_data(data_element, base64, -1); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
349 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
350 xmlnode_insert_child(set->node, data_element); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
351 |
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
352 purple_debug_info("jabber", |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
353 "IBB: setting send <iq/> callback for session %p %s\n", sess, |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
354 sess->sid); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
355 jabber_iq_set_callback(set, jabber_ibb_session_send_acknowledge_cb, sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
356 sess->last_iq_id = g_strdup(xmlnode_get_attrib(set->node, "id")); |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
357 purple_debug_info("jabber", "IBB: set sess->last_iq_id: %s\n", |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
358 sess->last_iq_id); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
359 jabber_iq_send(set); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
360 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
361 g_free(base64); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
362 (sess->send_seq)++; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
363 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
364 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
365 |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
366 static void |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
367 jabber_ibb_send_error_response(JabberStream *js, const char *to, const char *id) |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
368 { |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
369 JabberIq *result = jabber_iq_new(js, JABBER_IQ_ERROR); |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
370 xmlnode *error = xmlnode_new("error"); |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
371 xmlnode *item_not_found = xmlnode_new("item-not-found"); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
372 |
28650
9ae3e70a327b
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <paul@darkrain42.org>
parents:
28645
diff
changeset
|
373 xmlnode_set_namespace(item_not_found, NS_XMPP_STANZAS); |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
374 xmlnode_set_attrib(error, "code", "440"); |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
375 xmlnode_set_attrib(error, "type", "cancel"); |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
376 jabber_iq_set_id(result, id); |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
377 xmlnode_set_attrib(result->node, "to", to); |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
378 xmlnode_insert_child(error, item_not_found); |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
379 xmlnode_insert_child(result->node, error); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
380 |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
381 jabber_iq_send(result); |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
382 } |
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
383 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
384 void |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
385 jabber_ibb_parse(JabberStream *js, const char *who, JabberIqType type, |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
386 const char *id, xmlnode *child) |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
387 { |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
388 const char *name = child->name; |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
389 gboolean data = g_str_equal(name, "data"); |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
390 gboolean close = g_str_equal(name, "close"); |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
391 gboolean open = g_str_equal(name, "open"); |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
392 const gchar *sid = (data || close) ? |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
393 xmlnode_get_attrib(child, "sid") : NULL; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
394 JabberIBBSession *sess = |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
395 sid ? g_hash_table_lookup(jabber_ibb_sessions, sid) : NULL; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
396 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
397 if (sess) { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
398 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
399 if (strcmp(who, jabber_ibb_session_get_who(sess)) != 0) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
400 /* the iq comes from a different JID than the remote JID of the |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
401 session, ignore it */ |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
402 purple_debug_error("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
403 "Got IBB iq from wrong JID, ignoring\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
404 } else if (data) { |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
405 const gchar *seq_attr = xmlnode_get_attrib(child, "seq"); |
25759
69cf692c09f5
Fix error handling on missing "seq" attribute
Marcus Lundblad <ml@update.uu.se>
parents:
25756
diff
changeset
|
406 guint16 seq = (seq_attr ? atoi(seq_attr) : 0); |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
407 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
408 /* reject the data, and set the session in error if we get an |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
409 out-of-order packet */ |
25759
69cf692c09f5
Fix error handling on missing "seq" attribute
Marcus Lundblad <ml@update.uu.se>
parents:
25756
diff
changeset
|
410 if (seq_attr && seq == jabber_ibb_session_get_recv_seq(sess)) { |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
411 /* sequence # is the expected... */ |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
412 JabberIq *result = jabber_iq_new(js, JABBER_IQ_RESULT); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
413 |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
414 jabber_iq_set_id(result, id); |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
415 xmlnode_set_attrib(result->node, "to", who); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
416 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
417 if (sess->data_received_cb) { |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
418 gchar *base64 = xmlnode_get_data(child); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
419 gsize size; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
420 gpointer rawdata = purple_base64_decode(base64, &size); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
421 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
422 g_free(base64); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
423 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
424 if (rawdata) { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
425 purple_debug_info("jabber", |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
426 "got %" G_GSIZE_FORMAT " bytes of data on IBB stream\n", |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
427 size); |
29612
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
428 /* we accept other clients to send up to block-size |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
429 of _unencoded_ data, since there's been some confusions |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
430 regarding the interpretation of this attribute |
8f442c566ff2
jabber: Adjust amount of data to send in IBB packets so that at most block-size
Marcus Lundblad <ml@update.uu.se>
parents:
28650
diff
changeset
|
431 (including previous versions of libpurple) */ |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
432 if (size > jabber_ibb_session_get_block_size(sess)) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
433 purple_debug_error("jabber", |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
434 "IBB: received a too large packet\n"); |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
435 if (sess->error_cb) |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
436 sess->error_cb(sess); |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
437 g_free(rawdata); |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
438 return; |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
439 } else { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
440 purple_debug_info("jabber", |
25722
be762644486f
Actually close the assoiciated jsx when closing an IBB session.
Marcus Lundblad <ml@update.uu.se>
parents:
25719
diff
changeset
|
441 "calling IBB callback for received data\n"); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
442 sess->data_received_cb(sess, rawdata, size); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
443 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
444 g_free(rawdata); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
445 } else { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
446 purple_debug_error("jabber", |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
447 "IBB: invalid BASE64 data received\n"); |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
448 if (sess->error_cb) |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
449 sess->error_cb(sess); |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
450 return; |
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
451 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
452 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
453 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
454 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
455 (sess->recv_seq)++; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
456 jabber_iq_send(result); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
457 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
458 } else { |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
459 purple_debug_error("jabber", |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
460 "Received an out-of-order/invalid IBB packet\n"); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
461 sess->state = JABBER_IBB_SESSION_ERROR; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
462 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
463 if (sess->error_cb) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
464 sess->error_cb(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
465 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
466 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
467 } else if (close) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
468 sess->state = JABBER_IBB_SESSION_CLOSED; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
469 purple_debug_info("jabber", "IBB: received close\n"); |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
470 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
471 if (sess->closed_cb) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
472 purple_debug_info("jabber", "IBB: calling closed handler\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
473 sess->closed_cb(sess); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
474 } |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
475 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
476 } else { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
477 /* this should never happen */ |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
478 purple_debug_error("jabber", "Received bogus iq for IBB session\n"); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
479 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
480 } else if (open) { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
481 JabberIq *result; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
482 const GList *iterator; |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
483 |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
484 /* run all open handlers registered until one returns true */ |
25952
5f9a24d1c25e
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25759
diff
changeset
|
485 for (iterator = open_handlers ; iterator ; |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
486 iterator = g_list_next(iterator)) { |
25756
151b4054ce40
Trigger error callbacks when receiving a malformed-ish packet.
Paul Aurich <paul@darkrain42.org>
parents:
25755
diff
changeset
|
487 JabberIBBOpenHandler *handler = iterator->data; |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
488 |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
489 if (handler(js, who, id, child)) { |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
490 result = jabber_iq_new(js, JABBER_IQ_RESULT); |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
491 xmlnode_set_attrib(result->node, "to", who); |
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
492 jabber_iq_set_id(result, id); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
493 jabber_iq_send(result); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
494 return; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
495 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
496 } |
25733
51cbb9be484e
Set state error on IBBSession if the receiver gives an error.
Marcus Lundblad <ml@update.uu.se>
parents:
25722
diff
changeset
|
497 /* no open callback returned success, reject */ |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
498 jabber_ibb_send_error_response(js, who, id); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
499 } else { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
500 /* send error reply */ |
26473
50ff0162fe26
Convert IBB parser (and everything that then stems from that) to new iq-handler
Paul Aurich <paul@darkrain42.org>
parents:
26465
diff
changeset
|
501 jabber_ibb_send_error_response(js, who, id); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
502 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
503 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
504 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
505 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
506 jabber_ibb_register_open_handler(JabberIBBOpenHandler *cb) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
507 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
508 open_handlers = g_list_append(open_handlers, cb); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
509 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
510 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
511 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
512 jabber_ibb_unregister_open_handler(JabberIBBOpenHandler *cb) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
513 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
514 open_handlers = g_list_remove(open_handlers, cb); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
515 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
516 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
517 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
518 jabber_ibb_init(void) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
519 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
520 jabber_ibb_sessions = g_hash_table_new(g_str_hash, g_str_equal); |
26479
4dc4d0aa25f5
Move some IQ handler registrations to the appropriate init functions
Paul Aurich <paul@darkrain42.org>
parents:
26473
diff
changeset
|
521 |
28645
7b4ade7c6d8a
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents:
28070
diff
changeset
|
522 jabber_add_feature(NS_IBB, NULL); |
26803
1dfa009f6db5
Clean up jabber prpl memory allocations on uninit.
Nick Hebner <hebnern@gmail.com>
parents:
26479
diff
changeset
|
523 |
28645
7b4ade7c6d8a
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents:
28070
diff
changeset
|
524 jabber_iq_register_handler("close", NS_IBB, jabber_ibb_parse); |
7b4ade7c6d8a
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents:
28070
diff
changeset
|
525 jabber_iq_register_handler("data", NS_IBB, jabber_ibb_parse); |
7b4ade7c6d8a
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents:
28070
diff
changeset
|
526 jabber_iq_register_handler("open", NS_IBB, jabber_ibb_parse); |
25129
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
527 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
528 |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
529 void |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
530 jabber_ibb_uninit(void) |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
531 { |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
532 g_hash_table_destroy(jabber_ibb_sessions); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
533 g_list_free(open_handlers); |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
534 jabber_ibb_sessions = NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
535 open_handlers = NULL; |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
536 } |
b4ec5481a67a
Implements file transfers using in-band bytestreams for XMPP
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
537 |