comparison src/protocols/jabber/jabber.c @ 7642:9008b5be4275

[gaim-migrate @ 8285] let the xmlnode stuff handle embedded NULLs (i'll need this later) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Wed, 26 Nov 2003 17:28:13 +0000
parents 2df4d470c12a
children e87e7d9d0132
comparison
equal deleted inserted replaced
7641:a80010831ff8 7642:9008b5be4275
54 "xmlns='jabber:client' " 54 "xmlns='jabber:client' "
55 "xmlns:stream='http://etherx.jabber.org/streams' " 55 "xmlns:stream='http://etherx.jabber.org/streams' "
56 "version='1.0'>", 56 "version='1.0'>",
57 js->user->domain); 57 js->user->domain);
58 58
59 jabber_send_raw(js, open_stream); 59 jabber_send_raw(js, open_stream, -1);
60 60
61 g_free(open_stream); 61 g_free(open_stream);
62 } 62 }
63 63
64 static void 64 static void
213 gaim_debug(GAIM_DEBUG_WARNING, "jabber", "Unknown packet: %s\n", 213 gaim_debug(GAIM_DEBUG_WARNING, "jabber", "Unknown packet: %s\n",
214 packet->name); 214 packet->name);
215 } 215 }
216 } 216 }
217 217
218 void jabber_send_raw(JabberStream *js, const char *data) 218 void jabber_send_raw(JabberStream *js, const char *data, int len)
219 { 219 {
220 int ret; 220 int ret;
221 221
222 /* because printing a tab to debug every minute gets old */ 222 /* because printing a tab to debug every minute gets old */
223 if(strcmp(data, "\t")) 223 if(strcmp(data, "\t"))
224 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n", 224 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n",
225 js->gsc ? " (ssl)" : "", data); 225 js->gsc ? " (ssl)" : "", data);
226 226
227 if(js->gsc) { 227 if(js->gsc) {
228 ret = gaim_ssl_write(js->gsc, data, strlen(data)); 228 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len);
229 } else { 229 } else {
230 ret = write(js->fd, data, strlen(data)); 230 ret = write(js->fd, data, len == -1 ? strlen(data) : len);
231 } 231 }
232 232
233 if(ret < 0) 233 if(ret < 0)
234 gaim_connection_error(js->gc, _("Write error")); 234 gaim_connection_error(js->gc, _("Write error"));
235 235
236 } 236 }
237 237
238 void jabber_send(JabberStream *js, xmlnode *packet) 238 void jabber_send(JabberStream *js, xmlnode *packet)
239 { 239 {
240 char *txt; 240 char *txt;
241 241 int len;
242 txt = xmlnode_to_str(packet); 242
243 jabber_send_raw(js, txt); 243 txt = xmlnode_to_str(packet, &len);
244 jabber_send_raw(js, txt, len);
244 g_free(txt); 245 g_free(txt);
245 } 246 }
246 247
247 static void jabber_keepalive(GaimConnection *gc) 248 static void jabber_keepalive(GaimConnection *gc)
248 { 249 {
249 jabber_send_raw(gc->proto_data, "\t"); 250 jabber_send_raw(gc->proto_data, "\t", -1);
250 } 251 }
251 252
252 static void 253 static void
253 jabber_recv_cb_ssl(gpointer data, GaimSslConnection *gsc, 254 jabber_recv_cb_ssl(gpointer data, GaimSslConnection *gsc,
254 GaimInputCondition cond) 255 GaimInputCondition cond)
305 } 306 }
306 307
307 js->gsc = gsc; 308 js->gsc = gsc;
308 309
309 if(js->state == JABBER_STREAM_CONNECTING) 310 if(js->state == JABBER_STREAM_CONNECTING)
310 jabber_send_raw(js, "<?xml version='1.0' ?>"); 311 jabber_send_raw(js, "<?xml version='1.0' ?>", -1);
311 312
312 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); 313 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING);
313 gaim_ssl_input_add(gsc, jabber_recv_cb_ssl, gc); 314 gaim_ssl_input_add(gsc, jabber_recv_cb_ssl, gc);
314 } 315 }
315 316
326 } 327 }
327 328
328 js->fd = source; 329 js->fd = source;
329 330
330 if(js->state == JABBER_STREAM_CONNECTING) 331 if(js->state == JABBER_STREAM_CONNECTING)
331 jabber_send_raw(js, "<?xml version='1.0' ?>"); 332 jabber_send_raw(js, "<?xml version='1.0' ?>", -1);
332 333
333 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING); 334 jabber_stream_set_state(js, JABBER_STREAM_INITIALIZING);
334 gc->inpa = gaim_input_add(js->fd, GAIM_INPUT_READ, jabber_recv_cb, gc); 335 gc->inpa = gaim_input_add(js->fd, GAIM_INPUT_READ, jabber_recv_cb, gc);
335 } 336 }
336 337
720 721
721 static void jabber_close(GaimConnection *gc) 722 static void jabber_close(GaimConnection *gc)
722 { 723 {
723 JabberStream *js = gc->proto_data; 724 JabberStream *js = gc->proto_data;
724 725
725 jabber_send_raw(js, "</stream:stream>"); 726 jabber_send_raw(js, "</stream:stream>", -1);
726 727
727 if(js->gsc) { 728 if(js->gsc) {
728 gaim_ssl_close(js->gsc); 729 gaim_ssl_close(js->gsc);
729 } else { 730 } else {
730 if(js->gc->inpa) 731 if(js->gc->inpa)