comparison mcabber/src/jabglue.c @ 1213:4a7db2870685

Improve Private Storage detection. MCabber now correctly detects Private Storage support when receiving an item-not-found error (which doesn't mean the server has no support for P.S., but that it's empty). I've added a return value to the callback functions. For now the return value is only used for IQ error handling.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 01 May 2007 18:16:11 +0200
parents 3b21353e4ad3
children 80c095886fb5
comparison
equal deleted inserted replaced
1212:3b21353e4ad3 1213:4a7db2870685
56 56
57 static void statehandler(jconn, int); 57 static void statehandler(jconn, int);
58 static void packethandler(jconn, jpacket); 58 static void packethandler(jconn, jpacket);
59 static void handle_state_events(char* from, xmlnode xmldata); 59 static void handle_state_events(char* from, xmlnode xmldata);
60 60
61 static void evscallback_invitation(eviqs *evp, guint evcontext); 61 static int evscallback_invitation(eviqs *evp, guint evcontext);
62 62
63 static void logger(jconn j, int io, const char *buf) 63 static void logger(jconn j, int io, const char *buf)
64 { 64 {
65 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); 65 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
66 } 66 }
1744 char *sdesc; 1744 char *sdesc;
1745 int code = 0; 1745 int code = 0;
1746 char *s; 1746 char *s;
1747 const char *p; 1747 const char *p;
1748 1748
1749 if (!x) return;
1750
1749 /* RFC3920: 1751 /* RFC3920:
1750 * The <error/> element: 1752 * The <error/> element:
1751 * o MUST contain a child element corresponding to one of the defined 1753 * o MUST contain a child element corresponding to one of the defined
1752 * stanza error conditions specified below; this element MUST be 1754 * stanza error conditions specified below; this element MUST be
1753 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace. 1755 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace.
2140 muc_packet = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user"); 2142 muc_packet = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user");
2141 2143
2142 if (type && !strcmp(type, TMSG_ERROR)) { 2144 if (type && !strcmp(type, TMSG_ERROR)) {
2143 xmlnode x; 2145 xmlnode x;
2144 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); 2146 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r);
2145 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL) 2147 x = xmlnode_get_tag(xmldata, TMSG_ERROR);
2146 display_server_error(x); 2148 display_server_error(x);
2147 2149
2148 // Let's check it isn't a nickname conflict. 2150 // Let's check it isn't a nickname conflict.
2149 // XXX Note: We should handle the <conflict/> string condition. 2151 // XXX Note: We should handle the <conflict/> string condition.
2150 if ((p = xmlnode_get_attrib(x, "code")) != NULL) { 2152 if ((p = xmlnode_get_attrib(x, "code")) != NULL) {
2151 if (atoi(p) == 409) { 2153 if (atoi(p) == 409) {
2329 2331
2330 // Timestamp? 2332 // Timestamp?
2331 timestamp = xml_get_timestamp(xmldata); 2333 timestamp = xml_get_timestamp(xmldata);
2332 2334
2333 if (type && !strcmp(type, TMSG_ERROR)) { 2335 if (type && !strcmp(type, TMSG_ERROR)) {
2334 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL) 2336 x = xmlnode_get_tag(xmldata, TMSG_ERROR);
2335 display_server_error(x); 2337 display_server_error(x);
2336 #if defined JEP0022 || defined JEP0085 2338 #if defined JEP0022 || defined JEP0085
2337 // If the JEP85/22 support is probed, set it back to unknown so that 2339 // If the JEP85/22 support is probed, set it back to unknown so that
2338 // we probe it again. 2340 // we probe it again.
2339 chatstates_reset_probed(from); 2341 chatstates_reset_probed(from);
2340 #endif 2342 #endif
2465 2467
2466 update_roster = TRUE; 2468 update_roster = TRUE;
2467 #endif 2469 #endif
2468 } 2470 }
2469 2471
2470 static void evscallback_subscription(eviqs *evp, guint evcontext) 2472 static int evscallback_subscription(eviqs *evp, guint evcontext)
2471 { 2473 {
2472 char *barejid; 2474 char *barejid;
2473 char *buf; 2475 char *buf;
2474 2476
2475 if (evcontext == EVS_CONTEXT_TIMEOUT) { 2477 if (evcontext == EVS_CONTEXT_TIMEOUT) {
2476 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.", 2478 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.",
2477 evp->id); 2479 evp->id);
2478 return; 2480 return 0;
2479 } 2481 }
2480 if (evcontext == EVS_CONTEXT_CANCEL) { 2482 if (evcontext == EVS_CONTEXT_CANCEL) {
2481 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id); 2483 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id);
2482 return; 2484 return 0;
2483 } 2485 }
2484 if (!(evcontext & EVS_CONTEXT_USER)) 2486 if (!(evcontext & EVS_CONTEXT_USER))
2485 return; 2487 return 0;
2486 2488
2487 // Sanity check 2489 // Sanity check
2488 if (!evp->data) { 2490 if (!evp->data) {
2489 // Shouldn't happen, data should be set to the barejid. 2491 // Shouldn't happen, data should be set to the barejid.
2490 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); 2492 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
2491 return; 2493 return 0;
2492 } 2494 }
2493 2495
2494 // Ok, let's work now. 2496 // Ok, let's work now.
2495 // evcontext: 0, 1 == reject, accept 2497 // evcontext: 0, 1 == reject, accept
2496 2498
2512 } 2514 }
2513 } 2515 }
2514 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO); 2516 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO);
2515 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); 2517 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
2516 g_free(buf); 2518 g_free(buf);
2519 return 0;
2517 } 2520 }
2518 2521
2519 static void decline_invitation(event_muc_invitation *invitation, char *reason) 2522 static void decline_invitation(event_muc_invitation *invitation, char *reason)
2520 { 2523 {
2521 // cut and paste from jb_room_invite 2524 // cut and paste from jb_room_invite
2540 jab_send(jc, x); 2543 jab_send(jc, x);
2541 xmlnode_free(x); 2544 xmlnode_free(x);
2542 jb_reset_keepalive(); 2545 jb_reset_keepalive();
2543 } 2546 }
2544 2547
2545 static void evscallback_invitation(eviqs *evp, guint evcontext) 2548 static int evscallback_invitation(eviqs *evp, guint evcontext)
2546 { 2549 {
2547 event_muc_invitation *invitation = evp->data; 2550 event_muc_invitation *invitation = evp->data;
2548 2551
2549 // Sanity check 2552 // Sanity check
2550 if (!invitation) { 2553 if (!invitation) {
2551 // Shouldn't happen. 2554 // Shouldn't happen.
2552 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); 2555 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
2553 return; 2556 return 0;
2554 } 2557 }
2555 2558
2556 if (evcontext == EVS_CONTEXT_TIMEOUT) { 2559 if (evcontext == EVS_CONTEXT_TIMEOUT) {
2557 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.", evp->id); 2560 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.", evp->id);
2558 goto evscallback_invitation_free; 2561 goto evscallback_invitation_free;
2580 g_free(invitation->from); 2583 g_free(invitation->from);
2581 g_free(invitation->passwd); 2584 g_free(invitation->passwd);
2582 g_free(invitation->reason); 2585 g_free(invitation->reason);
2583 g_free(invitation); 2586 g_free(invitation);
2584 evp->data = NULL; 2587 evp->data = NULL;
2588 return 0;
2585 } 2589 }
2586 2590
2587 static void handle_packet_s10n(jconn conn, char *type, char *from, 2591 static void handle_packet_s10n(jconn conn, char *type, char *from,
2588 xmlnode xmldata) 2592 xmlnode xmldata)
2589 { 2593 {