1/* MiniUPnP project
2 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
3 * (c) 2006 Thomas Bernard
4 * This software is subject to the conditions detailed
5 * in the LICENCE file provided within the distribution */
6
7#ifndef __UPNPHTTP_H__
8#define __UPNPHTTP_H__
9
10#include <netinet/in.h>
11#include <sys/queue.h>
12
13#include "minidlnatypes.h"
14#include "config.h"
15
16/* server: HTTP header returned in all HTTP responses : */
17#define MINIDLNA_SERVER_STRING	OS_VERSION " DLNADOC/1.50 UPnP/1.0 MiniDLNA/1.0"
18
19/*
20 states :
21  0 - waiting for data to read
22  1 - waiting for HTTP Post Content.
23  ...
24  >= 100 - to be deleted
25*/
26enum httpCommands {
27	EUnknown = 0,
28	EGet,
29	EPost,
30	EHead,
31	ESubscribe,
32	EUnSubscribe
33};
34
35struct upnphttp {
36	int socket;
37	struct in_addr clientaddr;	/* client address */
38	int state;
39	char HttpVer[16];
40	/* request */
41	char * req_buf;
42	int req_buflen;
43	int req_contentlen;
44	int req_contentoff;     /* header length */
45	enum httpCommands req_command;
46	enum client_types req_client;
47	const char * req_soapAction;
48	int req_soapActionLen;
49	const char * req_Callback;	/* For SUBSCRIBE */
50	int req_CallbackLen;
51	int req_Timeout;
52	const char * req_SID;		/* For UNSUBSCRIBE */
53	int req_SIDLen;
54	off_t req_RangeStart;
55	off_t req_RangeEnd;
56	long int req_chunklen;
57	u_int32_t reqflags;
58	int respflags;
59	/* response */
60	char * res_buf;
61	int res_buflen;
62	int res_buf_alloclen;
63	/*int res_contentlen;*/
64	/*int res_contentoff;*/		/* header length */
65	LIST_ENTRY(upnphttp) entries;
66};
67
68#define FLAG_TIMEOUT            0x00000001
69#define FLAG_SID                0x00000002
70#define FLAG_RANGE              0x00000004
71#define FLAG_HOST               0x00000008
72
73#define FLAG_HTML               0x00000080
74#define FLAG_INVALID_REQ        0x00000010
75
76#define FLAG_CHUNKED            0x00000100
77#define FLAG_TIMESEEK           0x00000200
78#define FLAG_REALTIMEINFO       0x00000400
79#define FLAG_PLAYSPEED          0x00000800
80#define FLAG_XFERSTREAMING      0x00001000
81#define FLAG_XFERINTERACTIVE    0x00002000
82#define FLAG_XFERBACKGROUND     0x00004000
83#define FLAG_CAPTION            0x00008000
84
85#define FLAG_DLNA               0x00100000
86#define FLAG_MIME_AVI_DIVX      0x00200000
87#define FLAG_MIME_AVI_AVI       0x00400000
88#define FLAG_MIME_FLAC_FLAC     0x00800000
89#define FLAG_NO_RESIZE          0x01000000
90
91/* New_upnphttp() */
92struct upnphttp *
93New_upnphttp(int);
94
95/* CloseSocket_upnphttp() */
96void
97CloseSocket_upnphttp(struct upnphttp *);
98
99/* Delete_upnphttp() */
100void
101Delete_upnphttp(struct upnphttp *);
102
103/* Process_upnphttp() */
104void
105Process_upnphttp(struct upnphttp *);
106
107/* BuildHeader_upnphttp()
108 * build the header for the HTTP Response
109 * also allocate the buffer for body data */
110void
111BuildHeader_upnphttp(struct upnphttp * h, int respcode,
112                     const char * respmsg,
113                     int bodylen);
114
115/* BuildResp_upnphttp()
116 * fill the res_buf buffer with the complete
117 * HTTP 200 OK response from the body passed as argument */
118void
119BuildResp_upnphttp(struct upnphttp *, const char *, int);
120
121/* BuildResp2_upnphttp()
122 * same but with given response code/message */
123void
124BuildResp2_upnphttp(struct upnphttp * h, int respcode,
125                    const char * respmsg,
126                    const char * body, int bodylen);
127
128/* Error messages */
129void
130Send501(struct upnphttp *);
131
132/* SendResp_upnphttp() */
133void
134SendResp_upnphttp(struct upnphttp *);
135
136void
137SendResp_icon(struct upnphttp *, char * url);
138void
139SendResp_albumArt(struct upnphttp *, char * url);
140void
141SendResp_caption(struct upnphttp *, char * url);
142void
143SendResp_resizedimg(struct upnphttp *, char * url);
144void
145SendResp_thumbnail(struct upnphttp *, char * url);
146/* SendResp_dlnafile()
147 * send the actual file data for a UPnP-A/V or DLNA request. */
148void
149SendResp_dlnafile(struct upnphttp *, char * url);
150#endif
151
152