413 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
413 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; |
414 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
414 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; |
415 |
415 |
416 switch (packet->type) { |
416 switch (packet->type) { |
417 case JPACKET_MESSAGE: |
417 case JPACKET_MESSAGE: |
418 x = xmlnode_get_tag(packet->x, "body"); |
418 { |
419 p = xmlnode_get_data(x); if (p) body = p; |
419 char *tmp = NULL; |
420 char *tmp = NULL; |
420 x = xmlnode_get_tag(packet->x, "body"); |
421 |
421 p = xmlnode_get_data(x); if (p) body = p; |
422 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
422 |
423 if ((p = xmlnode_get_data(x)) != NULL) { |
423 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
424 tmp = malloc(strlen(body)+strlen(p)+3); |
424 if ((p = xmlnode_get_data(x)) != NULL) { |
425 *tmp = '['; |
425 tmp = malloc(strlen(body)+strlen(p)+3); |
426 strcpy(tmp+1, p); |
426 *tmp = '['; |
427 strcat(tmp, "]\n"); |
427 strcpy(tmp+1, p); |
428 strcat(tmp, body); |
428 strcat(tmp, "]\n"); |
429 body = tmp; |
429 strcat(tmp, body); |
|
430 body = tmp; |
|
431 } |
|
432 |
|
433 /* there can be multiple <x> tags. we're looking for one with |
|
434 xmlns = jabber:x:encrypted */ |
|
435 |
|
436 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) { |
|
437 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
|
438 if ((p = xmlnode_get_attrib(x, "xmlns")) && |
|
439 !strcasecmp(p, "jabber:x:encrypted")) |
|
440 if ((p = xmlnode_get_data(x)) != NULL) { |
|
441 enc = p; |
|
442 break; |
|
443 } |
430 } |
444 } |
431 |
445 |
432 /* there can be multiple <x> tags. we're looking for one with |
446 if (body) |
433 xmlns = jabber:x:encrypted */ |
447 gotmessage(type, from, body, enc); |
434 |
448 if (tmp) |
435 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) { |
449 free(tmp); |
436 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
|
437 if ((p = xmlnode_get_attrib(x, "xmlns")) && |
|
438 !strcasecmp(p, "jabber:x:encrypted")) |
|
439 if ((p = xmlnode_get_data(x)) != NULL) { |
|
440 enc = p; |
|
441 break; |
|
442 } |
|
443 } |
450 } |
444 |
|
445 if (body) |
|
446 gotmessage(type, from, body, enc); |
|
447 if (tmp) |
|
448 free(tmp); |
|
449 break; |
451 break; |
450 |
452 |
451 case JPACKET_IQ: |
453 case JPACKET_IQ: |
452 if (!strcmp(type, "result")) { |
454 if (!strcmp(type, "result")) { |
453 |
455 |
557 } |
559 } |
558 } |
560 } |
559 } else if (!strcmp(type, "set")) { |
561 } else if (!strcmp(type, "set")) { |
560 } else if (!strcmp(type, "error")) { |
562 } else if (!strcmp(type, "error")) { |
561 char *name=NULL, *desc=NULL; |
563 char *name=NULL, *desc=NULL; |
562 int code; |
564 int code = 0; |
563 |
565 |
564 x = xmlnode_get_tag(packet->x, "error"); |
566 x = xmlnode_get_tag(packet->x, "error"); |
565 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p); |
567 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p); |
566 p = xmlnode_get_attrib(x, "id"); if (p) name = p; |
568 p = xmlnode_get_attrib(x, "id"); if (p) name = p; |
567 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p; |
569 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p; |