From: Wilfried Goesgens Date: Fri, 15 Nov 2013 12:05:52 +0000 (+0100) Subject: XMPP: add proper cleanup; add basic support for body messages X-Git-Tag: v9.01~190 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=4ebdea1025ba5fdbcc8bdd6ba142557d216796d1 XMPP: add proper cleanup; add basic support for body messages --- diff --git a/citadel/modules/xmpp/serv_xmpp.c b/citadel/modules/xmpp/serv_xmpp.c index b06d11aef..63b27c513 100644 --- a/citadel/modules/xmpp/serv_xmpp.c +++ b/citadel/modules/xmpp/serv_xmpp.c @@ -64,11 +64,10 @@ #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 */ diff --git a/citadel/modules/xmpp/serv_xmpp.h b/citadel/modules/xmpp/serv_xmpp.h index 2137ea330..ba19e7af2 100644 --- a/citadel/modules/xmpp/serv_xmpp.h +++ b/citadel/modules/xmpp/serv_xmpp.h @@ -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 { diff --git a/citadel/modules/xmpp/token.def b/citadel/modules/xmpp/token.def index 6799c8dc2..26345c668 100644 --- a/citadel/modules/xmpp/token.def +++ b/citadel/modules/xmpp/token.def @@ -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); + }) + + +// gci diff --git a/citadel/modules/xmpp/xmpp_queue.c b/citadel/modules/xmpp/xmpp_queue.c index 8cb5662d8..024336df8 100644 --- a/citadel/modules/xmpp/xmpp_queue.c +++ b/citadel/modules/xmpp/xmpp_queue.c @@ -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"; +} diff --git a/citadel/modules/xmpp/xmpp_xmacros.c b/citadel/modules/xmpp/xmpp_xmacros.c index 3366cbcfc..3ef9f3161 100644 --- a/citadel/modules/xmpp/xmpp_xmacros.c +++ b/citadel/modules/xmpp/xmpp_xmacros.c @@ -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 diff --git a/citadel/modules/xmpp/xmpp_xmacros.h b/citadel/modules/xmpp/xmpp_xmacros.h index 3d5d94d53..f7427b835 100644 --- a/citadel/modules/xmpp/xmpp_xmacros.h +++ b/citadel/modules/xmpp/xmpp_xmacros.h @@ -3,12 +3,14 @@ * define the structures for one token each * typename: TheToken_ */ +#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