1 /*----------------------------------------------------------------------------
2 Name: xmlBlaster/src/c/util/msgUtil.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Author: "Marcel Ruff" <xmlBlaster@marcelruff.info>
6 -----------------------------------------------------------------------------*/
7 #ifndef XMLBLASTER_MSGUTIL_H
8 #define XMLBLASTER_MSGUTIL_H
9
10 #include <util/helper.h>
11
12 #ifdef __cplusplus
13 #ifndef XMLBLASTER_C_COMPILE_AS_CPP /* 'g++ -DXMLBLASTER_C_COMPILE_AS_CPP ...' allows to compile the lib as C++ code */
14 extern "C" {
15 #endif
16 #endif
17
18 #define MAX_ERRNO_LEN 256
19 #define XMLBLASTER_MAX_USAGE_LEN 2048 /* Change XmlBlasterAccessUnparsed.c accordingly */
20 #define MAX_REQUESTID_LEN 256
21 #define MAX_SECRETSESSIONID_LEN 256
22 #define MAX_SESSIONID_LEN 256
23
24 /* See org.xmlBlaster.util.def.MethodName.java */
25 #define MAX_METHODNAME_LEN 20
26 #define XMLBLASTER_CONNECT "connect"
27 #define XMLBLASTER_DISCONNECT "disconnect"
28 #define XMLBLASTER_PING "ping"
29 #define XMLBLASTER_UPDATE "update"
30 #define XMLBLASTER_UPDATE_ONEWAY "updateOneway"
31 #define XMLBLASTER_PUBLISH "publish"
32 #define XMLBLASTER_PUBLISH_ONEWAY "publishOneway"
33 #define XMLBLASTER_GET "get"
34 #define XMLBLASTER_SUBSCRIBE "subscribe"
35 #define XMLBLASTER_UNSUBSCRIBE "unSubscribe"
36 #define XMLBLASTER_ERASE "erase"
37
38 /**
39 * Holds arbitrary raw data and its length, see helper.h
40 */
41 typedef BlobHolder XmlBlasterBlob;
42
43 /**
44 * Holds a message
45 * All member pointers are allocated with malloc(), you need to free() them
46 * Needs to be consistent with MsgUnitUnmanaged declaration in C# (for P/Invoke)
47 */
48 typedef struct MsgUnit {
49 const char *key; /**< XML formatted ASCII string of the message topic */
50 size_t contentLen; /**< Number of bytes in content */
51 const char *content; /**< Raw data (not 0 terminated) */
52 const char *qos; /**< XML formatted ASCII string of Quality of Service */
53 char *responseQos; /**< Used to transport the response QoS string back to caller */
54 } MsgUnit;
55 /* Note: We use the above 'const' to simplify assignment from C++ like 'msgUnit.key = std::string.c_str() */
56
57 /**
58 * Holds an array of Messages
59 */
60 typedef struct MsgUnitStructArr {
61 /** Oneway updates are marked with true */
62 bool isOneway;
63 /** Authenticate callback messages, this sessionId is returned by xmlBlaster and was initially passed from the client on login */
64 char secretSessionId[MAX_SESSIONID_LEN];
65 uint32_t len;
66 MsgUnit *msgUnitArr;
67 } MsgUnitArr;
68
69 /**
70 * Holds an array of QoS XML strings returned by unSubscribe() and erase()
71 */
72 typedef struct QosStructArr {
73 uint32_t len; /* Number of XML QoS strings */
74 const char **qosArr;
75 } QosArr;
76
77 /**
78 * Used to transport information back to callback functions
79 */
80 typedef struct MsgRequestInfoStruct {
81 void *xa; /* XmlBlasterAccessUnparsed * */
82 char requestIdStr[MAX_REQUESTID_LEN];
83 const char *methodName;
84 char responseType; /* XMLBLASTER_MSG_TYPE_ENUM */
85 XmlBlasterBlob blob;
86 XmlBlasterBlob responseBlob;
87 #ifdef XB_USE_PTHREADS
88 pthread_mutex_t responseMutex; /* Needed for boss/worker model to block until an update arrives */
89 bool responseMutexIsValid;
90 pthread_cond_t responseCond;
91 #endif
92 bool rollback;
93 } MsgRequestInfo;
94
95 /* See helper.h */
96 #define XMLBLASTEREXCEPTION_ERRORCODE_LEN EXCEPTIONSTRUCT_ERRORCODE_LEN
97 #define XMLBLASTEREXCEPTION_MESSAGE_LEN EXCEPTIONSTRUCT_MESSAGE_LEN
98 typedef ExceptionStruct XmlBlasterException;
99
100 /** /node/heron/client/joe/session/9 */
101 typedef struct SessionName {
102 const char *nodeId; /**< heron */
103 const char *subjectId; /**< joe */
104 int sessionId; /**< 9 */
105 } SessionName;
106 Dll_Export extern SessionName *createSessionName(const char* const absoluteName);
107 Dll_Export extern void freeSessionName(SessionName *sessionName);
108
109 Dll_Export extern void initializeXmlBlasterException(XmlBlasterException *xmlBlasterException);
110
111 Dll_Export extern const char *getXmlBlasterVersion(void);
112 Dll_Export extern void xmlBlasterFree(char *p);
113 Dll_Export extern void xmlBlasterFree0(char **p);
114 Dll_Export extern void freeMsgUnitData(MsgUnit *msgUnit);
115 Dll_Export extern void freeMsgUnit(MsgUnit *msgUnit);
116 Dll_Export extern void freeMsgUnitArr(MsgUnitArr *msgUnitArr);
117 Dll_Export extern void freeMsgUnitArrInternal(MsgUnitArr *msgUnitArr);
118 Dll_Export extern void freeQosArr(QosArr *qosArr);
119 Dll_Export extern char *messageUnitToXml(MsgUnit *msg);
120 Dll_Export extern char *messageUnitToXmlLimited(MsgUnit *msg, int maxContentDumpLen);
121 Dll_Export extern struct hostent * gethostbyname_re (const char *host,struct hostent *hostbuf,char **tmphstbuf,size_t *hstbuflen,char errP[MAX_ERRNO_LEN]);
122
123 #ifdef __cplusplus
124 #ifndef XMLBLASTER_C_COMPILE_AS_CPP
125 } /* extern "C" */
126 #endif
127 #endif
128
129 #endif /* XMLBLASTER_MSGUTIL_H */
syntax highlighted by Code2HTML, v. 0.9.1