comparison libpurple/protocols/jabber/presence.c @ 25228:6fed1bb3b02e

Fix merge
author Marcus Lundblad <ml@update.uu.se>
date Wed, 17 Dec 2008 18:23:36 +0000
parents 9100b9176a16
children b1a16f0efec2
comparison
equal deleted inserted replaced
25227:9100b9176a16 25228:6fed1bb3b02e
149 149
150 #define CHANGED(a,b) ((!a && b) || (a && a[0] == '\0' && b && b[0] != '\0') || \ 150 #define CHANGED(a,b) ((!a && b) || (a && a[0] == '\0' && b && b[0] != '\0') || \
151 (a && !b) || (a && a[0] != '\0' && b && b[0] == '\0') || (a && b && strcmp(a,b))) 151 (a && !b) || (a && a[0] != '\0' && b && b[0] == '\0') || (a && b && strcmp(a,b)))
152 /* check if there are any differences to the <presence> and send them in that case */ 152 /* check if there are any differences to the <presence> and send them in that case */
153 if (allowBuzz != js->allowBuzz || js->old_state != state || CHANGED(js->old_msg, stripped) || 153 if (allowBuzz != js->allowBuzz || js->old_state != state || CHANGED(js->old_msg, stripped) ||
154 js->old_priority != priority || CHANGED(js->old_avatarhash, js->avatar_hash)) { 154 js->old_priority != priority || CHANGED(js->old_avatarhash, js->avatar_hash) ||
155 js->old_idle != js->idle) {
155 js->allowBuzz = allowBuzz; 156 js->allowBuzz = allowBuzz;
156 157
157 presence = jabber_presence_create_js(js, state, stripped, priority); 158 presence = jabber_presence_create_js(js, state, stripped, priority);
158 159
159 if(js->avatar_hash) { 160 if(js->avatar_hash) {
176 g_free(js->old_avatarhash); 177 g_free(js->old_avatarhash);
177 js->old_msg = g_strdup(stripped); 178 js->old_msg = g_strdup(stripped);
178 js->old_avatarhash = g_strdup(js->avatar_hash); 179 js->old_avatarhash = g_strdup(js->avatar_hash);
179 js->old_state = state; 180 js->old_state = state;
180 js->old_priority = priority; 181 js->old_priority = priority;
182 js->old_idle = js->idle;
181 } 183 }
182 g_free(stripped); 184 g_free(stripped);
183 185
184 /* next, check if there are any changes to the tune values */ 186 /* next, check if there are any changes to the tune values */
185 tune = purple_presence_get_status(p, "tune"); 187 tune = purple_presence_get_status(p, "tune");
258 pri = xmlnode_new_child(presence, "priority"); 260 pri = xmlnode_new_child(presence, "priority");
259 xmlnode_insert_data(pri, pstr, -1); 261 xmlnode_insert_data(pri, pstr, -1);
260 g_free(pstr); 262 g_free(pstr);
261 } 263 }
262 264
265 /* if we are idle and not offline, include idle */
266 if (js->idle && state != JABBER_BUDDY_STATE_UNAVAILABLE) {
267 xmlnode *query = xmlnode_new_child(presence, "query");
268 gchar seconds[10];
269 g_snprintf(seconds, 10, "%d", (int) (time(NULL) - js->idle));
270
271 xmlnode_set_namespace(query, "jabber:iq:last");
272 xmlnode_set_attrib(query, "seconds", seconds);
273 }
274
263 /* JEP-0115 */ 275 /* JEP-0115 */
264 c = xmlnode_new_child(presence, "c"); 276 c = xmlnode_new_child(presence, "c");
265 xmlnode_set_namespace(c, "http://jabber.org/protocol/caps"); 277 xmlnode_set_namespace(c, "http://jabber.org/protocol/caps");
266 xmlnode_set_attrib(c, "node", CAPS0115_NODE); 278 xmlnode_set_attrib(c, "node", CAPS0115_NODE);
267 xmlnode_set_attrib(c, "ver", VERSION); 279 xmlnode_set_attrib(c, "ver", VERSION);
425 JabberChat *chat; 437 JabberChat *chat;
426 JabberBuddy *jb; 438 JabberBuddy *jb;
427 JabberBuddyResource *jbr = NULL, *found_jbr = NULL; 439 JabberBuddyResource *jbr = NULL, *found_jbr = NULL;
428 PurpleConvChatBuddyFlags flags = PURPLE_CBFLAGS_NONE; 440 PurpleConvChatBuddyFlags flags = PURPLE_CBFLAGS_NONE;
429 gboolean delayed = FALSE; 441 gboolean delayed = FALSE;
442 const gchar *stamp = NULL; /* from <delayed/> element */
430 PurpleBuddy *b = NULL; 443 PurpleBuddy *b = NULL;
431 char *buddy_name; 444 char *buddy_name;
432 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN; 445 JabberBuddyState state = JABBER_BUDDY_STATE_UNKNOWN;
433 xmlnode *y; 446 xmlnode *y;
434 gboolean muc = FALSE; 447 gboolean muc = FALSE;
435 char *avatar_hash = NULL; 448 char *avatar_hash = NULL;
436 xmlnode *caps = NULL; 449 xmlnode *caps = NULL;
437 450 int idle = 0;
451
438 if(!(jb = jabber_buddy_find(js, from, TRUE))) 452 if(!(jb = jabber_buddy_find(js, from, TRUE)))
439 return; 453 return;
440 454
441 if(!(jid = jabber_id_new(from))) 455 if(!(jid = jabber_id_new(from)))
442 return; 456 return;
511 g_free(p); 525 g_free(p);
512 } 526 }
513 } else if(!strcmp(y->name, "delay") && !strcmp(xmlns, "urn:xmpp:delay")) { 527 } else if(!strcmp(y->name, "delay") && !strcmp(xmlns, "urn:xmpp:delay")) {
514 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ 528 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */
515 delayed = TRUE; 529 delayed = TRUE;
530 stamp = xmlnode_get_attrib(y, "stamp");
516 } else if(xmlns && !strcmp(y->name, "c") && !strcmp(xmlns, "http://jabber.org/protocol/caps")) { 531 } else if(xmlns && !strcmp(y->name, "c") && !strcmp(xmlns, "http://jabber.org/protocol/caps")) {
517 caps = y; /* store for later, when creating buddy resource */ 532 caps = y; /* store for later, when creating buddy resource */
518 } else if(!strcmp(y->name, "x")) { 533 } else if(!strcmp(y->name, "x")) {
519 const char *xmlns = xmlnode_get_namespace(y); 534 const char *xmlns = xmlnode_get_namespace(y);
520 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { 535 if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
521 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */ 536 /* XXX: compare the time. jabber:x:delay can happen on presence packets that aren't really and truly delayed */
522 delayed = TRUE; 537 delayed = TRUE;
538 stamp = xmlnode_get_attrib(y, "stamp");
523 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) { 539 } else if(xmlns && !strcmp(xmlns, "http://jabber.org/protocol/muc#user")) {
524 xmlnode *z; 540 xmlnode *z;
525 541
526 muc = TRUE; 542 muc = TRUE;
527 if((z = xmlnode_get_child(y, "status"))) { 543 if((z = xmlnode_get_child(y, "status"))) {
568 if(photo) { 584 if(photo) {
569 g_free(avatar_hash); 585 g_free(avatar_hash);
570 avatar_hash = xmlnode_get_data(photo); 586 avatar_hash = xmlnode_get_data(photo);
571 } 587 }
572 } 588 }
573 } 589 } else if (!strcmp(y->name, "query") &&
574 } 590 !strcmp(xmlnode_get_namespace(y), "jabber:iq:last")) {
575 591 /* resource has specified idle */
592 const gchar *seconds = xmlnode_get_attrib(y, "seconds");
593 if (seconds) {
594 /* we may need to take "delayed" into account here */
595 idle = atoi(seconds);
596 }
597 }
598 }
599
600 purple_debug_info("jabber", "got %d seconds idle from presence\n", idle);
601
602 if (idle && delayed && stamp) {
603 /* if we have a delayed presence, we need to add the delay to the idle
604 value */
605 time_t offset = time(NULL) - purple_str_to_time(stamp, TRUE, NULL, NULL,
606 NULL);
607 purple_debug_info("jabber", "got delay %s yielding %ld s offset\n",
608 stamp, offset);
609 idle += offset;
610 }
611
576 612
577 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { 613 if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) {
578 static int i = 1; 614 static int i = 1;
579 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); 615 char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain);
580 616
745 purple_conversation_set_name(conv, buddy_name); 781 purple_conversation_set_name(conv, buddy_name);
746 782
747 } else { 783 } else {
748 jbr = jabber_buddy_track_resource(jb, jid->resource, priority, 784 jbr = jabber_buddy_track_resource(jb, jid->resource, priority,
749 state, status); 785 state, status);
786 if (idle) {
787 jbr->idle = time(NULL) - idle;
788 } else {
789 jbr->idle = 0;
790 }
791
750 if(caps) { 792 if(caps) {
751 const char *node = xmlnode_get_attrib(caps,"node"); 793 const char *node = xmlnode_get_attrib(caps,"node");
752 const char *ver = xmlnode_get_attrib(caps,"ver"); 794 const char *ver = xmlnode_get_attrib(caps,"ver");
753 const char *ext = xmlnode_get_attrib(caps,"ext"); 795 const char *ext = xmlnode_get_attrib(caps,"ext");
754 796
763 } 805 }
764 806
765 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { 807 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) {
766 jabber_google_presence_incoming(js, buddy_name, found_jbr); 808 jabber_google_presence_incoming(js, buddy_name, found_jbr);
767 purple_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(found_jbr->state), "priority", found_jbr->priority, "message", found_jbr->status, NULL); 809 purple_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(found_jbr->state), "priority", found_jbr->priority, "message", found_jbr->status, NULL);
810 purple_prpl_got_user_idle(js->gc->account, buddy_name, found_jbr->idle, found_jbr->idle);
768 } else { 811 } else {
769 purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); 812 purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL);
770 } 813 }
771 g_free(buddy_name); 814 g_free(buddy_name);
772 } 815 }