start defining stuff that could handle subtokens - message-chatstate here.
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 29 Dec 2014 23:40:24 +0000 (00:40 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 29 Dec 2014 23:40:24 +0000 (00:40 +0100)
citadel/modules/xmpp/token.def
citadel/modules/xmpp/xmpp_xmacros.c
citadel/modules/xmpp/xmpp_xmacros.h

index a0013ef76f4085a566f0628490d72fe1e86c6602..d4470e02d38c89012d7027c4756d86013b927c69 100644 (file)
@@ -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);
+        });
 
 // <message type='chat' id='purplef5a7ed34' to='testuser@blarg.potzblitz.outgesourced.org'><active xmlns='http://jabber.org/protocol/chatstates'/><body>gci</body></message>
 
index b7f5e672e695b036416adabe217b0a3077d9baca..63c99edaba96809499ad178f457f630bf4b92f94 100644 (file)
@@ -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("</", 2);                                          \
+               XPut(#NAME, sizeof(#NAME));                             \
+               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
index f7427b835c9a396e33d22ee8f1ad4151cda8ad94..b38edbc703f7bbd0cefdc834da2bd09747fa61c0 100644 (file)
@@ -3,15 +3,25 @@
  * define the structures for one token each
  * typename: TheToken_<Tokenname>
  */
+
+#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
 
 
 /*
  # name: free_buf_<Tokenname>
  */
 
+#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_<Tokenname>
  */
+#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