annotate src/protocols/jabber/oob.c @ 13714:4cf1db3ffada

[gaim-migrate @ 16122] SF Patch #1479292 from resiak This cleans up the Ctrl-Tab and Ctrl-Shift-Tab handling so it's easier to understand. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 02 May 2006 01:44:14 +0000
parents 33bef17125c2
children 25e63008d3bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim - Jabber Protocol Plugin
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
7234
cd0cedf0edd0 [gaim-migrate @ 7806]
Nathan Walp <nwalp@pidgin.im>
parents: 7170
diff changeset
22 #include "debug.h"
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "ft.h"
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "util.h"
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 #include "jabber.h"
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "iq.h"
12324
90f488e08216 [gaim-migrate @ 14628]
Richard Laager <rlaager@wiktel.com>
parents: 12323
diff changeset
28 #include "oob.h"
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 typedef struct _JabberOOBXfer {
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 char *address;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 int port;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 char *page;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 GString *headers;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 char *iq_id;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 JabberStream *js;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
41 gchar *write_buffer;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
42 gsize written_len;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
43 guint writeh;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
44
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 } JabberOOBXfer;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 static void jabber_oob_xfer_init(GaimXfer *xfer)
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 {
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 JabberOOBXfer *jox = xfer->data;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 gaim_xfer_start(xfer, -1, jox->address, jox->port);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 }
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 static void jabber_oob_xfer_free(GaimXfer *xfer)
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 {
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 JabberOOBXfer *jox = xfer->data;
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7234
diff changeset
56 jox->js->oob_file_transfers = g_list_remove(jox->js->oob_file_transfers,
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7234
diff changeset
57 xfer);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 g_string_free(jox->headers, TRUE);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 g_free(jox->address);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 g_free(jox->page);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 g_free(jox->iq_id);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
63 g_free(jox->write_buffer);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
64 if(jox->writeh)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
65 gaim_input_remove(jox->writeh);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 g_free(jox);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 xfer->data = NULL;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 }
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 static void jabber_oob_xfer_end(GaimXfer *xfer)
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 {
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 JabberOOBXfer *jox = xfer->data;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74 JabberIq *iq;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 iq = jabber_iq_new(jox->js, JABBER_IQ_RESULT);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 xmlnode_set_attrib(iq->node, "to", xfer->who);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 jabber_iq_set_id(iq, jox->iq_id);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 jabber_iq_send(iq);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 jabber_oob_xfer_free(xfer);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 }
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
85 static void jabber_oob_xfer_request_send(gpointer data, gint source, GaimInputCondition cond) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
86 GaimXfer *xfer = data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
87 JabberOOBXfer *jox = xfer->data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
88 int len, total_len = strlen(jox->write_buffer);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
89
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
90 len = write(xfer->fd, jox->write_buffer + jox->written_len,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
91 total_len - jox->written_len);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
92
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
93 if(len < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
94 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
95 else if(len < 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
96 gaim_debug(GAIM_DEBUG_ERROR, "jabber", "Write error on oob xfer!\n");
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
97 gaim_input_remove(jox->writeh);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
98 gaim_xfer_cancel_local(xfer);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
99 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
100 jox->written_len += len;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
101
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
102 if(jox->written_len == total_len) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
103 gaim_input_remove(jox->writeh);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
104 g_free(jox->write_buffer);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
105 jox->write_buffer = NULL;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
106 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
107 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
108
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 static void jabber_oob_xfer_start(GaimXfer *xfer)
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 {
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 JabberOOBXfer *jox = xfer->data;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
113 if(jox->write_buffer == NULL) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
114 jox->write_buffer = g_strdup_printf(
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
115 "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n",
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116 jox->page, jox->address);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
117 jox->written_len = 0;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
118 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
119
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
120 jox->writeh = gaim_input_add(xfer->fd, GAIM_INPUT_WRITE,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
121 jabber_oob_xfer_request_send, xfer);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
122
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
123 jabber_oob_xfer_request_send(xfer, xfer->fd, GAIM_INPUT_WRITE);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124 }
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125
12151
de798f2f4bf1 [gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents: 11159
diff changeset
126 static gssize jabber_oob_xfer_read(guchar **buffer, GaimXfer *xfer) {
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 JabberOOBXfer *jox = xfer->data;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
128 char test[2048];
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
129 char *tmp, *lenstr;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
130 int len;
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
132 if((len = read(xfer->fd, test, sizeof(test))) > 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
133 jox->headers = g_string_append_len(jox->headers, test, len);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
134 if((tmp = strstr(jox->headers->str, "\r\n\r\n"))) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
135 *tmp = '\0';
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
136 lenstr = strstr(jox->headers->str, "Content-Length: ");
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
137 if(lenstr) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
138 int size;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
139 sscanf(lenstr, "Content-Length: %d", &size);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
140 gaim_xfer_set_size(xfer, size);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
142 gaim_xfer_set_read_fnc(xfer, NULL);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
143
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
144 tmp += 4;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
145
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
146 *buffer = g_strdup(tmp);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
147 return strlen(tmp);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
148 }
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 return 0;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12324
diff changeset
150 } else if (errno != EAGAIN) {
7234
cd0cedf0edd0 [gaim-migrate @ 7806]
Nathan Walp <nwalp@pidgin.im>
parents: 7170
diff changeset
151 gaim_debug(GAIM_DEBUG_ERROR, "jabber", "Read error on oob xfer!\n");
cd0cedf0edd0 [gaim-migrate @ 7806]
Nathan Walp <nwalp@pidgin.im>
parents: 7170
diff changeset
152 gaim_xfer_cancel_local(xfer);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 }
7234
cd0cedf0edd0 [gaim-migrate @ 7806]
Nathan Walp <nwalp@pidgin.im>
parents: 7170
diff changeset
154
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 return 0;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 }
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157
8399
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
158 static void jabber_oob_xfer_recv_error(GaimXfer *xfer, const char *code) {
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 JabberOOBXfer *jox = xfer->data;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 JabberIq *iq;
8399
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
161 xmlnode *y, *z;
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 iq = jabber_iq_new(jox->js, JABBER_IQ_ERROR);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 xmlnode_set_attrib(iq->node, "to", xfer->who);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 jabber_iq_set_id(iq, jox->iq_id);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 y = xmlnode_new_child(iq->node, "error");
8399
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
167 xmlnode_set_attrib(y, "code", code);
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
168 if(!strcmp(code, "406")) {
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
169 z = xmlnode_new_child(y, "not-acceptable");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
170 xmlnode_set_attrib(y, "type", "modify");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
171 xmlnode_set_attrib(z, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
172 } else if(!strcmp(code, "404")) {
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
173 z = xmlnode_new_child(y, "not-found");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
174 xmlnode_set_attrib(y, "type", "cancel");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
175 xmlnode_set_attrib(z, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
176 }
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177 jabber_iq_send(iq);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
178
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 jabber_oob_xfer_free(xfer);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180 }
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181
8399
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
182 static void jabber_oob_xfer_recv_denied(GaimXfer *xfer) {
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
183 jabber_oob_xfer_recv_error(xfer, "406");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
184 }
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
185
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
186 static void jabber_oob_xfer_recv_canceled(GaimXfer *xfer) {
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
187 jabber_oob_xfer_recv_error(xfer, "404");
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
188 }
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
189
12324
90f488e08216 [gaim-migrate @ 14628]
Richard Laager <rlaager@wiktel.com>
parents: 12323
diff changeset
190 void jabber_oob_parse(JabberStream *js, xmlnode *packet) {
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191 JabberOOBXfer *jox;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 GaimXfer *xfer;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
193 char *filename;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
194 char *url;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195 xmlnode *querynode, *urlnode;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 if(!(querynode = xmlnode_get_child(packet, "query")))
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 return;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 if(!(urlnode = xmlnode_get_child(querynode, "url")))
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 return;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 url = xmlnode_get_data(urlnode);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 jox = g_new0(JabberOOBXfer, 1);
9227
9171e528d7e5 [gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents: 8399
diff changeset
206 gaim_url_parse(url, &jox->address, &jox->port, &jox->page, NULL, NULL);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 g_free(url);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208 jox->js = js;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 jox->headers = g_string_new("");
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210 jox->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 xfer = gaim_xfer_new(js->gc->account, GAIM_XFER_RECEIVE,
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 xmlnode_get_attrib(packet, "from"));
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 xfer->data = jox;
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 if(!(filename = g_strdup(g_strrstr(jox->page, "/"))))
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 filename = g_strdup(jox->page);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 gaim_xfer_set_filename(xfer, filename);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 g_free(filename);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 gaim_xfer_set_init_fnc(xfer, jabber_oob_xfer_init);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 gaim_xfer_set_end_fnc(xfer, jabber_oob_xfer_end);
8399
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
225 gaim_xfer_set_request_denied_fnc(xfer, jabber_oob_xfer_recv_denied);
681b1661ee8b [gaim-migrate @ 9128]
Nathan Walp <nwalp@pidgin.im>
parents: 8311
diff changeset
226 gaim_xfer_set_cancel_recv_fnc(xfer, jabber_oob_xfer_recv_canceled);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227 gaim_xfer_set_read_fnc(xfer, jabber_oob_xfer_read);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228 gaim_xfer_set_start_fnc(xfer, jabber_oob_xfer_start);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7234
diff changeset
230 js->oob_file_transfers = g_list_append(js->oob_file_transfers, xfer);
7170
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 gaim_xfer_request(xfer);
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 }
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234
1cf80749f2f0 [gaim-migrate @ 7737]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235