![]() |
botsense
3.2.0
RoadNarrows Client-Server Proxied Services Framework
|
BotSense proxy IP server. More...
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/opts.h"
#include "rnr/dlistvoid.h"
#include "rnr/dliststr.h"
#include "rnr/new.h"
#include "rnr/sock.h"
#include "rnr/sockset.h"
#include "botsense/bsProxyMsgs.h"
#include "version.h"
#include "bsProxy.h"
Go to the source code of this file.
Macros | |
#define | SERVER_LOG_ERROR(ecode, efmt, ...) |
Log Proxy Server Specific Error. More... | |
#define | SERVER_LOG_SYSERROR(efmt, ...) |
Log Proxy Server Specific System Error. More... | |
Functions | |
static int | OptsCvtArgInterface (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
Convert command-line listen interface option string to network name/number and port number. More... | |
static int | OptsCvtArgLibPath (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
Append command-line library search path option to list of search paths. More... | |
static void | ServerLock () |
Lock server's mutual exclusion. | |
static void | ServerUnlock () |
Unlock server's mutual exclusion. | |
static bool_t | ServerTryLock () |
Try to lock global mutual exclusion. More... | |
static BsProxyClientHnd_T | BsProxyClientRegister (Socket_T *pSockClient) |
Register a new client with the server. More... | |
static void | BsProxyClientUnregister (BsProxyClientHnd_T hndClient) |
Unregister a client with the server. More... | |
static void | BsProxyServerDelete (BsProxyServerCtl_T *pServer) |
Delete a server control block. More... | |
static BsProxyServerCtl_T * | BsProxyServerNew (const char *sPrefix, const char *sLocalHostName, int nPort) |
Create new server control block. More... | |
static void | BsProxyDispatch (BsProxyClientHnd_T hndClient, BsProxyMsgHdr_T *pMsgHdr, byte_t bufReq[]) |
Dispatch client request. More... | |
static int | BsProxyServer (BsProxyServerCtl_T *pServer) |
Server mainloop. More... | |
static void | MainEnv () |
Get and set environment. | |
static void | MainCfg () |
Get configuration. | |
static void | MainInit (int argc, char *argv[]) |
Main initialization. More... | |
int | main (int argc, char *argv[]) |
bsProxy main() More... | |
Variables | |
const char * | Argv0 |
command base name | |
static char * | BsOptListenIFDft = NULL |
default listen interface | |
static DListVoid_T * | BsOptDListListenIF = NULL |
list of listen i/f's | |
static DListStr_T * | BsOptDListLibPath = NULL |
list of lib search paths | |
static OptsPgmInfo_T | BsProxyPgmInfo |
static OptsInfo_T | BsProxyOptsInfo [] |
BsProxyServerCtl_T * | BsServerCtl |
The server control block. More... | |
BotSense proxy IP server.
Definition in file bsProxy.c.
#define SERVER_LOG_ERROR | ( | ecode, | |
efmt, | |||
... | |||
) |
Log Proxy Server Specific Error.
ecode |
Definition at line 159 of file bsProxy.c.
Referenced by BsProxyServer().
#define SERVER_LOG_SYSERROR | ( | efmt, | |
... | |||
) |
Log Proxy Server Specific System Error.
efmt | Error output format string litteral. |
... | Error variable arguments. |
Definition at line 171 of file bsProxy.c.
Referenced by ServerLock(), and ServerUnlock().
|
static |
Register a new client with the server.
pSockClient | Accecpted client socket. |
Definition at line 224 of file bsProxy.c.
References ClientNew(), BsProxyClientCtl_T::m_pClientSock, BsProxyServerCtl_T::m_pServerRegClient, BsProxyServerCtl_T::m_pServerSockSet, BsProxyServerCtl_T::m_uServerRegClientCount, ServerClientSd2Hnd(), and ServerGet().
Referenced by BsProxyServer().
|
static |
Unregister a client with the server.
Okay, this is messy. A client may disconnect from the server at any time, leaving many virtual connections open. The server thread could be processing open and close requests on this zombie client while device threads could be sending responses on the same client. Hopefully, all will work out with only a few diagnotics messages printed.
hndClient |
Definition at line 266 of file bsProxy.c.
References BSPROXY_VCONN_MOD_MAX, BSPROXY_VCONN_MOD_MIN, BsProxyClientStateZombie, ClientAcquire(), ClientDelete(), ClientSetState(), BsProxyVConn_T::m_hndClient, BsProxyClientCtl_T::m_pClientSock, BsProxyServerCtl_T::m_pServerRegClient, BsProxyServerCtl_T::m_pServerSockSet, BsProxyClientCtl_T::m_uRefCnt, BsProxyServerCtl_T::m_uServerRegClientCount, ServerClientHnd2Sd(), ServerGet(), VConnClose(), and VConnGet().
Referenced by BsProxyServer(), and BsProxyServerDelete().
|
static |
Dispatch client request.
The client request is queued in the appropriate service thread.
hndClient |
Definition at line 423 of file bsProxy.c.
References BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_RSRC, BS_ECODE_NO_VCONN, BSPROXY_CHK_VCONN_HND, BSPROXY_SEND_ERROR_RSP, BsProxyMsgHdr_T::m_hdrBodyLen, BsProxyMsgHdr_T::m_hdrMsgId, BsProxyMsgHdr_T::m_hdrTid, BsProxyMsgHdr_T::m_hdrVConn, BsProxyVConn_T::m_pThCtl, ThQueue(), VConnAcquire(), and VConnRelease().
Referenced by BsProxyServer().
|
static |
Server mainloop.
Processes all client registrations, requests, and unregistrations.
pServer |
Definition at line 489 of file bsProxy.c.
References BS_ECODE_GEN, BS_ECODE_INTERNAL, BS_ECODE_SERVER_BAD_CLIENT, BS_ECODE_SERVER_CONN_DENY, BS_OK, BSPROXY_FD_SETSIZE, BSPROXY_REG_CLIENT_MAX, BSPROXY_TUNE_T_SELECT, BsProxyClientRegister(), BsProxyClientUnregister(), BsProxyDispatch(), ClientHasName(), ClientRecvReq(), BsProxyServerCtl_T::m_pServerSockListener, BsProxyServerCtl_T::m_pServerSockSet, BsProxyServerCtl_T::m_uServerRegClientCount, SERVER_LOG_ERROR, ServerClientSd2Hnd(), ServerGetClient(), ServerHasName(), and ServerHasPort().
Referenced by main().
|
static |
Delete a server control block.
pServer |
Definition at line 325 of file bsProxy.c.
References BSPROXY_FD_SETSIZE, BsProxyClientUnregister(), BsProxyServerCtl_T::m_mutex, BsProxyServerCtl_T::m_pServerRegClient, BsProxyServerCtl_T::m_pServerSockListener, BsProxyServerCtl_T::m_pServerSockSet, BsProxyServerCtl_T::m_sServerName, and ServerClientHnd2Sd().
Referenced by BsProxyServerNew().
|
static |
Create new server control block.
sPrefix | Server name prefix. |
sLocalHostName | Local host interface to bind to. |
nPort | Server listener TCP port number. |
Definition at line 355 of file bsProxy.c.
References BS_ECODE_INTERNAL, BS_ECODE_SYS, BS_OK, BsProxyServerDelete(), BsProxyServerCtl_T::m_mutex, BsProxyServerCtl_T::m_nServerPort, BsProxyServerCtl_T::m_pServerSockListener, BsProxyServerCtl_T::m_pServerSockSet, BsProxyServerCtl_T::m_sServerName, and BsProxyServerCtl_T::m_uServerRegClientCount.
Referenced by main().
int main | ( | int | argc, |
char * | argv[] | ||
) |
bsProxy main()
argc | Count of command-line options and arguments. |
argv | Array of command-line options and arguments. |
Definition at line 841 of file bsProxy.c.
References Argv0, BS_OK, BsOptDListLibPath, BsOptDListListenIF, BsProxyServer(), BsProxyServerNew(), ClientOneTimeInit(), BsProxyListenIF_T::m_nPort, BsProxyListenIF_T::m_sAddr, MainInit(), ModOneTimeInit(), PkgInfo, ServerHasName(), ThOneTimeInit(), VConnOneTimeInit(), and VConnOpenServer().
|
static |
Main initialization.
Parses command-line options and arguments and environment variables to configure the BotsSense Proxy server.
argc | Count of command-line options and arguments. |
argv | Array of command-line options and arguments. |
Definition at line 779 of file bsProxy.c.
References Argv0, BsOptDListLibPath, BsOptDListListenIF, BsOptListenIFDft, BSPROXY_LISTEN_PORT_DFT, BsProxyOptsInfo, BsProxyPgmInfo, BsProxyListenIF_T::m_nPort, BsProxyListenIF_T::m_sAddr, MainCfg(), MainEnv(), and PkgInfo.
Referenced by main().
|
static |
Convert command-line listen interface option string to network name/number and port number.
argv0 | Command name. | |
sOptName | Option name. | |
optarg | Parsed option argument to convert (optional). | |
[out] | pOptVal | Pointer to converted option value (not used). |
OptsInvalid() |
Definition at line 700 of file bsProxy.c.
References Argv0, BS_OK, BsOptDListListenIF, BSPROXY_LISTEN_PORT_DFT, BsProxyListenIF_T::m_nPort, and BsProxyListenIF_T::m_sAddr.
|
static |
Append command-line library search path option to list of search paths.
argv0 | Command name. | |
sOptName | Option name. | |
optarg | Parsed option argument to convert (optional). | |
[out] | pOptVal | Pointer to converted option value (not used). |
OptsInvalid() |
Definition at line 761 of file bsProxy.c.
References BS_OK, and BsOptDListLibPath.
|
inlinestatic |
Try to lock global mutual exclusion.
Definition at line 212 of file bsProxy.c.
References BsServerCtl, and BsProxyServerCtl_T::m_mutex.
|
static |
Command Line Options Information.
Definition at line 118 of file bsProxy.c.
Referenced by MainInit().
|
static |
Program Information
Definition at line 99 of file bsProxy.c.
Referenced by MainInit().
BsProxyServerCtl_T* BsServerCtl |
The server control block.
Definition at line 831 of file bsProxy.c.
Referenced by ServerGet(), ServerLock(), ServerTryLock(), and ServerUnlock().