The non-java project is being replaced by a client and a server project
in order to allow for the client component to be consumed by distributions targeting the desktop. This check-in is for the server project.
This commit is contained in:
		@@ -0,0 +1,126 @@
 | 
			
		||||
#######################################################################
 | 
			
		||||
#
 | 
			
		||||
#  Copyright (C) 2006 Novell, Inc.
 | 
			
		||||
#
 | 
			
		||||
#  This program is free software; you can redistribute it and/or
 | 
			
		||||
#  modify it under the terms of the GNU General Public
 | 
			
		||||
#  License as published by the Free Software Foundation; either
 | 
			
		||||
#  version 2 of the License, or (at your option) any later version.
 | 
			
		||||
#
 | 
			
		||||
#  This program is distributed in the hope that it will be useful,
 | 
			
		||||
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
#  General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
#  You should have received a copy of the GNU General Public
 | 
			
		||||
#  License along with this program; if not, write to the Free
 | 
			
		||||
#  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 | 
			
		||||
#
 | 
			
		||||
#  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
#
 | 
			
		||||
#######################################################################
 | 
			
		||||
 | 
			
		||||
if DEBUG
 | 
			
		||||
TARGET_CFG = Debug
 | 
			
		||||
CFLAGS += -v -w
 | 
			
		||||
DEFINES = -DDBG
 | 
			
		||||
else
 | 
			
		||||
TARGET_CFG = Release
 | 
			
		||||
DEFINES = -DNDEBUG
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
# Override the link setting for C++
 | 
			
		||||
LINK = g++
 | 
			
		||||
 | 
			
		||||
SUBDIRS =
 | 
			
		||||
 | 
			
		||||
DIST_SUBDIRS =
 | 
			
		||||
 | 
			
		||||
ROOT = ../../../..
 | 
			
		||||
 | 
			
		||||
LIBDIR = $(ROOT)/$(LIB)
 | 
			
		||||
 | 
			
		||||
# handle Mono secondary dependencies
 | 
			
		||||
export MONO_PATH := $(MONO_PATH)
 | 
			
		||||
 | 
			
		||||
COMMON = ../common
 | 
			
		||||
SERVER = .
 | 
			
		||||
 | 
			
		||||
MODULE_NAME = libcasa_s_ipc
 | 
			
		||||
MODULE_EXT = so
 | 
			
		||||
 | 
			
		||||
CFILES =
 | 
			
		||||
 | 
			
		||||
CPPFILES = schannel.cpp \
 | 
			
		||||
	   serverreq.cpp \
 | 
			
		||||
	   serverthread.cpp \
 | 
			
		||||
	   server.cpp
 | 
			
		||||
 | 
			
		||||
COMMONCPPFILES =  channelproto.cpp
 | 
			
		||||
 | 
			
		||||
CSFILES_CSC :=
 | 
			
		||||
INCLUDES = -I. -I.. -I../common -I../../../../include
 | 
			
		||||
RESOURCES =
 | 
			
		||||
 | 
			
		||||
if LIB64
 | 
			
		||||
DEFINES += -D_LIB64
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
CFLAGS += -Wno-format-extra-args -fno-strict-aliasing -fshort-wchar $(INCLUDES) $(DEFINES)
 | 
			
		||||
CPPFLAGS += -Wno-format-extra-args -fno-strict-aliasing -fshort-wchar -fPIC $(INCLUDES) $(DEFINES) $(RPM_OPT_FLAGS)
 | 
			
		||||
LIBS = -lpthread
 | 
			
		||||
LDFLAGS = -Bsymbolic -shared -Wl,-soname=$(MODULE_NAME).$(MODULE_EXT)
 | 
			
		||||
 | 
			
		||||
OBJDIR = ./$(TARGET_CFG)/$(LIB)
 | 
			
		||||
OBJS = $(addprefix $(OBJDIR)/, $(CFILES:%.c=%.o)) $(addprefix $(OBJDIR)/, $(COMMONCPPFILES:%.cpp=%.o)) $(addprefix $(OBJDIR)/, $(CPPFILES:%.cpp=%.o))
 | 
			
		||||
 | 
			
		||||
EXTRA_DIST = $(CFILES) $(CPPFILES) *.h
 | 
			
		||||
 | 
			
		||||
CUR_DIR := $(shell pwd)
 | 
			
		||||
 | 
			
		||||
all: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Pattern based rules.
 | 
			
		||||
#
 | 
			
		||||
vpath %.c $(SERVER) $(COMMON)
 | 
			
		||||
vpath %.cpp $(SERVER) $(COMMON)
 | 
			
		||||
 | 
			
		||||
$(OBJDIR)/%.o: %.c
 | 
			
		||||
	$(CC) -c $(CFLAGS) -o $@ $<
 | 
			
		||||
 | 
			
		||||
$(OBJDIR)/%.o: %.cpp
 | 
			
		||||
	$(CC) -c $(CPPFLAGS) -o $@ $<
 | 
			
		||||
 | 
			
		||||
$(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT): $(OBJDIR) $(OBJS)
 | 
			
		||||
	@echo [======== Linking $@ ========]
 | 
			
		||||
	$(LINK) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
 | 
			
		||||
	cp -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(LIBDIR)/$(TARGET_CFG)/$(MODULE_NAME).$(MODULE_EXT)
 | 
			
		||||
 | 
			
		||||
$(OBJDIR):
 | 
			
		||||
	[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR)
 | 
			
		||||
	[ -d $(LIBDIR) ] || mkdir -p $(LIBDIR)
 | 
			
		||||
	[ -d $(LIBDIR)/$(TARGET_CFG) ] || mkdir -p $(LIBDIR)/$(TARGET_CFG)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
install-exec-local: $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
 | 
			
		||||
	$(mkinstalldirs) $(DESTDIR)$(libdir)
 | 
			
		||||
	$(INSTALL_PROGRAM) $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT) $(DESTDIR)$(libdir)/
 | 
			
		||||
 | 
			
		||||
uninstall-local:
 | 
			
		||||
	cd $(DESTDIR)$(libdir); rm -f $(OBJDIR)/$(MODULE_NAME).$(MODULE_EXT)
 | 
			
		||||
	rmdir $(DESTDIR)$(libdir)
 | 
			
		||||
 | 
			
		||||
#installcheck-local: install
 | 
			
		||||
#	$(mkinstalldirs) $(DESTDIR)$(libdir)
 | 
			
		||||
#	$(INSTALL_PROGRAM) $(DESTDIR)$(libdir)
 | 
			
		||||
#	cd $(DESTDIR)$(libdir); $(MONO)
 | 
			
		||||
 | 
			
		||||
clean-local:
 | 
			
		||||
	if [ -d $(TARGET_CFG) ]; then  rm -rf $(TARGET_CFG); fi
 | 
			
		||||
 | 
			
		||||
distclean-local:
 | 
			
		||||
 | 
			
		||||
maintainer-clean-local:
 | 
			
		||||
	rm -f Makefile.in
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,776 @@
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * 
 | 
			
		||||
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is free software; you can redistribute it and/or
 | 
			
		||||
 *  modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 *  License as published by the Free Software Foundation; version 2.1
 | 
			
		||||
 *  of the License.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 *  Library Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 *  License along with this library; if not, Novell, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 *  To contact Novell about this file by physical or electronic mail, 
 | 
			
		||||
 *  you may find current contact information at www.novell.com.
 | 
			
		||||
 * 
 | 
			
		||||
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
 *
 | 
			
		||||
 ***********************************************************************/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Include files ]=====================================================
 | 
			
		||||
 | 
			
		||||
#include "ipcint.h"
 | 
			
		||||
#include "schannel.h"
 | 
			
		||||
#include "serverreq.h"
 | 
			
		||||
 | 
			
		||||
//===[ External data ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
extern int
 | 
			
		||||
ServiceRequest(
 | 
			
		||||
   ServerReq *pServerReq);
 | 
			
		||||
 | 
			
		||||
extern void
 | 
			
		||||
RemoveFromSChannelList(
 | 
			
		||||
   SChannel *pSChannel);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Manifest constants ]================================================
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Socket Mapping definitions
 | 
			
		||||
//
 | 
			
		||||
#define INVALID_SOCKET -1
 | 
			
		||||
#define SOCKET_ERROR -1
 | 
			
		||||
#define LINGER struct linger
 | 
			
		||||
#define SOCKADDR_IN struct sockaddr_in
 | 
			
		||||
#define closesocket close
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Object Counters
 | 
			
		||||
//
 | 
			
		||||
unsigned long numSChannelObjects = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
SChannel::SChannel(
 | 
			
		||||
   int connSocket) :
 | 
			
		||||
 | 
			
		||||
   m_state (State_Connected),
 | 
			
		||||
   m_socket (connSocket)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "SChannel::SChannel- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Initialize the mutex
 | 
			
		||||
   if (pthread_mutex_init(&m_mutex, NULL) != 0)
 | 
			
		||||
   {
 | 
			
		||||
      DbgTrace(0, "SChannel::SChannel- Mutex initialization failed\n", 0);
 | 
			
		||||
 | 
			
		||||
      // Throw exception
 | 
			
		||||
      throw bad_alloc();
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Increment the object count
 | 
			
		||||
   InterlockedIncrement(&numSChannelObjects);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::SChannel- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- SChannel::SChannel() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
SChannel::~SChannel(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "SChannel::~SChannel- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Cleanup resources allocated for the object
 | 
			
		||||
   pthread_mutex_destroy(&m_mutex);
 | 
			
		||||
 | 
			
		||||
   // Free connection socket if necessary
 | 
			
		||||
   if (m_socket != INVALID_SOCKET)
 | 
			
		||||
   {
 | 
			
		||||
      shutdown(m_socket, SHUT_RDWR);
 | 
			
		||||
      struct linger linger_opt = {1, 15};
 | 
			
		||||
      setsockopt(m_socket, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(linger_opt));
 | 
			
		||||
      closesocket(m_socket);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Decrement the object count
 | 
			
		||||
   InterlockedDecrement(&numSChannelObjects);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::~SChannel- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- SChannel::~SChannel() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
int
 | 
			
		||||
SChannel::init(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   int            retStatus = -1;
 | 
			
		||||
   SmartSChannel  *pSmartSChannel = NULL;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::init- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Verify the state of the object
 | 
			
		||||
   if (m_state == State_Connected)
 | 
			
		||||
   {
 | 
			
		||||
      // Launch a thread to service the channel connection
 | 
			
		||||
      try {
 | 
			
		||||
         // Create a SmartSChannel object to make sure that the object
 | 
			
		||||
         // does not get deleted prematurely.
 | 
			
		||||
         pSmartSChannel = new SmartSChannel(this);
 | 
			
		||||
 | 
			
		||||
         // Create the channel connection thread
 | 
			
		||||
         pthread_t thread;
 | 
			
		||||
         int threadCreateStatus = pthread_create(&thread,
 | 
			
		||||
                                                 NULL,
 | 
			
		||||
                                                 (void*(*)(void*))SChannel::connectionThread,
 | 
			
		||||
                                                 pSmartSChannel);
 | 
			
		||||
         if (threadCreateStatus == 0)
 | 
			
		||||
         {
 | 
			
		||||
            // We succeeded
 | 
			
		||||
            retStatus = 0;
 | 
			
		||||
         }
 | 
			
		||||
         else
 | 
			
		||||
         {
 | 
			
		||||
            DbgTrace(0, "SChannel::init- Unable to create channel connection thread, error = %08X\n", threadCreateStatus);
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
      catch (...) {
 | 
			
		||||
         DbgTrace(0, "SChannel::init- Exception caught creating smart pointer\n", 0);
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
   else
 | 
			
		||||
   {
 | 
			
		||||
      DbgTrace(0, "SChannel::init- invalid state, state = %d\n", m_state);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Deal with initialization failures
 | 
			
		||||
   if (retStatus)
 | 
			
		||||
   {
 | 
			
		||||
      // Adjust the object state
 | 
			
		||||
      m_state = State_FailedInitialization;
 | 
			
		||||
 | 
			
		||||
      // Free SmartSChannel just in case
 | 
			
		||||
      delete pSmartSChannel;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::init- End, status = %08X\n", retStatus);
 | 
			
		||||
 | 
			
		||||
   return retStatus;
 | 
			
		||||
 | 
			
		||||
}  /*-- SChannel::init() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void*
 | 
			
		||||
SChannel::connectionThread(
 | 
			
		||||
   SmartPtr<SChannel> *pSmartSChannel)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   SChannel       *pSChannel = *pSmartSChannel;
 | 
			
		||||
   bool           doneReceivingData = false;
 | 
			
		||||
   unsigned long  bytesReceived;
 | 
			
		||||
   unsigned long  bytesSent;
 | 
			
		||||
   uint32_t       reqId;
 | 
			
		||||
   int            payloadLength;
 | 
			
		||||
   unsigned long  totalPayloadBytesReceived = 0;
 | 
			
		||||
   char           reqDataPktHdr[ReqDataPktHdrTemplate.length()];
 | 
			
		||||
   char           reqErrorPktHdr[ReqErrorPktHdrTemplate.length()];
 | 
			
		||||
   char           *pRecvBuff;
 | 
			
		||||
   ServerReq      *pServerReq;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::connectionThread- Start, Obj = %08X\n", pSChannel);
 | 
			
		||||
 | 
			
		||||
   // Set the thread in the detached state so that it is cleaned up when it exits
 | 
			
		||||
	pthread_detach(pthread_self());
 | 
			
		||||
 | 
			
		||||
   // Check that we are still connected
 | 
			
		||||
   if (pSChannel->m_state == State_Connected)
 | 
			
		||||
   {
 | 
			
		||||
      // Receive and process channel data
 | 
			
		||||
      while (!doneReceivingData)
 | 
			
		||||
      {
 | 
			
		||||
         DbgTrace(2, "SChannel::connectionThread- Receive Loop, Obj = %08X\n", pSChannel);
 | 
			
		||||
 | 
			
		||||
         // Receive the ReqDataPktHdr. Note, if we add other packet types and if the
 | 
			
		||||
         // packet types have different header lengths, then we will need to modify
 | 
			
		||||
         // this code to first receive the packet type and then receive the rest
 | 
			
		||||
         // of the header based on type.
 | 
			
		||||
         while (1)
 | 
			
		||||
         {
 | 
			
		||||
            bytesReceived = recv(pSChannel->m_socket,
 | 
			
		||||
                                 reqDataPktHdr,
 | 
			
		||||
                                 ReqDataPktHdrTemplate.length(),
 | 
			
		||||
                                 MSG_WAITALL);
 | 
			
		||||
            if (bytesReceived != SOCKET_ERROR
 | 
			
		||||
                || errno != EINTR)
 | 
			
		||||
            {
 | 
			
		||||
               break;
 | 
			
		||||
            }
 | 
			
		||||
         }
 | 
			
		||||
         if (bytesReceived != SOCKET_ERROR)
 | 
			
		||||
         {
 | 
			
		||||
            // Check if the connection was terminated
 | 
			
		||||
            if (bytesReceived == ReqDataPktHdrTemplate.length())
 | 
			
		||||
            {
 | 
			
		||||
               // Get the reqId and payload length
 | 
			
		||||
               if (ChannelProto::getReqIdAndPayloadLength(reqDataPktHdr,
 | 
			
		||||
                                                          sizeof(reqDataPktHdr),
 | 
			
		||||
                                                          &reqId,
 | 
			
		||||
                                                          &payloadLength))
 | 
			
		||||
               {
 | 
			
		||||
                  // Procced based on the packet type
 | 
			
		||||
                  switch (ChannelProto::getPktType(*reqDataPktHdr))
 | 
			
		||||
                  {
 | 
			
		||||
                     case ChannelProto::ReqDataCarrierPacketType:
 | 
			
		||||
 | 
			
		||||
                        DbgTrace(2, "SChannel::connectionThread- Processing Request Data Packet, Obj = %08X\n", pSChannel);
 | 
			
		||||
 | 
			
		||||
                        // Allocate a buffer big enough to receive the payload. Allow space to NULL terminate.
 | 
			
		||||
                        pRecvBuff = new char[payloadLength + 1];
 | 
			
		||||
                        if (pRecvBuff != NULL)
 | 
			
		||||
                        {
 | 
			
		||||
                           pRecvBuff[payloadLength] = '\0';
 | 
			
		||||
 | 
			
		||||
                           // Buffer allocated, receive the Req payload.
 | 
			
		||||
                           while (1)
 | 
			
		||||
                           {
 | 
			
		||||
                              bytesReceived = recv(pSChannel->m_socket,
 | 
			
		||||
                                                   pRecvBuff,
 | 
			
		||||
                                                   payloadLength,
 | 
			
		||||
                                                   MSG_WAITALL);
 | 
			
		||||
                              if (bytesReceived != SOCKET_ERROR
 | 
			
		||||
                                  || errno != EINTR)
 | 
			
		||||
                              {
 | 
			
		||||
                                 break;
 | 
			
		||||
                              }
 | 
			
		||||
                           }
 | 
			
		||||
                           if (bytesReceived != SOCKET_ERROR)
 | 
			
		||||
                           {
 | 
			
		||||
                              // Verify that we received all of the payload
 | 
			
		||||
                              if (bytesReceived == payloadLength)
 | 
			
		||||
                              {
 | 
			
		||||
                                 // Received all of the payload data
 | 
			
		||||
                                 totalPayloadBytesReceived += bytesReceived;
 | 
			
		||||
 | 
			
		||||
                                 // Instantiate ServerReq object
 | 
			
		||||
                                 bool reqProcessingStartedSuccessfully = false;
 | 
			
		||||
 | 
			
		||||
                                 try {
 | 
			
		||||
                                    pServerReq = new ServerReq(pSChannel,
 | 
			
		||||
                                                               reqId,
 | 
			
		||||
                                                               pRecvBuff,
 | 
			
		||||
                                                               bytesReceived);
 | 
			
		||||
                                 }
 | 
			
		||||
                                 catch (...) {
 | 
			
		||||
                                    DbgTrace(0, "SChannel::connectionThread- Exception caught creating ServerReq obj\n", 0);
 | 
			
		||||
                                 }
 | 
			
		||||
 | 
			
		||||
                                 // Acquire exclusive access to the SChannel object
 | 
			
		||||
                                 pthread_mutex_lock(&pSChannel->m_mutex);
 | 
			
		||||
 | 
			
		||||
                                 if (pServerReq)
 | 
			
		||||
                                 {
 | 
			
		||||
                                    // Forget about the receive buffer
 | 
			
		||||
                                    pRecvBuff = NULL;
 | 
			
		||||
 | 
			
		||||
                                    // Start processing the Request
 | 
			
		||||
                                    if (ServiceRequest(pServerReq) != 0)
 | 
			
		||||
                                    {
 | 
			
		||||
                                       // Failed to start processing of the Request, delete the ServerReq object.
 | 
			
		||||
                                       DbgTrace(0, "SChannel::connectionThread- StartRequest failed, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                       delete pServerReq;
 | 
			
		||||
                                    }
 | 
			
		||||
                                    else
 | 
			
		||||
                                    {
 | 
			
		||||
                                       reqProcessingStartedSuccessfully = true;
 | 
			
		||||
                                    }
 | 
			
		||||
                                 }
 | 
			
		||||
                                 else
 | 
			
		||||
                                 {
 | 
			
		||||
                                    //DbgTrace(1, "SChannel::connectionThread- Failed to obtain idle ServerReq, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                    DbgTrace(0, "SChannel::connectionThread- Failed to obtain idle ServerReq, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                 }
 | 
			
		||||
 | 
			
		||||
                                 // Check if we must send an Request Error packet back to the client
 | 
			
		||||
                                 if (reqProcessingStartedSuccessfully == false)
 | 
			
		||||
                                 {
 | 
			
		||||
                                    // Build ReqErrorHeader
 | 
			
		||||
                                    if (ChannelProto::buildReqErrorPktHdr(reqId,
 | 
			
		||||
                                                                          0,
 | 
			
		||||
                                                                          reqErrorPktHdr) == 0)
 | 
			
		||||
                                    {
 | 
			
		||||
                                       // Packet header was built, now sent it to the client.
 | 
			
		||||
                                       bytesSent = send(pSChannel->m_socket,
 | 
			
		||||
                                                        reqErrorPktHdr,
 | 
			
		||||
                                                        sizeof(reqErrorPktHdr),
 | 
			
		||||
                                                        MSG_NOSIGNAL);
 | 
			
		||||
                                       if (bytesSent != sizeof(reqErrorPktHdr))
 | 
			
		||||
                                       {
 | 
			
		||||
                                          DbgTrace(1, "SChannel::connectionThread- Connection aborted prematurely, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                          //printf("SChannel::connectionThread- 1Connection aborted prematurely, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                          doneReceivingData = true;
 | 
			
		||||
                                       }
 | 
			
		||||
                                    }
 | 
			
		||||
                                    else
 | 
			
		||||
                                    {
 | 
			
		||||
                                       DbgTrace(0, "SChannel::connectionThread- Error building Req End Pkt Header, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                    }
 | 
			
		||||
                                 }
 | 
			
		||||
 | 
			
		||||
                                 // Release exclusive access to the SChannel object
 | 
			
		||||
                                 pthread_mutex_unlock(&pSChannel->m_mutex);
 | 
			
		||||
                              }
 | 
			
		||||
                              else
 | 
			
		||||
                              {
 | 
			
		||||
                                 DbgTrace(1, "SChannel::connectionThread- Connection aborted prematurely, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                 //printf("bytesReceived = %d, payloadLength = %d\n", bytesReceived, payloadLength); 
 | 
			
		||||
                                 //printf("SChannel::connectionThread- 2Connection aborted prematurely, Obj = %08X\n", pSChannel);
 | 
			
		||||
                                 doneReceivingData = true;
 | 
			
		||||
                              }
 | 
			
		||||
                           }
 | 
			
		||||
                           else
 | 
			
		||||
                           {
 | 
			
		||||
                              DbgTrace(1, "SChannel::connectionThread- Connection aborted prematurely, Obj = %08X\n", pSChannel);
 | 
			
		||||
                              //printf("Socket error = %d\n", errno);
 | 
			
		||||
                              //printf("SChannel::connectionThread- 3Connection aborted prematurely, Obj = %08X\n", pSChannel);
 | 
			
		||||
                              doneReceivingData = true;
 | 
			
		||||
                           }
 | 
			
		||||
 | 
			
		||||
                           // Free receive buffer if necessary
 | 
			
		||||
                           if (pRecvBuff)
 | 
			
		||||
                              delete[] pRecvBuff;
 | 
			
		||||
                        }
 | 
			
		||||
                        else
 | 
			
		||||
                        {
 | 
			
		||||
                           DbgTrace(0, "SChannel::connectionThread- Unable to allocate receive buffer, Obj = %08X\n", pSChannel);
 | 
			
		||||
                           doneReceivingData = true;
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
 | 
			
		||||
                     default:
 | 
			
		||||
 | 
			
		||||
                        DbgTrace(0, "SChannel::connectionThread- Unknown Packet Type, Obj = %08X\n", pSChannel);
 | 
			
		||||
                        doneReceivingData = true;
 | 
			
		||||
                        break;
 | 
			
		||||
                  }
 | 
			
		||||
               }
 | 
			
		||||
               else
 | 
			
		||||
               {
 | 
			
		||||
                  DbgTrace(1, "SChannel::connectionThread- Unable to obtain payload length, Obj = %08X\n", pSChannel);
 | 
			
		||||
                  doneReceivingData = true;
 | 
			
		||||
               }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
               DbgTrace(1, "SChannel::connectionThread- The channel connection was terminated, Obj = %08X\n", pSChannel);
 | 
			
		||||
               //printf("bytesReceived = %d, expected = %d\n", bytesReceived, ReqDataPktHdrTemplate.length()); 
 | 
			
		||||
               //printf("SChannel::connectionThread- 4The channel connection was terminated, Obj = %08X\n", pSChannel);
 | 
			
		||||
               doneReceivingData = true;
 | 
			
		||||
            }
 | 
			
		||||
         }
 | 
			
		||||
         else
 | 
			
		||||
         {
 | 
			
		||||
            DbgTrace(1, "SChannel::connectionThread- The channel connection was aborted, Obj = %08X\n", pSChannel);
 | 
			
		||||
            //printf("Socket error = %d\n", errno);
 | 
			
		||||
            //printf("SChannel::connectionThread- 5The channel connection was aborted, Obj = %08X\n", pSChannel);
 | 
			
		||||
            doneReceivingData = true;
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Acquire exclusive access to the SChannel object
 | 
			
		||||
   pthread_mutex_lock(&pSChannel->m_mutex);
 | 
			
		||||
 | 
			
		||||
   // Try to change the SChannel state to disconnected
 | 
			
		||||
   if (pSChannel->m_state == State_Connected)
 | 
			
		||||
      pSChannel->m_state = State_Disconnected;
 | 
			
		||||
 | 
			
		||||
   // Release exclusive access to the SChannel object
 | 
			
		||||
   pthread_mutex_unlock(&pSChannel->m_mutex);
 | 
			
		||||
 | 
			
		||||
   // Remove ourselves from the SChannel list
 | 
			
		||||
   RemoveFromSChannelList(pSChannel);
 | 
			
		||||
 | 
			
		||||
   // Free SmartSChannel
 | 
			
		||||
   delete pSmartSChannel;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::connectionThread- End\n", 0);
 | 
			
		||||
 | 
			
		||||
   // Exit
 | 
			
		||||
	pthread_exit(NULL);
 | 
			
		||||
 | 
			
		||||
	return 0;	// never-reached!
 | 
			
		||||
 | 
			
		||||
}  /*-- SChannel::connectionThread() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void
 | 
			
		||||
SChannel::closeChannel(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::closeChannel- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Acquire SChannel mutex
 | 
			
		||||
   pthread_mutex_lock(&m_mutex);
 | 
			
		||||
 | 
			
		||||
   // Switch the socket state to closed
 | 
			
		||||
   m_state = State_Closed;
 | 
			
		||||
 | 
			
		||||
   // Check if we must close the socket
 | 
			
		||||
   if (m_socket != INVALID_SOCKET)
 | 
			
		||||
   {
 | 
			
		||||
      // Socket needs to be closed, this will
 | 
			
		||||
      // release the channel connection thread
 | 
			
		||||
      // if it is active.
 | 
			
		||||
      shutdown(m_socket, SHUT_RDWR);
 | 
			
		||||
      struct linger linger_opt = {1, 15};
 | 
			
		||||
      setsockopt(m_socket, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(linger_opt));
 | 
			
		||||
      closesocket(m_socket);
 | 
			
		||||
      m_socket = INVALID_SOCKET;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Release SChannel mutex
 | 
			
		||||
   pthread_mutex_unlock(&m_mutex);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::closeChannel- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- SChannel::closeChannel() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
int
 | 
			
		||||
SChannel::sendReplyData(
 | 
			
		||||
   uint32_t reqId,
 | 
			
		||||
   char *pServerData,
 | 
			
		||||
   int32_t serverDataLen)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
//  Environment:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   int            retStatus = -1;
 | 
			
		||||
   char           reqDataPktHdr[ReqDataPktHdrTemplate.length()];
 | 
			
		||||
   struct msghdr  sendmsgHdr = {0};
 | 
			
		||||
   struct iovec   ioVectors[2];
 | 
			
		||||
   unsigned long  bytesSent;
 | 
			
		||||
   unsigned long  totalBytesSent = 0;
 | 
			
		||||
   unsigned long  bytesToSend = sizeof(reqDataPktHdr) + serverDataLen;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::sendReplyData- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Acquire exclusive access to the channel object
 | 
			
		||||
   pthread_mutex_lock(&m_mutex);
 | 
			
		||||
 | 
			
		||||
   // Verify that the channel is connected
 | 
			
		||||
   if (m_state == State_Connected)
 | 
			
		||||
   {
 | 
			
		||||
      // Build ReqDataHeader
 | 
			
		||||
      if (ChannelProto::buildReqDataPktHdr(reqId,
 | 
			
		||||
                                           serverDataLen,
 | 
			
		||||
                                           reqDataPktHdr) == 0)
 | 
			
		||||
      {
 | 
			
		||||
         // Packet header was built, now sent it along with the client data to
 | 
			
		||||
         // the server.
 | 
			
		||||
         ioVectors[0].iov_base = reqDataPktHdr;
 | 
			
		||||
         ioVectors[0].iov_len = sizeof(reqDataPktHdr);
 | 
			
		||||
         ioVectors[1].iov_base = (char*) pServerData;
 | 
			
		||||
         ioVectors[1].iov_len = serverDataLen;
 | 
			
		||||
         sendmsgHdr.msg_iov = ioVectors;
 | 
			
		||||
         sendmsgHdr.msg_iovlen = 2;
 | 
			
		||||
         while (1)
 | 
			
		||||
         {
 | 
			
		||||
            bytesSent = sendmsg(m_socket,
 | 
			
		||||
                                &sendmsgHdr,
 | 
			
		||||
                                MSG_NOSIGNAL);
 | 
			
		||||
            if (bytesSent == SOCKET_ERROR)
 | 
			
		||||
            {
 | 
			
		||||
               // Check if we were interrupted during the transfer
 | 
			
		||||
               if (errno == EINTR)
 | 
			
		||||
               {
 | 
			
		||||
                  // Just try again
 | 
			
		||||
                  continue;
 | 
			
		||||
               }
 | 
			
		||||
 | 
			
		||||
               // An unrecoverable error was encountered during the send operation,
 | 
			
		||||
               // assume there was a communication failure. Close the socket to make
 | 
			
		||||
               // sure that the connectionThread cleans up.
 | 
			
		||||
               //printf("SChannel::sendReplyData- sendmsgn error, totalBytesSent = %d, bytesToSend = %d, errno = %d\n", totalBytesSent, bytesToSend, errno);
 | 
			
		||||
               DbgTrace(0, "SChannel::sendReplyData- sendmsgn error, errno = %d\n", errno);
 | 
			
		||||
               m_state = State_Disconnected;
 | 
			
		||||
               shutdown(m_socket, SHUT_RDWR);
 | 
			
		||||
               struct linger linger_opt = {1, 15};
 | 
			
		||||
               setsockopt(m_socket, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(linger_opt));
 | 
			
		||||
               closesocket(m_socket);
 | 
			
		||||
               m_socket = INVALID_SOCKET;
 | 
			
		||||
               break;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
               // Account for the bytes sent
 | 
			
		||||
               totalBytesSent += bytesSent;
 | 
			
		||||
 | 
			
		||||
               // Check if we are done sending all of the data
 | 
			
		||||
               if (totalBytesSent >= bytesToSend)
 | 
			
		||||
               {
 | 
			
		||||
                  // We are done
 | 
			
		||||
                  break;
 | 
			
		||||
               }
 | 
			
		||||
               else
 | 
			
		||||
               {
 | 
			
		||||
                  // Adjust the ioVector structure to send data not yet sent
 | 
			
		||||
                  if (totalBytesSent >= sizeof(reqDataPktHdr))
 | 
			
		||||
                  {
 | 
			
		||||
                     // The packet header was sent, use only one ioVector.
 | 
			
		||||
                     int   serverDataAlreadySent = totalBytesSent - sizeof(reqDataPktHdr);
 | 
			
		||||
                     ioVectors[0].iov_base = (char*) pServerData + serverDataAlreadySent;
 | 
			
		||||
                     ioVectors[0].iov_len = serverDataLen - serverDataAlreadySent;
 | 
			
		||||
                     sendmsgHdr.msg_iov = ioVectors;
 | 
			
		||||
                     sendmsgHdr.msg_iovlen = 1;
 | 
			
		||||
                  }
 | 
			
		||||
                  else
 | 
			
		||||
                  {
 | 
			
		||||
                     // Not all of the packet header was sent, use two ioVectors.
 | 
			
		||||
                     ioVectors[0].iov_base = (char*) reqDataPktHdr + totalBytesSent;
 | 
			
		||||
                     ioVectors[0].iov_len = sizeof(reqDataPktHdr) - totalBytesSent;
 | 
			
		||||
                     ioVectors[1].iov_base = (char*) pServerData;
 | 
			
		||||
                     ioVectors[1].iov_len = serverDataLen;
 | 
			
		||||
                     sendmsgHdr.msg_iov = ioVectors;
 | 
			
		||||
                     sendmsgHdr.msg_iovlen = 2;
 | 
			
		||||
                  }
 | 
			
		||||
               }
 | 
			
		||||
            }
 | 
			
		||||
         }
 | 
			
		||||
 | 
			
		||||
         // Return success even if the send failed to allow things to be cleaned up
 | 
			
		||||
         // by the connectionThread routine.
 | 
			
		||||
         retStatus = 0;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
         DbgTrace(0, "SChannel::sendReplyData- Error building Req Data Pkt Header, Obj = %08X\n", this);
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
   else
 | 
			
		||||
   {
 | 
			
		||||
      DbgTrace(1, "SChannel::sendReplyData- Channel not connected, state = %08X\n", m_state);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Release exclusive access to the channel object
 | 
			
		||||
   pthread_mutex_unlock(&m_mutex);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::sendReplyData- End, retStatus = %08X\n", retStatus);
 | 
			
		||||
 | 
			
		||||
   return retStatus;
 | 
			
		||||
 | 
			
		||||
}  /*-- SChannel::sendReplyData() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
int
 | 
			
		||||
SChannel::sendReplyError(
 | 
			
		||||
   uint32_t reqId)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
//  Environment:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   int            retStatus = -1;
 | 
			
		||||
   char           reqErrorPktHdr[ReqErrorPktHdrTemplate.length()];
 | 
			
		||||
   struct msghdr  sendmsgHdr = {0};
 | 
			
		||||
   struct iovec   ioVectors[1];
 | 
			
		||||
   unsigned long  bytesSent;
 | 
			
		||||
   unsigned long  totalBytesSent = 0;
 | 
			
		||||
   unsigned long  bytesToSend = sizeof(reqErrorPktHdr);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::sendReplyError- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Acquire exclusive access to the channel object
 | 
			
		||||
   pthread_mutex_lock(&m_mutex);
 | 
			
		||||
 | 
			
		||||
   // Verify that the channel is connected
 | 
			
		||||
   if (m_state == State_Connected)
 | 
			
		||||
   {
 | 
			
		||||
      // Build ReqErrorHeader
 | 
			
		||||
      if (ChannelProto::buildReqErrorPktHdr(reqId,
 | 
			
		||||
                                            0,
 | 
			
		||||
                                            reqErrorPktHdr) == 0)
 | 
			
		||||
      {
 | 
			
		||||
         // Packet header was built, now sent it along with the client data to
 | 
			
		||||
         // the server.
 | 
			
		||||
         ioVectors[0].iov_base = reqErrorPktHdr;
 | 
			
		||||
         ioVectors[0].iov_len = sizeof(reqErrorPktHdr);
 | 
			
		||||
         sendmsgHdr.msg_iov = ioVectors;
 | 
			
		||||
         sendmsgHdr.msg_iovlen = 1;
 | 
			
		||||
         while (1)
 | 
			
		||||
         {
 | 
			
		||||
            bytesSent = sendmsg(m_socket,
 | 
			
		||||
                                &sendmsgHdr,
 | 
			
		||||
                                MSG_NOSIGNAL);
 | 
			
		||||
            if (bytesSent == SOCKET_ERROR)
 | 
			
		||||
            {
 | 
			
		||||
               // Check if we were interrupted during the transfer
 | 
			
		||||
               if (errno == EINTR)
 | 
			
		||||
               {
 | 
			
		||||
                  // Just try again
 | 
			
		||||
                  continue;
 | 
			
		||||
               }
 | 
			
		||||
 | 
			
		||||
               // An unrecoverable error was encountered during the send operation,
 | 
			
		||||
               // assume there was a communication failure. Close the socket to make
 | 
			
		||||
               // sure that the connectionThread cleans up.
 | 
			
		||||
               //printf("SChannel::sendReplyError- sendmsgn error, totalBytesSent = %d, bytesToSend = %d, errno = %d\n", totalBytesSent, bytesToSend, errno);
 | 
			
		||||
               DbgTrace(0, "SChannel::sendReplyError- sendmsgn error, errno = %d\n", errno);
 | 
			
		||||
               m_state = State_Disconnected;
 | 
			
		||||
               shutdown(m_socket, SHUT_RDWR);
 | 
			
		||||
               struct linger linger_opt = {1, 15};
 | 
			
		||||
               setsockopt(m_socket, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(linger_opt));
 | 
			
		||||
               closesocket(m_socket);
 | 
			
		||||
               m_socket = INVALID_SOCKET;
 | 
			
		||||
               break;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
               // Account for the bytes sent
 | 
			
		||||
               totalBytesSent += bytesSent;
 | 
			
		||||
 | 
			
		||||
               // Check if we are done sending all of the data
 | 
			
		||||
               if (totalBytesSent >= bytesToSend)
 | 
			
		||||
               {
 | 
			
		||||
                  // We are done
 | 
			
		||||
                  break;
 | 
			
		||||
               }
 | 
			
		||||
               else
 | 
			
		||||
               {
 | 
			
		||||
                  // Adjust the ioVector structure to send data not yet sent
 | 
			
		||||
                  ioVectors[0].iov_base = (char*) reqErrorPktHdr + totalBytesSent;
 | 
			
		||||
                  ioVectors[0].iov_len = sizeof(reqErrorPktHdr) - totalBytesSent;
 | 
			
		||||
                  sendmsgHdr.msg_iov = ioVectors;
 | 
			
		||||
                  sendmsgHdr.msg_iovlen = 1;
 | 
			
		||||
               }
 | 
			
		||||
            }
 | 
			
		||||
         }
 | 
			
		||||
 | 
			
		||||
         // Return success even if the send failed to allow things to be cleaned up
 | 
			
		||||
         // by the connectionThread routine.
 | 
			
		||||
         retStatus = 0;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
         DbgTrace(0, "SChannel::sendReplyError- Error building Req Data Pkt Header, Obj = %08X\n", this);
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
   else
 | 
			
		||||
   {
 | 
			
		||||
      DbgTrace(1, "SChannel::sendReplyError- Channel not connected, state = %08X\n", m_state);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Release exclusive access to the channel object
 | 
			
		||||
   pthread_mutex_unlock(&m_mutex);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "SChannel::sendReplyError- End, retStatus = %08X\n", retStatus);
 | 
			
		||||
 | 
			
		||||
   return retStatus;
 | 
			
		||||
 | 
			
		||||
}  /*-- SChannel::sendReplyError() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//=========================================================================
 | 
			
		||||
//=========================================================================
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										178
									
								
								CASA-auth-token/server/utilities/IpcLibs/linux/server/schannel.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								CASA-auth-token/server/utilities/IpcLibs/linux/server/schannel.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,178 @@
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * 
 | 
			
		||||
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is free software; you can redistribute it and/or
 | 
			
		||||
 *  modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 *  License as published by the Free Software Foundation; version 2.1
 | 
			
		||||
 *  of the License.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 *  Library Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 *  License along with this library; if not, Novell, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 *  To contact Novell about this file by physical or electronic mail, 
 | 
			
		||||
 *  you may find current contact information at www.novell.com.
 | 
			
		||||
 * 
 | 
			
		||||
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
 *
 | 
			
		||||
 ***********************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef _SCHANNEL_
 | 
			
		||||
#define _SCHANNEL_
 | 
			
		||||
 | 
			
		||||
//===[ Include files ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External data ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Manifest constants ]================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
// Forward reference
 | 
			
		||||
class ServerReq;
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// SChannel Class Definition
 | 
			
		||||
//
 | 
			
		||||
class SChannel : public ObjRef
 | 
			
		||||
{
 | 
			
		||||
   // Object State
 | 
			
		||||
   enum ChannelStates
 | 
			
		||||
   {
 | 
			
		||||
      State_FailedInitialization = 1,
 | 
			
		||||
      State_Connected,
 | 
			
		||||
      State_Disconnected,
 | 
			
		||||
      State_Closed
 | 
			
		||||
   };
 | 
			
		||||
   ChannelStates        m_state;
 | 
			
		||||
 | 
			
		||||
   // Connection socket
 | 
			
		||||
   int                  m_socket;
 | 
			
		||||
 | 
			
		||||
   // Synchronization variables
 | 
			
		||||
   pthread_mutex_t      m_mutex;
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Server Request Map - This map contains all of the active ServerReq objects.
 | 
			
		||||
   //                      The key used to obtain ServerReq object in the map
 | 
			
		||||
   //                      is the Request Id.
 | 
			
		||||
   //
 | 
			
		||||
   typedef map<uint32_t, ServerReq*> RSMap;
 | 
			
		||||
   typedef RSMap::iterator RSMapIter;
 | 
			
		||||
   typedef pair<RSMapIter, bool> RSIterBoolPair;
 | 
			
		||||
   RSMap                m_rsMap;
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Service connection thread procedure
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    pSmartSChannel (input) -
 | 
			
		||||
   //       Pointer to SmartPtr<SChannel> object.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Thread in charge of servicing channel connection.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   static void* connectionThread(SmartPtr<SChannel> *pSmartSChannel);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Constructor
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    connSocket (input) -
 | 
			
		||||
   //       Socket for channel connection.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Constructs SChannel object.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   SChannel(int connSocket);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Destructor
 | 
			
		||||
   ~SChannel(void);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Initialization routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters: None.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Initializes SChannel object.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: 0 if successful.
 | 
			
		||||
   //
 | 
			
		||||
   int init(void);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Close channel routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters: None.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Closes the channel.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   void closeChannel(void);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Send Reply Data routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    reqId (input) -
 | 
			
		||||
   //       Request Id.
 | 
			
		||||
   //       
 | 
			
		||||
   //    pServerData (input) -
 | 
			
		||||
   //       Pointer to server data that must be sent to
 | 
			
		||||
   //       the client. Buffer is NOT released by the
 | 
			
		||||
   //       procedure.
 | 
			
		||||
   //
 | 
			
		||||
   //    serverDataLen (input) -
 | 
			
		||||
   //       Length of the server data.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Sends data to the client for active Request.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: 0 if successful.
 | 
			
		||||
   //
 | 
			
		||||
   int sendReplyData(uint32_t reqId,
 | 
			
		||||
                     char *pServerData,
 | 
			
		||||
                     int32_t serverDataLen);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Send Reply Error routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    reqId (input) -
 | 
			
		||||
   //       Request Id.
 | 
			
		||||
   //       
 | 
			
		||||
   // Abstract: Indicates to the client that the request was
 | 
			
		||||
   //           not processed successfully..
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: 0 if successful.
 | 
			
		||||
   //
 | 
			
		||||
   int sendReplyError(uint32_t reqId);
 | 
			
		||||
};
 | 
			
		||||
typedef SmartPtr<SChannel> SmartSChannel;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // _SCHANNEL_
 | 
			
		||||
 | 
			
		||||
//=========================================================================
 | 
			
		||||
//=========================================================================
 | 
			
		||||
							
								
								
									
										1354
									
								
								CASA-auth-token/server/utilities/IpcLibs/linux/server/server.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1354
									
								
								CASA-auth-token/server/utilities/IpcLibs/linux/server/server.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,225 @@
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * 
 | 
			
		||||
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is free software; you can redistribute it and/or
 | 
			
		||||
 *  modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 *  License as published by the Free Software Foundation; version 2.1
 | 
			
		||||
 *  of the License.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 *  Library Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 *  License along with this library; if not, Novell, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 *  To contact Novell about this file by physical or electronic mail, 
 | 
			
		||||
 *  you may find current contact information at www.novell.com.
 | 
			
		||||
 * 
 | 
			
		||||
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
 *
 | 
			
		||||
 ***********************************************************************/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Include files ]=====================================================
 | 
			
		||||
 | 
			
		||||
#include "ipcint.h"
 | 
			
		||||
#include "schannel.h"
 | 
			
		||||
#include "serverreq.h"
 | 
			
		||||
#include <assert.h>     // Ensure that NDEBUG is defined for release builds!
 | 
			
		||||
 | 
			
		||||
//===[ External data ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Manifest constants ]================================================
 | 
			
		||||
 | 
			
		||||
#define SERVER_REQ_SIGNATURE  0x52525653 // SVRR
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Object Counters
 | 
			
		||||
//
 | 
			
		||||
unsigned long  numServerReqObjects = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
ServerReq::ServerReq(
 | 
			
		||||
   SChannel *pSChannel,
 | 
			
		||||
   uint32_t reqId,
 | 
			
		||||
   char *pClientData,
 | 
			
		||||
   int32_t clientDataLength) :
 | 
			
		||||
 | 
			
		||||
   m_signature (SERVER_REQ_SIGNATURE),
 | 
			
		||||
   m_reqId (reqId),
 | 
			
		||||
   m_pClientData (pClientData),
 | 
			
		||||
   m_clientDataLength (clientDataLength)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "ServerReq::ServerReq- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Create a SmartSChannel object to keep the SChannel object from
 | 
			
		||||
   // going away while we process the request.
 | 
			
		||||
   m_pSmartSChannel = new SmartSChannel(pSChannel);
 | 
			
		||||
 | 
			
		||||
   // Increment the object count
 | 
			
		||||
   InterlockedIncrement(&numServerReqObjects);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerReq::ServerReq- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerReq::ServerReq() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
ServerReq::~ServerReq(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "ServerReq::~ServerReq- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Free any client data that may be hanging around
 | 
			
		||||
   if (m_pClientData)
 | 
			
		||||
      free(m_pClientData);
 | 
			
		||||
 | 
			
		||||
   // Delete the SmartSChannel
 | 
			
		||||
   delete m_pSmartSChannel;
 | 
			
		||||
 | 
			
		||||
   // Decrement the object count
 | 
			
		||||
   InterlockedDecrement(&numServerReqObjects);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerReq::~ServerReq- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerReq::~ServerReq() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
int
 | 
			
		||||
ServerReq::getReqData(
 | 
			
		||||
   char **ppClientData)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "ServerReq::getReqData- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
#if DEBUG
 | 
			
		||||
   assert(m_signature == SERVER_REQ_SIGNATURE);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
   // Return pointer to the client data
 | 
			
		||||
   *ppClientData = m_pClientData;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerReq::getReqData- End, reqDataLen = %08X\n", m_clientDataLength);
 | 
			
		||||
 | 
			
		||||
   return m_clientDataLength;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void
 | 
			
		||||
ServerReq::complete(
 | 
			
		||||
   char *pServerData)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   SChannel    *pSChannel = *m_pSmartSChannel;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerReq::complete- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
#if DEBUG
 | 
			
		||||
   assert(m_signature == SERVER_REQ_SIGNATURE);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
   // Send data to the client
 | 
			
		||||
   pSChannel->sendReplyData(m_reqId,
 | 
			
		||||
                            pServerData,
 | 
			
		||||
                            strlen(pServerData));
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerReq::complete- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerReq::complete() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void
 | 
			
		||||
ServerReq::abort(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   SChannel    *pSChannel = *m_pSmartSChannel;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerReq::abort- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
#if DEBUG
 | 
			
		||||
   assert(m_signature == SERVER_REQ_SIGNATURE);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
   // Send an error to the client
 | 
			
		||||
   pSChannel->sendReplyError(m_reqId);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerReq::abort- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerReq::abort() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//=========================================================================
 | 
			
		||||
//=========================================================================
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,145 @@
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * 
 | 
			
		||||
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is free software; you can redistribute it and/or
 | 
			
		||||
 *  modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 *  License as published by the Free Software Foundation; version 2.1
 | 
			
		||||
 *  of the License.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 *  Library Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 *  License along with this library; if not, Novell, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 *  To contact Novell about this file by physical or electronic mail, 
 | 
			
		||||
 *  you may find current contact information at www.novell.com.
 | 
			
		||||
 * 
 | 
			
		||||
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
 *
 | 
			
		||||
 ***********************************************************************/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef _SERVERREQ_
 | 
			
		||||
#define _SERVERREQ_
 | 
			
		||||
 | 
			
		||||
//===[ Include files ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External data ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Manifest constants ]================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Server Request Class
 | 
			
		||||
//
 | 
			
		||||
class ServerReq
 | 
			
		||||
{
 | 
			
		||||
   // Signature
 | 
			
		||||
   unsigned long           m_signature;
 | 
			
		||||
 | 
			
		||||
   // Id of request being processed
 | 
			
		||||
   uint32_t                m_reqId;
 | 
			
		||||
 | 
			
		||||
   // SmartSChannel object pointer for request being processed.
 | 
			
		||||
   SmartSChannel           *m_pSmartSChannel;
 | 
			
		||||
 | 
			
		||||
   // Request Client Data
 | 
			
		||||
   char                    *m_pClientData;
 | 
			
		||||
   int32_t                 m_clientDataLength;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Destructor
 | 
			
		||||
   ~ServerReq(void);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Constructor
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    pSChannel (input) -
 | 
			
		||||
   //       Pointer to SChannel object.
 | 
			
		||||
   //
 | 
			
		||||
   //    reqId (input) -
 | 
			
		||||
   //       Request Id.
 | 
			
		||||
   //
 | 
			
		||||
   //    pClientData (input) -
 | 
			
		||||
   //       Pointer to buffer containing the client data.
 | 
			
		||||
   //       Buffer is released when the object is destroyed.
 | 
			
		||||
   //
 | 
			
		||||
   //    clientDataLength (input) -
 | 
			
		||||
   //       Length of the client data.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Constructs ServerReq object.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   ServerReq(SChannel *pSChannel,
 | 
			
		||||
             uint32_t reqId,
 | 
			
		||||
             char *pClientData,
 | 
			
		||||
             int32_t clientDataLength);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Get request Data routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    ppClientData (input/output) -
 | 
			
		||||
   //       Pointer to variable that will receive pointer to
 | 
			
		||||
   //       data sent by the client. Buffer should NOT released by
 | 
			
		||||
   //       caller.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Sends the requests reply data to the client.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: The length of the client request data. 0 if not successful.
 | 
			
		||||
   //
 | 
			
		||||
   int getReqData(char **ppClientData);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Complete Request routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    pServerData (input) -
 | 
			
		||||
   //       Pointer to server data that must be sent to
 | 
			
		||||
   //       the client. Buffer is NOT released by the
 | 
			
		||||
   //       procedure.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Completes the request.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   void complete(char *pServerData);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Abort Request routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters: None.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Aborts the request.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   void abort(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // _SERVERREQ_
 | 
			
		||||
 | 
			
		||||
//=========================================================================
 | 
			
		||||
//=========================================================================
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,181 @@
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * 
 | 
			
		||||
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is free software; you can redistribute it and/or
 | 
			
		||||
 *  modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 *  License as published by the Free Software Foundation; version 2.1
 | 
			
		||||
 *  of the License.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 *  Library Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 *  License along with this library; if not, Novell, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 *  To contact Novell about this file by physical or electronic mail, 
 | 
			
		||||
 *  you may find current contact information at www.novell.com.
 | 
			
		||||
 * 
 | 
			
		||||
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
 *
 | 
			
		||||
 ***********************************************************************/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Include files ]=====================================================
 | 
			
		||||
 | 
			
		||||
#include "ipcint.h"
 | 
			
		||||
#include "serverthread.h"
 | 
			
		||||
#include <assert.h>     // Ensure that NDEBUG is defined for release builds!
 | 
			
		||||
 | 
			
		||||
//===[ External data ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Manifest constants ]================================================
 | 
			
		||||
 | 
			
		||||
#define SERVER_THREAD_SIGNATURE  0x54525653 // SVRT
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Object Counters
 | 
			
		||||
//
 | 
			
		||||
unsigned long  numServerThreadObjects = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
ServerThread::ServerThread(void) :
 | 
			
		||||
 | 
			
		||||
   m_signature (SERVER_THREAD_SIGNATURE)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "ServerThread::ServerThread- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Initialize the condition
 | 
			
		||||
   if (pthread_cond_init(&m_condition, NULL) != 0)
 | 
			
		||||
   {
 | 
			
		||||
      DbgTrace(0, "ServerThread::ServerThread- Condition initialization failed\n", 0);
 | 
			
		||||
 | 
			
		||||
      // Throw exception
 | 
			
		||||
      throw bad_alloc();
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Increment the object count
 | 
			
		||||
   InterlockedIncrement(&numServerThreadObjects);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerThread::ServerThread- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerThread::ServerThread() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
ServerThread::~ServerThread(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "ServerThread::~ServerThread- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
   // Cleanup resources allocated for the object
 | 
			
		||||
   pthread_cond_destroy(&m_condition);
 | 
			
		||||
 | 
			
		||||
   // Decrement the object count
 | 
			
		||||
   InterlockedDecrement(&numServerThreadObjects);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerThread::~ServerThread- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerThread::~ServerThread() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void
 | 
			
		||||
ServerThread::awaken(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "ServerThread::awaken- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
#if DEBUG
 | 
			
		||||
   assert(m_signature == SERVER_THREAD_SIGNATURE);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
   // Signal ourselves to wake up
 | 
			
		||||
   pthread_cond_signal(&m_condition);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerThread::awaken- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerThread::awaken() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void
 | 
			
		||||
ServerThread::suspend(
 | 
			
		||||
   pthread_mutex_t *pMutex)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "ServerThread::suspend- Start, Obj = %08X\n", this);
 | 
			
		||||
 | 
			
		||||
#if DEBUG
 | 
			
		||||
   assert(m_signature == SERVER_THREAD_SIGNATURE);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
   // Wait until signaled to awaken 
 | 
			
		||||
   pthread_cond_wait(&m_condition, pMutex);
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ServerThread::suspend- End\n", 0);
 | 
			
		||||
 | 
			
		||||
}  /*-- ServerThread::suspend() --*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//=========================================================================
 | 
			
		||||
//=========================================================================
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,107 @@
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * 
 | 
			
		||||
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is free software; you can redistribute it and/or
 | 
			
		||||
 *  modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 *  License as published by the Free Software Foundation; version 2.1
 | 
			
		||||
 *  of the License.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 *  Library Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 *  License along with this library; if not, Novell, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 *  To contact Novell about this file by physical or electronic mail, 
 | 
			
		||||
 *  you may find current contact information at www.novell.com.
 | 
			
		||||
 * 
 | 
			
		||||
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
 *
 | 
			
		||||
 ***********************************************************************/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef _SERVERTHREAD_
 | 
			
		||||
#define _SERVERTHREAD_
 | 
			
		||||
 | 
			
		||||
//===[ Include files ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External data ]=====================================================
 | 
			
		||||
 | 
			
		||||
//===[ External prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Manifest constants ]================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// Server Thread Class
 | 
			
		||||
//
 | 
			
		||||
class ServerThread
 | 
			
		||||
{
 | 
			
		||||
   // Signature
 | 
			
		||||
   unsigned long           m_signature;
 | 
			
		||||
 | 
			
		||||
   // Synchronization variable
 | 
			
		||||
   pthread_cond_t          m_condition;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Destructor
 | 
			
		||||
   ~ServerThread(void);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Constructor
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters: None.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Constructs ServerThread object.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   ServerThread(void);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Awaken ServerThread routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters: None.
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Awakens a ServerThread.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   void awaken(void);
 | 
			
		||||
 | 
			
		||||
   //
 | 
			
		||||
   // Suspend ServerThread routine
 | 
			
		||||
   //
 | 
			
		||||
   // Parameters:
 | 
			
		||||
   //    pMutex (input) -
 | 
			
		||||
   //       Pointer to mutex to associate with
 | 
			
		||||
   //       condition used for waiting..
 | 
			
		||||
   //
 | 
			
		||||
   // Abstract: Suspends a ServerThread.
 | 
			
		||||
   //
 | 
			
		||||
   // Returns: Nothing.
 | 
			
		||||
   //
 | 
			
		||||
   void suspend(pthread_mutex_t *pMutex);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // _SERVERTHREAD_
 | 
			
		||||
 | 
			
		||||
//=========================================================================
 | 
			
		||||
//=========================================================================
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								CASA-auth-token/server/utilities/IpcLibs/linux/server/test/makeServer.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								CASA-auth-token/server/utilities/IpcLibs/linux/server/test/makeServer.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
gcc -o TestServer testServer.c -g -I../../../../../include -L../../../../../lib/Release -lpthread -lcasa_s_ipc -Xlinker -rpath -Xlinker ../../../../../lib/Release
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,311 @@
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * 
 | 
			
		||||
 *  Copyright (C) 2006 Novell, Inc. All Rights Reserved.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is free software; you can redistribute it and/or
 | 
			
		||||
 *  modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 *  License as published by the Free Software Foundation; version 2.1
 | 
			
		||||
 *  of the License.
 | 
			
		||||
 *
 | 
			
		||||
 *  This library is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 *  Library Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 *  License along with this library; if not, Novell, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 *  To contact Novell about this file by physical or electronic mail, 
 | 
			
		||||
 *  you may find current contact information at www.novell.com.
 | 
			
		||||
 * 
 | 
			
		||||
 *  Author: Juan Carlos Luciani <jluciani@novell.com>
 | 
			
		||||
 *
 | 
			
		||||
 ***********************************************************************/
 | 
			
		||||
 | 
			
		||||
//===[ Include files ]=====================================================
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <getopt.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/socket.h>
 | 
			
		||||
#include <netdb.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "casa_s_ipc.h"
 | 
			
		||||
 | 
			
		||||
//===[ Type definitions ]==================================================
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// DbgTrace macro define
 | 
			
		||||
//
 | 
			
		||||
#define DbgTrace(LEVEL, X, Y) {                          \
 | 
			
		||||
   if (LEVEL == 0)                                       \
 | 
			
		||||
      printf(X, Y);                                      \
 | 
			
		||||
   else if (DebugLevel >= LEVEL)                         \
 | 
			
		||||
         printf(X, Y);                                   \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//===[ Function prototypes ]===============================================
 | 
			
		||||
 | 
			
		||||
//===[ Global variables ]==================================================
 | 
			
		||||
 | 
			
		||||
// Usage string
 | 
			
		||||
char  usage[] = "\nTest: usage: -l lifetime [-D DebugLevel]\n";
 | 
			
		||||
 | 
			
		||||
int DebugLevel = 3;
 | 
			
		||||
 | 
			
		||||
// Test lifetime
 | 
			
		||||
int   testLifetime = 60; // Seconds
 | 
			
		||||
 | 
			
		||||
bool  processingRequests = true;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void* UnInitThread()
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
//  Environment:
 | 
			
		||||
//
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   DbgTrace(1, "UnInitThread- Start\n", 0);
 | 
			
		||||
 | 
			
		||||
   // Sleep for the configured amount
 | 
			
		||||
   sleep(testLifetime);
 | 
			
		||||
 | 
			
		||||
   // Stop processing Rpc Requests
 | 
			
		||||
   processingRequests = false;
 | 
			
		||||
 | 
			
		||||
   // Un-init the Svc Rpc Service Subsystem
 | 
			
		||||
   IpcServerShutdown();
 | 
			
		||||
   
 | 
			
		||||
   DbgTrace(1, "UnInitThread- End\n", 0);
 | 
			
		||||
 | 
			
		||||
   // Exit
 | 
			
		||||
   pthread_exit(NULL);
 | 
			
		||||
 | 
			
		||||
   return 0;   // never-reached!
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void* ProcessRequestThread(int32_t requestId)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
//  Environment:
 | 
			
		||||
//
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   char  *pReqData = NULL;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ProcessRequestThread- Start\n", 0);
 | 
			
		||||
 | 
			
		||||
   // Get the rpc data
 | 
			
		||||
   int dataLen = IpcServerGetRequestData(requestId, &pReqData);
 | 
			
		||||
   if (dataLen != 0)
 | 
			
		||||
   {
 | 
			
		||||
      // Just echo the data back as the reply
 | 
			
		||||
      IpcServerCompleteRequest(requestId,pReqData);
 | 
			
		||||
   }
 | 
			
		||||
   else
 | 
			
		||||
   {
 | 
			
		||||
      DbgTrace(0, "ProcessRequestThread- Error obtaining Request data\n", 0);
 | 
			
		||||
      IpcServerAbortRequest(requestId);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ProcessRequestThread- End\n", 0);
 | 
			
		||||
   
 | 
			
		||||
   // Exit
 | 
			
		||||
   pthread_exit(NULL);
 | 
			
		||||
 | 
			
		||||
   return 0;   // never-reached!
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
void
 | 
			
		||||
ExecuteTests(void)
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
//  Environment:
 | 
			
		||||
//
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   pthread_t   thread;
 | 
			
		||||
   int         threadCreateStatus;
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ExecuteTests- Start\n", 0);
 | 
			
		||||
 | 
			
		||||
   // Initialize the Svc Ipc Subsystem
 | 
			
		||||
   if (IpcServerInit("TestServer",
 | 
			
		||||
                     DebugLevel,
 | 
			
		||||
                     false) == 0)
 | 
			
		||||
   {
 | 
			
		||||
      // Set the server listen address
 | 
			
		||||
      if (IpcServerSetInAddress(5000) == 0)
 | 
			
		||||
      {
 | 
			
		||||
         // Now start servicing requests.
 | 
			
		||||
         if (IpcServerStart() == 0)
 | 
			
		||||
         {
 | 
			
		||||
            // The Ipc subsystem was started, now create a thread for
 | 
			
		||||
            // un-initializing the Ipc subsystem after a while.
 | 
			
		||||
            threadCreateStatus = pthread_create(&thread,
 | 
			
		||||
                                                NULL,
 | 
			
		||||
                                                (void*(*)(void*))UnInitThread,
 | 
			
		||||
                                                (void*)NULL);
 | 
			
		||||
            if (threadCreateStatus != 0)
 | 
			
		||||
            {
 | 
			
		||||
               DbgTrace(0, "ExecuteTests- Unable to create un-initialization thread, error = %08X\n", threadCreateStatus);
 | 
			
		||||
               IpcServerShutdown();
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
               // Process Incoming Requests
 | 
			
		||||
               while (processingRequests)
 | 
			
		||||
               {
 | 
			
		||||
                  int32_t requestId = IpcServerGetRequest();
 | 
			
		||||
                  if (requestId != 0)
 | 
			
		||||
                  {
 | 
			
		||||
                     // Create a thread to handle the request
 | 
			
		||||
                     threadCreateStatus = pthread_create(&thread,
 | 
			
		||||
                                                         NULL,
 | 
			
		||||
                                                         (void*(*)(void*))ProcessRequestThread,
 | 
			
		||||
                                                         (void*)requestId);
 | 
			
		||||
                     if (threadCreateStatus != 0)
 | 
			
		||||
                     {
 | 
			
		||||
                        DbgTrace(0, "ExecuteTests- Unable to create process request thread, error = %08X\n", threadCreateStatus);
 | 
			
		||||
                        IpcServerAbortRequest(requestId);
 | 
			
		||||
                     }
 | 
			
		||||
                  }
 | 
			
		||||
                  else
 | 
			
		||||
                  {
 | 
			
		||||
                     // No need to service requests any longer
 | 
			
		||||
                     break;
 | 
			
		||||
                  }
 | 
			
		||||
               }
 | 
			
		||||
            }
 | 
			
		||||
         }
 | 
			
		||||
         else
 | 
			
		||||
         {
 | 
			
		||||
            DbgTrace(0, "ExecuteTests- Error starting the Ipc subsystem\n", 0);
 | 
			
		||||
            IpcServerShutdown();
 | 
			
		||||
         }
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
         DbgTrace(0, "ExecuteTests- Error setting server address\n", 0);
 | 
			
		||||
         IpcServerShutdown();
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
   else
 | 
			
		||||
   {
 | 
			
		||||
      DbgTrace(0, "ExecuteTests- Ipc subsystem initialization failed\n", 0);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   DbgTrace(1, "ExecuteTests- End\n", 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//++=======================================================================
 | 
			
		||||
int
 | 
			
		||||
main(
 | 
			
		||||
   int argc,
 | 
			
		||||
   char* argv[])
 | 
			
		||||
//
 | 
			
		||||
//  Arguments: 
 | 
			
		||||
//
 | 
			
		||||
//  Returns:   
 | 
			
		||||
//
 | 
			
		||||
//  Abstract:  
 | 
			
		||||
//
 | 
			
		||||
//  Notes:
 | 
			
		||||
//
 | 
			
		||||
// L2
 | 
			
		||||
//=======================================================================--
 | 
			
		||||
{
 | 
			
		||||
   int         optionsSpecified = 0;
 | 
			
		||||
   bool        doneScanning = false;
 | 
			
		||||
   bool        invalidOption = false;
 | 
			
		||||
   int         option;
 | 
			
		||||
 | 
			
		||||
   printf("**** Ipc Server test ****\n");
 | 
			
		||||
 | 
			
		||||
   // Scan through the options specified
 | 
			
		||||
   while (!doneScanning)
 | 
			
		||||
   {
 | 
			
		||||
      opterr = 0;
 | 
			
		||||
      option = getopt(argc, argv, "l:D:");
 | 
			
		||||
 | 
			
		||||
      // Proceed based on the result
 | 
			
		||||
      switch (option)
 | 
			
		||||
      {
 | 
			
		||||
         case 'D':
 | 
			
		||||
            // Set the debug level
 | 
			
		||||
            printf("DebugLevel = %s\n", optarg);
 | 
			
		||||
            DebugLevel = atoi(optarg);
 | 
			
		||||
            optionsSpecified++;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
         case 'l':
 | 
			
		||||
            // Set the test lifetime
 | 
			
		||||
            printf("Lifetime = %s\n", optarg);
 | 
			
		||||
            testLifetime = atoi(optarg);
 | 
			
		||||
            optionsSpecified++;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
         case '?':
 | 
			
		||||
            // Invalid option detected
 | 
			
		||||
            doneScanning = true;
 | 
			
		||||
            invalidOption = true;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
         default:
 | 
			
		||||
            // Done scanning
 | 
			
		||||
            doneScanning = true;
 | 
			
		||||
            break;
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // Do some sanity checking
 | 
			
		||||
   if (!invalidOption)
 | 
			
		||||
   {
 | 
			
		||||
      ExecuteTests();
 | 
			
		||||
   }
 | 
			
		||||
   else
 | 
			
		||||
   {
 | 
			
		||||
      // Invalid option detected
 | 
			
		||||
      printf(usage, argv[0]);
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   return 0;
 | 
			
		||||
 | 
			
		||||
}  /*-- main() --*/
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user