📄 webserver.h
字号:
unsigned char *m_data; int m_width, m_height; wxString m_name; int m_size, m_alloc_size; wxString m_Http; void Realloc(int size); void SetHttpType(wxString ext); public: CAnyImage(int size); CAnyImage(int width, int height); virtual ~CAnyImage(); const wxString& GetHTTP() const { return m_Http; } virtual unsigned char *RequestData(int &size);};class CFileImage : public virtual CAnyImage { public: CFileImage(const wxString& name); bool OpenOk() { return m_size != 0; }};class CImage3D_Modifiers { unsigned char *m_modifiers; int m_width; public: CImage3D_Modifiers(int width); ~CImage3D_Modifiers(); unsigned char operator[](int i) { return (i < m_width) ? m_modifiers[i] : 0; }};class CProgressImage : public virtual CAnyImage { protected: DownloadFile *m_file; wxString m_template; // // sorted list of gaps int m_gap_buf_size, m_gap_alloc_size; Gap_Struct *m_gap_buf; void ReallocGapBuffer(); void InitSortedGaps(); // for qsort static int compare_gaps(const void *, const void *); // // Turn list of gaps, partstatus into array of color strips typedef struct Color_Gap_Struct : public Gap_Struct { uint32 color; } Color_Gap_Struct; // result of rendering - single line uint32 *m_ColorLine; void CreateSpan(); public: CProgressImage(int w, int h, wxString &tmpl, DownloadFile *file); ~CProgressImage(); const wxString &Name() { return m_name; } virtual wxString GetHTML() = 0;};#ifdef WITH_LIBPNG//// Dynamic png image generation//class CDynPngImage : public virtual CAnyImage { public: CDynPngImage(int w, int h); ~CDynPngImage(); virtual unsigned char *RequestData(int &size); protected: png_bytep m_img_data; png_bytep *m_row_ptrs; static void png_write_fn(png_structp png_ptr, png_bytep data, png_size_t length); };//// Dynamic png image generation from gap infoclass CDynProgressImage : public virtual CProgressImage, public virtual CDynPngImage { CImage3D_Modifiers m_modifiers; void DrawImage(); public: CDynProgressImage(int w, int h, wxString &tmpl, DownloadFile *file); ~CDynProgressImage(); virtual unsigned char *RequestData(int &size); virtual wxString GetHTML();};#else//// Fallback to original implementationclass CDynProgressImage : public virtual CProgressImage { public: CDynProgressImage(int w, int h, wxString &tmpl, DownloadFile *file); virtual wxString GetHTML();};#endif//// Representing statistical sample for some parameter. Circular buffer// inside to avoid rellocations//class CStatsData { uint32 *m_data; uint32 m_max_value; int m_size; int m_start_index, m_end_index, m_curr_index; public: CStatsData(int size); ~CStatsData(); int Size() const { return m_size; } uint32 Max() const { return m_max_value; } uint32 GetFirst(); uint32 GetNext(); void PushSample(uint32 sample);};class CStatsCollection { CStatsData *m_down_speed, *m_up_speed, *m_conn_number, *m_kad_count; CamulewebApp *m_iface; double m_LastTimeStamp; int m_size; public: CStatsCollection(int size, CamulewebApp *iface); ~CStatsCollection(); CStatsData *DownloadSpeed() { return m_down_speed; } CStatsData *UploadSpeed() { return m_up_speed; } CStatsData *ConnCount() { return m_conn_number; } CStatsData *KadCount() { return m_kad_count; } void ReQuery();};#ifdef WITH_LIBPNG//// This gonna to represent data used to "write" numbers on// dynamically generated images.// Easiest way to represt numbers: 7-segments model//class CNumImageMask { png_bytep *m_row_mask_ptrs; int m_width, m_height; int m_v_segsize, m_h_segsize; // mask generation void DrawHorzLine(int off); void DrawVertLine(int offx, int offy); void DrawSegment(int id); static const int m_num_to_7_decode[10]; public: CNumImageMask(int number, int width, int height); ~CNumImageMask(); void Apply(png_bytep *image, int offx, int offy);};class CDynStatisticImage : public virtual CDynPngImage { CStatsData *m_data; // size of "font" of imprinted numbers int m_num_font_w_size, m_num_font_h_size; int m_left_margin, m_bottom_margin; int m_y_axis_size; // hope nobody needs "define" for 10 ! CNumImageMask *m_digits[10]; // indicates whether data should be divided on 1024 before // drawing graph. bool m_scale1024; // // Prepared background // png_bytep m_background; png_bytep *m_row_bg_ptrs; void DrawImage(); public: CDynStatisticImage(int height, bool scale1024, CStatsData *data); ~CDynStatisticImage(); virtual unsigned char *RequestData(int &size); virtual wxString GetHTML();};#endifclass CImageLib { std::map<wxString, CAnyImage *> m_image_map; wxString m_image_dir; public: CImageLib(wxString image_dir); ~CImageLib(); CAnyImage *GetImage(wxString &name); void AddImage(CAnyImage *img, const wxString &name); void RemoveImage(const wxString &name);};class CUrlDecodeTable { static CUrlDecodeTable* ms_instance; static wxCriticalSection ms_instance_guard; wxString m_enc_u_str[256], m_enc_l_str[256], m_dec_str[256]; CUrlDecodeTable(); public: static CUrlDecodeTable* GetInstance(); void DecodeString(wxString &str);};class CParsedUrl { wxString m_path, m_file; std::map<wxString, wxString> m_params; public: CParsedUrl(const wxString &url); const wxString &Path() { return m_path; } const wxString &File() { return m_file; } const wxString &Param(const wxString &key) { return m_params[key]; } void ConvertParams(std::map<std::string, std::string> &);};// Changing this to a typedef struct{} makes egcs compiler do it all wrong and crash on runstruct ThreadData { CParsedUrl parsedURL; wxString sURL; int SessionID; CWebSocket *pSocket;};enum { // Socket handlers ID_WEBLISTENSOCKET_EVENT = wxID_HIGHEST+123, // random safe ID ID_WEBCLIENTSOCKET_ENENT,};#ifdef ENABLE_UPNPclass CUPnPControlPoint;class CUPnPPortMapping;#endifclass CWebServerBase : public wxEvtHandler { protected: //CWSThread *wsThread; wxSocketServer *m_webserver_socket; wxMutex m_mutexChildren; ServersInfo m_ServersInfo; SharedFileInfo m_SharedFileInfo; DownloadFileInfo m_DownloadFileInfo; UploadsInfo m_UploadsInfo; SearchInfo m_SearchInfo; CStatsCollection m_Stats; CImageLib m_ImageLib; virtual void ProcessURL(ThreadData) = 0; virtual void ProcessImgFileReq(ThreadData) = 0; int GzipCompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level); friend class CWebSocket; friend class CPhPLibContext; bool m_upnpEnabled; int m_upnpTCPPort;#ifdef ENABLE_UPNP CUPnPControlPoint *m_upnp; std::vector<CUPnPPortMapping> m_upnpMappings;#endif void OnWebSocketServerEvent(wxSocketEvent& event); void OnWebSocketEvent(wxSocketEvent& event); DECLARE_EVENT_TABLE(); public: CWebServerBase(CamulewebApp *webApp, const wxString& templateDir); virtual ~CWebServerBase() { } void Send_Discard_V2_Request(CECPacket *request); void StartServer(); void StopServer(); void Print(const wxString &s); long GetWSPrefs(); // // Command interface // void Send_ReloadSharedFile_Cmd(); void Send_SharedFile_Cmd(wxString file_hash, wxString cmd, uint32 opt_arg = 0); void Send_DownloadFile_Cmd(wxString file_hash, wxString cmd, uint32 opt_arg = 0); void Send_DownloadSearchFile_Cmd(wxString file_hash, uint8 cat); void Send_Server_Cmd(uint32 ip, uint16 port, wxString cmd); void Send_AddServer_Cmd(wxString addr, wxString port, wxString name); void Send_Search_Cmd(wxString search, wxString extention, wxString type, EC_SEARCH_TYPE search_type, uint32 avail, uint32 min_size, uint32 max_size); bool Send_DownloadEd2k_Cmd(wxString link, uint8 cat); void Reload_Stats() { m_Stats.ReQuery(); } CamulewebApp *webInterface;};class CSession { public: bool m_loggedin; time_t m_last_access; std::map<std::string, std::string> m_vars, m_get_vars; void LoadVars(CParsedUrl &url);};/* * Script based webserver */class CScriptWebServer : public CWebServerBase { wxString m_wwwroot; wxString m_index; char *ProcessHtmlRequest(const char *filename, long &size); char *ProcessPhpRequest(const char *filename, CSession *sess, long &size); char *GetErrorPage(const char *message, long &size); char *Get_404_Page(long &size); std::map<int, CSession> m_sessions; CSession *CheckLoggedin(ThreadData &); protected: virtual void ProcessURL(ThreadData); virtual void ProcessImgFileReq(ThreadData); public: CScriptWebServer(CamulewebApp *webApp, const wxString& templateDir); ~CScriptWebServer();};class CNoTemplateWebServer : public CScriptWebServer { protected: virtual void ProcessURL(ThreadData); public: CNoTemplateWebServer(CamulewebApp *webApp); ~CNoTemplateWebServer();};#endif // WEBSERVER_H// File_checked_for_headers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -