00001
00002
00003
00004
00005
00006
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
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
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
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
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 class ZZ_API CzzHTTPServer
00097 {
00098 public:
00099
00100 CzzHTTPServer( CzzAccessLog* log );
00101
00102
00103
00104
00105 CzzHTTPServer( const char* port,
00106 int que
00107 );
00108
00109 CzzHTTPServer( const char* port,
00110 int que,
00111 CzzAccessLog* accesslog );
00112
00113
00114 virtual ~CzzHTTPServer();
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 virtual CzzHTTPRequest* waitForRequest( void );
00128
00129
00130
00131
00132
00133
00134
00135
00136 void reply( CzzHTTPRequest* req,
00137 ZZ_HTTP_STATUS status,
00138 ZZ_HTTP_CONTENT_TYPE content_type,
00139 CzzBuffer& data,
00140 const CzzString& err_msg = ""
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
00151
00152
00153
00154
00155
00156 void reply( CzzHTTPRequest* req,
00157 ZZ_HTTP_STATUS status,
00158 CzzBuffer& data,
00159 CzzHTTPHeaders& headers,
00160 const CzzString& err_msg = ""
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