inet/zz_http_server.h

Go to the documentation of this file.
00001 /* libzzinet
00002  *
00003  * This program is distributed under the GNU General Public License, version 2.
00004  * A copy of this license is included with this source.
00005  *
00006  * Copyright 2000-2006, Toni Thomsson <toni@tonjac.org> 
00007 */
00008 
00009 #ifndef zz_http_server_h
00010 #define zz_http_server_h
00011 
00012 #include <zz_socket.h>
00013 #include <zz_http_request.h>
00014 #include <zz_log.h>
00015 #include <zz_export.h>
00016 #include <zz_access_log.h>
00017 #include <zz_win_threadmutex.h>
00018 
00019 // RFC1945, status koder
00020 typedef enum
00021 {
00022     ZZ_HTTP_STATUS_INFO,
00023     ZZ_HTTP_STATUS_OK,
00024     ZZ_HTTP_STATUS_BAD_REQUEST,
00025     ZZ_HTTP_STATUS_FORBIDDEN,
00026     ZZ_HTTP_STATUS_NOT_FOUND,
00027     ZZ_HTTP_STATUS_AUTHORIZATION,
00028     ZZ_HTTP_STATUS_INTERNAL_SERVER_ERROR,
00029     ZZ_HTTP_STATUS_INVALID
00030 
00031 } ZZ_HTTP_STATUS;
00032 
00033 // RFC1945 defined response codes
00034 static char* zz_http_status[] = 
00035 { 
00036     "100 Info",
00037     "200 OK", 
00038     "400 Bad request",
00039     "403 Forbidden",
00040     "404 Not found",
00041     "401 Unauthorized",
00042     "500 Internal server error",
00043     "<not supported>"
00044 }; 
00045 
00046 // RFC1945, Innehållstyper
00047 typedef enum
00048 {
00049         ZZ_HTTP_CONTENT_TYPE_M3U,
00050     ZZ_HTTP_CONTENT_TYPE_MP3,
00051         ZZ_HTTP_CONTENT_TYPE_CSS,
00052         ZZ_HTTP_CONTENT_TYPE_TEXT,
00053     ZZ_HTTP_CONTENT_TYPE_HTML,
00054     ZZ_HTTP_CONTENT_TYPE_GIF,
00055     ZZ_HTTP_CONTENT_TYPE_BITMAP,
00056     ZZ_HTTP_CONTENT_TYPE_JPEG,
00057     ZZ_HTTP_CONTENT_TYPE_PJPEG,
00058     ZZ_HTTP_CONTENT_TYPE_ZIP,
00059     ZZ_HTTP_CONTENT_TYPE_ALL,
00060     ZZ_HTTP_CONTENT_TYPE_INVALID
00061 
00062 } ZZ_HTTP_CONTENT_TYPE;
00063 
00064 static char* zz_http_content_type[] =
00065 {
00066     "audio/x-mpegurl",
00067         "audio/mpeg",
00068         "text/css",
00069         "text/plain",
00070     "text/html",
00071     "image/gif", 
00072     "image/x-xbitmap", 
00073     "image/jpeg", 
00074     "image/pjpeg",
00075     "zip/gzip",
00076     "*/*",
00077     "<not supported>"
00078 };
00079 
00080 /*
00081         Description:
00082         Easy HTTP server (HTTP/1.0) 
00083     
00084     Remarks:
00085     Ingen 100% komplett implementation
00086 
00087         Author: 
00088         Toni Thomsson, toni@tonjac.org
00089 
00090         Library:
00091         libzzinet.a (HPUX) libzzinet.lib (win32)
00092 
00093         Platform:
00094         HPUX, win32
00095 */
00096 class ZZ_API CzzHTTPServer
00097 {
00098 public:
00099 
00100         CzzHTTPServer( CzzAccessLog* log );
00101 
00102     /*
00103                 Description: Skapar ett HTTP-server objekt
00104         */
00105     CzzHTTPServer( const char* port,    // IN, port som servern lyssnar på
00106                     int que             // IN, antal anrop som kan köas upp 
00107                     );
00108 
00109         CzzHTTPServer( const char* port,    // IN, port som servern lyssnar på
00110                     int que,            // IN, antal anrop som kan köas upp 
00111                     CzzAccessLog* accesslog );
00112 
00113     // Description: Destruktor
00114     virtual ~CzzHTTPServer();
00115 
00116 
00117     /*
00118                 Description: 
00119                 Väntar på anrop från klienter
00120 
00121             Returns:
00122         Ett anropsobjekt
00123 
00124                 Throws:
00125                 CzzException
00126         */
00127     virtual CzzHTTPRequest* waitForRequest( void );
00128 
00129     /*
00130                 Description: 
00131                 Skicka svar till klient med "standard" headers
00132 
00133                 Throws:
00134                 CzzException
00135         */
00136     void reply( CzzHTTPRequest* req,
00137                                 ZZ_HTTP_STATUS status,              // IN, status
00138                 ZZ_HTTP_CONTENT_TYPE content_type,  // IN, innehållstyp
00139                 CzzBuffer& data,                    // IN, data som skall skickas
00140                 const CzzString& err_msg = ""       // IN, ev felmeddelande
00141                 );
00142 
00143         void reply( CzzHTTPRequest* req, 
00144                         ZZ_HTTP_STATUS status, 
00145                         const char* content_type, 
00146                         CzzBuffer& data, const 
00147                         CzzString& err_msg = "" );
00148 
00149     /*
00150                 Description: 
00151                 Skicka svar till klient med valfria headers
00152 
00153                 Throws:
00154                 CzzException
00155         */
00156     void reply( CzzHTTPRequest* req,
00157                                 ZZ_HTTP_STATUS status,              // IN, status
00158                 CzzBuffer& data,                    // IN, data som skall skickas
00159                 CzzHTTPHeaders& headers,            // IN, headers
00160                 const CzzString& err_msg = ""       // IN, ev felmeddelande
00161                 );
00162 
00163         
00164 
00165 protected:
00166         
00167         CzzLog m_Log;
00168     CzzAccessLog* m_AccessLog;
00169 
00170 private:
00171 
00172     int receiveHeaders( CzzBuffer* buff, int* read_bytes, CzzSocket* reqsock );
00173     CzzString getDate( void );
00174 
00175     CzzSocket* m_Socket;
00176     static CzzWinThreadMutex m_Mutex;
00177 };
00178 
00179 #endif // zz_http_server_h
00180 
00181 
00182 
00183 

Generated on Thu Sep 21 21:45:42 2006 for tonjac.org MINI/C++ library by  doxygen 1.4.6-NO