]> andersk Git - test.git/blame - libhttp/http.h
Started working on support for WebSockets.
[test.git] / libhttp / http.h
CommitLineData
7460295f 1// http.h -- Library for implementing embedded custom HTTP servers
bc83b450 2// Copyright (C) 2008-2010 Markus Gutschke <markus@shellinabox.com>
7460295f
MG
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License version 2 as
6// published by the Free Software Foundation.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License along
14// with this program; if not, write to the Free Software Foundation, Inc.,
15// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16//
17// In addition to these license terms, the author grants the following
18// additional rights:
19//
20// If you modify this program, or any covered work, by linking or
21// combining it with the OpenSSL project's OpenSSL library (or a
22// modified version of that library), containing parts covered by the
23// terms of the OpenSSL or SSLeay licenses, the author
24// grants you additional permission to convey the resulting work.
25// Corresponding Source for a non-source form of such a combination
26// shall include the source code for the parts of OpenSSL used as well
27// as that of the covered work.
28//
29// You may at your option choose to remove this additional permission from
30// the work, or from any part of it.
31//
32// It is possible to build this program in a way that it loads OpenSSL
33// libraries at run-time. If doing so, the following notices are required
34// by the OpenSSL and SSLeay licenses:
35//
36// This product includes software developed by the OpenSSL Project
37// for use in the OpenSSL Toolkit. (http://www.openssl.org/)
38//
39// This product includes cryptographic software written by Eric Young
40// (eay@cryptsoft.com)
41//
42//
43// The most up-to-date version of this program is always available from
44// http://shellinabox.com
45
46#ifndef LIB_HTTP_H__
47#define LIB_HTTP_H__
48
49#include <errno.h>
50#include <stdarg.h>
51#include <time.h>
52
53#define HTTP_DONE 0
54#define HTTP_ERROR 1
55#define HTTP_READ_MORE 2
56#define HTTP_SUSPEND 3
57#define HTTP_PARTIAL_REPLY 4
58
bc83b450
MG
59#define WS_START_OF_FRAME 0x0100
60#define WS_END_OF_FRAME 0x0200
61#define WS_CONNECTION_OPENED 0xFF00
62#define WS_CONNECTION_CLOSED 0x7F00
63
9b850878 64#define NO_MSG "\001"
bc83b450 65#define BINARY_MSG "\001%d%p"
9b850878 66
7460295f
MG
67#define NOINTR(x) ({ int i__; while ((i__ = (x)) < 0 && errno == EINTR); i__;})
68
69typedef struct HashMap HashMap;
70typedef struct HttpConnection HttpConnection;
71typedef struct ServerConnection ServerConnection;
72typedef struct Server Server;
73typedef struct URL URL;
74
53b27f78
MG
75Server *newCGIServer(int localhostOnly, int portMin, int portMax, int timeout);
76Server *newServer(int localhostOnly, int port);
7460295f 77void deleteServer(Server *server);
d1edcc0e
MG
78int serverGetListeningPort(Server *server);
79int serverGetFd(Server *server);
7460295f
MG
80void serverRegisterHttpHandler(Server *server, const char *url,
81 int (*handler)(HttpConnection *, void *,
82 const char *, int), void *arg);
83void serverRegisterStreamingHttpHandler(Server *server, const char *url,
84 int (*handler)(HttpConnection *, void *),
85 void *arg);
bc83b450
MG
86void serverRegisterWebSocketHandler(Server *server, const char *url,
87 int (*handler)(HttpConnection *, void *, int, const char *, int),
88 void *arg);
7460295f
MG
89ServerConnection *serverAddConnection(Server *server, int fd,
90 int (*handleConnection)(ServerConnection *,
91 void *arg, short *events,
92 short revents),
93 void (*destroyConnection)(void *arg),
94 void *arg);
95void serverDeleteConnection(Server *server, int fd);
96void serverSetTimeout(ServerConnection *connection, time_t timeout);
97time_t serverGetTimeout(ServerConnection *connection);
98ServerConnection *serverGetConnection(Server *server, ServerConnection *hint,
99 int fd);
100short serverConnectionSetEvents(Server *server, ServerConnection *connection,
101 short events);
102void serverExitLoop(Server *server, int exitAll);
103void serverLoop(Server *server);
104int serverSupportsSSL();
105void serverEnableSSL(Server *server, int flag);
106void serverSetCertificate(Server *server, const char *filename,
107 int autoGenerateMissing);
dc6575f2 108void serverSetCertificateFd(Server *server, int fd);
7460295f
MG
109void serverSetNumericHosts(Server *server, int numericHosts);
110
111void httpTransfer(HttpConnection *http, char *msg, int len);
112void httpTransferPartialReply(HttpConnection *http, char *msg, int len);
113void httpSetCallback(HttpConnection *http,
114 int (*callback)(HttpConnection *, void *,
115 const char *, int), void *arg);
116void *httpGetPrivate(HttpConnection *http);
117void *httpSetPrivate(HttpConnection *http, void *private);
118void httpSendReply(HttpConnection *http, int code,
119 const char *msg, const char *fmt, ...)
120 __attribute__((format(printf, 4, 5)));
bc83b450
MG
121void httpSendWebSocketTextMsg(HttpConnection *http, int type, const char *fmt,
122 ...) __attribute__((format(printf, 3, 4)));
123void httpSendWebSocketBinaryMsg(HttpConnection *http, int type,
124 const void *buf, int len);
7460295f
MG
125void httpExitLoop(HttpConnection *http, int exitAll);
126Server *httpGetServer(const HttpConnection *http);
127ServerConnection *httpGetServerConnection(const HttpConnection *);
128int httpGetFd(const HttpConnection *http);
129const char *httpGetPeerName(const HttpConnection *http);
130const char *httpGetMethod(const HttpConnection *http);
131const char *httpGetVersion(const HttpConnection *http);
132const HashMap *httpGetHeaders(const HttpConnection *http);
133URL *newURL(const HttpConnection *http, const char *buf, int len);
134void deleteURL(URL *url);
135const char *urlGetProtocol(URL *url);
136const char *urlGetUser(URL *url);
137const char *urlGetPassword(URL *url);
138const char *urlGetHost(URL *url);
139int urlGetPort(URL *url);
140const char *urlGetPath(URL *url);
141const char *urlGetPathInfo(URL *url);
142const char *urlGetQuery(URL *url);
143const char *urlGetAnchor(URL *url);
90cccba6 144const char *urlGetURL(URL *url);
7460295f
MG
145const HashMap *urlGetArgs(URL *url);
146HashMap *newHashMap(void (*destructor)(void *arg, char *key, char *value),
147 void *arg);
148void deleteHashMap(HashMap *hashmap);
149const void *addToHashMap(HashMap *hashmap, const char *key, const char *value);
150void deleteFromHashMap(HashMap *hashmap, const char *key);
151char **getRefFromHashMap(const HashMap *hashmap, const char *key);
152const char *getFromHashMap(const HashMap *hashmap, const char *key);
153void iterateOverHashMap(struct HashMap *hashmap,
154 int (*fnc)(void *arg, const char *key, char **value),
155 void *arg);
156int getHashmapSize(const HashMap *hashmap);
157
158#endif /* LIB_HTTP_H__ */
This page took 0.064959 seconds and 5 git commands to generate.