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.
 
 
 
 
 
 

206 lines
6.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_IMPL_CACHED_SETTINGS
  9. #define CPPCMS_IMPL_CACHED_SETTINGS
  10. #include <cppcms/json.h>
  11. #include <booster/thread.h>
  12. #include <cppcms/http_cookie.h>
  13. #include <booster/log.h>
  14. namespace cppcms {
  15. namespace impl {
  16. struct cached_settings {
  17. struct cached_security {
  18. long long multipart_form_data_limit;
  19. long long content_length_limit;
  20. int file_in_memory_limit;
  21. std::string uploads_path;
  22. bool display_error_message;
  23. std::string email_error_message;
  24. struct cached_csrf {
  25. bool enable;
  26. bool automatic;
  27. bool exposed;
  28. cached_csrf(json::value const &v)
  29. {
  30. enable = v.get("security.csrf.enable",false);
  31. automatic = v.get("security.csrf.automatic",true);
  32. exposed = v.get("security.csrf.exposed",false);
  33. }
  34. } csrf;
  35. cached_security(json::value const &v) :
  36. csrf(v)
  37. {
  38. multipart_form_data_limit = v.get("security.multipart_form_data_limit",64*1024);
  39. content_length_limit = v.get("security.content_length_limit",1024);
  40. file_in_memory_limit = v.get("security.file_in_memory_limit",128*1024);
  41. uploads_path = v.get("security.uploads_path","");
  42. display_error_message = v.get("security.display_error_message",false);
  43. email_error_message = v.get("security.email_error_message","");
  44. }
  45. } security;
  46. struct cached_fastcgi {
  47. int cuncurrency_hint;
  48. cached_fastcgi(json::value const &v)
  49. {
  50. cuncurrency_hint = v.get("fastcgi.cuncurrency_hint",-1);
  51. }
  52. } fastcgi;
  53. struct cached_service {
  54. std::string ip;
  55. int port;
  56. int output_buffer_size;
  57. int input_buffer_size;
  58. int async_output_buffer_size;
  59. bool disable_xpowered_by;
  60. bool disable_xpowered_by_version;
  61. bool generate_http_headers;
  62. int worker_threads;
  63. int worker_processes;
  64. cached_service(json::value const &v)
  65. {
  66. ip = v.get("service.ip","127.0.0.1");
  67. port = v.get("service.port",8080);
  68. output_buffer_size = v.get("service.output_buffer_size",16384);
  69. input_buffer_size = v.get("service.input_buffer_size",65536);
  70. async_output_buffer_size = v.get("service.async_output_buffer_size",1024);
  71. disable_xpowered_by = v.get("service.disable_xpowered_by",false);
  72. disable_xpowered_by_version = v.get("service.disable_xpowered_by_version",false);
  73. unsigned cpus = booster::thread::hardware_concurrency();
  74. if(cpus == 0)
  75. cpus = 1;
  76. worker_threads = v.get("service.worker_threads",5 * cpus);
  77. worker_processes = v.get("service.worker_processes",0);
  78. generate_http_headers = v.get("service.generate_http_headers",false);
  79. }
  80. } service;
  81. struct cached_localization {
  82. bool disable_charset_in_content_type;
  83. cached_localization(json::value const &v) :
  84. disable_charset_in_content_type(v.get("localization.disable_charset_in_content_type",false))
  85. {
  86. }
  87. } localization;
  88. struct cached_gzip {
  89. bool enable;
  90. int level;
  91. int buffer;
  92. cached_gzip(json::value const &v)
  93. {
  94. enable=v.get("gzip.enable",true);
  95. level=v.get("gzip.level",-1);
  96. buffer=v.get("gzip.buffer",-1);
  97. }
  98. } gzip;
  99. struct cached_http {
  100. struct cached_proxy {
  101. bool behind;
  102. std::vector<std::string> remote_addr_cgi_variables;
  103. } proxy;
  104. std::vector<std::string> script_names;
  105. int timeout;
  106. cached_http(json::value const &v)
  107. {
  108. proxy.behind=v.get("http.proxy.behind",false);
  109. std::vector<std::string> default_headers;
  110. default_headers.push_back("X-Forwarded-For");
  111. std::vector<std::string> remote_addr_headers =
  112. v.get("http.proxy.remote_addr_headers",default_headers);
  113. for(size_t i=0;i<remote_addr_headers.size();i++) {
  114. std::string name = "HTTP_" + remote_addr_headers[i];
  115. for(unsigned i=0;i<name.size();i++) {
  116. if(name[i] == '-')
  117. name[i]='_';
  118. else if('a' <= name[i] && name[i] <='z')
  119. name[i]=name[i]-'a' + 'A';
  120. }
  121. proxy.remote_addr_cgi_variables.push_back(name);
  122. }
  123. script_names = v.get("http.script_names",std::vector<std::string>());
  124. std::string script = v.get("http.script","");
  125. /* TODO: need to detect "" vs. missing (nullish) */
  126. //if(!script.empty())
  127. script_names.push_back(script);
  128. timeout = v.get("http.timeout",30);
  129. }
  130. } http;
  131. struct cached_session {
  132. int timeout;
  133. std::string expire;
  134. bool disable_automatic_load;
  135. struct cached_cookies {
  136. std::string prefix;
  137. std::string domain;
  138. std::string path;
  139. int time_shift;
  140. bool use_age;
  141. bool use_exp;
  142. bool secure;
  143. bool remove_unknown_cookies;
  144. } cookies;
  145. cached_session(json::value const &v)
  146. {
  147. timeout = v.get("session.timeout",24*3600);
  148. expire = v.get("session.expire","browser");
  149. disable_automatic_load = v.get("session.disable_automatic_load",false);
  150. cookies.prefix = v.get("session.cookies.prefix","cppcms_session");
  151. cookies.domain = v.get("session.cookies.domain","");
  152. cookies.path = v.get("session.cookies.path","/");
  153. cookies.time_shift = v.get("session.cookies.time_shift",0);
  154. std::string method = v.get("session.cookies.expiration_method","both");
  155. cookies.remove_unknown_cookies = v.get("session.cookies.remove_unknown_cookies",true);
  156. if(method == "both") {
  157. cookies.use_age = cookies.use_exp = true;
  158. }
  159. else if (method == "expires") {
  160. cookies.use_age = false;
  161. cookies.use_exp = true;
  162. }
  163. else if(method == "max-age") {
  164. cookies.use_age = true;
  165. cookies.use_exp = false;
  166. }
  167. else {
  168. BOOSTER_WARNING("cppcms") << "Invalid session.cookies.expiration_method "
  169. "should be one of 'max-age', 'expires' or 'both' assuming default 'both'";
  170. cookies.use_age = cookies.use_exp = true;
  171. }
  172. cookies.secure = v.get("session.cookies.secure",false);
  173. }
  174. } session;
  175. struct cached_misc {
  176. bool invalid_url_throws;
  177. cached_misc(json::value const &v)
  178. {
  179. invalid_url_throws = v.get("misc.invalid_url_throws",false);
  180. }
  181. } misc;
  182. cached_settings(json::value const &v) :
  183. security(v),
  184. fastcgi(v),
  185. service(v),
  186. localization(v),
  187. gzip(v),
  188. http(v),
  189. session(v),
  190. misc(v)
  191. {
  192. }
  193. };
  194. } // impl
  195. } // cppcms
  196. #endif