2014-12-09 10:04:15 +00:00
|
|
|
/* $Id: upnphttp.h,v 1.39 2014/12/09 09:46:46 nanard Exp $ */
|
2011-09-28 19:13:20 +00:00
|
|
|
/* MiniUPnP project
|
|
|
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
2014-04-09 13:35:06 +00:00
|
|
|
* (c) 2006-2014 Thomas Bernard
|
2011-09-28 19:13:20 +00:00
|
|
|
* This software is subject to the conditions detailed
|
|
|
|
* in the LICENCE file provided within the distribution */
|
|
|
|
|
2012-09-20 20:52:51 +00:00
|
|
|
#ifndef UPNPHTTP_H_INCLUDED
|
|
|
|
#define UPNPHTTP_H_INCLUDED
|
2011-09-28 19:13:20 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2014-04-09 13:35:06 +00:00
|
|
|
#ifdef ENABLE_HTTPS
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#endif /* ENABLE_HTTPS */
|
|
|
|
|
2012-04-06 17:28:05 +00:00
|
|
|
#if 0
|
|
|
|
/* according to "UPnP Device Architecture 1.0" */
|
|
|
|
#define UPNP_VERSION_STRING "UPnP/1.0"
|
|
|
|
#else
|
|
|
|
/* according to "UPnP Device Architecture 1.1" */
|
|
|
|
#define UPNP_VERSION_STRING "UPnP/1.1"
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 19:13:20 +00:00
|
|
|
/* server: HTTP header returned in all HTTP responses : */
|
2012-04-06 17:28:05 +00:00
|
|
|
#define MINIUPNPD_SERVER_STRING OS_VERSION " " UPNP_VERSION_STRING " MiniUPnPd/" MINIUPNPD_VERSION
|
2011-09-28 19:13:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
states :
|
|
|
|
0 - waiting for data to read
|
|
|
|
1 - waiting for HTTP Post Content.
|
|
|
|
...
|
|
|
|
>= 100 - to be deleted
|
|
|
|
*/
|
2012-02-07 00:26:15 +00:00
|
|
|
enum httpStates {
|
|
|
|
EWaitingForHttpRequest = 0,
|
|
|
|
EWaitingForHttpContent,
|
2012-09-28 09:12:50 +00:00
|
|
|
ESendingContinue,
|
2012-02-07 00:26:15 +00:00
|
|
|
ESendingAndClosing,
|
|
|
|
EToDelete = 100
|
|
|
|
};
|
|
|
|
|
2011-09-28 19:13:20 +00:00
|
|
|
enum httpCommands {
|
|
|
|
EUnknown = 0,
|
|
|
|
EGet,
|
|
|
|
EPost,
|
|
|
|
ESubscribe,
|
|
|
|
EUnSubscribe
|
|
|
|
};
|
|
|
|
|
|
|
|
struct upnphttp {
|
|
|
|
int socket;
|
|
|
|
struct in_addr clientaddr; /* client address */
|
|
|
|
#ifdef ENABLE_IPV6
|
|
|
|
int ipv6;
|
|
|
|
struct in6_addr clientaddr_v6;
|
2014-04-09 13:35:06 +00:00
|
|
|
#endif /* ENABLE_IPV6 */
|
|
|
|
#ifdef ENABLE_HTTPS
|
|
|
|
SSL * ssl;
|
|
|
|
#endif /* ENABLE_HTTPS */
|
2012-02-07 00:26:15 +00:00
|
|
|
enum httpStates state;
|
2011-09-28 19:13:20 +00:00
|
|
|
char HttpVer[16];
|
|
|
|
/* request */
|
|
|
|
char * req_buf;
|
2012-09-28 09:10:20 +00:00
|
|
|
char accept_language[8];
|
2011-09-28 19:13:20 +00:00
|
|
|
int req_buflen;
|
|
|
|
int req_contentlen;
|
|
|
|
int req_contentoff; /* header length */
|
|
|
|
enum httpCommands req_command;
|
2012-04-25 22:30:32 +00:00
|
|
|
int req_soapActionOff;
|
2011-09-28 19:13:20 +00:00
|
|
|
int req_soapActionLen;
|
|
|
|
#ifdef ENABLE_EVENTS
|
2012-04-25 22:30:32 +00:00
|
|
|
int req_CallbackOff; /* For SUBSCRIBE */
|
2011-09-28 19:13:20 +00:00
|
|
|
int req_CallbackLen;
|
|
|
|
int req_Timeout;
|
2012-04-25 22:30:32 +00:00
|
|
|
int req_SIDOff; /* For UNSUBSCRIBE */
|
2011-09-28 19:13:20 +00:00
|
|
|
int req_SIDLen;
|
2012-04-25 22:30:32 +00:00
|
|
|
const char * res_SID;
|
2012-10-04 22:25:08 +00:00
|
|
|
#ifdef UPNP_STRICT
|
|
|
|
int req_NTOff;
|
|
|
|
int req_NTLen;
|
|
|
|
#endif
|
2011-09-28 19:13:20 +00:00
|
|
|
#endif
|
|
|
|
int respflags; /* see FLAG_* constants below */
|
|
|
|
/* response */
|
|
|
|
char * res_buf;
|
|
|
|
int res_buflen;
|
2012-02-07 00:26:15 +00:00
|
|
|
int res_sent;
|
2011-09-28 19:13:20 +00:00
|
|
|
int res_buf_alloclen;
|
|
|
|
LIST_ENTRY(upnphttp) entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Include the "Timeout:" header in response */
|
|
|
|
#define FLAG_TIMEOUT 0x01
|
|
|
|
/* Include the "SID:" header in response */
|
|
|
|
#define FLAG_SID 0x02
|
|
|
|
|
2012-09-28 09:12:50 +00:00
|
|
|
/* If set, the POST request included a "Expect: 100-continue" header */
|
|
|
|
#define FLAG_CONTINUE 0x40
|
|
|
|
|
2011-09-28 19:13:20 +00:00
|
|
|
/* If set, the Content-Type is set to text/xml, otherwise it is text/xml */
|
|
|
|
#define FLAG_HTML 0x80
|
|
|
|
|
2012-05-31 13:29:18 +00:00
|
|
|
/* If set, the corresponding Allow: header is set */
|
|
|
|
#define FLAG_ALLOW_POST 0x100
|
|
|
|
#define FLAG_ALLOW_SUB_UNSUB 0x200
|
|
|
|
|
2014-04-09 13:35:06 +00:00
|
|
|
#ifdef ENABLE_HTTPS
|
|
|
|
int init_ssl(void);
|
2014-04-09 14:09:31 +00:00
|
|
|
void free_ssl(void);
|
2014-04-09 13:35:06 +00:00
|
|
|
#endif /* ENABLE_HTTPS */
|
2012-09-28 09:10:20 +00:00
|
|
|
|
2011-09-28 19:13:20 +00:00
|
|
|
/* New_upnphttp() */
|
|
|
|
struct upnphttp *
|
|
|
|
New_upnphttp(int);
|
2014-04-09 13:35:06 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_HTTPS
|
|
|
|
void
|
|
|
|
InitSSL_upnphttp(struct upnphttp *);
|
|
|
|
#endif /* ENABLE_HTTPS */
|
2011-09-28 19:13:20 +00:00
|
|
|
|
|
|
|
/* CloseSocket_upnphttp() */
|
|
|
|
void
|
|
|
|
CloseSocket_upnphttp(struct upnphttp *);
|
|
|
|
|
|
|
|
/* Delete_upnphttp() */
|
|
|
|
void
|
|
|
|
Delete_upnphttp(struct upnphttp *);
|
|
|
|
|
|
|
|
/* Process_upnphttp() */
|
|
|
|
void
|
|
|
|
Process_upnphttp(struct upnphttp *);
|
|
|
|
|
|
|
|
/* BuildHeader_upnphttp()
|
|
|
|
* build the header for the HTTP Response
|
2014-12-09 10:04:15 +00:00
|
|
|
* also allocate the buffer for body data
|
|
|
|
* return -1 on error */
|
|
|
|
int
|
2011-09-28 19:13:20 +00:00
|
|
|
BuildHeader_upnphttp(struct upnphttp * h, int respcode,
|
|
|
|
const char * respmsg,
|
|
|
|
int bodylen);
|
|
|
|
|
2012-03-01 01:44:38 +00:00
|
|
|
/* BuildResp_upnphttp()
|
2011-09-28 19:13:20 +00:00
|
|
|
* fill the res_buf buffer with the complete
|
|
|
|
* HTTP 200 OK response from the body passed as argument */
|
|
|
|
void
|
|
|
|
BuildResp_upnphttp(struct upnphttp *, const char *, int);
|
|
|
|
|
|
|
|
/* BuildResp2_upnphttp()
|
|
|
|
* same but with given response code/message */
|
|
|
|
void
|
|
|
|
BuildResp2_upnphttp(struct upnphttp * h, int respcode,
|
|
|
|
const char * respmsg,
|
|
|
|
const char * body, int bodylen);
|
|
|
|
|
2012-09-28 09:12:50 +00:00
|
|
|
int
|
|
|
|
SendResp_upnphttp(struct upnphttp *);
|
|
|
|
|
2011-11-18 11:23:16 +00:00
|
|
|
/* SendRespAndClose_upnphttp() */
|
2011-09-28 19:13:20 +00:00
|
|
|
void
|
2011-11-18 11:23:16 +00:00
|
|
|
SendRespAndClose_upnphttp(struct upnphttp *);
|
2011-09-28 19:13:20 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|