Update of /cvsroot/mod-c/ehtml/include
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16020/include
Modified Files:
EHTMLApplication.h Request.h
Log Message:
Added file upload support.
Uploaded files are saved in a temporary file, which is unlinked as soon as
created. Application must copy the file contents to final destination,
possibly with sendfile(2).
Upload progress capability is supported. A virtual method
(UploadProgressCallback) is called on each chunk.
Index: EHTMLApplication.h
===================================================================
RCS file: /cvsroot/mod-c/ehtml/include/EHTMLApplication.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** EHTMLApplication.h 6 Nov 2006 17:09:54 -0000 1.12
--- EHTMLApplication.h 6 Dec 2006 15:30:02 -0000 1.13
***************
*** 251,254 ****
--- 251,261 ----
Session* GetSession() { return session; }
+ /**
+ * Called when the request is a file upload.
+ * Should be overloaded by your application, but your application should call
+ * EHTMLApplication::UploadProgressCallback() any way.
+ * The progress information is located in GetRequest()->{ReadSoFar,ContentLength}.
+ */
+ virtual void UploadProgressCallback();
protected:
friend class Session;
Index: Request.h
===================================================================
RCS file: /cvsroot/mod-c/ehtml/include/Request.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Request.h 1 Dec 2006 14:45:47 -0000 1.11
--- Request.h 6 Dec 2006 15:30:03 -0000 1.12
***************
*** 104,107 ****
--- 104,122 ----
/**
+ * Returns the file descriptor associated with the file uploaded
+ *
+ * @param name
+ * The name of the form input type=file.
+ */
+ int GetFile( const std::string& name ) const;
+
+ /*
+ * Return the list of uploaded files.
+ *
+ * @return the list of uploaded files.
+ */
+ const std::map<std::string,int>& GetFiles() { return Files; }
+
+ /**
* Error logging method.
*/
***************
*** 144,148 ****
--- 159,173 ----
mutable std::list<std::string> cookies_returned;
+ /**
+ * Uploaded files.
+ *
+ * As a file is uploaded, it is saved under a temporary file (which is created with mkstemp).
+ */
+ std::map<std::string,int> Files;
+
+
void ProcessCookieHeader(const char* value);
+
+ void ProcessUploadChunk(char* buf, size_t& nbytes, char& state, char*& varname);
public:
/**
***************
*** 188,191 ****
--- 213,247 ----
*/
long ContentLength;
+ /**
+ * How many bytes have been read so far.
+ * Begins with 0. Remain 0 if the reques has no body
+ */
+ long ReadSoFar;
+ /**
+ * Recognized content type enumeration.
+ */
+ typedef enum ctype {
+ CT_NONE,
+ CT_MULTIPART_FORM_DATA,
+ CT_APPLICATION_URLENCODED
+ } ctype_t;
+ /**
+ * The content type of the request.
+ * Currently, it only supports these two values:
+ * <li> multipart/form-data (for file uploads)
+ * <li> application/x-www-form-urlencoded (for normal posts)
+ */
+ ctype_t ContentType;
+
+ /**
+ * If this request is a file upload, the boundary is set.
+ */
+ char* boundary;
+
+ /**
+ * length of the boundary string (strlen(boundary)).
+ */
+ size_t boundary_length;
+
/**
* A list of special headers.
|