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	enum client_types 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#define FLAG_DLNA               0x00100000
132#define FLAG_MIME_AVI_DIVX      0x00200000
133#define FLAG_MIME_AVI_AVI       0x00400000
134#define FLAG_MIME_FLAC_FLAC     0x00800000
135#define FLAG_MIME_WAV_WAV       0x01000000
136#define FLAG_RESIZE_THUMBS      0x02000000
137#define FLAG_NO_RESIZE          0x04000000
138#define FLAG_MS_PFS             0x08000000 // Microsoft PlaysForSure client
139#define FLAG_SAMSUNG            0x10000000
140#define FLAG_SAMSUNG_TV         0x20000000
141#define FLAG_AUDIO_ONLY         0x40000000
142
143#define FLAG_FREE_OBJECT_ID     0x00000001
144#define FLAG_ROOT_CONTAINER     0x00000002
145
146/* New_upnphttp() */
147struct upnphttp *
148New_upnphttp(int);
149
150/* CloseSocket_upnphttp() */
151void
152CloseSocket_upnphttp(struct upnphttp *);
153
154/* Delete_upnphttp() */
155void
156Delete_upnphttp(struct upnphttp *);
157
158/* Process_upnphttp() */
159void
160Process_upnphttp(struct upnphttp *);
161
162/* BuildHeader_upnphttp()
163 * build the header for the HTTP Response
164 * also allocate the buffer for body data */
165void
166BuildHeader_upnphttp(struct upnphttp * h, int respcode,
167                     const char * respmsg,
168                     int bodylen);
169
170/* BuildResp_upnphttp()
171 * fill the res_buf buffer with the complete
172 * HTTP 200 OK response from the body passed as argument */
173void
174BuildResp_upnphttp(struct upnphttp *, const char *, int);
175
176/* BuildResp2_upnphttp()
177 * same but with given response code/message */
178void
179BuildResp2_upnphttp(struct upnphttp * h, int respcode,
180                    const char * respmsg,
181                    const char * body, int bodylen);
182
183/* Error messages */
184void
185Send500(struct upnphttp *);
186void
187Send501(struct upnphttp *);
188
189/* SendResp_upnphttp() */
190void
191SendResp_upnphttp(struct upnphttp *);
192
193int
194SearchClientCache(struct in_addr addr, int quiet);
195
196void
197SendResp_icon(struct upnphttp *, char * url);
198void
199SendResp_albumArt(struct upnphttp *, char * url);
200void
201SendResp_caption(struct upnphttp *, char * url);
202void
203SendResp_resizedimg(struct upnphttp *, char * url);
204void
205SendResp_thumbnail(struct upnphttp *, char * url);
206/* SendResp_dlnafile()
207 * send the actual file data for a UPnP-A/V or DLNA request. */
208void
209SendResp_dlnafile(struct upnphttp *, char * url);
210#endif
211
212