Mercurial > pidgin
annotate src/protocols/jabber/oob.c @ 10830:692da861f43c
[gaim-migrate @ 12497]
Fix pre-filling the screenname when adding a new person with the gevolution
plugin
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 16 Apr 2005 16:28:44 +0000 |
parents | 9171e528d7e5 |
children | bd8ac1d4b2f2 |
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 | |
8399 | 120 static void jabber_oob_xfer_recv_error(GaimXfer *xfer, const char *code) { |
7170 | 121 JabberOOBXfer *jox = xfer->data; |
122 JabberIq *iq; | |
8399 | 123 xmlnode *y, *z; |
7170 | 124 |
125 iq = jabber_iq_new(jox->js, JABBER_IQ_ERROR); | |
126 xmlnode_set_attrib(iq->node, "to", xfer->who); | |
127 jabber_iq_set_id(iq, jox->iq_id); | |
128 y = xmlnode_new_child(iq->node, "error"); | |
8399 | 129 xmlnode_set_attrib(y, "code", code); |
130 if(!strcmp(code, "406")) { | |
131 z = xmlnode_new_child(y, "not-acceptable"); | |
132 xmlnode_set_attrib(y, "type", "modify"); | |
133 xmlnode_set_attrib(z, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas"); | |
134 } else if(!strcmp(code, "404")) { | |
135 z = xmlnode_new_child(y, "not-found"); | |
136 xmlnode_set_attrib(y, "type", "cancel"); | |
137 xmlnode_set_attrib(z, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas"); | |
138 } | |
7170 | 139 jabber_iq_send(iq); |
140 | |
141 jabber_oob_xfer_free(xfer); | |
142 } | |
143 | |
8399 | 144 static void jabber_oob_xfer_recv_denied(GaimXfer *xfer) { |
145 jabber_oob_xfer_recv_error(xfer, "406"); | |
146 } | |
147 | |
148 static void jabber_oob_xfer_recv_canceled(GaimXfer *xfer) { | |
149 jabber_oob_xfer_recv_error(xfer, "404"); | |
150 } | |
151 | |
7170 | 152 void jabber_oob_parse(JabberStream *js, xmlnode *packet) { |
153 JabberOOBXfer *jox; | |
154 GaimXfer *xfer; | |
155 char *filename; | |
156 char *url; | |
157 xmlnode *querynode, *urlnode; | |
158 | |
159 if(!(querynode = xmlnode_get_child(packet, "query"))) | |
160 return; | |
161 | |
162 if(!(urlnode = xmlnode_get_child(querynode, "url"))) | |
163 return; | |
164 | |
165 url = xmlnode_get_data(urlnode); | |
166 | |
167 jox = g_new0(JabberOOBXfer, 1); | |
9227
9171e528d7e5
[gaim-migrate @ 10023]
Christian Hammond <chipx86@chipx86.com>
parents:
8399
diff
changeset
|
168 gaim_url_parse(url, &jox->address, &jox->port, &jox->page, NULL, NULL); |
7170 | 169 g_free(url); |
170 jox->js = js; | |
171 jox->headers = g_string_new(""); | |
172 jox->iq_id = g_strdup(xmlnode_get_attrib(packet, "id")); | |
173 | |
174 xfer = gaim_xfer_new(js->gc->account, GAIM_XFER_RECEIVE, | |
175 xmlnode_get_attrib(packet, "from")); | |
176 xfer->data = jox; | |
177 | |
178 if(!(filename = g_strdup(g_strrstr(jox->page, "/")))) | |
179 filename = g_strdup(jox->page); | |
180 | |
181 gaim_xfer_set_filename(xfer, filename); | |
182 | |
183 g_free(filename); | |
184 | |
185 gaim_xfer_set_init_fnc(xfer, jabber_oob_xfer_init); | |
186 gaim_xfer_set_end_fnc(xfer, jabber_oob_xfer_end); | |
8399 | 187 gaim_xfer_set_request_denied_fnc(xfer, jabber_oob_xfer_recv_denied); |
188 gaim_xfer_set_cancel_recv_fnc(xfer, jabber_oob_xfer_recv_canceled); | |
7170 | 189 gaim_xfer_set_read_fnc(xfer, jabber_oob_xfer_read); |
190 gaim_xfer_set_start_fnc(xfer, jabber_oob_xfer_start); | |
191 | |
7395 | 192 js->oob_file_transfers = g_list_append(js->oob_file_transfers, xfer); |
7170 | 193 |
194 gaim_xfer_request(xfer); | |
195 } | |
196 | |
197 |