socket/CallbackServerUnparsed.c File Reference

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <socket/xmlBlasterSocket.h>
#include <CallbackServerUnparsed.h>

Include dependency graph for CallbackServerUnparsed.c:

Go to the source code of this file.

Functions

static int useThisSocket (CallbackServerUnparsed *cb, int socketToUse, int socketToUseUdp)
static int runCallbackServer (CallbackServerUnparsed *cb)
 Open a socket, this method is usually called from the new thread (see pthread_create()) and only leaves when the connection is lost (on EOF), in this case implicit pthread_exit() is called.
static int createCallbackServer (CallbackServerUnparsed *cb)
 Is only called if we start a dedicated callback server (not tunneling through the connection socket).
static int isListening (CallbackServerUnparsed *cb)
static int readMessage (CallbackServerUnparsed *cb, SocketDataHolder *socketDataHolder, XmlBlasterException *exception, int udp)
 Parse the update message from xmlBlaster.
static ssize_t writenPlain (void *userP, int fd, char *ptr, size_t nbytes)
 Write uncompressed to socket (not thread safe).
static ssize_t readnPlain (void *userP, int fd, char *ptr, size_t nbytes, XmlBlasterNumReadFunc fpNumRead, void *userP2)
 Read data from socket, uncompress data if needed (not thread safe).
static int addResponseListener (CallbackServerUnparsed *cb, MsgRequestInfo *msgRequestInfoP, ResponseFp responseEventFp)
static ResponseListenerremoveResponseListener (CallbackServerUnparsed *cb, char *requestId)
static void voidSendResponse (CallbackServerUnparsed *cb, void *socketDataHolder, MsgUnitArr *msgUnitArrP)
 A helper to cast to SocketDataHolder.
static void sendResponse (CallbackServerUnparsed *cb, SocketDataHolder *socketDataHolder, MsgUnitArr *msgUnitArr)
static void voidSendXmlBlasterException (CallbackServerUnparsed *cb, void *socketDataHolder, XmlBlasterException *exception)
static void sendXmlBlasterException (CallbackServerUnparsed *cb, SocketDataHolder *socketDataHolder, XmlBlasterException *exception)
static void voidSendResponseOrException (int success, CallbackServerUnparsed *cb, void *socketDataHolder, MsgUnitArr *msgUnitArrP, XmlBlasterException *exception)
 A helper to cast to SocketDataHolder Frees msgUnitArrP.
static void sendResponseOrException (int success, CallbackServerUnparsed *cb, SocketDataHolder *socketDataHolder, MsgUnitArr *msgUnitArrP, XmlBlasterException *exception)
 Takes care of both successful responses as well as exceptions Frees msgUnitArrP.
static void shutdownCallbackServer (CallbackServerUnparsed *cb)
 Used internally only to close the socket, calling multiple times makes no harm.
static void closeAcceptSocket (CallbackServerUnparsed *cb)
 Force closing socket.
CallbackServerUnparsedgetCallbackServerUnparsed (int argc, char **argv, UpdateCbFp updateCb, void *updateCbUserData)
 See header for a description.
void freeCallbackServerUnparsed (CallbackServerUnparsed **cb_)
 free() the CallbackServerUnparsed structure and sets *callbackData to 0 Call freeCallbackServerUnparsed(&cb);
static ResponseListenergetResponseListener (CallbackServerUnparsed *cb, char *requestId)
static void handleMessage (CallbackServerUnparsed *cb, SocketDataHolder *socketDataHolder, XmlBlasterException *xmlBlasterException, int success)
static int listenLoop (ListenLoopArgs *ls)
 The run method of the two threads.
char * callbackServerRawUsage ()
 Help on configuration.


Function Documentation

static int addResponseListener ( CallbackServerUnparsed cb,
MsgRequestInfo msgRequestInfoP,
ResponseFp  responseEventFp 
) [static]

Definition at line 154 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, MAX_RESPONSE_LISTENER_SIZE, ResponseListenerStruct::msgRequestInfoP, MsgRequestInfoStruct::requestIdStr, ResponseListenerStruct::responseEventFp, CallbackServerUnparsedStruct::responseListener, and XMLBLASTER_LOG_TRACE.

Referenced by getCallbackServerUnparsed().

char* callbackServerRawUsage (  ) 

Help on configuration.

Definition at line 758 of file CallbackServerUnparsed.c.

Referenced by xmlBlasterAccessUnparsedUsage().

static void closeAcceptSocket ( CallbackServerUnparsed cb  )  [static]

Force closing socket.

Definition at line 700 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::acceptSocket, closeSocket(), CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, and XMLBLASTER_LOG_TRACE.

Referenced by handleMessage(), and shutdownCallbackServer().

Here is the call graph for this function:

static int createCallbackServer ( CallbackServerUnparsed cb  )  [static]

Is only called if we start a dedicated callback server (not tunneling through the connection socket).

Returns:
true The callback server is started, false on error

Definition at line 443 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::acceptSocket, EXCEPTIONSTRUCT_MESSAGE_LEN, gethostbyname_re(), CallbackServerUnparsedStruct::hostCB, CallbackServerUnparsedStruct::isShutdown, CallbackServerUnparsedStruct::listenSocket, CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, MAX_ERRNO_LEN, CallbackServerUnparsedStruct::portCB, SNPRINTF, strcpyRealloc(), XMLBLASTER_LOG_ERROR, XMLBLASTER_LOG_INFO, XMLBLASTER_LOG_TRACE, XMLBLASTER_LOG_WARN, and XMLBLASTEREXCEPTION_MESSAGE_LEN.

Referenced by runCallbackServer().

Here is the call graph for this function:

void freeCallbackServerUnparsed ( CallbackServerUnparsed **  cb_  ) 

free() the CallbackServerUnparsed structure and sets *callbackData to 0 Call freeCallbackServerUnparsed(&cb);

Definition at line 127 of file CallbackServerUnparsed.c.

References freeProperties(), CallbackServerUnparsedStruct::props, and shutdownCallbackServer().

Referenced by freeXmlBlasterAccessUnparsed(), getCallbackServerUnparsed(), and initialize().

Here is the call graph for this function:

CallbackServerUnparsed* getCallbackServerUnparsed ( int  argc,
char **  argv,
UpdateCbFp  updateCb,
void *  updateCbUserData 
)

See header for a description.

Definition at line 55 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::acceptSocket, addResponseListener(), CallbackServerUnparsedStruct::addResponseListener, createProperties(), DEFAULT_CALLBACK_SERVER_PORT, freeCallbackServerUnparsed(), PropertiesStruct::getInt, PropertiesStruct::getString, CallbackServerUnparsedStruct::hostCB, isListening(), CallbackServerUnparsedStruct::isListening, CallbackServerUnparsedStruct::isShutdown, CallbackServerUnparsedStruct::listenSocket, CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, MAX_RESPONSE_LISTENER_SIZE, XmlBlasterReadFromSocketFuncHolder::numReadFuncP, XmlBlasterReadFromSocketFuncHolder::numReadUserP, parseLogLevel(), CallbackServerUnparsedStruct::portCB, CallbackServerUnparsedStruct::props, CallbackServerUnparsedStruct::readFromSocket, XmlBlasterReadFromSocketFuncHolder::readFromSocketFuncP, readnPlain(), removeResponseListener(), CallbackServerUnparsedStruct::removeResponseListener, CallbackServerUnparsedStruct::responseListener, CallbackServerUnparsedStruct::reusingConnectionSocket, runCallbackServer(), CallbackServerUnparsedStruct::runCallbackServer, CallbackServerUnparsedStruct::sendResponse, CallbackServerUnparsedStruct::sendResponseOrException, CallbackServerUnparsedStruct::sendXmlBlasterException, CallbackServerUnparsedStruct::shutdown, shutdownCallbackServer(), CallbackServerUnparsedStruct::socketUdp, CallbackServerUnparsedStruct::stopListenLoop, strcpyAlloc(), CallbackServerUnparsedStruct::updateCb, CallbackServerUnparsedStruct::updateCbUserData, XmlBlasterReadFromSocketFuncHolder::userP, XmlBlasterWriteToSocketFuncHolder::userP, useThisSocket(), CallbackServerUnparsedStruct::useThisSocket, voidSendResponse(), voidSendResponseOrException(), voidSendXmlBlasterException(), writenPlain(), CallbackServerUnparsedStruct::writeToSocket, XmlBlasterWriteToSocketFuncHolder::writeToSocketFuncP, and xmlBlasterDefaultLogging().

Here is the call graph for this function:

static ResponseListener* getResponseListener ( CallbackServerUnparsed cb,
char *  requestId 
) [static]

Definition at line 173 of file CallbackServerUnparsed.c.

References MAX_RESPONSE_LISTENER_SIZE, ResponseListenerStruct::msgRequestInfoP, MsgRequestInfoStruct::requestIdStr, and CallbackServerUnparsedStruct::responseListener.

static void handleMessage ( CallbackServerUnparsed cb,
SocketDataHolder socketDataHolder,
XmlBlasterException xmlBlasterException,
int  success 
) [static]

Definition at line 205 of file CallbackServerUnparsed.c.

References SocketDataHolder::blob, closeAcceptSocket(), encodeXmlBlasterException(), freeBlobHolderContent(), initializeXmlBlasterException(), CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, MAX_METHODNAME_LEN, MAX_REQUESTID_LEN, MAX_RESPONSE_LISTENER_SIZE, SocketDataHolder::methodName, MSG_TYPE_EXCEPTION, ResponseListenerStruct::msgRequestInfoP, SocketDataHolder::requestId, CallbackServerUnparsedStruct::responseListener, CallbackServerUnparsedStruct::reusingConnectionSocket, SNPRINTF, strncpy0(), SocketDataHolder::type, XMLBLASTER_LOG_TRACE, XMLBLASTER_LOG_WARN, XMLBLASTEREXCEPTION_ERRORCODE_LEN, and XMLBLASTEREXCEPTION_MESSAGE_LEN.

Referenced by listenLoop().

Here is the call graph for this function:

static int isListening ( CallbackServerUnparsed cb  )  [static]

Definition at line 537 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::listenSocket.

Referenced by getCallbackServerUnparsed(), and shutdownCallbackServer().

static int listenLoop ( ListenLoopArgs ls  )  [static]

The run method of the two threads.

Definition at line 327 of file CallbackServerUnparsed.c.

References ListenLoopArgsStruct::cb, handleMessage(), CallbackServerUnparsedStruct::listenMutex, CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, readMessage(), CallbackServerUnparsedStruct::socketUdp, CallbackServerUnparsedStruct::stopListenLoop, ListenLoopArgsStruct::udp, XMLBLASTER_LOG_ERROR, and XMLBLASTER_LOG_TRACE.

Referenced by runCallbackServer().

Here is the call graph for this function:

static int readMessage ( CallbackServerUnparsed cb,
SocketDataHolder socketDataHolder,
XmlBlasterException exception,
int  udp 
) [static]

Parse the update message from xmlBlaster.

This method blocks until data arrives. The socketDataHolder holds all informations about the returned data from xmlBlaster, on error the exception struct is filled.

Parameters:
cb The 'this' pointer
socketDataHolder You need to free(socketDataHolder->data) if return is 'true'.
exception Contains the exception thrown (on error only)
udp If UDP to use
Returns:
true if OK or on exception, false on EOF

Definition at line 559 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::acceptSocket, CallbackServerUnparsedStruct::logLevel, parseSocketData(), CallbackServerUnparsedStruct::readFromSocket, CallbackServerUnparsedStruct::socketUdp, CallbackServerUnparsedStruct::stopListenLoop, and XMLBLASTER_LOG_DUMP.

Referenced by listenLoop().

Here is the call graph for this function:

static ssize_t readnPlain ( void *  cb,
int  fd,
char *  ptr,
size_t  nbytes,
XmlBlasterNumReadFunc  fpNumRead,
void *  userP2 
) [static]

Read data from socket, uncompress data if needed (not thread safe).

Definition at line 149 of file CallbackServerUnparsed.c.

References readn().

Referenced by getCallbackServerUnparsed(), initConnection(), and initialize().

Here is the call graph for this function:

static ResponseListener * removeResponseListener ( CallbackServerUnparsed cb,
char *  requestId 
) [static]

Definition at line 190 of file CallbackServerUnparsed.c.

References MAX_RESPONSE_LISTENER_SIZE, ResponseListenerStruct::msgRequestInfoP, MsgRequestInfoStruct::requestIdStr, and CallbackServerUnparsedStruct::responseListener.

Referenced by getCallbackServerUnparsed().

static int runCallbackServer ( CallbackServerUnparsed cb  )  [static]

Open a socket, this method is usually called from the new thread (see pthread_create()) and only leaves when the connection is lost (on EOF), in this case implicit pthread_exit() is called.

xmlBlaster will connect and receive callback messages.

Returns:
0 on success, 1 on error. The return value is the exit value returned by pthread_join()

Definition at line 377 of file CallbackServerUnparsed.c.

References ListenLoopArgsStruct::cb, createCallbackServer(), CallbackServerUnparsedStruct::isShutdown, listenLoop(), CallbackServerUnparsedStruct::listenMutex, CallbackServerUnparsedStruct::listenSocket, CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, CallbackServerUnparsedStruct::socketUdp, ListenLoopArgsStruct::udp, XMLBLASTER_LOG_ERROR, and XMLBLASTER_LOG_TRACE.

Referenced by getCallbackServerUnparsed().

Here is the call graph for this function:

static void sendResponse ( CallbackServerUnparsed cb,
SocketDataHolder socketDataHolder,
MsgUnitArr msgUnitArr 
) [static]

Definition at line 571 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::acceptSocket, BlobHolder::data, BlobHolder::dataLen, encodeMsgUnit(), encodeSocketMessage(), MsgUnitStructArr::len, CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, SocketDataHolder::methodName, MSG_TYPE_RESPONSE, MsgUnitStructArr::msgUnitArr, MsgUnit::qos, SocketDataHolder::requestId, MsgUnit::responseQos, SocketDataHolder::secretSessionId, strcpyAlloc(), CallbackServerUnparsedStruct::updateCbUserData, CallbackServerUnparsedStruct::writeToSocket, XmlBlasterWriteToSocketFuncHolder::writeToSocketFuncP, XMLBLASTER_LOG_DUMP, and XMLBLASTER_LOG_TRACE.

Referenced by sendResponseOrException(), and voidSendResponse().

Here is the call graph for this function:

static void sendResponseOrException ( int  success,
CallbackServerUnparsed cb,
SocketDataHolder socketDataHolder,
MsgUnitArr msgUnitArrP,
XmlBlasterException exception 
) [static]

Takes care of both successful responses as well as exceptions Frees msgUnitArrP.

Definition at line 672 of file CallbackServerUnparsed.c.

References ExceptionStruct::errorCode, freeMsgUnitArr(), CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, ExceptionStruct::message, SocketDataHolder::methodName, SocketDataHolder::requestId, sendResponse(), sendXmlBlasterException(), XMLBLASTER_LOG_TRACE, and XMLBLASTER_UPDATE_ONEWAY.

Referenced by voidSendResponseOrException().

Here is the call graph for this function:

static void sendXmlBlasterException ( CallbackServerUnparsed cb,
SocketDataHolder socketDataHolder,
XmlBlasterException exception 
) [static]

Definition at line 626 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::acceptSocket, MsgUnit::content, MsgUnit::contentLen, BlobHolder::data, BlobHolder::dataLen, encodeMsgUnit(), encodeSocketMessage(), ExceptionStruct::errorCode, CallbackServerUnparsedStruct::logLevel, ExceptionStruct::message, SocketDataHolder::methodName, MsgUnit::qos, SocketDataHolder::requestId, SocketDataHolder::secretSessionId, CallbackServerUnparsedStruct::updateCbUserData, CallbackServerUnparsedStruct::writeToSocket, XmlBlasterWriteToSocketFuncHolder::writeToSocketFuncP, and XMLBLASTER_LOG_DUMP.

Referenced by sendResponseOrException(), and voidSendXmlBlasterException().

Here is the call graph for this function:

static void shutdownCallbackServer ( CallbackServerUnparsed cb  )  [static]

Used internally only to close the socket, calling multiple times makes no harm.

Definition at line 717 of file CallbackServerUnparsed.c.

References closeAcceptSocket(), closeSocket(), CallbackServerUnparsedStruct::hostCB, isListening(), CallbackServerUnparsedStruct::listenSocket, CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, XmlBlasterReadFromSocketFuncHolder::numReadFuncP, CallbackServerUnparsedStruct::readFromSocket, CallbackServerUnparsedStruct::reusingConnectionSocket, CallbackServerUnparsedStruct::stopListenLoop, and XMLBLASTER_LOG_TRACE.

Referenced by freeCallbackServerUnparsed(), and getCallbackServerUnparsed().

Here is the call graph for this function:

int useThisSocket ( CallbackServerUnparsed cb,
int  socketToUse,
int  socketToUseUdp 
) [static]

Definition at line 103 of file CallbackServerUnparsed.c.

References CallbackServerUnparsedStruct::acceptSocket, CallbackServerUnparsedStruct::hostCB, CallbackServerUnparsedStruct::listenSocket, CallbackServerUnparsedStruct::log, CallbackServerUnparsedStruct::logLevel, CallbackServerUnparsedStruct::logUserP, CallbackServerUnparsedStruct::portCB, CallbackServerUnparsedStruct::reusingConnectionSocket, CallbackServerUnparsedStruct::socketUdp, strcpyRealloc(), XMLBLASTER_LOG_INFO, and XMLBLASTER_LOG_WARN.

Referenced by getCallbackServerUnparsed().

Here is the call graph for this function:

static void voidSendResponse ( CallbackServerUnparsed cb,
void *  socketDataHolder,
MsgUnitArr msgUnitArr 
) [static]

A helper to cast to SocketDataHolder.

Definition at line 566 of file CallbackServerUnparsed.c.

References sendResponse().

Referenced by getCallbackServerUnparsed().

Here is the call graph for this function:

static void voidSendResponseOrException ( int  success,
CallbackServerUnparsed cb,
void *  socketDataHolder,
MsgUnitArr msgUnitArrP,
XmlBlasterException exception 
) [static]

A helper to cast to SocketDataHolder Frees msgUnitArrP.

Definition at line 663 of file CallbackServerUnparsed.c.

References sendResponseOrException().

Referenced by getCallbackServerUnparsed().

Here is the call graph for this function:

static void voidSendXmlBlasterException ( CallbackServerUnparsed cb,
void *  socketDataHolder,
XmlBlasterException exception 
) [static]

Definition at line 621 of file CallbackServerUnparsed.c.

References sendXmlBlasterException().

Referenced by getCallbackServerUnparsed().

Here is the call graph for this function:

static ssize_t writenPlain ( void *  cb,
int  fd,
char *  ptr,
size_t  nbytes 
) [static]

Write uncompressed to socket (not thread safe).

Definition at line 141 of file CallbackServerUnparsed.c.

References writen().

Referenced by getCallbackServerUnparsed(), initConnection(), and initialize().

Here is the call graph for this function: