X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fchat.git;a=blobdiff_plain;f=hook.c;h=43eeef2766dfd71a8e839cc944eaff010bbed12e;hp=766d6a16e304c50304ca46f8f5e5c3a1e83ab347;hb=d70ec81b50760c6a78bec8c13b52c0d345374667;hpb=282bba49cf4dcad9e844e61d70d0ab7ea1c7cb22 diff --git a/hook.c b/hook.c index 766d6a1..43eeef2 100644 --- a/hook.c +++ b/hook.c @@ -25,30 +25,42 @@ #include "sasl.h" #include "bind.h" #include "disco.h" +#include "xmpp_internal.h" + +void +hc_xmpp_hook_bind (hc_xmpp_t *xmpp, iks *stanza) +{ + hc_xmpp_bind_result (xmpp, stanza); + if (hc_xmpp_status (xmpp) == HC_XMPP_BOUND && + hc_xmpp_is_session_supported (xmpp)) + hc_xmpp_session (xmpp); +} + +void +hc_xmpp_hook_session (hc_xmpp_t *xmpp, iks *stanza) +{ + hc_xmpp_session_result (xmpp, stanza); + if (hc_xmpp_status (xmpp) == HC_XMPP_SESSION) + hc_xmpp_send_disco_info (xmpp, hc_xmpp_server (xmpp)); +} + +void +hc_xmpp_hook_disco (hc_xmpp_t *xmpp, iks *stanza) +{ + hc_xmpp_recv_disco (xmpp, stanza); +} int hc_xmpp_hook (void *data, int type, iks *stanza) { + hc_xmpp_t *xmpp = (hc_xmpp_t *) data; if (!iks_strcmp (iks_name (stanza), "iq")) { char *ns = iks_find_attrib (iks_child (stanza), "xmlns"); - if (!iks_strcmp (ns, HC_XMPP_NS_BIND)) - { - hc_xmpp_bind_result (data, stanza); - if (hc_xmpp_status (data) == HC_XMPP_BOUND && - hc_xmpp_is_session_supported (data)) - hc_xmpp_session (data); - } - else if (!iks_strcmp (ns, HC_XMPP_NS_SESSION)) - { - hc_xmpp_session_result (data, stanza); - if (hc_xmpp_status (data) == HC_XMPP_SESSION) - hc_xmpp_send_disco_info (data, hc_xmpp_server (data)); - } - else if (!iks_strcmp (ns, HC_XMPP_NS_DISCO_INFO)) - { - hc_xmpp_recv_disco (data, stanza); - } + hc_xmpp_hook_t hook; + if (g_hash_table_lookup_extended (xmpp->nshooks, ns, + NULL, (gpointer *) &hook)) + hook (xmpp, stanza); } else if (!iks_strcmp (iks_name (stanza), "stream:features")) {