1 // ------------------------------------------------
7 // (c) 2002 peercast.org
8 // ------------------------------------------------
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
14 // This program 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 // ------------------------------------------------
25 // -------------------------------------
26 class HTTPException : public StreamException
29 HTTPException(const char *m, int c) : StreamException(m) {code=c;}
33 // --------------------------------------------
34 static const char *HTTP_SC_OK = "HTTP/1.0 200 OK";
35 static const char *HTTP_SC_NOTFOUND = "HTTP/1.0 404 Not Found";
36 static const char *HTTP_SC_UNAVAILABLE = "HTTP/1.0 503 Service Unavailable";
37 static const char *HTTP_SC_UNAUTHORIZED = "HTTP/1.0 401 Unauthorized";
38 static const char *HTTP_SC_FOUND = "HTTP/1.0 302 Found";
39 static const char *HTTP_SC_BADREQUEST = "HTTP/1.0 400 Bad Request";
40 static const char *HTTP_SC_FORBIDDEN = "HTTP/1.0 403 Forbidden";
41 static const char *HTTP_SC_SWITCH = "HTTP/1.0 101 Switch protocols";
43 static const char *RTSP_SC_OK = "RTSP/1.0 200 OK";
46 static const char *HTTP_PROTO1 = "HTTP/1.";
47 static const char *RTSP_PROTO1 = "RTSP/1.";
49 static const char *HTTP_HS_SERVER = "Server:";
50 static const char *HTTP_HS_AGENT = "User-Agent:";
51 static const char *HTTP_HS_CONTENT = "Content-Type:";
52 static const char *HTTP_HS_CACHE = "Cache-Control:";
53 static const char *HTTP_HS_CONNECTION = "Connection:";
54 static const char *HTTP_HS_SETCOOKIE = "Set-Cookie:";
55 static const char *HTTP_HS_COOKIE = "Cookie:";
56 static const char *HTTP_HS_HOST = "Host:";
57 static const char *HTTP_HS_ACCEPT = "Accept:";
58 static const char *HTTP_HS_LENGTH = "Content-Length:";
60 static const char *MIME_MP3 = "audio/mpeg";
61 static const char *MIME_XMP3 = "audio/x-mpeg";
62 static const char *MIME_OGG = "application/ogg";
63 static const char *MIME_XOGG = "application/x-ogg";
64 static const char *MIME_MOV = "video/quicktime";
65 static const char *MIME_MPG = "video/mpeg";
66 static const char *MIME_NSV = "video/nsv";
67 static const char *MIME_ASF = "video/x-ms-asf";
68 static const char *MIME_ASX = "video/x-ms-asf"; // same as ASF
69 static const char *MIME_MMS = "application/x-mms-framed";
71 static const char *MIME_RAM = "audio/x-pn-realaudio";
74 static const char *MIME_WMA = "audio/x-ms-wma";
75 static const char *MIME_WMV = "video/x-ms-wmv";
77 static const char *MIME_HTML = "text/html";
78 static const char *MIME_XML = "text/xml";
79 static const char *MIME_CSS = "text/css";
80 static const char *MIME_TEXT = "text/plain";
81 static const char *MIME_PLS = "audio/mpegurl";
82 static const char *MIME_XPLS = "audio/x-mpegurl";
83 static const char *MIME_XSCPLS = "audio/x-scpls";
84 static const char *MIME_SDP = "application/sdp";
85 static const char *MIME_M3U = "audio/m3u";
86 static const char *MIME_MPEGURL = "audio/mpegurl";
87 static const char *MIME_XM3U = "audio/x-mpegurl";
88 static const char *MIME_XPEERCAST = "application/x-peercast";
89 static const char *MIME_XPCP = "application/x-peercast-pcp";
90 static const char *MIME_RAW = "application/binary";
91 static const char *MIME_JPEG = "image/jpeg";
92 static const char *MIME_GIF = "image/gif";
93 static const char *MIME_PNG = "image/png";
96 // --------------------------------------------
112 void set(const char *i, unsigned int nip)
114 strncpy(id,i,sizeof(id)-1);
118 bool compare(Cookie &c)
121 if (strcmp(c.id,id)==0)
127 void logDebug(const char *,int);
134 // --------------------------------------------
146 void remove(Cookie &);
147 bool contains(Cookie &);
150 Cookie list[MAX_COOKIES];
155 // --------------------------------------------
156 class HTTP : public IndirectStream
164 void initRequest(const char *r)
169 bool isRequest(const char *);
172 bool checkResponse(int);
175 bool isHeader(const char *);
179 void getAuthUserPass(char *, char *);
181 char cmdLine[8192],*arg;