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