ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

126 lines
3.5 KiB

  1. #ifndef CPPCMS_IMPL_CGI_API_H
  2. #define CPPCMS_IMPL_CGI_API_H
  3. #include "noncopyable.h"
  4. #include "refcounted.h"
  5. #include "intrusive_ptr.h"
  6. #include <vector>
  7. #include <map>
  8. #include "config.h"
  9. #ifdef CPPCMS_USE_EXTERNAL_BOOST
  10. # include <boost/function.hpp>
  11. # include <boost/system/error_code.hpp>
  12. namespace boost { namespace asio { class io_service; } }
  13. #else // Internal Boost
  14. # include <cppcms_boost/function.hpp>
  15. # include <cppcms_boost/system/error_code.hpp>
  16. namespace cppcms_boost { namespace asio { class io_service; } }
  17. namespace boost = cppcms_boost;
  18. #endif
  19. namespace cppcms {
  20. class service;
  21. class application;
  22. namespace http {
  23. class request;
  24. class response;
  25. }
  26. namespace impl {
  27. namespace cgi {
  28. typedef boost::function<void(boost::system::error_code const &e)> handler;
  29. typedef boost::function<void(boost::system::error_code const &e,size_t)> io_handler;
  30. typedef boost::function<void()> callback;
  31. typedef boost::function<void(bool)> ehandler;
  32. class acceptor : public util::noncopyable {
  33. public:
  34. virtual void async_accept() = 0;
  35. virtual void stop() = 0;
  36. virtual ~acceptor(){}
  37. };
  38. class connection : public refcounted
  39. {
  40. public:
  41. connection(cppcms::service &srv);
  42. virtual ~connection();
  43. cppcms::service &service();
  44. void async_prepare_request( http::request &request,
  45. ehandler const &on_post_data_ready);
  46. void async_write_response( http::response &response,
  47. bool complete_response,
  48. ehandler const &on_response_written);
  49. void async_complete_response( ehandler const &on_response_complete);
  50. void aync_wait_for_close_by_peer(callback const &on_eof);
  51. virtual std::string getenv(std::string const &key) = 0;
  52. virtual std::map<std::string,std::string> const &getenv() = 0;
  53. size_t write(void const *data,size_t n);
  54. bool is_reuseable();
  55. std::string last_error();
  56. protected:
  57. /****************************************************************************/
  58. // These are abstract member function that should be implemented by
  59. // actual protocol like FCGI, SCGI, HTTP or CGI
  60. virtual void async_read_headers(handler const &h) = 0;
  61. virtual bool keep_alive() = 0;
  62. virtual void close() = 0;
  63. // Concept implementation headers
  64. virtual void async_read_some(void *,size_t,io_handler const &h) = 0;
  65. virtual void async_read_eof(callback const &h) = 0;
  66. virtual void async_write_some(void const *,size_t,io_handler const &h) = 0;
  67. virtual void async_write_eof(handler const &h) = 0;
  68. virtual size_t write_some(void const *,size_t) = 0;
  69. virtual boost::asio::io_service &get_io_service() = 0;
  70. /****************************************************************************/
  71. protected:
  72. intrusive_ptr<connection> self();
  73. void async_read(void *,size_t,io_handler const &h);
  74. void async_write(void const *,size_t,io_handler const &h);
  75. private:
  76. struct reader;
  77. struct writer;
  78. friend struct reader;
  79. friend struct writer;
  80. void set_error(ehandler const &h,std::string s);
  81. void load_content(boost::system::error_code const &e,http::request *request,ehandler const &h);
  82. void on_post_data_loaded(boost::system::error_code const &e,http::request *r,ehandler const &h);
  83. void on_async_write_written(boost::system::error_code const &e,bool complete_response,ehandler const &h);
  84. void on_eof_written(boost::system::error_code const &e,ehandler const &h);
  85. void handle_eof(callback const &on_eof);
  86. std::vector<char> content_;
  87. cppcms::service *service_;
  88. std::string async_chunk_;
  89. std::string error_;
  90. bool request_in_progress_;
  91. };
  92. } // cgi
  93. } // impl
  94. } // cppcms
  95. #endif