OSDN Git Service

GUI終了時のエラー落ちを修正(?)
[peercast-im/PeerCastIM.git] / PeerCast.root / PeerCast / 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_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";
94
95
96 // --------------------------------------------
97 class Cookie
98 {
99 public:
100         Cookie()
101         {
102                 clear();
103         }
104
105         void    clear()
106         {
107                 time = 0;
108                 ip = 0;
109                 id[0]=0;
110         }
111
112         void    set(const char *i, unsigned int nip)
113         {
114                 strncpy(id,i,sizeof(id)-1);
115                 id[sizeof(id)-1]=0;
116                 ip = nip;
117         }
118         bool    compare(Cookie &c)
119         {
120                 if (c.ip == ip)
121                         if (strcmp(c.id,id)==0)
122                                 return true;
123
124                 return false;
125         }
126
127         void    logDebug(const char *,int);
128
129         unsigned int ip;
130         char    id[64];
131         unsigned int time;
132 };
133
134 // --------------------------------------------
135 class CookieList
136 {
137 public:
138         enum {
139                 MAX_COOKIES = 32
140         };
141
142
143
144         void    init();
145         bool    add(Cookie &);
146         void    remove(Cookie &);
147         bool    contains(Cookie &);
148
149
150         Cookie list[MAX_COOKIES];
151         bool    neverExpire;
152
153 };
154
155 // --------------------------------------------
156 class HTTP : public IndirectStream
157 {
158 public:
159         HTTP(Stream &s)
160         {
161                 init(&s);
162         }
163
164         void    initRequest(const char *r)
165         {
166                 strcpy(cmdLine,r);
167         }
168         void    readRequest();
169         bool    isRequest(const char *);
170
171         int             readResponse();
172         bool    checkResponse(int);
173
174         bool    nextHeader();
175         bool    isHeader(const char *);
176         char    *getArgStr();
177         int             getArgInt();
178
179         void    getAuthUserPass(char *, char *);
180
181         char    cmdLine[8192],*arg;
182
183 };
184
185 #endif