OSDN Git Service

FLV配信用パッチをマージ。(github:niwakazoider/peercast@21998fef7e24f437ef8d50e17562ba95eb5c1843)
[peercast-im/PeerCastIM.git] / core / common / http.h
1 // ------------------------------------------------
2 // File : http.h
3 // Date: 4-apr-2002
4 // Author: giles
5 // Desc: 
6 //
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.
13
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 // ------------------------------------------------
19
20 #ifndef _HTTP_H
21 #define _HTTP_H
22
23 #include "stream.h"
24
25 // -------------------------------------
26 class HTTPException : public StreamException
27 {
28 public:
29         HTTPException(const char *m, int c) : StreamException(m) {code=c;}
30         int code;
31 };
32
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";
42
43 static const char *RTSP_SC_OK                   = "RTSP/1.0 200 OK";
44
45
46 static const char *HTTP_PROTO1          = "HTTP/1.";
47 static const char *RTSP_PROTO1          = "RTSP/1.";
48
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:";
59
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";
70
71 static const char *MIME_RAM                     = "audio/x-pn-realaudio";
72
73
74 static const char *MIME_WMA                     = "audio/x-ms-wma";
75 static const char *MIME_WMV                     = "video/x-ms-wmv";
76
77 static const char *MIME_FLV             = "video/flv";
78
79 static const char *MIME_HTML            = "text/html";
80 static const char *MIME_XML                     = "text/xml";
81 static const char *MIME_CSS                     = "text/css";
82 static const char *MIME_TEXT            = "text/plain";
83 static const char *MIME_PLS                     = "audio/mpegurl";
84 static const char *MIME_XPLS            = "audio/x-mpegurl";
85 static const char *MIME_XSCPLS          = "audio/x-scpls";
86 static const char *MIME_SDP                     = "application/sdp";
87 static const char *MIME_M3U                     = "audio/m3u";
88 static const char *MIME_MPEGURL         = "audio/mpegurl";
89 static const char *MIME_XM3U            = "audio/x-mpegurl";
90 static const char *MIME_XPEERCAST       = "application/x-peercast";
91 static const char *MIME_XPCP            = "application/x-peercast-pcp";
92 static const char *MIME_RAW                     = "application/binary";
93 static const char *MIME_JPEG            = "image/jpeg";
94 static const char *MIME_GIF                     = "image/gif";
95 static const char *MIME_PNG                     = "image/png";
96
97
98 // --------------------------------------------
99 class Cookie
100 {
101 public:
102         Cookie()
103         {
104                 clear();
105         }
106
107         void    clear()
108         {
109                 time = 0;
110                 ip = 0;
111                 id[0]=0;
112         }
113
114         void    set(const char *i, unsigned int nip)
115         {
116                 strncpy(id,i,sizeof(id)-1);
117                 id[sizeof(id)-1]=0;
118                 ip = nip;
119         }
120         bool    compare(Cookie &c)
121         {
122                 if (c.ip == ip)
123                         if (strcmp(c.id,id)==0)
124                                 return true;
125
126                 return false;
127         }
128
129         void    logDebug(const char *,int);
130
131         unsigned int ip;
132         char    id[64];
133         unsigned int time;
134 };
135
136 // --------------------------------------------
137 class CookieList
138 {
139 public:
140         enum {
141                 MAX_COOKIES = 32
142         };
143
144
145
146         void    init();
147         bool    add(Cookie &);
148         void    remove(Cookie &);
149         bool    contains(Cookie &);
150
151
152         Cookie list[MAX_COOKIES];
153         bool    neverExpire;
154
155 };
156
157 // --------------------------------------------
158 class HTTP : public IndirectStream
159 {
160 public:
161         HTTP(Stream &s)
162         {
163                 init(&s);
164         }
165
166         void    initRequest(const char *r)
167         {
168                 strcpy(cmdLine,r);
169         }
170         void    readRequest();
171         bool    isRequest(const char *);
172
173         int             readResponse();
174         bool    checkResponse(int);
175
176         bool    nextHeader();
177         bool    isHeader(const char *);
178         char    *getArgStr();
179         int             getArgInt();
180
181         void    getAuthUserPass(char *, char *, size_t, size_t);
182
183         char    cmdLine[8192],*arg;
184
185 };
186
187 #endif