XMPP: add proper cleanup; add basic support for body messages
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 15 Nov 2013 12:05:52 +0000 (13:05 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Fri, 15 Nov 2013 12:05:52 +0000 (13:05 +0100)
citadel/modules/xmpp/serv_xmpp.c
citadel/modules/xmpp/serv_xmpp.h
citadel/modules/xmpp/token.def
citadel/modules/xmpp/xmpp_queue.c
citadel/modules/xmpp/xmpp_xmacros.c
citadel/modules/xmpp/xmpp_xmacros.h

index b06d11aef107c4017d3849be24ecf9b932ccd44a..63b27c5138936a650f58d9a4eecae8a45a2d0a1b 100644 (file)
 #define HAVE_XML_STOPPARSER
 #endif
 
-struct xmpp_event *xmpp_queue = NULL;
 HashList *XMPP_StartHandlers = NULL;
 HashList *XMPP_EndHandlers = NULL;
 HashList *XMPP_SupportedNamespaces = NULL;
-HashList *XMPP_NameSpaces = 0;
+HashList *XMPP_NameSpaces = NULL;
 HashList *FlatToken = NULL;
 
 int XMPPSrvDebugEnable = 0;
@@ -272,27 +271,6 @@ void xmpp_start_bind(void *data, const char *supplied_el, const char **attr)
        XMPP->bind_requested = 1;
 }
 
-void xmpp_start_iq(void *data, const char *supplied_el, const char **attr)
-{
-/*
-       int i;
-       for (i=0; attr[i] != NULL; i+=2) {
-               if (!strcasecmp(attr[i], "type")) {
-                       safestrncpy(XMPP->iq_type, attr[i+1], sizeof XMPP->iq_type);
-               }
-               else if (!strcasecmp(attr[i], "id")) {
-                       safestrncpy(XMPP->iq_id, attr[i+1], sizeof XMPP->iq_id);
-               }
-               else if (!strcasecmp(attr[i], "from")) {
-                       safestrncpy(XMPP->iq_from, attr[i+1], sizeof XMPP->iq_from);
-               }
-               else if (!strcasecmp(attr[i], "to")) {
-                       safestrncpy(XMPP->iq_to, attr[i+1], sizeof XMPP->iq_to);
-               }
-       }
-*/
-}
-
 void xmpp_start_auth(void *data, const char *supplied_el, const char **attr)
 {
        int i;
@@ -808,7 +786,6 @@ void LogXMPPSrvDebugEnable(const int n)
        XMPPSrvDebugEnable = n;
 }
 const char *CitadelServiceXMPP="XMPP";
-extern void xmpp_cleanup_events(void);
 
 
 
@@ -900,7 +877,9 @@ void XMPP_RegisterTokenProperty(const char *NS, long NSLen,
                Put(ThisNamespace, Token, TLen, th, HDeleteTokenHandler);
        }
 
-       Put(th->Properties, Property, PLen, h, HFreePropertyHandler);
+
+       if (PLen > 0)
+               Put(th->Properties, Property, PLen, h, HFreePropertyHandler);
        /*
        if (!GetHash(FlatToken, Token, TLen, &pv))
        {
@@ -910,7 +889,14 @@ void XMPP_RegisterTokenProperty(const char *NS, long NSLen,
        */
 }
 
-
+void xmpp_cleanup(void)
+{
+       DeleteHash(&XMPP_StartHandlers);
+       DeleteHash(&XMPP_EndHandlers);
+       DeleteHash(&XMPP_SupportedNamespaces);
+       DeleteHash(&XMPP_NameSpaces);
+       DeleteHash(&FlatToken);
+}
 
 CTDL_MODULE_INIT(xmpp)
 {
@@ -944,7 +930,6 @@ CTDL_MODULE_INIT(xmpp)
                AddXMPPStartHandler(HKEY("stream"),     xmpp_stream_start, 0);
                AddXMPPStartHandler(HKEY("query"),      xmpp_start_query, 0);
                AddXMPPStartHandler(HKEY("bind"),       xmpp_start_bind, 0);
-               AddXMPPStartHandler(HKEY("iq"),         xmpp_start_iq, 0);
                AddXMPPStartHandler(HKEY("auth"),       xmpp_start_auth, 0);
                AddXMPPStartHandler(HKEY("message"),    xmpp_start_message, 0);
                AddXMPPStartHandler(HKEY("html"),       xmpp_start_html, 0);
@@ -956,7 +941,7 @@ CTDL_MODULE_INIT(xmpp)
                 CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT, PRIO_LOGOUT + 90);
                 CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH, PRIO_UNSTEALTH + 1);
                 CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH, PRIO_STEALTH + 1);
-               CtdlRegisterCleanupHook(xmpp_cleanup_events);
+               CtdlRegisterCleanupHook(xmpp_cleanup);
        }
 
        /* return our module name for the log */
index 2137ea33088967f5be102c9967b7f29fbc5ba53c..ba19e7af26265f92f62c8edb615b3e3ad811fa63 100644 (file)
@@ -59,7 +59,6 @@ struct xmpp_event {
        int session_which_generated_this_event;
 };
 
-extern struct xmpp_event *xmpp_queue;
 extern int queue_event_seq;
 
 enum {
index 6799c8dc2b52a90737fdf8a0cfc9616cc2165623..26345c6683b27252a5c5a709469c435f543aee7a 100644 (file)
@@ -18,3 +18,15 @@ TOKEN(piq,
              STRPROP(piq, from);
              STRPROP(piq, to);
       })
+
+#define NAMESPACE_message "jabber:client"
+TOKEN(message,
+       {
+               STRPROP(message, to);
+               STRPROP(message, type);
+               STRPROP(message, id);
+               PAYLOAD(message, body);
+       })
+
+
+// <message type='chat' id='purplef5a7ed34' to='testuser@blarg.potzblitz.outgesourced.org'><active xmlns='http://jabber.org/protocol/chatstates'/><body>gci</body></message>
index 8cb5662d89f846728c2b53140692325e18553b79..024336df871e7de743e3bebd19bbcbba902b45f9 100644 (file)
@@ -57,6 +57,7 @@
 #include "serv_xmpp.h"
 
 int queue_event_seq = 0;
+struct xmpp_event *xmpp_queue = NULL;
 
 void xmpp_queue_event(int event_type, char *email_addr) {
 
@@ -162,3 +163,14 @@ void xmpp_cleanup_events(void)
         end_critical_section(S_XMPP_QUEUE);
 
 }
+
+CTDL_MODULE_INIT(xmpp_queue)
+{
+       if (!threading) {
+
+               CtdlRegisterCleanupHook(xmpp_cleanup_events);
+       }
+
+       /* return our module name for the log */
+       return "xmpp_queue";
+}
index 3366cbcfc9cc5b64d17e2af63b45de637a028059..3ef9f3161c8db450ef00ac9ef030d56bed7cf524 100644 (file)
@@ -13,6 +13,11 @@ void *GetToken_piq(void)
        return NULL;
 }
 
+void *GetToken_message(void)
+{
+       return NULL;
+}
+
 
 #define STRPROP(STRUCTNAME, NAME)                                      \
        if (StrLength(pdata->NAME) > 0)                                 \
@@ -23,6 +28,12 @@ void *GetToken_piq(void)
        XPut("\" ", 2);                                                 \
        }
 
+#define PAYLOAD(STRUCTNAME, NAME)                                      \
+       XPrint(#NAME, sizeof(#NAME) -1,                                 \
+              XCLOSED,                                                 \
+              TYPE_BODYSTR, SKEY(pdata->NAME),                         \
+              TYPE_ARGEND);
+
 #define THENAMESPACE(STRUCTNAME, NAME)                                 \
        XPut(#NAME, sizeof(#NAME) - 1);                                 \
        XPut("=\"", 2);                                                 \
@@ -48,12 +59,16 @@ void *GetToken_piq(void)
 
 #include "token.def"
 #undef STRPROP
+#undef PAYLOAD
 #undef TOKEN
 
 
 #define STRPROP(STRUCTNAME, NAME)                                      \
        FreeStrBuf(&pdata->NAME);
 
+#define PAYLOAD(STRUCTNAME, NAME)                                      \
+       FreeStrBuf(&pdata->NAME);
+
 #define TOKEN(NAME, STRUCT)                                            \
        void free_buf_##NAME(TheToken_##NAME *pdata)                    \
        {                                                               \
@@ -62,6 +77,7 @@ void *GetToken_piq(void)
 
 #include "token.def"
 #undef STRPROP
+#undef PAYLOAD
 #undef TOKEN
 
 #define TOKEN(NAME, STRUCT)                                            \
@@ -90,6 +106,16 @@ CTDL_MODULE_INIT(xmpp_xmacros)
                        #PROPERTYNAME, sizeof(#PROPERTYNAME)-1,         \
                        GetToken_##TOKENNAME,                           \
                        offset##PROPERTYNAME);
+#define PAYLOAD(TOKENNAME, PROPERTYNAME)                               \
+               long offset##PROPERTYNAME =                             \
+                       offsetof(TheToken_##TOKENNAME, PROPERTYNAME);   \
+               XMPP_RegisterTokenProperty(                             \
+                       NAMESPACE_##TOKENNAME,                          \
+                       sizeof(NAMESPACE_##TOKENNAME)-1,                \
+                       #TOKENNAME, sizeof(#TOKENNAME)-1,               \
+                       NULL, 0,                                        \
+                       GetToken_##TOKENNAME,                           \
+                       offset##PROPERTYNAME);
 #define TOKEN(NAME, STRUCT) STRUCT
 #include "token.def"
 #undef STRPROP
index 3d5d94d539f941b07780c2c1506aca935f68b524..f7427b835c9a396e33d22ee8f1ad4151cda8ad94 100644 (file)
@@ -3,12 +3,14 @@
  * define the structures for one token each
  * typename: TheToken_<Tokenname>
  */
+#define PAYLOAD(STRUCTNAME, NAME) StrBuf *NAME;int encoding_##NAME;
 #define STRPROP(STRUCTNAME, NAME) StrBuf *NAME;
 #define TOKEN(NAME, STRUCT) typedef struct __##NAME    \
        STRUCT                                          \
        TheToken_##NAME;
 #include "token.def"
 #undef STRPROP
+#undef PAYLOAD
 #undef TOKEN
 
 
@@ -21,6 +23,7 @@
        void free_buf_##NAME(TheToken_##NAME *pdata);
 #include "token.def"
 #undef STRPROP
+#undef PAYLOAD
 #undef TOKEN
 
 /*
@@ -32,4 +35,5 @@
 
 #include "token.def"
 #undef STRPROP
+#undef PAYLOAD
 #undef TOKEN