abyss_server.c File Reference

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <grp.h>
#include <fcntl.h>
#include <xmlrpc-c/config.h>
#include "abyss_mallocvar.h"
#include "abyss_xmlrpc_int.h"
#include <xmlrpc-c/abyss.h>
#include "abyss_trace.h"
#include "abyss_session.h"
#include "abyss_conn.h"
#include "abyss_socket.h"
#include "abyss_socket_unix.h"
#include "abyss_http.h"
#include "abyss_date.h"
#include "abyss_info.h"
#include "abyss_server.h"
#include "../../dprint.h"

Include dependency graph for abyss_server.c:

Go to the source code of this file.

Data Structures

struct  outstandingConnList

Defines

#define BOUNDARY   "##123456789###BOUNDARY"

Typedefs

typedef int(* TQSortProc )(const void *, const void *)

Functions

static void addToOutstandingConnList (outstandingConnList *const listP, TConn *const connectionP)
static int cmpfiledates (const TFileInfo **f1, const TFileInfo **f2)
static int cmpfilenames (const TFileInfo **f1, const TFileInfo **f2)
static void createAndBindSocket (struct _TServer *const srvP)
static URIHandler2 * createHandler (URIHandler const function)
static void createOutstandingConnList (outstandingConnList **const listPP)
static void createServer (struct _TServer **const srvPP, abyss_bool const noAccept, TSocket *const userSocketP, uint16_t const portNumber, const char **const errorP)
static void createSocketFromOsSocket (TOsSocket const osSocket, TSocket **const socketPP)
static void destroyConnSocket (void *const userHandle)
static void destroyOutstandingConnList (outstandingConnList *const listP)
static void determineSortType (const char *const query, abyss_bool *const ascendingP, uint16_t *const sortP, abyss_bool *const textP, const char **const errorP)
static void fileDate (TSession *const sessionP, time_t const statFilemodTime, TDate *const fileDateP)
static void freeFinishedConns (outstandingConnList *const listP)
static void generateListing (TList *const listP, char *const z, const char *const uri, TPool *const poolP, const char **const errorP, uint16_t *const responseStatusP)
static void initSocketStuff (struct _TServer *const srvP, abyss_bool const noAccept, TSocket *const userSocketP, uint16_t const port, const char **const errorP)
static void initUnixStuff (struct _TServer *const srvP)
static void logClose (struct _TServer *const srvP)
static abyss_bool logOpen (struct _TServer *const srvP)
void LogWrite (TServer *const serverP, const char *const msg)
static void processDataFromClient (TConn *const connectionP, abyss_bool const lastReqOnConn, abyss_bool *const keepAliveP)
static void runUserHandler (TSession *const sessionP, struct _TServer *const srvP)
static void sendBody (TSession *const sessionP, TFile *const fileP, uint64_t const filesize, const char *const mediatype, uint64_t const start0, uint64_t const end0, char *const z)
static void sendDirectoryDocument (TList *const listP, abyss_bool const ascending, uint16_t const sort, abyss_bool const text, const char *const uri, MIMEType *const mimeTypeP, TSession *const sessionP, char *const z)
abyss_bool ServerAddHandler (TServer *const serverP, URIHandler const function)
void ServerAddHandler2 (TServer *const serverP, URIHandler2 *const handlerArgP, abyss_bool *const successP)
abyss_bool ServerCreate (TServer *const serverP, const char *const name, uint16_t const portNumber, const char *const filesPath, const char *const logFileName)
abyss_bool ServerCreateNoAccept (TServer *const serverP, const char *const name, const char *const filesPath, const char *const logFileName)
abyss_bool ServerCreateSocket (TServer *const serverP, const char *const name, TOsSocket const socketFd, const char *const filesPath, const char *const logFileName)
void ServerCreateSocket2 (TServer *const serverP, TSocket *const socketP, const char **const errorP)
void ServerDaemonize (TServer *const serverP)
void ServerDefaultHandler (TServer *const serverP, URIHandler const handler)
static abyss_bool ServerDefaultHandlerFunc (TSession *const sessionP)
static abyss_bool ServerDirectoryHandler (TSession *const r, char *const z, time_t const fileModTime, MIMEType *const mimeTypeP)
static abyss_bool ServerFileHandler (TSession *const r, char *const z, time_t const fileModTime, MIMEType *const mimeTypeP)
void ServerFree (TServer *const serverP)
static void serverFunc (void *const userHandle)
void ServerHandleSigchld (pid_t const pid)
void ServerInit (TServer *const serverP)
void ServerResetTerminate (TServer *const serverP)
void ServerRun (TServer *const serverP)
static void serverRun2 (TServer *const serverP)
void ServerRunConn (TServer *const serverP, TOsSocket const connectedOsSocket)
static void serverRunConn (TServer *const serverP, TSocket *const connectedSocketP)
void ServerRunConn2 (TServer *const serverP, TSocket *const connectedSocketP, const char **const errorP)
void ServerRunOnce (TServer *const serverP)
void ServerRunOnce2 (TServer *const serverP, enum abyss_foreback const foregroundBackground ATTR_UNUSED)
void ServerSetAdvertise (TServer *const serverP, abyss_bool const advertise)
void ServerSetFilesPath (TServer *const serverP, const char *const filesPath)
void ServerSetKeepaliveMaxConn (TServer *const serverP, uint32_t const keepaliveMaxConn)
void ServerSetKeepaliveTimeout (TServer *const serverP, uint32_t const keepaliveTimeout)
void ServerSetLogFileName (TServer *const serverP, const char *const logFileName)
void ServerSetMimeType (TServer *const serverP, MIMEType *const MIMETypeP)
void ServerSetName (TServer *const serverP, const char *const name)
void ServerSetTimeout (TServer *const serverP, uint32_t const timeout)
void ServerTerminate (TServer *const serverP)
void ServerUseSigchld (TServer *const serverP)
static void setGroups (void)
static void setNamePathLog (TServer *const serverP, const char *const name, const char *const filesPath, const char *const logFileName)
static void terminateHandlers (TList *const handlersP)
static void waitForConnectionCapacity (outstandingConnList *const outstandingConnListP)
static void waitForConnectionFreed (outstandingConnList *const outstandingConnListP ATTR_UNUSED)
static void waitForNoConnections (outstandingConnList *const outstandingConnListP)

Variables

TThreadDoneFn destroySocket
static TThreadProc serverFunc


Define Documentation

#define BOUNDARY   "##123456789###BOUNDARY"

Definition at line 409 of file abyss_server.c.

Referenced by sendBody(), and ServerFileHandler().


Typedef Documentation

typedef int(* TQSortProc)(const void *, const void *)

Definition at line 57 of file abyss_server.c.


Function Documentation

static void addToOutstandingConnList ( outstandingConnList *const   listP,
TConn *const   connectionP 
) [static]

static int cmpfiledates ( const TFileInfo **  f1,
const TFileInfo **  f2 
) [static]

Definition at line 70 of file abyss_server.c.

References A_SUBDIR.

Referenced by sendDirectoryDocument().

static int cmpfilenames ( const TFileInfo **  f1,
const TFileInfo **  f2 
) [static]

Definition at line 60 of file abyss_server.c.

References A_SUBDIR.

Referenced by sendDirectoryDocument().

static void createAndBindSocket ( struct _TServer *const   srvP  )  [static]

static URIHandler2* createHandler ( URIHandler const   function  )  [static]

Definition at line 1694 of file abyss_server.c.

References MALLOCVAR, and NULL.

Referenced by ServerAddHandler().

static void createOutstandingConnList ( outstandingConnList **const   listPP  )  [static]

Definition at line 1234 of file abyss_server.c.

References outstandingConnList::count, outstandingConnList::firstP, MALLOCVAR_NOFAIL, and NULL.

Referenced by serverRun2().

static void createServer ( struct _TServer **const   srvPP,
abyss_bool const   noAccept,
TSocket *const   userSocketP,
uint16_t const   portNumber,
const char **const   errorP 
) [static]

static void createSocketFromOsSocket ( TOsSocket const   osSocket,
TSocket **const   socketPP 
) [static]

Definition at line 820 of file abyss_server.c.

References SocketUnixCreateFd().

Referenced by ServerCreateSocket(), and ServerRunConn().

static void destroyConnSocket ( void *const   userHandle  )  [static]

Definition at line 1374 of file abyss_server.c.

References SocketDestroy(), and _TConn::socketP.

Referenced by serverRun2().

static void destroyOutstandingConnList ( outstandingConnList *const   listP  )  [static]

Definition at line 1249 of file abyss_server.c.

References outstandingConnList::count, outstandingConnList::firstP, and NULL.

Referenced by serverRun2().

static void determineSortType ( const char *const   query,
abyss_bool *const   ascendingP,
uint16_t *const   sortP,
abyss_bool *const   textP,
const char **const   errorP 
) [static]

Definition at line 82 of file abyss_server.c.

References FALSE, NULL, TRUE, xmlrpc_asprintf(), and xmlrpc_streq().

Referenced by ServerDirectoryHandler().

static void fileDate ( TSession *const   sessionP,
time_t const   statFilemodTime,
TDate *const   fileDateP 
) [static]

Definition at line 312 of file abyss_server.c.

References TSession::date, DateCompare(), and DateFromLocal().

Referenced by ServerDirectoryHandler(), and ServerFileHandler().

static void freeFinishedConns ( outstandingConnList *const   listP  )  [static]

static void generateListing ( TList *const   listP,
char *const   z,
const char *const   uri,
TPool *const   poolP,
const char **const   errorP,
uint16_t *const   responseStatusP 
) [static]

static void initSocketStuff ( struct _TServer *const   srvP,
abyss_bool const   noAccept,
TSocket *const   userSocketP,
uint16_t const   port,
const char **const   errorP 
) [static]

static void initUnixStuff ( struct _TServer *const   srvP  )  [static]

Definition at line 647 of file abyss_server.c.

References _TServer::gid, _TServer::pidfile, and _TServer::uid.

Referenced by createServer().

static void logClose ( struct _TServer *const   srvP  )  [static]

static abyss_bool logOpen ( struct _TServer *const   srvP  )  [static]

void LogWrite ( TServer *const   serverP,
const char *const   msg 
)

static void processDataFromClient ( TConn *const   connectionP,
abyss_bool const   lastReqOnConn,
abyss_bool *const   keepAliveP 
) [static]

static void runUserHandler ( TSession *const   sessionP,
struct _TServer *const   srvP 
) [static]

static void sendBody ( TSession *const   sessionP,
TFile *const   fileP,
uint64_t const   filesize,
const char *const   mediatype,
uint64_t const   start0,
uint64_t const   end0,
char *const   z 
) [static]

static void sendDirectoryDocument ( TList *const   listP,
abyss_bool const   ascending,
uint16_t const   sort,
abyss_bool const   text,
const char *const   uri,
MIMEType *const   mimeTypeP,
TSession *const   sessionP,
char *const   z 
) [static]

abyss_bool ServerAddHandler ( TServer *const   serverP,
URIHandler const   function 
)

Definition at line 1712 of file abyss_server.c.

References createHandler(), FALSE, TServer::handlers, ListAdd(), and NULL.

Referenced by xmlrpc_process().

void ServerAddHandler2 ( TServer *const   serverP,
URIHandler2 *const   handlerArgP,
abyss_bool *const   successP 
)

Definition at line 1666 of file abyss_server.c.

References FALSE, TServer::handlers, ListAdd(), MALLOCVAR, NULL, and TRUE.

Referenced by setHandler().

abyss_bool ServerCreate ( TServer *const   serverP,
const char *const   name,
uint16_t const   portNumber,
const char *const   filesPath,
const char *const   logFileName 
)

Definition at line 791 of file abyss_server.c.

References createServer(), FALSE, NULL, setNamePathLog(), TraceMsg(), TRUE, and xmlrpc_strfree().

abyss_bool ServerCreateNoAccept ( TServer *const   serverP,
const char *const   name,
const char *const   filesPath,
const char *const   logFileName 
)

Definition at line 869 of file abyss_server.c.

References createServer(), FALSE, NULL, setNamePathLog(), TraceMsg(), TRUE, and xmlrpc_strfree().

abyss_bool ServerCreateSocket ( TServer *const   serverP,
const char *const   name,
TOsSocket const   socketFd,
const char *const   filesPath,
const char *const   logFileName 
)

void ServerCreateSocket2 ( TServer *const   serverP,
TSocket *const   socketP,
const char **const   errorP 
)

Definition at line 896 of file abyss_server.c.

References createServer(), and FALSE.

Referenced by createServerBoundSocket().

void ServerDaemonize ( TServer *const   serverP  ) 

void ServerDefaultHandler ( TServer *const   serverP,
URIHandler const   handler 
)

Definition at line 1734 of file abyss_server.c.

References TServer::defaulthandler, and ServerDefaultHandlerFunc().

Referenced by setHandlers(), and xmlrpc_process().

static abyss_bool ServerDefaultHandlerFunc ( TSession *const   sessionP  )  [static]

static abyss_bool ServerDirectoryHandler ( TSession *const   r,
char *const   z,
time_t const   fileModTime,
MIMEType *const   mimeTypeP 
) [static]

static abyss_bool ServerFileHandler ( TSession *const   r,
char *const   z,
time_t const   fileModTime,
MIMEType *const   mimeTypeP 
) [static]

void ServerFree ( TServer *const   serverP  ) 

static void serverFunc ( void *const   userHandle  )  [static]

void ServerHandleSigchld ( pid_t const   pid  ) 

Definition at line 1353 of file abyss_server.c.

References ThreadHandleSigchld().

Referenced by sigchld(), and xmlrpc_sigchld().

void ServerInit ( TServer *const   serverP  ) 

void ServerResetTerminate ( TServer *const   serverP  ) 

Definition at line 48 of file abyss_server.c.

References _TServer::terminationRequested.

void ServerRun ( TServer *const   serverP  ) 

static void serverRun2 ( TServer *const   serverP  )  [static]

void ServerRunConn ( TServer *const   serverP,
TOsSocket const   connectedOsSocket 
)

static void serverRunConn ( TServer *const   serverP,
TSocket *const   connectedSocketP 
) [static]

void ServerRunConn2 ( TServer *const   serverP,
TSocket *const   connectedSocketP,
const char **const   errorP 
)

Definition at line 1493 of file abyss_server.c.

References NULL, _TServer::serverAcceptsConnections, serverRunConn(), and xmlrpc_asprintf().

Referenced by ServerRunConn().

void ServerRunOnce ( TServer *const   serverP  ) 

void ServerRunOnce2 ( TServer *const   serverP,
enum abyss_foreback const foregroundBackground  ATTR_UNUSED 
)

Definition at line 1579 of file abyss_server.c.

References ServerRunOnce().

void ServerSetAdvertise ( TServer *const   serverP,
abyss_bool const   advertise 
)

Definition at line 1020 of file abyss_server.c.

References TServer::advertise.

Referenced by setAdditionalServerParms().

void ServerSetFilesPath ( TServer *const   serverP,
const char *const   filesPath 
)

Definition at line 968 of file abyss_server.c.

References TServer::filespath, and xmlrpc_strfree().

Referenced by setNamePathLog().

void ServerSetKeepaliveMaxConn ( TServer *const   serverP,
uint32_t const   keepaliveMaxConn 
)

Definition at line 1002 of file abyss_server.c.

References TServer::keepalivemaxconn.

Referenced by setAdditionalServerParms().

void ServerSetKeepaliveTimeout ( TServer *const   serverP,
uint32_t const   keepaliveTimeout 
)

Definition at line 993 of file abyss_server.c.

References TServer::keepalivetimeout.

Referenced by setAdditionalServerParms().

void ServerSetLogFileName ( TServer *const   serverP,
const char *const   logFileName 
)

Definition at line 979 of file abyss_server.c.

References _TServer::logfilename, and xmlrpc_strfree().

Referenced by createServerBoundSocket(), and setNamePathLog().

void ServerSetMimeType ( TServer *const   serverP,
MIMEType *const   MIMETypeP 
)

Definition at line 1029 of file abyss_server.c.

void ServerSetName ( TServer *const   serverP,
const char *const   name 
)

Definition at line 957 of file abyss_server.c.

References TServer::name, and xmlrpc_strfree().

Referenced by createServerBoundSocket(), and setNamePathLog().

void ServerSetTimeout ( TServer *const   serverP,
uint32_t const   timeout 
)

Definition at line 1011 of file abyss_server.c.

References TServer::timeout.

Referenced by setAdditionalServerParms().

void ServerTerminate ( TServer *const   serverP  ) 

Definition at line 38 of file abyss_server.c.

References _TServer::terminationRequested.

Referenced by shutdownAbyss().

void ServerUseSigchld ( TServer *const   serverP  ) 

Definition at line 1362 of file abyss_server.c.

References TRUE, and _TServer::useSigchld.

Referenced by normalLevelAbyssRun(), and runServerDaemon().

static void setGroups ( void   )  [static]

Definition at line 1597 of file abyss_server.c.

References NULL, and TraceExit().

Referenced by ServerDaemonize().

static void setNamePathLog ( TServer *const   serverP,
const char *const   name,
const char *const   filesPath,
const char *const   logFileName 
) [static]

static void terminateHandlers ( TList *const   handlersP  )  [static]

Definition at line 910 of file abyss_server.c.

References TList::item, and TList::size.

Referenced by ServerFree().

static void waitForConnectionCapacity ( outstandingConnList *const   outstandingConnListP  )  [static]

static void waitForConnectionFreed ( outstandingConnList *const outstandingConnListP  ATTR_UNUSED  )  [static]

Definition at line 1304 of file abyss_server.c.

References xmlrpc_millisecond_sleep().

Referenced by waitForConnectionCapacity(), and waitForNoConnections().

static void waitForNoConnections ( outstandingConnList *const   outstandingConnListP  )  [static]

Definition at line 1324 of file abyss_server.c.

References outstandingConnList::firstP, freeFinishedConns(), and waitForConnectionFreed().

Referenced by serverRun2().


Variable Documentation

Definition at line 1371 of file abyss_server.c.

TThreadProc serverFunc [static]

Definition at line 1096 of file abyss_server.c.

Referenced by serverRun2(), and serverRunConn().


Generated on Thu May 17 10:00:33 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6