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.
 
 
 
 
 
 

137 lines
4.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Lesser General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef CPPCMS_IMPL_CGI_API_H
  20. #define CPPCMS_IMPL_CGI_API_H
  21. #include <booster/noncopyable.h>
  22. #include "refcounted.h"
  23. #include "intrusive_ptr.h"
  24. #include <vector>
  25. #include <map>
  26. #include <booster/function.h>
  27. #include "config.h"
  28. #include <booster/system_error.h>
  29. namespace booster { namespace aio { class io_service; }}
  30. namespace cppcms {
  31. class service;
  32. class application;
  33. namespace http {
  34. class request;
  35. class response;
  36. }
  37. namespace impl {
  38. namespace cgi {
  39. typedef booster::function<void(booster::system::error_code const &e)> handler;
  40. typedef booster::function<void(booster::system::error_code const &e,size_t)> io_handler;
  41. typedef booster::function<void()> callback;
  42. typedef booster::function<void(bool)> ehandler;
  43. class acceptor : public booster::noncopyable {
  44. public:
  45. virtual void async_accept() = 0;
  46. virtual void stop() = 0;
  47. virtual ~acceptor(){}
  48. };
  49. class connection : public refcounted
  50. {
  51. public:
  52. connection(cppcms::service &srv);
  53. virtual ~connection();
  54. cppcms::service &service();
  55. void async_prepare_request( http::request &request,
  56. ehandler const &on_post_data_ready);
  57. void async_write_response( http::response &response,
  58. bool complete_response,
  59. ehandler const &on_response_written);
  60. void async_complete_response( ehandler const &on_response_complete);
  61. void aync_wait_for_close_by_peer(callback const &on_eof);
  62. virtual std::string getenv(std::string const &key) = 0;
  63. virtual std::map<std::string,std::string> const &getenv() = 0;
  64. size_t write(void const *data,size_t n);
  65. bool is_reuseable();
  66. std::string last_error();
  67. protected:
  68. /****************************************************************************/
  69. // These are abstract member function that should be implemented by
  70. // actual protocol like FCGI, SCGI, HTTP or CGI
  71. virtual void async_read_headers(handler const &h) = 0;
  72. virtual bool keep_alive() = 0;
  73. virtual void close() = 0;
  74. // Concept implementation headers
  75. virtual void async_read_some(void *,size_t,io_handler const &h) = 0;
  76. virtual void async_read_eof(callback const &h) = 0;
  77. virtual void async_write_some(void const *,size_t,io_handler const &h) = 0;
  78. virtual void async_write_eof(handler const &h) = 0;
  79. virtual size_t write_some(void const *,size_t) = 0;
  80. virtual booster::aio::io_service &get_io_service() = 0;
  81. /****************************************************************************/
  82. protected:
  83. intrusive_ptr<connection> self();
  84. void async_read(void *,size_t,io_handler const &h);
  85. void async_write(void const *,size_t,io_handler const &h);
  86. private:
  87. struct reader;
  88. struct writer;
  89. friend struct reader;
  90. friend struct writer;
  91. void set_error(ehandler const &h,std::string s);
  92. void load_content(booster::system::error_code const &e,http::request *request,ehandler const &h);
  93. void on_post_data_loaded(booster::system::error_code const &e,http::request *r,ehandler const &h);
  94. void on_async_write_written(booster::system::error_code const &e,bool complete_response,ehandler const &h);
  95. void on_eof_written(booster::system::error_code const &e,ehandler const &h);
  96. void handle_eof(callback const &on_eof);
  97. std::vector<char> content_;
  98. cppcms::service *service_;
  99. std::string async_chunk_;
  100. std::string error_;
  101. bool request_in_progress_;
  102. };
  103. } // cgi
  104. } // impl
  105. } // cppcms
  106. #endif