Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jab_iq.c @ 1353:7caedca15e50
Add post-connect internal hook
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 10 Nov 2007 23:06:28 +0100 |
parents | 26d1dd2c948f |
children | 9716cf8a0726 |
comparison
equal
deleted
inserted
replaced
1352:61a54e172010 | 1353:7caedca15e50 |
---|---|
31 #include "utils.h" | 31 #include "utils.h" |
32 #include "screen.h" | 32 #include "screen.h" |
33 #include "settings.h" | 33 #include "settings.h" |
34 #include "hbuf.h" | 34 #include "hbuf.h" |
35 #include "commands.h" | 35 #include "commands.h" |
36 #include "hooks.h" | |
36 | 37 |
37 #ifdef ENABLE_HGCSET | 38 #ifdef ENABLE_HGCSET |
38 # include "hgcset.h" | 39 # include "hgcset.h" |
39 #endif | 40 #endif |
40 | 41 |
244 scr_LogPrint(LPRINT_LOGNORM, "Id [%s]", i->id); | 245 scr_LogPrint(LPRINT_LOGNORM, "Id [%s]", i->id); |
245 } | 246 } |
246 scr_LogPrint(LPRINT_LOGNORM, "End of IQ list."); | 247 scr_LogPrint(LPRINT_LOGNORM, "End of IQ list."); |
247 } | 248 } |
248 | 249 |
249 static void request_roster(void) | |
250 { | |
251 eviqs *iqn = iqs_new(JPACKET__GET, NS_ROSTER, "Roster", IQS_DEFAULT_TIMEOUT); | |
252 jab_send(jc, iqn->xmldata); | |
253 iqs_del(iqn->id); // XXX | |
254 } | |
255 | |
256 static void handle_iq_roster(xmlnode x) | 250 static void handle_iq_roster(xmlnode x) |
257 { | 251 { |
258 xmlnode y; | 252 xmlnode y; |
259 const char *fjid, *name, *group, *sub, *ask; | 253 const char *fjid, *name, *group, *sub, *ask; |
260 char *cleanalias; | 254 char *cleanalias; |
323 | 317 |
324 buddylist_build(); | 318 buddylist_build(); |
325 update_roster = TRUE; | 319 update_roster = TRUE; |
326 if (need_refresh) | 320 if (need_refresh) |
327 scr_UpdateBuddyWindow(); | 321 scr_UpdateBuddyWindow(); |
322 } | |
323 | |
324 // This callback is reached when mcabber receives the first roster update | |
325 // after the connection. | |
326 static int iqscallback_gotroster(eviqs *iqp, xmlnode xml_result, guint iqcontext) | |
327 { | |
328 xmlnode x; | |
329 char *ns; | |
330 | |
331 // Leave now if we cannot process xml_result | |
332 if (!xml_result || iqcontext) return -1; | |
333 | |
334 // Only execute the hook if the roster has been successfully retrieved | |
335 if (iqcontext != IQS_CONTEXT_RESULT) | |
336 return 0; | |
337 | |
338 x = xmlnode_get_tag(xml_result, "query"); | |
339 if (!x) | |
340 return -1; | |
341 ns = xmlnode_get_attrib(x, "xmlns"); | |
342 if (!ns) | |
343 return -1; | |
344 | |
345 if (!strcmp(ns, NS_ROSTER)) // The check is probably useless... | |
346 handle_iq_roster(x); | |
347 | |
348 // Post-login stuff | |
349 jb_setprevstatus(); | |
350 hook_execute_internal("hook-post-connect"); | |
351 | |
352 return 0; | |
353 } | |
354 | |
355 static void request_roster(void) | |
356 { | |
357 eviqs *iqn = iqs_new(JPACKET__GET, NS_ROSTER, "Roster", IQS_DEFAULT_TIMEOUT); | |
358 iqn->callback = &iqscallback_gotroster; | |
359 jab_send(jc, iqn->xmldata); | |
328 } | 360 } |
329 | 361 |
330 static int iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext) | 362 static int iqscallback_version(eviqs *iqp, xmlnode xml_result, guint iqcontext) |
331 { | 363 { |
332 xmlnode ansqry; | 364 xmlnode ansqry; |
893 return 0; | 925 return 0; |
894 } | 926 } |
895 | 927 |
896 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata) | 928 static void handle_iq_result(jconn conn, char *from, xmlnode xmldata) |
897 { | 929 { |
898 xmlnode x; | 930 char *id = xmlnode_get_attrib(xmldata, "id"); |
899 char *id; | 931 |
900 char *ns; | |
901 | |
902 id = xmlnode_get_attrib(xmldata, "id"); | |
903 if (!id) { | 932 if (!id) { |
904 scr_LogPrint(LPRINT_LOG, "IQ result stanza with no ID, ignored."); | 933 scr_LogPrint(LPRINT_LOG, "IQ result stanza with no ID, ignored."); |
905 return; | 934 return; |
906 } | 935 } |
907 | 936 |
908 if (!iqs_callback(id, xmldata, IQS_CONTEXT_RESULT)) | 937 (void)iqs_callback(id, xmldata, IQS_CONTEXT_RESULT); |
909 return; | |
910 | |
911 x = xmlnode_get_tag(xmldata, "query"); | |
912 if (!x) return; | |
913 | |
914 ns = xmlnode_get_attrib(x, "xmlns"); | |
915 if (!ns) return; | |
916 | |
917 if (!strcmp(ns, NS_ROSTER)) { | |
918 handle_iq_roster(x); | |
919 | |
920 // Post-login stuff | |
921 // Usually we request the roster only at connection time | |
922 // so we should be there only once. (That's ugly, however) | |
923 jb_setprevstatus(); | |
924 } | |
925 } | 938 } |
926 | 939 |
927 // FIXME highly duplicated code | 940 // FIXME highly duplicated code |
928 static void send_iq_not_implemented(jconn conn, char *from, xmlnode xmldata) | 941 static void send_iq_not_implemented(jconn conn, char *from, xmlnode xmldata) |
929 { | 942 { |