X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fchat.git;a=blobdiff_plain;f=hook.c;h=e91e9fbb714aeef1f17fab38c548d0c8fc330309;hp=766d6a16e304c50304ca46f8f5e5c3a1e83ab347;hb=88e19a4fe878276d64b1aa2fcd5d1efa524508ba;hpb=2dd07de4ac61aea2ce976ea0841d597d8801b139 diff --git a/hook.c b/hook.c index 766d6a1..e91e9fb 100644 --- a/hook.c +++ b/hook.c @@ -25,30 +25,46 @@ #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) { - if (!iks_strcmp (iks_name (stanza), "iq")) + hc_xmpp_t *xmpp = (hc_xmpp_t *) data; + if (!iks_strcmp (iks_name (stanza), "message")) + { + hc_xmpp_recv_message (xmpp, stanza); + } + else 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")) {