00001 /*---------------------------------------------------------------------------- 00002 Name: xmlBlasterSocket.h 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: SOCKET internal header (not included directly by clients) 00006 Author: "Marcel Ruff" <xmlBlaster@marcelruff.info> 00007 -----------------------------------------------------------------------------*/ 00008 #ifndef XMLBLASTER_SOCKET_H 00009 #define XMLBLASTER_SOCKET_H 00010 00011 #include <stdlib.h> 00012 #include <util/basicDefs.h> /* Needed only to define _WINDOWS */ 00013 00014 #ifdef _WINDOWS 00015 /* #if _MSC_VER > 1300 (which is VC7) but also for 1400 (which is VC8 2005) */ 00016 #include <Winsock2.h> /* WS2_32.DLL: The newer lib which extends winsock.h, new: Ws2tcpip.h */ 00017 00018 /*# include <winsock.h> */ /* WSOCK32.DLL: The old lib, if you activate replace SD_BOTH with 2 in XmlBlasterConnectionUnparsed.c */ 00019 /* From a mailing list: 00020 #ifndef INCL_WINSOCK_API_TYPEDEFS 00021 #define INCL_WINSOCK_API_TYPEDEFS 1 00022 #endif 00023 00024 // then include: 00025 #include <winsock2.h> 00026 00027 also any header you include ( mainly a concern in your stdafx.h file ) that may suck in the winsock.h file you should do a: 00028 00029 #define _WINSOCKAPI_ 00030 */ 00031 # define ssize_t signed int 00032 #else 00033 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__hpux__) 00034 # include <sys/types.h> /* Needed for __FreeBSD__ */ 00035 # include <netinet/in.h> 00036 # endif 00037 # include <sys/socket.h> 00038 # include <netdb.h> 00039 # include <arpa/inet.h> /* inet_addr() */ 00040 #endif 00041 #include <util/msgUtil.h> 00042 00043 #ifdef __cplusplus 00044 #ifndef XMLBLASTER_C_COMPILE_AS_CPP /* 'g++ -DXMLBLASTER_C_COMPILE_AS_CPP ...' allows to compile the lib as C++ code */ 00045 extern "C" { 00046 #endif 00047 #endif 00048 00049 #define MAX_MSG_LEN 1000000000 00050 00054 typedef enum XMLBLASTER_MSG_TYPE_ENUM { 00055 MSG_TYPE_INVOKE = 73, 00056 MSG_TYPE_RESPONSE = 82, 00057 MSG_TYPE_EXCEPTION = 69 00058 } XMLBLASTER_MSG_TYPE; 00059 00063 typedef struct SocketDataHolder { 00064 size_t msgLen; 00065 bool checksum; 00066 bool compressed; 00067 char type; 00068 char version; 00069 char requestId[MAX_REQUESTID_LEN]; 00070 char methodName[MAX_METHODNAME_LEN]; 00071 char secretSessionId[MAX_SESSIONID_LEN]; 00072 size_t dataLenUncompressed; 00073 XmlBlasterBlob blob; 00074 } SocketDataHolder; 00075 00076 #define MSG_LEN_FIELD_LEN 10 00077 #define MAX_PACKET_SIZE 10*1024 00078 #define MSG_FLAG_FIELD_LEN 6 00079 /* static const int MSG_FLAG_FIELD_LEN = 6; */ 00080 enum MSG_FLAG_POS_ENUM { 00081 MSG_FLAG_POS_CHECKSUM = MSG_LEN_FIELD_LEN, 00082 MSG_FLAG_POS_COMPRESS, 00083 MSG_FLAG_POS_TYPE, 00084 MSG_FLAG_POS_RESERVED1, 00085 MSG_FLAG_POS_RESERVED2, 00086 MSG_FLAG_POS_VERSION, 00087 MSG_POS_REQESTID 00088 }; 00089 00090 #define XMLBLASTER_SOCKET_VERSION 49 00091 00092 00093 extern void closeSocket(int fd); 00094 extern ssize_t writen(const int fd, const char *ptr, const size_t nbytes); 00095 extern ssize_t readn(const int fd, char *ptr, const size_t nbytes, XmlBlasterNumReadFunc fpNumRead, void *userP); 00096 00097 extern bool xbl_isOneway(XMLBLASTER_MSG_TYPE msgType, const char *const methodName); 00098 00112 extern char *encodeSocketMessage( 00113 enum XMLBLASTER_MSG_TYPE_ENUM msgType, 00114 const char * const requestId, 00115 const char * const methodName, 00116 const char * const secretSessionId, 00117 const char *data, 00118 size_t dataLen, 00119 bool debug, 00120 size_t *rawMsgLen); 00121 Dll_Export BlobHolder encodeMsgUnit(MsgUnit *msgUnit, bool debug); /* export for C++ embedding */ 00122 Dll_Export BlobHolder encodeMsgUnitArr(MsgUnitArr *msgUnitArr, bool debug); 00123 Dll_Export bool parseSocketData(int xmlBlasterSocket, const XmlBlasterReadFromSocketFuncHolder *fpHolder, SocketDataHolder *socketDataHolder, XmlBlasterException *exception, bool *stopP, bool udp, bool debug); 00124 Dll_Export void convertToXmlBlasterException(const XmlBlasterBlob *blob, XmlBlasterException *exception, bool debug); 00125 Dll_Export void encodeXmlBlasterException(XmlBlasterBlob *blob, const XmlBlasterException *exception, bool debug); 00126 Dll_Export MsgUnitArr *parseMsgUnitArr(size_t dataLen, char *data); 00127 Dll_Export QosArr *parseQosArr(size_t dataLen, char *data); 00128 00129 #ifdef __cplusplus 00130 #ifndef XMLBLASTER_C_COMPILE_AS_CPP 00131 } /* extern "C" */ 00132 #endif 00133 #endif 00134 00135 #endif /* XMLBLASTER_SOCKET_H */ 00136