Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 51:85bbc6ed3796
[/trunk] Changeset 67 by mikael
* "Warnings killing party"
* Some minor changes (for ex. fix a memory leak)
author | mikael |
---|---|
date | Wed, 06 Apr 2005 11:13:19 +0000 |
parents | f22e1d120606 |
children | 7d1c22aa2e5f |
comparison
equal
deleted
inserted
replaced
50:5425ee13dce6 | 51:85bbc6ed3796 |
---|---|
23 | 23 |
24 #include "../libjabber/jabber.h" | 24 #include "../libjabber/jabber.h" |
25 #include "jabglue.h" | 25 #include "jabglue.h" |
26 #include "screen.h" | 26 #include "screen.h" |
27 #include "utils.h" | 27 #include "utils.h" |
28 #include "buddies.h" | |
28 | 29 |
29 #define JABBERPORT 5222 | 30 #define JABBERPORT 5222 |
30 #define JABBERSSLPORT 5223 | 31 #define JABBERSSLPORT 5223 |
31 | 32 |
32 jconn jc; | 33 jconn jc; |
106 } | 107 } |
107 | 108 |
108 if (jc) | 109 if (jc) |
109 free(jc); | 110 free(jc); |
110 | 111 |
111 jc = jab_new(jid, pass, port, ssl); | 112 jc = jab_new((char*)jid, (char*)pass, port, ssl); |
112 | 113 |
113 jab_logger(jc, file_logger); | 114 jab_logger(jc, file_logger); |
114 jab_packet_handler(jc, &packethandler); | 115 jab_packet_handler(jc, &packethandler); |
115 jab_state_handler(jc, &statehandler); | 116 jab_state_handler(jc, &statehandler); |
116 | 117 |
204 break; | 205 break; |
205 | 206 |
206 case invisible: | 207 case invisible: |
207 xmlnode_put_attrib(x, "type", "invisible"); | 208 xmlnode_put_attrib(x, "type", "invisible"); |
208 break; | 209 break; |
210 | |
211 default: | |
212 break; | |
209 } | 213 } |
210 | 214 |
211 /* TODO | 215 /* TODO |
212 if (!add["prio"].empty()) | 216 if (!add["prio"].empty()) |
213 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), | 217 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), |
214 add["prio"].c_str(), (unsigned) -1); | 218 add["prio"].c_str(), (unsigned) -1); |
215 */ | 219 */ |
216 | 220 |
217 if (!msg || !*msg) { | 221 if (!msg || !*msg) { |
218 msg = "unknownStatus"; // FIXME | 222 msg = ""; // FIXME |
219 //msg = imstatus2str(st); | 223 //msg = imstatus2str(st); |
220 } | 224 } |
221 | 225 |
222 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg, | 226 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg, |
223 (unsigned) -1); | 227 (unsigned) -1); |
230 // XXX logger.putourstatus(proto, getstatus(), ourstatus = st); | 234 // XXX logger.putourstatus(proto, getstatus(), ourstatus = st); |
231 } | 235 } |
232 | 236 |
233 void jb_send_msg(const char *jid, const char *text) | 237 void jb_send_msg(const char *jid, const char *text) |
234 { | 238 { |
235 xmlnode x = jutil_msgnew(TMSG_CHAT, jid, 0, text); | 239 xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)text); |
236 jab_send(jc, x); | 240 jab_send(jc, x); |
237 xmlnode_free(x); | 241 xmlnode_free(x); |
238 } | 242 } |
239 | 243 |
240 void postlogin() | 244 void postlogin() |
307 { | 311 { |
308 xmlnode y, z; | 312 xmlnode y, z; |
309 | 313 |
310 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { | 314 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { |
311 const char *alias = xmlnode_get_attrib(y, "jid"); | 315 const char *alias = xmlnode_get_attrib(y, "jid"); |
312 const char *sub = xmlnode_get_attrib(y, "subscription"); | 316 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used |
313 const char *name = xmlnode_get_attrib(y, "name"); | 317 const char *name = xmlnode_get_attrib(y, "name"); |
314 const char *group = 0; | 318 const char *group = 0; |
315 | 319 |
316 z = xmlnode_get_tag(y, "group"); | 320 z = xmlnode_get_tag(y, "group"); |
317 if (z) group = xmlnode_get_data(z); | 321 if (z) group = xmlnode_get_data(z); |
318 | 322 |
319 if (alias) { | 323 if (alias) { |
320 char *buddyname; | 324 char *buddyname; |
321 if (name) | 325 if (name) |
322 buddyname = name; | 326 buddyname = (char*)name; |
323 else | 327 else |
324 buddyname = jidtodisp(alias); | 328 buddyname = jidtodisp(alias); |
325 | 329 |
326 bud_AddBuddy(alias, buddyname); | 330 bud_AddBuddy(alias, buddyname); |
327 if (!name) | 331 if (!name) |
411 | 415 |
412 switch (packet->type) { | 416 switch (packet->type) { |
413 case JPACKET_MESSAGE: | 417 case JPACKET_MESSAGE: |
414 x = xmlnode_get_tag(packet->x, "body"); | 418 x = xmlnode_get_tag(packet->x, "body"); |
415 p = xmlnode_get_data(x); if (p) body = p; | 419 p = xmlnode_get_data(x); if (p) body = p; |
420 char *tmp = NULL; | |
416 | 421 |
417 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) | 422 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
418 if ((p = xmlnode_get_data(x)) != NULL) { | 423 if ((p = xmlnode_get_data(x)) != NULL) { |
419 char *tmp = malloc(strlen(body)+strlen(p)+3); | 424 tmp = malloc(strlen(body)+strlen(p)+3); |
420 *tmp = '['; | 425 *tmp = '['; |
421 strcpy(tmp+1, p); | 426 strcpy(tmp+1, p); |
422 strcat(tmp, "]\n"); | 427 strcat(tmp, "]\n"); |
423 strcat(tmp, body); | 428 strcat(tmp, body); |
424 body = tmp; // XXX we should free it later... | 429 body = tmp; |
425 } | 430 } |
426 | 431 |
427 /* there can be multiple <x> tags. we're looking for one with | 432 /* there can be multiple <x> tags. we're looking for one with |
428 xmlns = jabber:x:encrypted */ | 433 xmlns = jabber:x:encrypted */ |
429 | 434 |
435 enc = p; | 440 enc = p; |
436 break; | 441 break; |
437 } | 442 } |
438 } | 443 } |
439 | 444 |
440 if (body) { | 445 if (body) |
441 gotmessage(type, from, body, enc); | 446 gotmessage(type, from, body, enc); |
442 } | 447 if (tmp) |
448 free(tmp); | |
443 break; | 449 break; |
444 | 450 |
445 case JPACKET_IQ: | 451 case JPACKET_IQ: |
446 if (!strcmp(type, "result")) { | 452 if (!strcmp(type, "result")) { |
447 | 453 |
448 if (p = xmlnode_get_attrib(packet->x, "id")) { | 454 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
449 int iid = atoi(p); | 455 int iid = atoi(p); |
450 | 456 |
451 ut_WriteLog("iid = %d\n", iid); | 457 ut_WriteLog("iid = %d\n", iid); |
452 if (iid == s_id) { | 458 if (iid == s_id) { |
453 if (!regmode) { | 459 if (!regmode) { |
454 if (jstate == STATE_GETAUTH) { | 460 if (jstate == STATE_GETAUTH) { |
455 if (x = xmlnode_get_tag(packet->x, "query")) | 461 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
456 if (!xmlnode_get_tag(x, "digest")) { | 462 if (!xmlnode_get_tag(x, "digest")) { |
457 jc->sid = 0; | 463 jc->sid = 0; |
458 } | 464 } |
459 | 465 |
460 s_id = atoi(jab_auth(jc)); | 466 s_id = atoi(jab_auth(jc)); |
481 scr_LogPrint("Got version"); | 487 scr_LogPrint("Got version"); |
482 return; | 488 return; |
483 } | 489 } |
484 } | 490 } |
485 | 491 |
486 if (x = xmlnode_get_tag(packet->x, "query")) { | 492 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
487 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; | 493 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
488 | 494 |
489 if (!strcmp(ns, NS_ROSTER)) { | 495 if (!strcmp(ns, NS_ROSTER)) { |
490 gotroster(x); | 496 gotroster(x); |
491 } else if (!strcmp(ns, NS_AGENTS)) { | 497 } else if (!strcmp(ns, NS_AGENTS)) { |
493 const char *alias = xmlnode_get_attrib(y, "jid"); | 499 const char *alias = xmlnode_get_attrib(y, "jid"); |
494 | 500 |
495 if (alias) { | 501 if (alias) { |
496 const char *name = xmlnode_get_tag_data(y, "name"); | 502 const char *name = xmlnode_get_tag_data(y, "name"); |
497 const char *desc = xmlnode_get_tag_data(y, "description"); | 503 const char *desc = xmlnode_get_tag_data(y, "description"); |
498 const char *service = xmlnode_get_tag_data(y, "service"); | 504 // const char *service = xmlnode_get_tag_data(y, "service"); TODO |
499 enum agtype atype = unknown; | 505 enum agtype atype = unknown; |
500 | 506 |
501 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else | 507 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else |
502 if (xmlnode_get_tag(y, "transport")) atype = transport; else | 508 if (xmlnode_get_tag(y, "transport")) atype = transport; else |
503 if (xmlnode_get_tag(y, "search")) atype = search; | 509 if (xmlnode_get_tag(y, "search")) atype = search; |