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