CppCMS
cppcms/http_file.h
00001 
00002 //                                                                             
00003 //  Copyright (C) 2008-2012  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>     
00004 //                                                                             
00005 //  See accompanying file COPYING.TXT file for licensing details.
00006 //
00008 #ifndef CPPCMS_HTTP_FILE_H
00009 #define CPPCMS_HTTP_FILE_H
00010 
00011 #include <cppcms/defs.h>
00012 #include <cppcms/cstdint.h>
00013 #include <booster/hold_ptr.h>
00014 #include <booster/nowide/fstream.h>
00015 #include <booster/noncopyable.h>
00016 #include <sstream>
00017 #include <fstream>
00018 
00019 namespace cppcms { namespace http {
00020 
00021         class request;
00022 
00032         class CPPCMS_API file : public booster::noncopyable {
00033         public:
00037                 std::string name() const;
00041                 std::string mime() const;
00045                 std::string filename() const;
00046 
00051                 std::istream &data();
00052                 
00056                 long long size();
00057                 
00067                 void save_to(std::string const &filename);
00068 
00070 
00071                 void name(std::string const &);
00072                 void mime(std::string const &);
00073                 void filename(std::string const &);
00074                 std::ostream &write_data();
00075 
00076                 file();
00077                 ~file();
00078 
00079                 void set_memory_limit(size_t size);
00080                 void set_temporary_directory(std::string const &dir);
00081 
00083 
00084         private:
00085                 std::string name_;
00086                 std::string mime_;
00087                 std::string filename_;
00088                 size_t size_limit_;
00089 
00090                 booster::nowide::fstream file_;
00091                 std::stringstream file_data_;
00092                 std::string tmp_file_name_;
00093                 std::string temporary_dir_;
00094 
00095                 void move_to_file();
00096                 void save_by_copy(std::string const &file_name,std::istream &in);
00097                 void copy_stream(std::istream &in,std::ostream &out);
00098 
00099                 
00100                 uint32_t saved_in_file_ : 1;
00101                 uint32_t removed_ : 1 ;
00102                 uint32_t reserverd_ : 30;
00103 
00104                 struct impl_data; // for future use
00105                 booster::hold_ptr<impl_data> d;
00106                 friend class request;
00107         };
00108 
00109 
00110 } } //::cppcms::http
00111 
00112 
00113 #endif