Rework LuCI build system
[project/luci.git] / libs / luci-lib-nixio / axTLS / httpd / axhttp.h
1 /*
2  * Copyright (c) 2007, Cameron Rich
3  * 
4  * All rights reserved.
5  * 
6  * Redistribution and use in source and binary forms, with or without 
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, 
10  *   this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice, 
12  *   this list of conditions and the following disclaimer in the documentation 
13  *   and/or other materials provided with the distribution.
14  * * Neither the name of the axTLS project nor the names of its contributors 
15  *   may be used to endorse or promote products derived from this software 
16  *   without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "ssl.h"
32
33 #define BACKLOG 15
34 #define VERSION "1.0.0"
35 #ifdef CONFIG_HTTP_HAS_IPV6
36 #define HAVE_IPV6
37 #endif
38
39 #define MAXPOSTDATASIZE                     30000
40 #define MAXREQUESTLENGTH                    256
41 #define BLOCKSIZE                           4096
42
43 #define INITIAL_CONNECTION_SLOTS            10
44 #define CONFIG_HTTP_DEFAULT_SSL_OPTIONS     SSL_DISPLAY_CERTS
45
46 #define STATE_WANT_TO_READ_HEAD             1
47 #define STATE_WANT_TO_SEND_HEAD             2
48 #define STATE_WANT_TO_READ_FILE             3
49 #define STATE_WANT_TO_SEND_FILE             4
50 #define STATE_DOING_DIR                     5
51
52 enum
53 {
54     TYPE_GET,
55     TYPE_HEAD,
56     TYPE_POST
57 };
58
59 struct connstruct 
60 {
61     struct connstruct *next;
62     int state;
63     int reqtype;
64     int networkdesc;
65     int filedesc;
66     SSL *ssl;
67
68 #if defined(CONFIG_HTTP_DIRECTORIES)
69 #ifdef WIN32
70     HANDLE dirp;
71     WIN32_FIND_DATA file_data;
72 #else
73     DIR *dirp;
74 #endif
75 #endif
76
77     time_t timeout;
78     char actualfile[MAXREQUESTLENGTH];
79     char filereq[MAXREQUESTLENGTH];
80     char dirname[MAXREQUESTLENGTH];
81     char server_name[MAXREQUESTLENGTH];
82     int numbytes;
83     char databuf[BLOCKSIZE];
84     uint8_t is_ssl;
85     uint8_t close_when_done;
86     time_t if_modified_since;
87
88 #if defined(CONFIG_HTTP_HAS_CGI)
89     uint8_t is_cgi;
90 #ifdef CONFIG_HTTP_ENABLE_LUA
91     uint8_t is_lua;
92 #endif
93     int content_length;
94     char remote_addr[MAXREQUESTLENGTH];
95     char uri_request[MAXREQUESTLENGTH];
96     char uri_path_info[MAXREQUESTLENGTH];
97     char uri_query[MAXREQUESTLENGTH];
98     char cookie[MAXREQUESTLENGTH];
99 #endif
100 #if defined(CONFIG_HTTP_HAS_AUTHORIZATION)
101     char authorization[MAXREQUESTLENGTH];
102 #endif
103   int post_read;
104   int post_state;
105   char *post_data;
106 };
107
108 struct serverstruct 
109 {
110     struct serverstruct *next;
111     int sd;
112     int is_ssl;
113     SSL_CTX *ssl_ctx;
114 };
115
116 #if defined(CONFIG_HTTP_HAS_CGI)
117 struct cgiextstruct 
118 {
119     struct cgiextstruct *next;
120     char *ext;
121 };
122 #endif
123
124 /* global prototypes */
125 extern struct serverstruct *servers;
126 extern struct connstruct *usedconns;
127 extern struct connstruct *freeconns;
128 extern const char * const server_version;
129
130 #if defined(CONFIG_HTTP_HAS_CGI)
131 extern struct cgiextstruct *cgiexts;
132 #endif
133
134 /* conn.c prototypes */
135 void removeconnection(struct connstruct *cn);
136
137 /* proc.c prototypes */
138 void procdodir(struct connstruct *cn);
139 void procreadhead(struct connstruct *cn);
140 void procsendhead(struct connstruct *cn);
141 void procreadfile(struct connstruct *cn);
142 void procsendfile(struct connstruct *cn);
143 #if defined(CONFIG_HTTP_HAS_CGI)
144 void read_post_data(struct connstruct *cn);
145 #endif
146
147 /* misc.c prototypes */
148 char *my_strncpy(char *dest, const char *src, size_t n);
149 int isdir(const char *name);
150
151 /* tdate prototypes */
152 void tdate_init(void);
153 time_t tdate_parse(const char* str);
154