]> andersk Git - test.git/blame - libhttp/httpconnection.h
Use 2048-bit RSA keys for auto-generated certificates.
[test.git] / libhttp / httpconnection.h
CommitLineData
7460295f 1// httpconnection.h -- Manage state machine for HTTP connections
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 HTTP_CONNECTION__
47#define HTTP_CONNECTION__
48
49#include <time.h>
50
51#include "libhttp/hashmap.h"
52#include "libhttp/trie.h"
53#include "libhttp/server.h"
54#include "libhttp/http.h"
55#include "libhttp/ssl.h"
56
57#define HTTP_DONE 0
58#define HTTP_ERROR 1
59#define HTTP_READ_MORE 2
60#define HTTP_SUSPEND 3
61#define HTTP_PARTIAL_REPLY 4
62
bc83b450
MG
63#define WS_UNDEFINED 0x1000
64#define WS_START_OF_FRAME 0x0100
65#define WS_END_OF_FRAME 0x0200
66
9b850878
MG
67#define NO_MSG "\001"
68
7460295f
MG
69struct HttpConnection {
70 struct Server *server;
71 struct ServerConnection *connection;
72 int fd;
73 int port;
74 int closed;
75 int isSuspended;
76 int isPartialReply;
77 int done;
bc83b450
MG
78 enum { SNIFFING_SSL, COMMAND, HEADERS, PAYLOAD, DISCARD_PAYLOAD,
79 WEBSOCKET } state;
7460295f
MG
80 char *peerName;
81 int peerPort;
82 char *url;
83 char *method;
84 char *path;
85 char *matchedPath;
86 char *pathInfo;
87 char *query;
88 char *version;
89 struct HashMap header;
90 int headerLength;
91 char *key;
92 char *partial;
93 int partialLength;
94 char *msg;
95 int msgLength;
96 int msgOffset;
97 int totalWritten;
98 int expecting;
bc83b450 99 int websocketType;
7460295f
MG
100 int (*callback)(struct HttpConnection *, void *,
101 const char *,int);
bc83b450
MG
102 int (*websocketHandler)(struct HttpConnection *, void *,
103 int, const char *, int);
7460295f
MG
104 void *arg;
105 void *private;
106 int code;
107 struct SSLSupport *ssl;
108 SSL *sslHndl;
109 int lastError;
110};
111
112struct HttpHandler {
113 int (*handler)(struct HttpConnection *, void *);
114 int (*streamingHandler)(struct HttpConnection *, void *, const char *, int);
bc83b450
MG
115 int (*websocketHandler)(struct HttpConnection *, void *, int,
116 const char *, int);
7460295f
MG
117 void *arg, *streamingArg;
118
119};
120
121struct HttpConnection *newHttpConnection(struct Server *server, int fd,
122 int port, struct SSLSupport *ssl,
123 int numericHosts);
124void initHttpConnection(struct HttpConnection *http, struct Server *server,
125 int fd, int port, struct SSLSupport *ssl,
126 int numericHosts);
127void destroyHttpConnection(struct HttpConnection *http);
128void deleteHttpConnection(struct HttpConnection *http);
129void httpTransfer(struct HttpConnection *http, char *msg, int len);
130void httpTransferPartialReply(struct HttpConnection *http, char *msg, int len);
131int httpHandleConnection(struct ServerConnection *connection, void *http_,
132 short *events, short revents);
133void httpSetCallback(struct HttpConnection *http,
134 int (*callback)(struct HttpConnection *, void *,
135 const char *, int), void *arg);
136void *httpGetPrivate(struct HttpConnection *http);
137void *httpSetPrivate(struct HttpConnection *http, void *private);
138void httpSendReply(struct HttpConnection *http, int code,
139 const char *msg, const char *fmt, ...)
140 __attribute__((format(printf, 4, 5)));
bc83b450
MG
141void httpSendWebSocketTextMsg(struct HttpConnection *http, int type,
142 const char *fmt, ...)
143 __attribute__((format(printf, 3, 4)));
144void httpSendWebSocketBinaryMsg(struct HttpConnection *http, int type,
145 const void *buf, int len);
7460295f
MG
146void httpExitLoop(struct HttpConnection *http, int exitAll);
147struct Server *httpGetServer(const struct HttpConnection *http);
148struct ServerConnection *httpGetServerConnection(const struct HttpConnection*);
149int httpGetFd(const HttpConnection *http);
150const char *httpGetPeerName(const struct HttpConnection *http);
151const char *httpGetMethod(const struct HttpConnection *http);
152const char *httpGetProtocol(const struct HttpConnection *http);
153const char *httpGetHost(const struct HttpConnection *http);
154int httpGetPort(const struct HttpConnection *http);
155const char *httpGetPath(const struct HttpConnection *http);
156const char *httpGetPathInfo(const struct HttpConnection *http);
157const char *httpGetQuery(const struct HttpConnection *http);
158const char *httpGetURL(const struct HttpConnection *http);
159const char *httpGetVersion(const struct HttpConnection *http);
160const struct HashMap *httpGetHeaders(const struct HttpConnection *http);
161
162#endif /* HTTP_CONNECTION__ */
This page took 1.135094 seconds and 5 git commands to generate.