From d13759233eefc3f1d7141b1e10b685bd96c80da5 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Tue, 30 Dec 2014 00:40:24 +0100 Subject: [PATCH] start defining stuff that could handle subtokens - message-chatstate here. --- citadel/modules/xmpp/token.def | 42 ++++++++++++++++++++++++++--- citadel/modules/xmpp/xmpp_xmacros.c | 36 ++++++++++++++++++++++++- citadel/modules/xmpp/xmpp_xmacros.h | 18 +++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/citadel/modules/xmpp/token.def b/citadel/modules/xmpp/token.def index a0013ef76..d4470e02d 100644 --- a/citadel/modules/xmpp/token.def +++ b/citadel/modules/xmpp/token.def @@ -6,7 +6,7 @@ TOKEN(iq, STRPROP(iq, id); STRPROP(iq, from); STRPROP(iq, to); - }) + }); #define NAMESPACE_piq "bub" @@ -17,7 +17,7 @@ TOKEN(piq, STRPROP(piq, id); STRPROP(piq, from); STRPROP(piq, to); - }) + }); #define NAMESPACE_message "jabber:client" TOKEN(message, @@ -26,8 +26,44 @@ TOKEN(message, STRPROP(message, type); STRPROP(message, id); PAYLOAD(message, body); - }) + }); +#define NAMESPACE_message_chatstate "http://jabber.org/protocol/chatstates" + +SUBTOKEN(message, + chatstate, + active, + { + CALLBACK(active); + }); + +SUBTOKEN(message, + chatstate, + composing, + { + CALLBACK(composing); + }); + +SUBTOKEN(message, + chatstate, + paused, + { + CALLBACK(paused); + }); + +SUBTOKEN(message, + chatstate, + inactive, + { + CALLBACK(inactive); + }); + +SUBTOKEN(message, + chatstate, + gone, + { + CALLBACK(gone); + }); // gci diff --git a/citadel/modules/xmpp/xmpp_xmacros.c b/citadel/modules/xmpp/xmpp_xmacros.c index b7f5e672e..63c99edab 100644 --- a/citadel/modules/xmpp/xmpp_xmacros.c +++ b/citadel/modules/xmpp/xmpp_xmacros.c @@ -18,6 +18,8 @@ void *GetToken_message(void) return &XMPP->Message; } +/// TODO +#define CALLBACK(NAME); #define STRPROP(STRUCTNAME, NAME) \ if (StrLength(pdata->NAME) > 0) \ @@ -57,11 +59,28 @@ void *GetToken_message(void) } \ } +#define SUBTOKEN(NAME, NS, STOKEN, STRUCT) \ + void serialize_##NAME##NS##STOKEN( \ + theSubToken_##NAME##NS##STOKEN *pdata, int Close) \ + { \ + XPUT("<"); \ + XPut(#NAME, sizeof(#NAME)); \ + XPUT(" "); \ + STRUCT ; \ + XPUT(">"); \ + if (Close) \ + { \ + XPut("", 1); \ + } \ + } + #include "token.def" #undef STRPROP #undef PAYLOAD #undef TOKEN - +#undef SUBTOKEN #define STRPROP(STRUCTNAME, NAME) \ FreeStrBuf(&pdata->NAME); @@ -75,10 +94,16 @@ void *GetToken_message(void) STRUCT ; \ } +#define SUBTOKEN(NAME, NS, STOKEN, STRUCT) void free_buf__##NAME##NS##STOKEN \ + (theSubToken_##NAME##NS##STOKEN *pdata){ \ + STRUCT ; \ + } + #include "token.def" #undef STRPROP #undef PAYLOAD #undef TOKEN +#undef SUBTOKEN #define TOKEN(NAME, STRUCT) \ void free_##NAME(TheToken_##NAME *pdata) \ @@ -87,9 +112,17 @@ void *GetToken_message(void) free(pdata); \ } +#define SUBTOKEN(NAME, NS, STOKEN, STRUCT) void free__##NAME##NS##STOKEN \ + (theSubToken_##NAME##NS##STOKEN *pdata) \ + { \ + free_buf__##NAME##NS##STOKEN(pdata); \ + free(pdata); \ + } + #include "token.def" #undef STRPROP #undef TOKEN +#undef SUBTOKEN @@ -117,6 +150,7 @@ CTDL_MODULE_INIT(xmpp_xmacros) GetToken_##TOKENNAME, \ offset##PROPERTYNAME); #define TOKEN(NAME, STRUCT) STRUCT +#define SUBTOKEN(NAME, NS, STOKEN, STRUCT) STRUCT #include "token.def" #undef STRPROP #undef TOKEN diff --git a/citadel/modules/xmpp/xmpp_xmacros.h b/citadel/modules/xmpp/xmpp_xmacros.h index f7427b835..b38edbc70 100644 --- a/citadel/modules/xmpp/xmpp_xmacros.h +++ b/citadel/modules/xmpp/xmpp_xmacros.h @@ -3,15 +3,25 @@ * define the structures for one token each * typename: TheToken_ */ + +#define XMPPARGS char *token, long len +typedef void (*XMPP_callback)(XMPPARGS); +#define CALLBACK(NAME) XMPP_callback CB_##NAME; #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; +#define SUBTOKEN(NAME, NS, STOKEN, STRUCT) typedef struct __##NAME##NS##STOKEN \ + STRUCT \ + theSubToken_##NAME##NS##STOKEN; + #include "token.def" + #undef STRPROP #undef PAYLOAD #undef TOKEN +#undef SUBTOKEN /* @@ -19,17 +29,22 @@ # name: free_buf_ */ +#define SUBTOKEN(NAME, NS, STOKEN, STRUCT) void free_buf__##NAME##NS##STOKEN \ + (theSubToken_##NAME##NS##STOKEN *pdata); #define TOKEN(NAME, STRUCT) \ void free_buf_##NAME(TheToken_##NAME *pdata); #include "token.def" #undef STRPROP #undef PAYLOAD #undef TOKEN +#undef SUBTOKEN /* * forward declarations, freeing structs and member. * name: free_ */ +#define SUBTOKEN(NAME, NS, STOKEN, STRUCT) void free__##NAME##NS##STOKEN \ + (theSubToken_##NAME##NS##STOKEN *pdata); #define TOKEN(NAME, STRUCT) \ void free_##NAME(TheToken_##NAME *pdata); @@ -37,3 +52,6 @@ #undef STRPROP #undef PAYLOAD #undef TOKEN +#undef SUBTOKEN + +#undef CALLBACK -- 2.30.2