Created extensible hooks
[cascardo/chat.git] / hook.c
diff --git a/hook.c b/hook.c
index 766d6a1..43eeef2 100644 (file)
--- a/hook.c
+++ b/hook.c
 #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"))
     {