00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _SOCKETS_HttpdForm_H
00035 #define _SOCKETS_HttpdForm_H
00036
00037 #include "sockets-config.h"
00038 #include <string>
00039 #include <list>
00040 #include <cstdio>
00041 #include <cstring>
00042 #include <vector>
00043
00044 #ifdef SOCKETS_NAMESPACE
00045 namespace SOCKETS_NAMESPACE {
00046 #endif
00047
00048
00049 class IFile;
00050 class IFileUpload;
00051 class IStream;
00052
00055 class HttpdForm
00056 {
00062 struct CGI
00063 {
00064 CGI(const std::string& n,const std::string& v) : name(n),value(v) {}
00065 CGI(const std::string& n,const std::string& v,const std::string& p) : name(n),value(v),path(p) {}
00066 std::string name;
00067 std::string value;
00068 std::string path;
00069 };
00071 typedef std::list<CGI *> cgi_v;
00072
00073 public:
00077 HttpdForm(FILE *);
00083 HttpdForm(IFile *, const std::string& content_type, size_t content_length);
00090 HttpdForm(const std::string& query_string,size_t length);
00091 ~HttpdForm();
00092
00099 void ParseFormData(IFile *, const std::string&, size_t);
00100 void ParseQueryString(const std::string& query_string, size_t length);
00101
00102 void EnableRaw(bool);
00103
00105 void strcpyval(std::string&,const char *) const;
00106
00107
00108 bool getfirst(std::string& n) const;
00109 bool getnext(std::string& n) const;
00110
00111
00112 bool getfirst(std::string& n,std::string& v) const;
00113 bool getnext(std::string& n,std::string& v) const;
00114
00115
00116 int getvalue(const std::string& ,std::string& ) const;
00117 std::string getvalue(const std::string& ) const;
00118 size_t getlength(const std::string& ) const;
00119 cgi_v& getbase();
00120
00121 const std::string& GetBoundary() const;
00122
00124 void SetFileUpload(IFileUpload& cb);
00125
00126 bool ContentAvailable() const { return !m_content.empty(); }
00127 const std::vector<char>& GetContent() const { return m_content; }
00128
00129 private:
00130 HttpdForm(const HttpdForm& ) {}
00131 HttpdForm& operator=(const HttpdForm& ) { return *this; }
00132 cgi_v m_cgi;
00133 mutable cgi_v::const_iterator m_current;
00134 std::string m_strBoundary;
00135 bool raw;
00136 IFileUpload *m_file_upload;
00137 IStream *m_upload_stream;
00138 std::vector<char> m_content;
00139 };
00140
00141
00142 #ifdef SOCKETS_NAMESPACE
00143 }
00144 #endif
00145
00146 #endif // _SOCKETS_HttpdForm_H
00147