Electroneum
upnphttp.h
Go to the documentation of this file.
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 */
8 
9 #ifndef UPNPHTTP_H_INCLUDED
10 #define UPNPHTTP_H_INCLUDED
11 
12 #include <netinet/in.h>
13 #include <sys/queue.h>
14 
15 #include "config.h"
16 
17 #ifdef ENABLE_HTTPS
18 #include <openssl/ssl.h>
19 #endif /* ENABLE_HTTPS */
20 
21 #define UPNP_VERSION_STRING "UPnP/" UPNP_VERSION_MAJOR_STR "." UPNP_VERSION_MINOR_STR
22 
23 /* server: HTTP header returned in all HTTP responses : */
24 #define MINIUPNPD_SERVER_STRING OS_VERSION " " UPNP_VERSION_STRING " MiniUPnPd/" MINIUPNPD_VERSION
25 
26 /*
27  states :
28  0 - waiting for data to read
29  1 - waiting for HTTP Post Content.
30  ...
31  >= 100 - to be deleted
32 */
33 enum httpStates {
38  EToDelete = 100
39 };
40 
42  EUnknown = 0,
47 };
48 
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 */
61  char HttpVer[16];
62  /* request */
63  char * req_buf;
64  char accept_language[8];
67  int req_contentoff; /* header length */
71  int req_HostOff; /* Host: header */
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;
89  int res_sent;
91  LIST_ENTRY(upnphttp) entries;
92 };
93 
94 /* Include the "Timeout:" header in response */
95 #define FLAG_TIMEOUT 0x01
96 /* Include the "SID:" header in response */
97 #define FLAG_SID 0x02
98 
99 /* If set, the POST request included a "Expect: 100-continue" header */
100 #define FLAG_CONTINUE 0x40
101 
102 /* If set, the Content-Type is set to text/xml, otherwise it is text/xml */
103 #define FLAG_HTML 0x80
104 
105 /* If set, the corresponding Allow: header is set */
106 #define FLAG_ALLOW_POST 0x100
107 #define FLAG_ALLOW_SUB_UNSUB 0x200
108 
109 #ifdef ENABLE_HTTPS
110 int init_ssl(void);
111 void free_ssl(void);
112 #endif /* ENABLE_HTTPS */
113 
114 /* New_upnphttp() */
115 struct upnphttp *
116 New_upnphttp(int);
117 
118 #ifdef ENABLE_HTTPS
119 void
120 InitSSL_upnphttp(struct upnphttp *);
121 #endif /* ENABLE_HTTPS */
122 
123 /* CloseSocket_upnphttp() */
124 void
126 
127 /* Delete_upnphttp() */
128 void
129 Delete_upnphttp(struct upnphttp *);
130 
131 /* Process_upnphttp() */
132 void
133 Process_upnphttp(struct upnphttp *);
134 
135 /* BuildHeader_upnphttp()
136  * build the header for the HTTP Response
137  * also allocate the buffer for body data
138  * return -1 on error */
139 int
140 BuildHeader_upnphttp(struct upnphttp * h, int respcode,
141  const char * respmsg,
142  int bodylen);
143 
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);
149 
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);
156 
157 int
158 SendResp_upnphttp(struct upnphttp *);
159 
160 /* SendRespAndClose_upnphttp() */
161 void
163 
164 #endif
165 
int BuildHeader_upnphttp(struct upnphttp *h, int respcode, const char *respmsg, int bodylen)
int req_contentlen
Definition: upnphttp.h:66
int req_buflen
Definition: upnphttp.h:65
int res_sent
Definition: upnphttp.h:89
struct upnphttp * New_upnphttp(int)
int socket
Definition: upnphttp.h:50
int res_buf_alloclen
Definition: upnphttp.h:90
void BuildResp2_upnphttp(struct upnphttp *h, int respcode, const char *respmsg, const char *body, int bodylen)
Definition: upnphttp.h:44
httpStates
Definition: upnphttp.h:33
int req_HostLen
Definition: upnphttp.h:72
enum httpStates state
Definition: upnphttp.h:60
void Process_upnphttp(struct upnphttp *)
int req_HostOff
Definition: upnphttp.h:71
char accept_language[8]
Definition: upnphttp.h:64
char HttpVer[16]
Definition: upnphttp.h:61
int respflags
Definition: upnphttp.h:85
char * req_buf
Definition: upnphttp.h:63
LIST_ENTRY(upnphttp) entries
void SendRespAndClose_upnphttp(struct upnphttp *)
struct in_addr clientaddr
Definition: upnphttp.h:51
int req_soapActionLen
Definition: upnphttp.h:70
int res_buflen
Definition: upnphttp.h:88
Definition: upnphttp.h:43
void BuildResp_upnphttp(struct upnphttp *, const char *, int)
void Delete_upnphttp(struct upnphttp *)
char clientaddr_str[64]
Definition: upnphttp.h:59
int SendResp_upnphttp(struct upnphttp *)
void CloseSocket_upnphttp(struct upnphttp *)
char * res_buf
Definition: upnphttp.h:87
int req_soapActionOff
Definition: upnphttp.h:69
httpCommands
Definition: upnphttp.h:41
int req_contentoff
Definition: upnphttp.h:67
enum httpCommands req_command
Definition: upnphttp.h:68