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