TOR: fix compilation
[tomato.git] / release / src / router / miniupnpd / upnphttp.h
blobbf48b47b49ac68c62e877bd97f8be0afb395fdc9
1 /* $Id: upnphttp.h,v 1.42 2015/12/16 10:21:49 nanard Exp $ */
2 /* vim: tabstop=4 shiftwidth=4 noexpandtab */
3 /* MiniUPnP project
4 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5 * (c) 2006-2015 Thomas Bernard
6 * This software is subject to the conditions detailed
7 * in the LICENCE file provided within the distribution */
9 #ifndef UPNPHTTP_H_INCLUDED
10 #define UPNPHTTP_H_INCLUDED
12 #include <netinet/in.h>
13 #include <sys/queue.h>
15 #include "config.h"
17 #ifdef ENABLE_HTTPS
18 #include <openssl/ssl.h>
19 #endif /* ENABLE_HTTPS */
21 #define UPNP_VERSION_STRING "UPnP/" UPNP_VERSION_MAJOR_STR "." UPNP_VERSION_MINOR_STR
23 /* server: HTTP header returned in all HTTP responses : */
24 #define MINIUPNPD_SERVER_STRING OS_VERSION " " UPNP_VERSION_STRING " MiniUPnPd/" MINIUPNPD_VERSION
27 states :
28 0 - waiting for data to read
29 1 - waiting for HTTP Post Content.
30 ...
31 >= 100 - to be deleted
33 enum httpStates {
34 EWaitingForHttpRequest = 0,
35 EWaitingForHttpContent,
36 ESendingContinue,
37 ESendingAndClosing,
38 EToDelete = 100
41 enum httpCommands {
42 EUnknown = 0,
43 EGet,
44 EPost,
45 ESubscribe,
46 EUnSubscribe
49 struct upnphttp {
50 int socket;
51 struct in_addr clientaddr; /* client address */
52 #ifdef ENABLE_IPV6
53 int ipv6;
54 struct in6_addr clientaddr_v6;
55 #endif /* ENABLE_IPV6 */
56 #ifdef ENABLE_HTTPS
57 SSL * ssl;
58 #endif /* ENABLE_HTTPS */
59 char clientaddr_str[64]; /* used for syslog() output */
60 enum httpStates state;
61 char HttpVer[16];
62 /* request */
63 char * req_buf;
64 char accept_language[8];
65 int req_buflen;
66 int req_contentlen;
67 int req_contentoff; /* header length */
68 enum httpCommands req_command;
69 int req_soapActionOff;
70 int req_soapActionLen;
71 int req_HostOff; /* Host: header */
72 int req_HostLen;
73 #ifdef ENABLE_EVENTS
74 int req_CallbackOff; /* For SUBSCRIBE */
75 int req_CallbackLen;
76 int req_Timeout;
77 int req_SIDOff; /* For UNSUBSCRIBE */
78 int req_SIDLen;
79 const char * res_SID;
80 #ifdef UPNP_STRICT
81 int req_NTOff;
82 int req_NTLen;
83 #endif
84 #endif
85 int respflags; /* see FLAG_* constants below */
86 /* response */
87 char * res_buf;
88 int res_buflen;
89 int res_sent;
90 int res_buf_alloclen;
91 LIST_ENTRY(upnphttp) entries;
94 /* Include the "Timeout:" header in response */
95 #define FLAG_TIMEOUT 0x01
96 /* Include the "SID:" header in response */
97 #define FLAG_SID 0x02
99 /* If set, the POST request included a "Expect: 100-continue" header */
100 #define FLAG_CONTINUE 0x40
102 /* If set, the Content-Type is set to text/xml, otherwise it is text/xml */
103 #define FLAG_HTML 0x80
105 /* If set, the corresponding Allow: header is set */
106 #define FLAG_ALLOW_POST 0x100
107 #define FLAG_ALLOW_SUB_UNSUB 0x200
109 #ifdef ENABLE_HTTPS
110 int init_ssl(void);
111 void free_ssl(void);
112 #endif /* ENABLE_HTTPS */
114 /* New_upnphttp() */
115 struct upnphttp *
116 New_upnphttp(int);
118 #ifdef ENABLE_HTTPS
119 void
120 InitSSL_upnphttp(struct upnphttp *);
121 #endif /* ENABLE_HTTPS */
123 /* CloseSocket_upnphttp() */
124 void
125 CloseSocket_upnphttp(struct upnphttp *);
127 /* Delete_upnphttp() */
128 void
129 Delete_upnphttp(struct upnphttp *);
131 /* Process_upnphttp() */
132 void
133 Process_upnphttp(struct upnphttp *);
135 /* BuildHeader_upnphttp()
136 * build the header for the HTTP Response
137 * also allocate the buffer for body data
138 * return -1 on error */
140 BuildHeader_upnphttp(struct upnphttp * h, int respcode,
141 const char * respmsg,
142 int bodylen);
144 /* BuildResp_upnphttp()
145 * fill the res_buf buffer with the complete
146 * HTTP 200 OK response from the body passed as argument */
147 void
148 BuildResp_upnphttp(struct upnphttp *, const char *, int);
150 /* BuildResp2_upnphttp()
151 * same but with given response code/message */
152 void
153 BuildResp2_upnphttp(struct upnphttp * h, int respcode,
154 const char * respmsg,
155 const char * body, int bodylen);
158 SendResp_upnphttp(struct upnphttp *);
160 /* SendRespAndClose_upnphttp() */
161 void
162 SendRespAndClose_upnphttp(struct upnphttp *);
164 #endif