Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 387:2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 29 Jul 2005 19:09:07 +0100 |
parents | d59e9b8c91d3 |
children | f8f3c7493457 |
comparison
equal
deleted
inserted
replaced
386:41ef80a34ba5 | 387:2bbeef7b4fdd |
---|---|
33 #define JABBERPORT 5222 | 33 #define JABBERPORT 5222 |
34 #define JABBERSSLPORT 5223 | 34 #define JABBERSSLPORT 5223 |
35 | 35 |
36 #define JABBER_AGENT_GROUP "Jabber Agents" | 36 #define JABBER_AGENT_GROUP "Jabber Agents" |
37 | 37 |
38 #define to_utf8(s) ((s) ? g_locale_to_utf8((s), -1, NULL,NULL,NULL) : NULL) | |
39 #define from_utf8(s) ((s) ? g_locale_from_utf8((s), -1, NULL,NULL,NULL) : NULL) | |
40 | |
38 jconn jc; | 41 jconn jc; |
39 static time_t LastPingTime; | 42 static time_t LastPingTime; |
40 static unsigned int KeepaliveDelay; | 43 static unsigned int KeepaliveDelay; |
41 static unsigned int prio; | 44 static unsigned int prio; |
42 static int s_id; | 45 static int s_id; |
284 } | 287 } |
285 | 288 |
286 if (!msg) | 289 if (!msg) |
287 msg = settings_get_status_msg(st); | 290 msg = settings_get_status_msg(st); |
288 | 291 |
289 utf8_msg = g_locale_to_utf8(msg, -1, NULL, NULL, NULL); | 292 utf8_msg = to_utf8(msg); |
290 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg, | 293 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg, |
291 (unsigned) -1); | 294 (unsigned) -1); |
292 | 295 |
293 jab_send(jc, x); | 296 jab_send(jc, x); |
294 xmlnode_free(x); | 297 xmlnode_free(x); |
305 mystatus = st; | 308 mystatus = st; |
306 } | 309 } |
307 | 310 |
308 void jb_send_msg(const char *jid, const char *text) | 311 void jb_send_msg(const char *jid, const char *text) |
309 { | 312 { |
310 gchar *buffer = g_locale_to_utf8(text, -1, NULL, NULL, NULL); | 313 gchar *buffer = to_utf8(text); |
311 xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)buffer); | 314 xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)buffer); |
312 jab_send(jc, x); | 315 jab_send(jc, x); |
313 xmlnode_free(x); | 316 xmlnode_free(x); |
314 g_free(buffer); | 317 g_free(buffer); |
315 jb_reset_keepalive(); | 318 jb_reset_keepalive(); |
335 y = xmlnode_get_tag(x, "query"); | 338 y = xmlnode_get_tag(x, "query"); |
336 z = xmlnode_insert_tag(y, "item"); | 339 z = xmlnode_insert_tag(y, "item"); |
337 xmlnode_put_attrib(z, "jid", jid); | 340 xmlnode_put_attrib(z, "jid", jid); |
338 | 341 |
339 if (name) { | 342 if (name) { |
340 gchar *name_utf8 = g_locale_to_utf8(name, -1, NULL, NULL, NULL); | 343 gchar *name_utf8 = to_utf8(name); |
341 z = xmlnode_insert_tag(z, "name"); | 344 z = xmlnode_insert_tag(z, "name"); |
342 xmlnode_insert_cdata(z, name_utf8, (unsigned) -1); | 345 xmlnode_insert_cdata(z, name_utf8, (unsigned) -1); |
343 g_free(name_utf8); | 346 g_free(name_utf8); |
344 } | 347 } |
345 | 348 |
346 if (group) { | 349 if (group) { |
347 char *group_utf8 = g_locale_to_utf8(group, -1, NULL, NULL, NULL); | 350 char *group_utf8 = to_utf8(group); |
348 z = xmlnode_insert_tag(z, "group"); | 351 z = xmlnode_insert_tag(z, "group"); |
349 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1); | 352 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1); |
350 g_free(group_utf8); | 353 g_free(group_utf8); |
351 } | 354 } |
352 | 355 |
412 if (!online) return; | 415 if (!online) return; |
413 | 416 |
414 // XXX We should check name's and group's correctness | 417 // XXX We should check name's and group's correctness |
415 | 418 |
416 cleanjid = jidtodisp(jid); | 419 cleanjid = jidtodisp(jid); |
417 name_utf8 = g_locale_to_utf8(name, -1, NULL, NULL, NULL); | 420 name_utf8 = to_utf8(name); |
418 | 421 |
419 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | 422 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); |
420 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | 423 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); |
421 xmlnode_put_attrib(y, "jid", cleanjid); | 424 xmlnode_put_attrib(y, "jid", cleanjid); |
422 xmlnode_put_attrib(y, "name", name_utf8); | 425 xmlnode_put_attrib(y, "name", name_utf8); |
423 | 426 |
424 if (group) { | 427 if (group) { |
425 gchar *group_utf8 = g_locale_to_utf8(group, -1, NULL, NULL, NULL); | 428 gchar *group_utf8 = to_utf8(group); |
426 y = xmlnode_insert_tag(y, "group"); | 429 y = xmlnode_insert_tag(y, "group"); |
427 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1); | 430 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1); |
428 g_free(group_utf8); | 431 g_free(group_utf8); |
429 } | 432 } |
430 | 433 |
519 char *cleanalias = jidtodisp(alias); | 522 char *cleanalias = jidtodisp(alias); |
520 gchar *name_noutf8 = NULL; | 523 gchar *name_noutf8 = NULL; |
521 gchar *group_noutf8 = NULL; | 524 gchar *group_noutf8 = NULL; |
522 | 525 |
523 if (name) { | 526 if (name) { |
524 name_noutf8 = g_locale_from_utf8(name, -1, NULL, NULL, NULL); | 527 name_noutf8 = from_utf8(name); |
525 buddyname = name_noutf8; | 528 buddyname = name_noutf8; |
526 } else | 529 } else |
527 buddyname = cleanalias; | 530 buddyname = cleanalias; |
528 | 531 |
529 if (group) | 532 if (group) |
530 group_noutf8 = g_locale_from_utf8(group, -1, NULL, NULL, NULL); | 533 group_noutf8 = from_utf8(group); |
531 | 534 |
532 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER); | 535 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER); |
533 if (name_noutf8) g_free(name_noutf8); | 536 if (name_noutf8) g_free(name_noutf8); |
534 if (group_noutf8) g_free(group_noutf8); | 537 if (group_noutf8) g_free(group_noutf8); |
535 g_free(cleanalias); | 538 g_free(cleanalias); |
541 | 544 |
542 void gotmessage(char *type, const char *from, const char *body, | 545 void gotmessage(char *type, const char *from, const char *body, |
543 const char *enc, time_t timestamp) | 546 const char *enc, time_t timestamp) |
544 { | 547 { |
545 char *jid; | 548 char *jid; |
546 gchar *buffer = g_locale_from_utf8(body, -1, NULL, NULL, NULL); | 549 gchar *buffer = from_utf8(body); |
547 | 550 |
548 /* | 551 /* |
549 //char *u, *h, *r; | 552 //char *u, *h, *r; |
550 //jidsplit(from, &u, &h, &r); | 553 //jidsplit(from, &u, &h, &r); |
551 // Maybe we should remember the resource? | 554 // Maybe we should remember the resource? |
850 | 853 |
851 if (type && !strcmp(type, "unavailable")) | 854 if (type && !strcmp(type, "unavailable")) |
852 ust = offline; | 855 ust = offline; |
853 | 856 |
854 if ((x = xmlnode_get_tag(packet->x, "status")) != NULL) | 857 if ((x = xmlnode_get_tag(packet->x, "status")) != NULL) |
855 p = g_locale_from_utf8(xmlnode_get_data(x), -1, NULL, NULL, NULL); | 858 p = from_utf8(xmlnode_get_data(x)); |
856 else | 859 else |
857 p = NULL; | 860 p = NULL; |
858 | 861 |
859 r = jidtodisp(from); | 862 r = jidtodisp(from); |
860 // Call hk_statuschange() if status has changed or if the | 863 // Call hk_statuschange() if status has changed or if the |