Mercurial > pidgin.yaz
comparison plugins/jabber/jabber.c @ 1920:5bed3bc833b5
[gaim-migrate @ 1930]
in addition, frombase64 mods, needed for buddy icon in toc.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 30 May 2001 18:26:52 +0000 |
parents | fdb2fe2a043e |
children | 8de58cd2892f |
comparison
equal
deleted
inserted
replaced
1919:4dcaa4afc6c0 | 1920:5bed3bc833b5 |
---|---|
578 return result; | 578 return result; |
579 } | 579 } |
580 | 580 |
581 static void jabber_handlemessage(gjconn j, jpacket p) | 581 static void jabber_handlemessage(gjconn j, jpacket p) |
582 { | 582 { |
583 xmlnode y, xmlns; | 583 xmlnode y, xmlns, subj; |
584 | 584 |
585 char *from = NULL, *msg = NULL, *type = NULL; | 585 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; |
586 char m[BUF_LONG * 2]; | 586 char m[BUF_LONG * 2]; |
587 | 587 |
588 type = xmlnode_get_attrib(p->x, "type"); | 588 type = xmlnode_get_attrib(p->x, "type"); |
589 | 589 |
590 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { | 590 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { |
656 if ((y = xmlnode_get_tag(p->x, "body"))) { | 656 if ((y = xmlnode_get_tag(p->x, "body"))) { |
657 msg = xmlnode_get_data(y); | 657 msg = xmlnode_get_data(y); |
658 } | 658 } |
659 | 659 |
660 msg = utf8_to_str(msg); | 660 msg = utf8_to_str(msg); |
661 | |
662 if ((subj = xmlnode_get_tag(p->x, "subject"))) { | |
663 topic = xmlnode_get_data(subj); | |
664 } | |
665 topic = utf8_to_str(topic); | |
661 | 666 |
662 jc = find_existing_chat(GJ_GC(j), p->from); | 667 jc = find_existing_chat(GJ_GC(j), p->from); |
663 if (!jc) { | 668 if (!jc) { |
664 /* we're not in this chat. are we supposed to be? */ | 669 /* we're not in this chat. are we supposed to be? */ |
665 struct jabber_data *jd = GJ_GC(j)->proto_data; | 670 struct jabber_data *jd = GJ_GC(j)->proto_data; |
686 p->from->resource, msg); | 691 p->from->resource, msg); |
687 write_to_conv(jc->b, buf, WFLAG_SYSTEM, NULL, time(NULL)); | 692 write_to_conv(jc->b, buf, WFLAG_SYSTEM, NULL, time(NULL)); |
688 } | 693 } |
689 } else if (jc->b && msg) { | 694 } else if (jc->b && msg) { |
690 char buf[8192]; | 695 char buf[8192]; |
696 | |
697 if (topic) { | |
698 char tbuf[8192]; | |
699 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
700 chat_set_topic(jc->b, p->from->resource, tbuf); | |
701 } | |
702 | |
703 | |
691 g_snprintf(buf, sizeof(buf), "%s", msg); | 704 g_snprintf(buf, sizeof(buf), "%s", msg); |
692 serv_got_chat_in(GJ_GC(j), jc->b->id, p->from->resource, 0, buf, time(NULL)); | 705 serv_got_chat_in(GJ_GC(j), jc->b->id, p->from->resource, 0, buf, time(NULL)); |
693 } | 706 } |
707 } else { /* message from the server */ | |
708 if(jc->b && topic) { | |
709 char tbuf[8192]; | |
710 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
711 chat_set_topic(jc->b, "", tbuf); | |
712 } | |
694 } | 713 } |
695 | 714 |
696 free(msg); | 715 free(msg); |
716 free(topic); | |
697 | 717 |
698 } else { | 718 } else { |
699 debug_printf("unhandled message %s\n", type); | 719 debug_printf("unhandled message %s\n", type); |
700 } | 720 } |
701 } | 721 } |
1491 xmlnode_put_attrib(x, "type", "groupchat"); | 1511 xmlnode_put_attrib(x, "type", "groupchat"); |
1492 | 1512 |
1493 if (message && strlen(message)) { | 1513 if (message && strlen(message)) { |
1494 y = xmlnode_insert_tag(x, "body"); | 1514 y = xmlnode_insert_tag(x, "body"); |
1495 xmlnode_insert_cdata(y, message, -1); | 1515 xmlnode_insert_cdata(y, message, -1); |
1516 } | |
1517 | |
1518 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | |
1519 xmlnode_free(x); | |
1520 } | |
1521 | |
1522 static void jabber_chat_set_topic(struct gaim_connection *gc, int id, char *topic) | |
1523 { | |
1524 GSList *bcs = gc->buddy_chats; | |
1525 struct conversation *b; | |
1526 struct jabber_data *jd = gc->proto_data; | |
1527 xmlnode x, y; | |
1528 struct jabber_chat *jc; | |
1529 char *chatname; | |
1530 char buf[8192]; | |
1531 | |
1532 while (bcs) { | |
1533 b = bcs->data; | |
1534 if (id == b->id) | |
1535 break; | |
1536 bcs = bcs->next; | |
1537 } | |
1538 if (!bcs) | |
1539 return; | |
1540 | |
1541 bcs = jd->existing_chats; | |
1542 while (bcs) { | |
1543 jc = bcs->data; | |
1544 if (jc->b == b) | |
1545 break; | |
1546 bcs = bcs->next; | |
1547 } | |
1548 if (!bcs) | |
1549 return; | |
1550 | |
1551 x = xmlnode_new_tag("message"); | |
1552 xmlnode_put_attrib(x, "from", jid_full(jc->Jid)); | |
1553 chatname = g_strdup_printf("%s@%s", jc->Jid->user, jc->Jid->server); | |
1554 xmlnode_put_attrib(x, "to", chatname); | |
1555 g_free(chatname); | |
1556 xmlnode_put_attrib(x, "type", "groupchat"); | |
1557 | |
1558 if (topic && strlen(topic)) { | |
1559 y = xmlnode_insert_tag(x, "subject"); | |
1560 xmlnode_insert_cdata(y, topic, -1); | |
1561 y = xmlnode_insert_tag(x, "body"); | |
1562 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", topic); | |
1563 xmlnode_insert_cdata(y, buf, -1); | |
1496 } | 1564 } |
1497 | 1565 |
1498 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); | 1566 gjab_send(((struct jabber_data *)gc->proto_data)->jc, x); |
1499 xmlnode_free(x); | 1567 xmlnode_free(x); |
1500 } | 1568 } |
1941 ret->accept_chat = NULL; | 2009 ret->accept_chat = NULL; |
1942 ret->join_chat = jabber_join_chat; | 2010 ret->join_chat = jabber_join_chat; |
1943 ret->chat_invite = jabber_chat_invite; | 2011 ret->chat_invite = jabber_chat_invite; |
1944 ret->chat_leave = jabber_chat_leave; | 2012 ret->chat_leave = jabber_chat_leave; |
1945 ret->chat_whisper = jabber_chat_whisper; | 2013 ret->chat_whisper = jabber_chat_whisper; |
2014 ret->chat_set_topic = jabber_chat_set_topic; | |
1946 ret->chat_send = jabber_chat_send; | 2015 ret->chat_send = jabber_chat_send; |
1947 ret->keepalive = NULL; | 2016 ret->keepalive = NULL; |
1948 ret->normalize = jabber_normalize; | 2017 ret->normalize = jabber_normalize; |
1949 | 2018 |
1950 my_protocol = ret; | 2019 my_protocol = ret; |