Mercurial > pidgin
annotate src/protocols/jabber/oob.c @ 8231:f50c059b6384
[gaim-migrate @ 8954]
This is Tim Ringenbach's patch to move some IP-related functions into the
new gaim_network namespace, improve the local IP checking functionality by
opening a socket, change some prefs, and add the ability to modify these
prefs in the UI. Some ft.c bugs were fixed, and OSCAR, Jabber and Yahoo
were updated to reflect the changes. The DCC SEND portion of this patch was
not committed, as per his request (unless I misunderstood? :)
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 12 Feb 2004 00:36:55 +0000 |
parents | b250288fa948 |
children | b5dbd1839716 |
rev | line source |
---|---|
7170 | 1 /* |
2 * gaim - Jabber Protocol Plugin | |
3 * | |
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 #include "internal.h" | |
7234 | 22 #include "debug.h" |
7170 | 23 #include "ft.h" |
24 #include "util.h" | |
25 | |
26 #include "jabber.h" | |
27 #include "iq.h" | |
28 | |
29 typedef struct _JabberOOBXfer { | |
30 char *address; | |
31 int port; | |
32 char *page; | |
33 | |
34 GString *headers; | |
35 gboolean newline; | |
36 | |
37 char *iq_id; | |
38 | |
39 JabberStream *js; | |
40 | |
41 } JabberOOBXfer; | |
42 | |
43 static void jabber_oob_xfer_init(GaimXfer *xfer) | |
44 { | |
45 JabberOOBXfer *jox = xfer->data; | |
46 gaim_xfer_start(xfer, -1, jox->address, jox->port); | |
47 } | |
48 | |
49 static void jabber_oob_xfer_free(GaimXfer *xfer) | |
50 { | |
51 JabberOOBXfer *jox = xfer->data; | |
7395 | 52 jox->js->oob_file_transfers = g_list_remove(jox->js->oob_file_transfers, |
53 xfer); | |
7170 | 54 |
55 g_string_free(jox->headers, TRUE); | |
56 g_free(jox->address); | |
57 g_free(jox->page); | |
58 g_free(jox->iq_id); | |
59 g_free(jox); | |
60 | |
61 xfer->data = NULL; | |
62 } | |
63 | |
64 static void jabber_oob_xfer_end(GaimXfer *xfer) | |
65 { | |
66 JabberOOBXfer *jox = xfer->data; | |
67 JabberIq *iq; | |
68 | |
69 iq = jabber_iq_new(jox->js, JABBER_IQ_RESULT); | |
70 xmlnode_set_attrib(iq->node, "to", xfer->who); | |
71 jabber_iq_set_id(iq, jox->iq_id); | |
72 | |
73 jabber_iq_send(iq); | |
74 | |
75 jabber_oob_xfer_free(xfer); | |
76 } | |
77 | |
78 static void jabber_oob_xfer_start(GaimXfer *xfer) | |
79 { | |
80 JabberOOBXfer *jox = xfer->data; | |
81 | |
82 char *buf = g_strdup_printf("GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", | |
83 jox->page, jox->address); | |
84 write(xfer->fd, buf, strlen(buf)); | |
85 g_free(buf); | |
86 } | |
87 | |
8231
f50c059b6384
[gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
7395
diff
changeset
|
88 static ssize_t jabber_oob_xfer_read(char **buffer, GaimXfer *xfer) { |
7170 | 89 JabberOOBXfer *jox = xfer->data; |
90 char test; | |
91 int size; | |
92 | |
93 if(read(xfer->fd, &test, sizeof(test)) > 0) { | |
94 jox->headers = g_string_append_c(jox->headers, test); | |
95 if(test == '\r') | |
96 return 0; | |
97 if(test == '\n') { | |
98 if(jox->newline) { | |
99 gchar *lenstr = strstr(jox->headers->str, "Content-Length: "); | |
100 if(lenstr) { | |
101 sscanf(lenstr, "Content-Length: %d", &size); | |
102 gaim_xfer_set_size(xfer, size); | |
103 } | |
104 gaim_xfer_set_read_fnc(xfer, NULL); | |
105 return 0; | |
106 } else | |
107 jox->newline = TRUE; | |
108 return 0; | |
109 } | |
110 jox->newline = FALSE; | |
111 return 0; | |
7234 | 112 } else { |
113 gaim_debug(GAIM_DEBUG_ERROR, "jabber", "Read error on oob xfer!\n"); | |
114 gaim_xfer_cancel_local(xfer); | |
7170 | 115 } |
7234 | 116 |
7170 | 117 return 0; |
118 } | |
119 | |
120 static void jabber_oob_xfer_cancel_send(GaimXfer *xfer) { | |
121 } | |
122 | |
123 static void jabber_oob_xfer_cancel_recv(GaimXfer *xfer) { | |
124 JabberOOBXfer *jox = xfer->data; | |
125 JabberIq *iq; | |
126 xmlnode *y; | |
127 | |
128 iq = jabber_iq_new(jox->js, JABBER_IQ_ERROR); | |
129 xmlnode_set_attrib(iq->node, "to", xfer->who); | |
130 jabber_iq_set_id(iq, jox->iq_id); | |
131 y = xmlnode_new_child(iq->node, "error"); | |
132 /* FIXME: need to handle other kinds of errors here */ | |
133 xmlnode_set_attrib(y, "code", "406"); | |
134 xmlnode_insert_data(y, "File Transfer Refused", -1); | |
135 | |
136 jabber_iq_send(iq); | |
137 | |
138 jabber_oob_xfer_free(xfer); | |
139 } | |
140 | |
141 void jabber_oob_parse(JabberStream *js, xmlnode *packet) { | |
142 JabberOOBXfer *jox; | |
143 GaimXfer *xfer; | |
144 char *filename; | |
145 char *url; | |
146 xmlnode *querynode, *urlnode; | |
147 | |
148 if(!(querynode = xmlnode_get_child(packet, "query"))) | |
149 return; | |
150 | |
151 if(!(urlnode = xmlnode_get_child(querynode, "url"))) | |
152 return; | |
153 | |
154 url = xmlnode_get_data(urlnode); | |
155 | |
156 jox = g_new0(JabberOOBXfer, 1); | |
157 gaim_url_parse(url, &jox->address, &jox->port, &jox->page); | |
158 g_free(url); | |
159 jox->js = js; | |
160 jox->headers = g_string_new(""); | |
161 jox->iq_id = g_strdup(xmlnode_get_attrib(packet, "id")); | |
162 | |
163 xfer = gaim_xfer_new(js->gc->account, GAIM_XFER_RECEIVE, | |
164 xmlnode_get_attrib(packet, "from")); | |
165 xfer->data = jox; | |
166 | |
167 if(!(filename = g_strdup(g_strrstr(jox->page, "/")))) | |
168 filename = g_strdup(jox->page); | |
169 | |
170 gaim_xfer_set_filename(xfer, filename); | |
171 | |
172 g_free(filename); | |
173 | |
174 gaim_xfer_set_init_fnc(xfer, jabber_oob_xfer_init); | |
175 gaim_xfer_set_end_fnc(xfer, jabber_oob_xfer_end); | |
176 gaim_xfer_set_cancel_send_fnc(xfer, jabber_oob_xfer_cancel_send); | |
177 gaim_xfer_set_cancel_recv_fnc(xfer, jabber_oob_xfer_cancel_recv); | |
178 gaim_xfer_set_read_fnc(xfer, jabber_oob_xfer_read); | |
179 gaim_xfer_set_start_fnc(xfer, jabber_oob_xfer_start); | |
180 | |
7395 | 181 js->oob_file_transfers = g_list_append(js->oob_file_transfers, xfer); |
7170 | 182 |
183 gaim_xfer_request(xfer); | |
184 } | |
185 | |
186 |