From: Gonzalo A. <ga...@us...> - 2006-12-06 15:30:08
|
Update of /cvsroot/mod-c/ehtml/samples In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16020/samples Modified Files: Makefile.am Added Files: 03upload.cpp 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: Makefile.am =================================================================== RCS file: /cvsroot/mod-c/ehtml/samples/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile.am 17 Sep 2006 18:14:51 -0000 1.6 --- Makefile.am 6 Dec 2006 15:30:03 -0000 1.7 *************** *** 12,16 **** # -shared -o basic.so -lehtml samplesdir=$(libdir)/ehtml/samples ! samples_LTLIBRARIES = libsamplebasic.la libsamplesession.la libsamplebasic_la_SOURCES = 01basic.cpp libsamplebasic_la_LDFLAGS = -shared -module --- 12,16 ---- # -shared -o basic.so -lehtml samplesdir=$(libdir)/ehtml/samples ! samples_LTLIBRARIES = libsamplebasic.la libsamplesession.la libsampleupload.la libsamplebasic_la_SOURCES = 01basic.cpp libsamplebasic_la_LDFLAGS = -shared -module *************** *** 20,21 **** --- 20,24 ---- libsamplesession_la_LDFLAGS = -shared -module + libsampleupload_la_SOURCES = 03upload.cpp + libsampleupload_la_LDFLAGS = -shared -module + --- NEW FILE: 03upload.cpp --- // $Id: 03upload.cpp,v 1.1 2006/12/06 15:30:03 garana Exp $ #include <ehtml.h> #include <EHTMLApplication.h> #include <Page.h> #include <Label.h> #include <http_log.h> #include <time.h> #include <iomanip> using namespace std; static const char* fldName = "file0"; class FileUploadEHTMLApp: public EHTMLApplication { int fd; public: FileUploadEHTMLApp(request_context* req): EHTMLApplication(req), fd(-1) { req->r->content_type = "text/html"; } virtual int DoReadStage() { int dev = EHTMLApplication::DoReadStage(); // file contents are is read return dev; } virtual int DoInitStage() { int dev = EHTMLApplication::DoInitStage(); fd = GetRequest()->GetFile(fldName); Debug("%s => %d", fldName, fd); return dev; } virtual int DoRenderStage() { ostream& out = GetResponse()->GetStream(); if (fd >= 0) { struct stat st; if (fstat(fd, &st) < 0) { out << "Error statting fd=" << fd << ": " << strerror(errno) << endl; return 0; } out << "dev.ino=" << hex << setw(8) << setfill('0') << st.st_dev << '.' << hex << setw(8) << setfill('0') << st.st_ino << "<br/>" << endl; out << "mode=" << oct << setw(6) << setfill('0') << st.st_mode << dec << " owner=" << st.st_uid << ":" << st.st_gid << "<br/>" << endl; out << "nlink=" << st.st_nlink << "<br/>" << endl; out << "size=" << st.st_size << "<br/>" << endl; return 0; } out << "<form action=\"?\" method=\"POST\" enctype=\"multipart/form-data\">" << endl << "file: <input type=\"file\" name=\"file0\"><br/>" << endl << "<input type=\"submit\" name=\"send file\"><br/>" << endl; return 0; } }; extern "C" int ehtml_run(request_context* rc) { FileUploadEHTMLApp ap(rc); return ap.Run(); } |