comparison mcabber/src/jabglue.c @ 37:1441ba37a5c1

[/trunk] Changeset 53 by mikael * Work on libjabber integration. * Clean up.
author mikael
date Mon, 04 Apr 2005 20:16:16 +0000
parents 8f1a5e79ca40
children d79ff2ce61c4
comparison
equal deleted inserted replaced
36:8f1a5e79ca40 37:1441ba37a5c1
317 if (name) 317 if (name)
318 buddyname = name; 318 buddyname = name;
319 else 319 else
320 buddyname = jidtodisp(alias); 320 buddyname = jidtodisp(alias);
321 321
322 //scr_LogPrint("New buddy: %s", buddyname);
323 bud_AddBuddy(alias, buddyname); 322 bud_AddBuddy(alias, buddyname);
324 if (!name) 323 if (!name)
325 free(buddyname); 324 free(buddyname);
326 } 325 }
327 } 326 }
352 351
353 ut_WriteLog("StateHandler called (state=%d).\n", state); 352 ut_WriteLog("StateHandler called (state=%d).\n", state);
354 353
355 switch(state) { 354 switch(state) {
356 case JCONN_STATE_OFF: 355 case JCONN_STATE_OFF:
357 scr_LogPrint("+ JCONN_STATE_OFF"); 356
358 /* 357 /* jhook.flogged = jhook.fonline = FALSE; */
359 jhook.flogged = jhook.fonline = FALSE; 358
360 359 if (previous_state != JCONN_STATE_OFF) {
361 if (previous_state != JCONN_STATE_OFF) { 360 scr_LogPrint("+ JCONN_STATE_OFF");
362 logger.putourstatus(jhook.proto, jhook.getstatus(), jhook.ourstatus = offline); 361 /*
363 jhook.log(logDisconnected);
364 jhook.roster.clear(); 362 jhook.roster.clear();
365 jhook.agents.clear(); 363 jhook.agents.clear();
366 } 364 */
367 */ 365 }
368 break; 366 break;
369 367
370 case JCONN_STATE_CONNECTED: 368 case JCONN_STATE_CONNECTED:
371 scr_LogPrint("+ JCONN_STATE_CONNECTED"); 369 scr_LogPrint("+ JCONN_STATE_CONNECTED");
372 break; 370 break;
391 } 389 }
392 390
393 void packethandler(jconn conn, jpacket packet) 391 void packethandler(jconn conn, jpacket packet)
394 { 392 {
395 char *p; 393 char *p;
396 xmlnode x; // , y; 394 xmlnode x, y;
397 // string from, type, body, enc, ns, id, u, h, s; 395 // string from, type, body, enc, ns, id, u, h, s;
398 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; 396 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
399 char *ns=NULL; 397 char *ns=NULL;
400 char *id=NULL; 398 char *id=NULL;
401 enum imstatus ust; 399 enum imstatus ust;
404 402
405 jpacket_reset(packet); 403 jpacket_reset(packet);
406 404
407 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; 405 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
408 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; 406 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
409 //imcontact ic(jidtodisp(from), jhook.proto);
410 407
411 switch (packet->type) { 408 switch (packet->type) {
412 case JPACKET_MESSAGE: 409 case JPACKET_MESSAGE:
413 x = xmlnode_get_tag(packet->x, "body"); 410 x = xmlnode_get_tag(packet->x, "body");
414 p = xmlnode_get_data(x); if (p) body = p; 411 p = xmlnode_get_data(x); if (p) body = p;
417 if ((p = xmlnode_get_data(x)) != NULL) { 414 if ((p = xmlnode_get_data(x)) != NULL) {
418 char *tmp = malloc(strlen(body)+strlen(p)+3); 415 char *tmp = malloc(strlen(body)+strlen(p)+3);
419 strcpy(tmp, p); 416 strcpy(tmp, p);
420 strcat(tmp, ": "); 417 strcat(tmp, ": ");
421 strcat(tmp, body); 418 strcat(tmp, body);
422 body = tmp; // XXX check it is free'd later... 419 body = tmp; // XXX we should free it later...
423 } 420 }
424 421
425 /* there can be multiple <x> tags. we're looking for one with 422 /* there can be multiple <x> tags. we're looking for one with
426 xmlns = jabber:x:encrypted */ 423 xmlns = jabber:x:encrypted */
427 424
428 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) { 425 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
429 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) 426 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
430 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcasecmp(p, "jabber:x:encrypted")) 427 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
428 !strcasecmp(p, "jabber:x:encrypted"))
431 if ((p = xmlnode_get_data(x)) != NULL) { 429 if ((p = xmlnode_get_data(x)) != NULL) {
432 enc = p; 430 enc = p;
433 break; 431 break;
434 } 432 }
435 } 433 }
484 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; 482 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
485 483
486 if (!strcmp(ns, NS_ROSTER)) { 484 if (!strcmp(ns, NS_ROSTER)) {
487 gotroster(x); 485 gotroster(x);
488 } else if (!strcmp(ns, NS_AGENTS)) { 486 } else if (!strcmp(ns, NS_AGENTS)) {
489 /* TODO...
490 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { 487 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
491 const char *alias = xmlnode_get_attrib(y, "jid"); 488 const char *alias = xmlnode_get_attrib(y, "jid");
492 489
493 if (alias) { 490 if (alias) {
494 const char *name = xmlnode_get_tag_data(y, "name"); 491 const char *name = xmlnode_get_tag_data(y, "name");
495 const char *desc = xmlnode_get_tag_data(y, "description"); 492 const char *desc = xmlnode_get_tag_data(y, "description");
496 const char *service = xmlnode_get_tag_data(y, "service"); 493 const char *service = xmlnode_get_tag_data(y, "service");
497 agent::agent_type atype = agent::atUnknown; 494 enum agtype atype = unknown;
498 495
499 if (xmlnode_get_tag(y, "groupchat")) atype = agent::atGroupchat; else 496 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else
500 if (xmlnode_get_tag(y, "transport")) atype = agent::atTransport; else 497 if (xmlnode_get_tag(y, "transport")) atype = transport; else
501 if (xmlnode_get_tag(y, "search")) atype = agent::atSearch; 498 if (xmlnode_get_tag(y, "search")) atype = search;
502 499
503 if (alias && name && desc) { 500 if (alias && name && desc) {
504 jhook.agents.push_back(agent(alias, name, desc, atype)); 501 scr_LogPrint("Agent: %s / %s / %s / type=%d",
505 502 alias, name, desc, atype);
506 if (atype == agent::atSearch) { 503
504 if (atype == search) {
507 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); 505 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
508 xmlnode_put_attrib(x, "to", alias); 506 xmlnode_put_attrib(x, "to", alias);
509 xmlnode_put_attrib(x, "id", "Agent info"); 507 xmlnode_put_attrib(x, "id", "Agent info");
510 jab_send(conn, x); 508 jab_send(conn, x);
511 xmlnode_free(x); 509 xmlnode_free(x);
520 } 518 }
521 } 519 }
522 } 520 }
523 } 521 }
524 522
523 /*
525 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) 524 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
526 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, 525 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
527 _("Default Jabber conference server"), agent::atGroupchat)); 526 _("Default Jabber conference server"), agent::atGroupchat));
528 527
529 */ 528 */