00001 #ifndef dsHttpd_h 00002 #define dsHttpd_h 00003 00004 #ifdef HAVE_CONFIG_H 00005 # include <config.h> 00006 #endif 00007 00008 #include <dsSmartException.h> 00009 #include <dsDaemon.h> 00010 #include <dsSocket.h> 00011 #include <dsHashTable.h> 00012 #include <dsStrstream.h> 00013 #include <dsutil.h> 00014 00015 00016 DECLARE_EXCEPTION(dsHttpd); 00017 DECLARE_EXCEPTION2(dsHttpdHandled, dsHttpd); 00018 00019 class dsHttpDaemon: public dsDaemon 00020 { 00021 protected: 00022 dsServerSocket* _ss; 00023 00024 char* _server_root; 00025 int _bind_port; 00026 00027 virtual int child_work(); 00028 virtual int init_globals(); 00029 virtual pid_t fork_child(); 00030 virtual void shutdown_child(); 00031 00032 void http_request_headers(dsStrstream& src); 00033 int end_of_header(dsStrstream& req); 00034 00035 bool parse_first_line(dsStrstream& src); 00036 bool parse_header_line(dsStrstream& src); 00037 00038 dsHashTable* _ht; 00039 00043 virtual void http_common_headers(std::ostream &os); 00044 00050 virtual void http_server_sign(std::ostream &os); 00051 00056 virtual int http_500(const char *message = 0); 00057 virtual int http_501(const char *method, const char *implemented = "GET"); 00058 virtual int http_400(const char *req_url); 00059 virtual int http_403(const char *req_url); 00060 virtual int http_404(const char *req_url); 00061 virtual int http_200(const char *mime_type, dsStrstream& body); 00062 virtual int http_200(const char *mime_type, int cont_length); 00064 00067 virtual void vhost_setup(dsStrstream& src); 00068 00072 virtual const char* content_type(const char *url); 00073 00079 virtual int process_request(dsStrstream& src); 00080 00081 public: 00082 dsHttpDaemon(char *server_root, int bind_port, char *daemon_name, int max_childs, int flags); 00083 00084 virtual ~dsHttpDaemon(); 00085 }; 00086 00087 #endif