1 /*****************************************************************************
3 ******************************************************************************
5 This file is the interface header for the Abyss HTTP server component of
6 XML-RPC For C/C++ (Xmlrpc-c).
8 The Abyss component of Xmlrpc-c is based on the independently developed
9 and distributed Abyss web server package from 2001.
11 Copyright information is at the end of the file.
12 ****************************************************************************/
22 #include <sys/types.h>
25 #include "xmlrpc_config.h"
30 /****************************************************************************
31 STUFF FOR THE OUTER CONTROL PROGRAM TO USE
32 ****************************************************************************/
34 typedef int abyss_bool;
36 /*********************************************************************
38 *********************************************************************/
40 typedef struct MIMEType MIMEType;
46 MIMETypeDestroy(MIMEType * const MIMETypeP);
55 MIMETypeAdd2(MIMEType * const MIMETypeP,
56 const char * const type,
57 const char * const ext);
60 MIMETypeAdd(const char * const type,
61 const char * const ext);
64 enum abyss_foreback {ABYSS_FOREGROUND, ABYSS_BACKGROUND};
67 typedef struct _TSocket TSocket;
69 /* TOsSocket is the type of a conventional socket offered by our OS.
70 This is for backward compatibility; everyone should use TSocket
75 SocketWinCreate(TSocket ** const socketPP);
78 SocketWinCreateWinsock(SOCKET const winsock,
79 TSocket ** const socketPP);
81 typedef SOCKET TOsSocket;
86 SocketUnixCreate(TSocket ** const socketPP);
89 SocketUnixCreateFd(int const fd,
90 TSocket ** const socketPP);
92 typedef int TOsSocket;
96 SocketDestroy(TSocket * const socketP);
100 /* Before Xmlrpc-c 1.04, the internal server representation,
101 struct _TServer, was exposed to users and was the only way to
102 set certain parameters of the server. Now, use the (new)
103 ServerSet...() functions. Use the HAVE_ macros to determine
104 which method you have to use.
106 struct _TServer * srvP;
109 typedef struct _TSession TSession;
112 ServerCreate(TServer * const serverP,
113 const char * const name,
115 const char * const filespath,
116 const char * const logfilename);
119 ServerCreateSocket(TServer * const serverP,
120 const char * const name,
121 TOsSocket const socketFd,
122 const char * const filespath,
123 const char * const logfilename);
125 #define HAVE_SERVER_CREATE_SOCKET_2
127 ServerCreateSocket2(TServer * const serverP,
128 TSocket * const socketP,
129 const char ** const errorP);
132 ServerCreateNoAccept(TServer * const serverP,
133 const char * const name,
134 const char * const filespath,
135 const char * const logfilename);
138 ServerFree(TServer * const serverP);
141 ServerSetName(TServer * const serverP,
142 const char * const name);
145 ServerSetFilesPath(TServer * const serverP,
146 const char * const filesPath);
149 ServerSetLogFileName(TServer * const serverP,
150 const char * const logFileName);
152 #define HAVE_SERVER_SET_KEEPALIVE_TIMEOUT 1
154 ServerSetKeepaliveTimeout(TServer * const serverP,
155 uint32_t const keepaliveTimeout);
157 #define HAVE_SERVER_SET_KEEPALIVE_MAX_CONN 1
159 ServerSetKeepaliveMaxConn(TServer * const serverP,
160 uint32_t const keepaliveMaxConn);
162 #define HAVE_SERVER_SET_TIMEOUT 1
164 ServerSetTimeout(TServer * const serverP,
165 uint32_t const timeout);
167 #define HAVE_SERVER_SET_ADVERTISE 1
169 ServerSetAdvertise(TServer * const serverP,
170 abyss_bool const advertise);
172 #define HAVE_SERVER_SET_MIME_TYPE 1
174 ServerSetMimeType(TServer * const serverP,
175 MIMEType * const MIMETypeP);
178 ServerInit(TServer * const serverP);
181 ServerRun(TServer * const serverP);
184 ServerRunOnce(TServer * const serverP);
186 /* ServerRunOnce2() is obsolete. See user's guide. */
188 ServerRunOnce2(TServer * const serverP,
189 enum abyss_foreback const foregroundBackground);
192 ServerRunConn(TServer * const serverP,
193 TOsSocket const connectedSocket);
195 #define HAVE_SERVER_RUN_CONN_2
197 ServerRunConn2(TServer * const serverP,
198 TSocket * const connectedSocketP,
199 const char ** const errorP);
202 ServerDaemonize(TServer * const serverP);
205 ServerTerminate(TServer * const serverP);
208 ServerResetTerminate(TServer * const serverP);
211 ServerUseSigchld(TServer * const serverP);
215 ServerHandleSigchld(pid_t const pid);
218 typedef abyss_bool (*URIHandler) (TSession *); /* deprecated */
222 typedef void (*initHandlerFn)(struct URIHandler2 *,
225 typedef void (*termHandlerFn)(void *);
227 typedef void (*handleReq2Fn)(struct URIHandler2 *,
231 typedef struct URIHandler2 {
234 handleReq2Fn handleReq2;
235 URIHandler handleReq1; /* deprecated */
240 ServerAddHandler2(TServer * const srvP,
241 URIHandler2 * const handlerP,
242 abyss_bool * const successP);
245 ServerAddHandler(TServer * const srvP,
246 URIHandler const handler);
249 ServerDefaultHandler(TServer * const srvP,
250 URIHandler const handler);
252 /* This is inappropriately named; it was a mistake. But then, so is
253 having this function at all. The config file is inappropriate for
257 ConfReadServerFile(const char * const filename,
258 TServer * const srvP);
261 LogWrite(TServer * const srvP,
262 const char * const c);
264 /****************************************************************************
265 STUFF FOR URI HANDLERS TO USE
266 ****************************************************************************/
269 m_unknown, m_get, m_put, m_head, m_post, m_delete, m_trace, m_options
275 /* This is NOT the URI. It is the pathname part of the URI.
276 We really should fix that and put the pathname in another
280 /* The query part of the URI (stuff after '?') */
282 /* NOT the value of the host: header. Rather, the name of the
283 target host (could be part of the host: value). No port number.
286 const char * useragent;
287 const char * referer;
288 const char * requestline;
291 abyss_bool keepalive;
295 SessionRefillBuffer(TSession * const sessionP);
298 SessionReadDataAvail(TSession * const sessionP);
301 SessionGetReadData(TSession * const sessionP,
303 const char ** const outStartP,
304 size_t * const outLenP);
307 SessionGetRequestInfo(TSession * const sessionP,
308 const TRequestInfo ** const requestInfoPP);
311 RequestHeaderValue(TSession * const sessionP,
315 ResponseAddField(TSession * const sessionP,
316 const char * const name,
317 const char * const value);
320 ResponseWriteStart(TSession * const sessionP);
322 /* For backward compatibility: */
323 #define ResponseWrite ResponseWriteStart
326 ResponseWriteBody(TSession * const sessionP,
327 const char * const data,
331 ResponseWriteEnd(TSession * const sessionP);
334 ResponseChunked(TSession * const sessionP);
337 ResponseStatusFromErrno(int const errnoArg);
340 ResponseStatus(TSession * const sessionP,
341 uint16_t const code);
344 ResponseStatusErrno(TSession * const sessionP);
347 ResponseContentType(TSession * const serverP,
348 const char * const type);
351 ResponseContentLength(TSession * const sessionP,
355 ResponseError(TSession * const sessionP);
358 MIMETypeFromExt(const char * const ext);
361 MIMETypeFromExt2(MIMEType * const MIMETypeP,
362 const char * const ext);
365 MIMETypeFromFileName2(MIMEType * const MIMETypeP,
366 const char * const fileName);
369 MIMETypeFromFileName(const char * const fileName);
372 MIMETypeGuessFromFile2(MIMEType * const MIMETypeP,
373 const char * const fileName);
376 MIMETypeGuessFromFile(const char * const filename);
379 /****************************************************************************
380 STUFF THAT PROBABLY DOESN'T BELONG IN THIS FILE BECAUSE IT IS INTERNAL
382 Some day, we sort this out.
383 ****************************************************************************/
390 /*********************************************************************
391 ** Paths and so on...
392 *********************************************************************/
395 #define DEFAULT_ROOT "c:\\abyss"
396 #define DEFAULT_DOCS DEFAULT_ROOT"\\htdocs"
397 #define DEFAULT_CONF_FILE DEFAULT_ROOT"\\conf\\abyss.conf"
398 #define DEFAULT_LOG_FILE DEFAULT_ROOT"\\log\\abyss.log"
401 #define DEFAULT_ROOT "/abyss"
403 #define DEFAULT_ROOT "/usr/local/abyss"
405 #define DEFAULT_DOCS DEFAULT_ROOT"/htdocs"
406 #define DEFAULT_CONF_FILE DEFAULT_ROOT"/conf/abyss.conf"
407 #define DEFAULT_LOG_FILE DEFAULT_ROOT"/log/abyss.log"
410 /*********************************************************************
411 ** Maximum number of simultaneous connections
412 *********************************************************************/
416 /*********************************************************************
417 ** General purpose definitions
418 *********************************************************************/
421 #define NULL ((void *)0)
432 /*********************************************************************
434 *********************************************************************/
443 abyss_bool BufferAlloc(TBuffer *buf,uint32_t memsize);
444 abyss_bool BufferRealloc(TBuffer *buf,uint32_t memsize);
445 void BufferFree(TBuffer *buf);
448 /*********************************************************************
450 *********************************************************************/
458 abyss_bool StringAlloc(TString *s);
459 abyss_bool StringConcat(TString *s,char *s2);
460 abyss_bool StringBlockConcat(TString *s,char *s2,char **ref);
461 void StringFree(TString *s);
462 char *StringData(TString *s);
465 /*********************************************************************
467 *********************************************************************/
470 RangeDecode(char *str,
475 abyss_bool DateInit(void);
477 /*********************************************************************
479 *********************************************************************/
481 void Base64Encode(char *s,char *d);
483 /*********************************************************************
485 *********************************************************************/
487 abyss_bool SessionLog(TSession *s);
496 /*****************************************************************************
497 ** Here is the copyright notice from the Abyss web server project file from
498 ** which this file is derived.
500 ** Copyright (C) 2000 by Moez Mahfoudh <mmoez@bigfoot.com>.
501 ** All rights reserved.
503 ** Redistribution and use in source and binary forms, with or without
504 ** modification, are permitted provided that the following conditions
506 ** 1. Redistributions of source code must retain the above copyright
507 ** notice, this list of conditions and the following disclaimer.
508 ** 2. Redistributions in binary form must reproduce the above copyright
509 ** notice, this list of conditions and the following disclaimer in the
510 ** documentation and/or other materials provided with the distribution.
511 ** 3. The name of the author may not be used to endorse or promote products
512 ** derived from this software without specific prior written permission.
514 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
515 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
516 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
517 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
518 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
519 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
520 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
521 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
522 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
523 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
526 ******************************************************************************/
527 #endif /* _ABYSS_H_ */