1/* MiniDLNA project
2 *
3 * http://sourceforge.net/projects/minidlna/
4 *
5 * MiniDLNA media server
6 * Copyright (C) 2008-2012  Justin Maggard
7 *
8 * This file is part of MiniDLNA.
9 *
10 * MiniDLNA is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * MiniDLNA is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * Portions of the code from the MiniUPnP project:
23 *
24 * Copyright (c) 2006-2007, Thomas Bernard
25 * All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions are met:
29 *     * Redistributions of source code must retain the above copyright
30 *       notice, this list of conditions and the following disclaimer.
31 *     * Redistributions in binary form must reproduce the above copyright
32 *       notice, this list of conditions and the following disclaimer in the
33 *       documentation and/or other materials provided with the distribution.
34 *     * The name of the author may not be used to endorse or promote products
35 *       derived from this software without specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
41 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47 * POSSIBILITY OF SUCH DAMAGE.
48 */
49#ifndef __UPNPHTTP_H__
50#define __UPNPHTTP_H__
51
52#include <netinet/in.h>
53#include <sys/queue.h>
54
55#include "minidlnatypes.h"
56#include "config.h"
57
58/* server: HTTP header returned in all HTTP responses : */
59#define MINIDLNA_SERVER_STRING	OS_VERSION " DLNADOC/1.50 UPnP/1.0 " SERVER_NAME "/" MINIDLNA_VERSION
60
61/*
62 states :
63  0 - waiting for data to read
64  1 - waiting for HTTP Post Content.
65  ...
66  >= 100 - to be deleted
67*/
68enum httpCommands {
69	EUnknown = 0,
70	EGet,
71	EPost,
72	EHead,
73	ESubscribe,
74	EUnSubscribe
75};
76
77struct upnphttp {
78	int socket;
79	struct in_addr clientaddr;	/* client address */
80	int iface;
81	int state;
82	char HttpVer[16];
83	/* request */
84	char * req_buf;
85	int req_buflen;
86	int req_contentlen;
87	int req_contentoff;     /* header length */
88	enum httpCommands req_command;
89	struct client_cache_s * req_client;
90	const char * req_soapAction;
91	int req_soapActionLen;
92	const char * req_Callback;	/* For SUBSCRIBE */
93	int req_CallbackLen;
94	const char * req_NT;
95	int req_NTLen;
96	int req_Timeout;
97	const char * req_SID;		/* For UNSUBSCRIBE */
98	int req_SIDLen;
99	off_t req_RangeStart;
100	off_t req_RangeEnd;
101	long int req_chunklen;
102	uint32_t reqflags;
103	/* response */
104	char * res_buf;
105	int res_buflen;
106	int res_buf_alloclen;
107	uint32_t respflags;
108	/*int res_contentlen;*/
109	/*int res_contentoff;*/		/* header length */
110	LIST_ENTRY(upnphttp) entries;
111};
112
113#define FLAG_TIMEOUT            0x00000001
114#define FLAG_SID                0x00000002
115#define FLAG_RANGE              0x00000004
116#define FLAG_HOST               0x00000008
117#define FLAG_LANGUAGE           0x00000010
118
119#define FLAG_INVALID_REQ        0x00000040
120#define FLAG_HTML               0x00000080
121
122#define FLAG_CHUNKED            0x00000100
123#define FLAG_TIMESEEK           0x00000200
124#define FLAG_REALTIMEINFO       0x00000400
125#define FLAG_PLAYSPEED          0x00000800
126#define FLAG_XFERSTREAMING      0x00001000
127#define FLAG_XFERINTERACTIVE    0x00002000
128#define FLAG_XFERBACKGROUND     0x00004000
129#define FLAG_CAPTION            0x00008000
130
131#ifndef MSG_MORE
132#define MSG_MORE 0
133#endif
134
135/* New_upnphttp() */
136struct upnphttp *
137New_upnphttp(int);
138
139/* CloseSocket_upnphttp() */
140void
141CloseSocket_upnphttp(struct upnphttp *);
142
143/* Delete_upnphttp() */
144void
145Delete_upnphttp(struct upnphttp *);
146
147/* Process_upnphttp() */
148void
149Process_upnphttp(struct upnphttp *);
150
151/* BuildHeader_upnphttp()
152 * build the header for the HTTP Response
153 * also allocate the buffer for body data */
154void
155BuildHeader_upnphttp(struct upnphttp * h, int respcode,
156                     const char * respmsg,
157                     int bodylen);
158
159/* BuildResp_upnphttp()
160 * fill the res_buf buffer with the complete
161 * HTTP 200 OK response from the body passed as argument */
162void
163BuildResp_upnphttp(struct upnphttp *, const char *, int);
164
165/* BuildResp2_upnphttp()
166 * same but with given response code/message */
167void
168BuildResp2_upnphttp(struct upnphttp * h, int respcode,
169                    const char * respmsg,
170                    const char * body, int bodylen);
171
172/* Error messages */
173void
174Send500(struct upnphttp *);
175void
176Send501(struct upnphttp *);
177
178/* SendResp_upnphttp() */
179void
180SendResp_upnphttp(struct upnphttp *);
181
182#endif
183
184