passenger 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (254) hide show
  1. data/DEVELOPERS.TXT +13 -3
  2. data/Rakefile +42 -33
  3. data/bin/passenger-install-apache2-module +1 -2
  4. data/bin/passenger-install-nginx-module +7 -19
  5. data/bin/passenger-status +64 -15
  6. data/bin/passenger-stress-test +2 -2
  7. data/doc/ApplicationPool algorithm.txt +26 -22
  8. data/doc/Users guide Apache.html +374 -149
  9. data/doc/Users guide Apache.txt +318 -51
  10. data/doc/Users guide Nginx.html +13 -13
  11. data/doc/Users guide Nginx.txt +7 -2
  12. data/doc/cxxapi/Bucket_8h-source.html +62 -25
  13. data/doc/cxxapi/Configuration_8h-source.html +343 -326
  14. data/doc/cxxapi/DirectoryMapper_8h-source.html +12 -12
  15. data/doc/cxxapi/Hooks_8h-source.html +1 -1
  16. data/doc/cxxapi/annotated.html +1 -1
  17. data/doc/cxxapi/classHooks-members.html +1 -1
  18. data/doc/cxxapi/classHooks.html +1 -1
  19. data/doc/cxxapi/classPassenger_1_1DirectoryMapper-members.html +2 -2
  20. data/doc/cxxapi/classPassenger_1_1DirectoryMapper.html +9 -9
  21. data/doc/cxxapi/classes.html +1 -1
  22. data/doc/cxxapi/definitions_8h-source.html +1 -1
  23. data/doc/cxxapi/files.html +1 -1
  24. data/doc/cxxapi/functions.html +2 -2
  25. data/doc/cxxapi/functions_func.html +2 -2
  26. data/doc/cxxapi/graph_legend.html +1 -1
  27. data/doc/cxxapi/group__Configuration.html +1 -1
  28. data/doc/cxxapi/group__Core.html +1 -1
  29. data/doc/cxxapi/group__Hooks.html +1 -1
  30. data/doc/cxxapi/group__Support.html +1 -1
  31. data/doc/cxxapi/main.html +1 -1
  32. data/doc/cxxapi/modules.html +1 -1
  33. data/doc/rdoc/classes/ConditionVariable.html +194 -0
  34. data/doc/rdoc/classes/Exception.html +120 -0
  35. data/doc/rdoc/classes/GC.html +113 -0
  36. data/doc/rdoc/classes/IO.html +169 -0
  37. data/doc/rdoc/classes/PhusionPassenger.html +238 -0
  38. data/doc/rdoc/classes/PhusionPassenger/AbstractInstaller.html +153 -0
  39. data/doc/rdoc/classes/PhusionPassenger/AbstractRequestHandler.html +517 -0
  40. data/doc/rdoc/classes/PhusionPassenger/AbstractServer.html +719 -0
  41. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerAlreadyStarted.html +97 -0
  42. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerError.html +96 -0
  43. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerNotStarted.html +97 -0
  44. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/UnknownMessage.html +96 -0
  45. data/doc/rdoc/classes/PhusionPassenger/AbstractServerCollection.html +598 -0
  46. data/doc/rdoc/classes/PhusionPassenger/AdminTools.html +140 -0
  47. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess.html +317 -0
  48. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess/Instance.html +138 -0
  49. data/doc/rdoc/classes/PhusionPassenger/AppInitError.html +154 -0
  50. data/doc/rdoc/classes/PhusionPassenger/Application.html +283 -0
  51. data/doc/rdoc/classes/PhusionPassenger/ConsoleTextTemplate.html +172 -0
  52. data/doc/rdoc/classes/PhusionPassenger/FrameworkInitError.html +145 -0
  53. data/doc/rdoc/classes/PhusionPassenger/HTMLTemplate.html +175 -0
  54. data/doc/rdoc/classes/PhusionPassenger/InitializationError.html +141 -0
  55. data/doc/rdoc/classes/PhusionPassenger/InvalidPath.html +92 -0
  56. data/doc/rdoc/classes/PhusionPassenger/MessageChannel.html +489 -0
  57. data/doc/rdoc/classes/PhusionPassenger/NativeSupport.html +350 -0
  58. data/doc/rdoc/classes/PhusionPassenger/Rack.html +91 -0
  59. data/doc/rdoc/classes/PhusionPassenger/Rack/ApplicationSpawner.html +188 -0
  60. data/doc/rdoc/classes/PhusionPassenger/Rack/RequestHandler.html +194 -0
  61. data/doc/rdoc/classes/PhusionPassenger/Railz.html +95 -0
  62. data/doc/rdoc/classes/PhusionPassenger/Railz/ApplicationSpawner.html +442 -0
  63. data/doc/rdoc/classes/PhusionPassenger/Railz/ApplicationSpawner/Error.html +98 -0
  64. data/doc/rdoc/classes/PhusionPassenger/Railz/CGIFixed.html +200 -0
  65. data/doc/rdoc/classes/PhusionPassenger/Railz/FrameworkSpawner.html +436 -0
  66. data/doc/rdoc/classes/PhusionPassenger/Railz/FrameworkSpawner/Error.html +98 -0
  67. data/doc/rdoc/classes/PhusionPassenger/Railz/RequestHandler.html +155 -0
  68. data/doc/rdoc/classes/PhusionPassenger/SpawnManager.html +402 -0
  69. data/doc/rdoc/classes/PhusionPassenger/UnknownError.html +125 -0
  70. data/doc/rdoc/classes/PhusionPassenger/Utils.html +805 -0
  71. data/doc/rdoc/classes/PhusionPassenger/VersionNotFound.html +140 -0
  72. data/doc/rdoc/classes/PhusionPassenger/WSGI.html +89 -0
  73. data/doc/rdoc/classes/PhusionPassenger/WSGI/ApplicationSpawner.html +188 -0
  74. data/doc/rdoc/classes/PlatformInfo.html +831 -0
  75. data/doc/rdoc/classes/RakeExtensions.html +197 -0
  76. data/doc/rdoc/classes/Signal.html +131 -0
  77. data/doc/rdoc/created.rid +1 -0
  78. data/doc/rdoc/files/DEVELOPERS_TXT.html +255 -0
  79. data/doc/rdoc/files/README.html +157 -0
  80. data/doc/rdoc/files/ext/phusion_passenger/native_support_c.html +92 -0
  81. data/doc/rdoc/files/lib/phusion_passenger/abstract_installer_rb.html +129 -0
  82. data/doc/rdoc/files/lib/phusion_passenger/abstract_request_handler_rb.html +131 -0
  83. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_collection_rb.html +126 -0
  84. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_rb.html +130 -0
  85. data/doc/rdoc/files/lib/phusion_passenger/admin_tools/control_process_rb.html +130 -0
  86. data/doc/rdoc/files/lib/phusion_passenger/admin_tools_rb.html +122 -0
  87. data/doc/rdoc/files/lib/phusion_passenger/application_rb.html +127 -0
  88. data/doc/rdoc/files/lib/phusion_passenger/console_text_template_rb.html +126 -0
  89. data/doc/rdoc/files/lib/phusion_passenger/constants_rb.html +122 -0
  90. data/doc/rdoc/files/lib/phusion_passenger/dependencies_rb.html +134 -0
  91. data/doc/rdoc/files/lib/phusion_passenger/events_rb.html +122 -0
  92. data/doc/rdoc/files/lib/phusion_passenger/exceptions_rb.html +122 -0
  93. data/doc/rdoc/files/lib/phusion_passenger/html_template_rb.html +126 -0
  94. data/doc/rdoc/files/lib/phusion_passenger/message_channel_rb.html +122 -0
  95. data/doc/rdoc/files/lib/phusion_passenger/packaging_rb.html +122 -0
  96. data/doc/rdoc/files/lib/phusion_passenger/platform_info_rb.html +127 -0
  97. data/doc/rdoc/files/lib/phusion_passenger/rack/application_spawner_rb.html +133 -0
  98. data/doc/rdoc/files/lib/phusion_passenger/rack/request_handler_rb.html +127 -0
  99. data/doc/rdoc/files/lib/phusion_passenger/railz/application_spawner_rb.html +143 -0
  100. data/doc/rdoc/files/lib/phusion_passenger/railz/cgi_fixed_rb.html +126 -0
  101. data/doc/rdoc/files/lib/phusion_passenger/railz/framework_spawner_rb.html +145 -0
  102. data/doc/rdoc/files/lib/phusion_passenger/railz/request_handler_rb.html +127 -0
  103. data/doc/rdoc/files/lib/phusion_passenger/simple_benchmarking_rb.html +122 -0
  104. data/doc/rdoc/files/lib/phusion_passenger/spawn_manager_rb.html +161 -0
  105. data/doc/rdoc/files/lib/phusion_passenger/utils_rb.html +175 -0
  106. data/doc/rdoc/files/lib/phusion_passenger/wsgi/application_spawner_rb.html +129 -0
  107. data/doc/rdoc/files/misc/rake/extensions_rb.html +130 -0
  108. data/doc/rdoc/fr_class_index.html +90 -0
  109. data/doc/rdoc/fr_file_index.html +76 -0
  110. data/doc/rdoc/fr_method_index.html +200 -0
  111. data/doc/rdoc/index.html +26 -0
  112. data/doc/rdoc/rdoc-style.css +187 -0
  113. data/doc/users_guide_snippets/rackup_specifications.txt +2 -8
  114. data/ext/apache2/Bucket.cpp +71 -38
  115. data/ext/apache2/Bucket.h +53 -16
  116. data/ext/apache2/Configuration.cpp +15 -0
  117. data/ext/apache2/Configuration.h +19 -2
  118. data/ext/apache2/DirectoryMapper.h +10 -10
  119. data/ext/apache2/Hooks.cpp +334 -74
  120. data/ext/boost/mpl/apply.hpp +5 -1
  121. data/ext/boost/mpl/apply_wrap.hpp +5 -2
  122. data/ext/boost/mpl/aux_/full_lambda.hpp +5 -1
  123. data/ext/boost/mpl/bind.hpp +5 -1
  124. data/ext/common/Application.h +11 -31
  125. data/ext/common/ApplicationPool.h +2 -1
  126. data/ext/common/ApplicationPoolServer.h +61 -20
  127. data/ext/common/ApplicationPoolServerExecutable.cpp +132 -4
  128. data/ext/common/ApplicationPoolStatusReporter.h +189 -65
  129. data/ext/common/Base64.cpp +143 -0
  130. data/ext/common/Base64.h +57 -0
  131. data/ext/common/CachedFileStat.cpp +25 -82
  132. data/ext/common/CachedFileStat.h +11 -125
  133. data/ext/common/CachedFileStat.hpp +243 -0
  134. data/ext/common/Exceptions.h +13 -0
  135. data/ext/common/FileChangeChecker.h +209 -0
  136. data/ext/common/Logging.h +3 -2
  137. data/ext/common/MessageChannel.h +10 -10
  138. data/ext/common/PoolOptions.h +72 -5
  139. data/ext/common/SpawnManager.h +11 -8
  140. data/ext/common/StandardApplicationPool.h +38 -39
  141. data/ext/common/StaticString.h +1 -0
  142. data/ext/common/StringListCreator.h +83 -0
  143. data/ext/common/SystemTime.h +3 -2
  144. data/ext/common/Timer.h +88 -0
  145. data/ext/common/Utils.cpp +161 -42
  146. data/ext/common/Utils.h +62 -31
  147. data/ext/common/Version.h +1 -1
  148. data/ext/nginx/Configuration.c +0 -4
  149. data/ext/nginx/ContentHandler.c +8 -6
  150. data/ext/nginx/HelperServer.cpp +45 -55
  151. data/ext/nginx/HttpStatusExtractor.h +4 -0
  152. data/ext/nginx/StaticContentHandler.c +25 -5
  153. data/ext/nginx/config +3 -0
  154. data/ext/nginx/ngx_http_passenger_module.c +72 -17
  155. data/ext/nginx/ngx_http_passenger_module.h +2 -2
  156. data/lib/phusion_passenger/abstract_request_handler.rb +15 -7
  157. data/lib/phusion_passenger/abstract_server.rb +16 -2
  158. data/lib/phusion_passenger/admin_tools/control_process.rb +36 -25
  159. data/lib/phusion_passenger/constants.rb +1 -1
  160. data/lib/phusion_passenger/dependencies.rb +10 -0
  161. data/lib/phusion_passenger/platform_info.rb +1 -1
  162. data/lib/phusion_passenger/rack/application_spawner.rb +21 -2
  163. data/lib/phusion_passenger/rack/request_handler.rb +10 -0
  164. data/lib/phusion_passenger/railz/application_spawner.rb +38 -2
  165. data/lib/phusion_passenger/railz/framework_spawner.rb +26 -28
  166. data/lib/phusion_passenger/railz/request_handler.rb +5 -1
  167. data/lib/phusion_passenger/spawn_manager.rb +6 -2
  168. data/lib/phusion_passenger/utils.rb +79 -27
  169. data/misc/rake/cplusplus.rb +5 -5
  170. data/test/ApplicationPoolServerTest.cpp +42 -0
  171. data/test/ApplicationPoolTest.cpp +255 -267
  172. data/test/Base64Test.cpp +48 -0
  173. data/test/CachedFileStatTest.cpp +243 -103
  174. data/test/FileChangeCheckerTest.cpp +331 -0
  175. data/test/PoolOptionsTest.cpp +80 -0
  176. data/test/UtilsTest.cpp +5 -17
  177. data/test/integration_tests/apache2_tests.rb +15 -4
  178. data/test/integration_tests/mycook_spec.rb +3 -4
  179. data/test/oxt/syscall_interruption_test.cpp +2 -14
  180. data/test/ruby/abstract_server_collection_spec.rb +1 -1
  181. data/test/ruby/abstract_server_spec.rb +35 -1
  182. data/test/ruby/rack/application_spawner_spec.rb +23 -6
  183. data/test/ruby/rails/application_spawner_spec.rb +6 -6
  184. data/test/ruby/rails/framework_spawner_spec.rb +6 -5
  185. data/test/ruby/rails/minimal_spawner_spec.rb +19 -0
  186. data/test/ruby/rails/spawner_error_handling_spec.rb +62 -7
  187. data/test/ruby/spawn_manager_spec.rb +10 -7
  188. data/test/ruby/spawn_server_spec.rb +1 -1
  189. data/test/ruby/utils_spec.rb +193 -20
  190. data/test/ruby/wsgi/application_spawner_spec.rb +3 -1
  191. data/test/stub/apache2/httpd.conf.erb +3 -0
  192. data/test/stub/rack/config.ru +1 -1
  193. data/test/stub/rails_apps/mycook/app/controllers/welcome_controller.rb +8 -0
  194. data/test/support/Support.cpp +84 -0
  195. data/test/support/Support.h +66 -8
  196. data/test/support/config.rb +14 -2
  197. data/test/support/test_helper.rb +5 -0
  198. data/vendor/rack-1.0.0-git/lib/rack/auth/openid.rb +123 -116
  199. data/vendor/rack-1.0.0-git/lib/rack/cascade.rb +17 -12
  200. data/vendor/rack-1.0.0-git/lib/rack/commonlogger.rb +34 -43
  201. data/vendor/rack-1.0.0-git/lib/rack/handler/cgi.rb +1 -1
  202. data/vendor/rack-1.0.0-git/lib/rack/handler/fastcgi.rb +1 -1
  203. data/vendor/rack-1.0.0-git/lib/rack/handler/lsws.rb +1 -1
  204. data/vendor/rack-1.0.0-git/lib/rack/handler/mongrel.rb +1 -1
  205. data/vendor/rack-1.0.0-git/lib/rack/handler/scgi.rb +1 -1
  206. data/vendor/rack-1.0.0-git/lib/rack/handler/webrick.rb +1 -1
  207. data/vendor/rack-1.0.0-git/lib/rack/mock.rb +4 -17
  208. data/vendor/rack-1.0.0-git/lib/rack/request.rb +3 -9
  209. data/vendor/rack-1.0.0-git/lib/rack/rewindable_input.rb +2 -0
  210. data/vendor/rack-1.0.0-git/lib/rack/utils.rb +38 -12
  211. metadata +231 -186
  212. data/ext/common/FileChecker.h +0 -112
  213. data/test/FileCheckerTest.cpp +0 -79
  214. data/test/stub/minimal-railsapp/README +0 -3
  215. data/test/stub/minimal-railsapp/config/application.rb +0 -0
  216. data/test/stub/minimal-railsapp/config/environment.rb +0 -3
  217. data/test/stub/minimal-railsapp/vendor/rails/actionmailer/lib/action_mailer.rb +0 -0
  218. data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_controller.rb +0 -10
  219. data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_pack.rb +0 -0
  220. data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_view.rb +0 -0
  221. data/test/stub/minimal-railsapp/vendor/rails/activerecord/lib/active_record.rb +0 -7
  222. data/test/stub/minimal-railsapp/vendor/rails/activeresource/lib/active_resource.rb +0 -0
  223. data/test/stub/minimal-railsapp/vendor/rails/activesupport/lib/active_support.rb +0 -17
  224. data/test/stub/minimal-railsapp/vendor/rails/activesupport/lib/active_support/whiny_nil.rb +0 -0
  225. data/test/stub/minimal-railsapp/vendor/rails/railties/lib/dispatcher.rb +0 -0
  226. data/test/stub/minimal-railsapp/vendor/rails/railties/lib/initializer.rb +0 -8
  227. data/test/stub/minimal-railsapp/vendor/rails/railties/lib/ruby_version_check.rb +0 -1
  228. data/test/stub/railsapp/app/controllers/application.rb +0 -12
  229. data/test/stub/railsapp/app/controllers/bar_controller.rb +0 -5
  230. data/test/stub/railsapp/app/controllers/bar_controller_1.txt +0 -5
  231. data/test/stub/railsapp/app/controllers/bar_controller_2.txt +0 -5
  232. data/test/stub/railsapp/app/controllers/foo_controller.rb +0 -9
  233. data/test/stub/railsapp/app/helpers/application_helper.rb +0 -3
  234. data/test/stub/railsapp/config/boot.rb +0 -108
  235. data/test/stub/railsapp/config/database.yml +0 -19
  236. data/test/stub/railsapp/config/environment.rb +0 -59
  237. data/test/stub/railsapp/config/environments/development.rb +0 -18
  238. data/test/stub/railsapp/config/environments/production.rb +0 -19
  239. data/test/stub/railsapp/config/initializers/inflections.rb +0 -10
  240. data/test/stub/railsapp/config/initializers/mime_types.rb +0 -5
  241. data/test/stub/railsapp/config/routes.rb +0 -35
  242. data/test/stub/railsapp/public/useless.txt +0 -1
  243. data/test/stub/railsapp2/app/controllers/application.rb +0 -12
  244. data/test/stub/railsapp2/app/controllers/foo_controller.rb +0 -5
  245. data/test/stub/railsapp2/app/helpers/application_helper.rb +0 -3
  246. data/test/stub/railsapp2/config/boot.rb +0 -108
  247. data/test/stub/railsapp2/config/database.yml +0 -19
  248. data/test/stub/railsapp2/config/environment.rb +0 -59
  249. data/test/stub/railsapp2/config/environments/development.rb +0 -18
  250. data/test/stub/railsapp2/config/environments/production.rb +0 -19
  251. data/test/stub/railsapp2/config/initializers/inflections.rb +0 -10
  252. data/test/stub/railsapp2/config/initializers/mime_types.rb +0 -5
  253. data/test/stub/railsapp2/config/routes.rb +0 -35
  254. data/test/stub/railsapp2/public/useless.txt +0 -1
@@ -0,0 +1,143 @@
1
+ /*
2
+ * Base64 encoding and decoding routines
3
+ *
4
+ * Copyright (C) 2004-2008 René Nyffenegger
5
+ * Modified by Phusion for inclusion in Phusion Passenger.
6
+ *
7
+ * This source code is provided 'as-is', without any express or implied
8
+ * warranty. In no event will the author be held liable for any damages
9
+ * arising from the use of this software.
10
+ *
11
+ * Permission is granted to anyone to use this software for any purpose,
12
+ * including commercial applications, and to alter it and redistribute it
13
+ * freely, subject to the following restrictions:
14
+ *
15
+ * 1. The origin of this source code must not be misrepresented; you must not
16
+ * claim that you wrote the original source code. If you use this source code
17
+ * in a product, an acknowledgment in the product documentation would be
18
+ * appreciated but is not required.
19
+ *
20
+ * 2. Altered source versions must be plainly marked as such, and must not be
21
+ * misrepresented as being the original source code.
22
+ *
23
+ * 3. This notice may not be removed or altered from any source distribution.
24
+ *
25
+ * René Nyffenegger rene.nyffenegger@adp-gmbh.ch
26
+ *
27
+ */
28
+
29
+ #include <ctype.h>
30
+ #include "Base64.h"
31
+
32
+ namespace Passenger {
33
+
34
+ static const std::string base64_chars =
35
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
36
+ "abcdefghijklmnopqrstuvwxyz"
37
+ "0123456789+/";
38
+
39
+
40
+ static inline bool
41
+ is_base64(unsigned char c) {
42
+ return isalnum(c) || c == '+' || c == '/';
43
+ }
44
+
45
+ string
46
+ Base64::encode(const unsigned char *bytes_to_encode, unsigned int in_len) {
47
+ std::string ret;
48
+ int i = 0;
49
+ int j = 0;
50
+ unsigned char char_array_3[3];
51
+ unsigned char char_array_4[4];
52
+
53
+ // According to Wikipedia, base64-encoded data is usually 137%
54
+ // + 814 bytes larger than the original. Here we reserve a little
55
+ // more than that to avoid memory reallocations.
56
+ ret.reserve((std::string::size_type) (in_len * 1.37) + 1024);
57
+
58
+ while (in_len--) {
59
+ char_array_3[i++] = *(bytes_to_encode++);
60
+ if (i == 3) {
61
+ char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
62
+ char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
63
+ char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
64
+ char_array_4[3] = char_array_3[2] & 0x3f;
65
+
66
+ for(i = 0; i < 4; i++) {
67
+ ret += base64_chars[char_array_4[i]];
68
+ }
69
+ i = 0;
70
+ }
71
+ }
72
+
73
+ if (i) {
74
+ for(j = i; j < 3; j++)
75
+ char_array_3[j] = '\0';
76
+
77
+ char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
78
+ char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
79
+ char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
80
+ char_array_4[3] = char_array_3[2] & 0x3f;
81
+
82
+ for (j = 0; (j < i + 1); j++)
83
+ ret += base64_chars[char_array_4[j]];
84
+
85
+ while((i++ < 3))
86
+ ret += '=';
87
+ }
88
+
89
+ return ret;
90
+ }
91
+
92
+ std::string
93
+ Base64::decode(const unsigned char *base64_data, unsigned int in_len) {
94
+ int i = 0;
95
+ int j = 0;
96
+ int in_ = 0;
97
+ unsigned char char_array_4[4], char_array_3[3];
98
+ std::string ret;
99
+ unsigned int reserved_size;
100
+
101
+ // The decoded data should be about this large.
102
+ if (in_len > 814) {
103
+ reserved_size = (unsigned int) ((in_len - 814) / 137.0) * 100;
104
+ } else {
105
+ reserved_size = in_len;
106
+ }
107
+ ret.reserve(reserved_size);
108
+
109
+ while (in_len-- && ( base64_data[in_] != '=') && is_base64(base64_data[in_])) {
110
+ char_array_4[i++] = base64_data[in_]; in_++;
111
+ if (i == 4) {
112
+ for (i = 0; i <4; i++)
113
+ char_array_4[i] = base64_chars.find(char_array_4[i]);
114
+
115
+ char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
116
+ char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
117
+ char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
118
+
119
+ for (i = 0; i < 3; i++)
120
+ ret += char_array_3[i];
121
+ i = 0;
122
+ }
123
+ }
124
+
125
+ if (i) {
126
+ for (j = i; j <4; j++)
127
+ char_array_4[j] = 0;
128
+
129
+ for (j = 0; j <4; j++)
130
+ char_array_4[j] = base64_chars.find(char_array_4[j]);
131
+
132
+ char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
133
+ char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
134
+ char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
135
+
136
+ for (j = 0; (j < i - 1); j++)
137
+ ret += char_array_3[j];
138
+ }
139
+
140
+ return ret;
141
+ }
142
+
143
+ } // namespace Passenger
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Base64 encoding and decoding routines
3
+ *
4
+ * Copyright (C) 2004-2008 René Nyffenegger
5
+ * Modified by Phusion for inclusion in Phusion Passenger.
6
+ *
7
+ * This source code is provided 'as-is', without any express or implied
8
+ * warranty. In no event will the author be held liable for any damages
9
+ * arising from the use of this software.
10
+ *
11
+ * Permission is granted to anyone to use this software for any purpose,
12
+ * including commercial applications, and to alter it and redistribute it
13
+ * freely, subject to the following restrictions:
14
+ *
15
+ * 1. The origin of this source code must not be misrepresented; you must not
16
+ * claim that you wrote the original source code. If you use this source code
17
+ * in a product, an acknowledgment in the product documentation would be
18
+ * appreciated but is not required.
19
+ *
20
+ * 2. Altered source versions must be plainly marked as such, and must not be
21
+ * misrepresented as being the original source code.
22
+ *
23
+ * 3. This notice may not be removed or altered from any source distribution.
24
+ *
25
+ * René Nyffenegger rene.nyffenegger@adp-gmbh.ch
26
+ *
27
+ */
28
+
29
+ #ifndef _PASSENGER_BASE64_H_
30
+ #define _PASSENGER_BASE64_H_
31
+
32
+ #include <iostream>
33
+ #include <string>
34
+ #include "StaticString.h"
35
+
36
+ namespace Passenger {
37
+
38
+ using namespace std;
39
+
40
+ class Base64 {
41
+ public:
42
+ static string encode(const StaticString &data) {
43
+ return encode((const unsigned char *) data.data(), data.size());
44
+ }
45
+
46
+ static string decode(const StaticString &base64_data) {
47
+ return decode((const unsigned char *) base64_data.data(), base64_data.size());
48
+ }
49
+
50
+ static string encode(const unsigned char *data, unsigned int len);
51
+
52
+ static string decode(const unsigned char *base64_data, unsigned int len);
53
+ };
54
+
55
+ } // namespace Passenger
56
+
57
+ #endif /* _PASSENGER_BASE64_H_ */
@@ -23,97 +23,40 @@
23
23
  * THE SOFTWARE.
24
24
  */
25
25
  #include "CachedFileStat.h"
26
+ #include "CachedFileStat.hpp"
26
27
 
27
- #include <map>
28
- #include <list>
28
+ extern "C" {
29
29
 
30
- #include <boost/shared_ptr.hpp>
31
- #include <boost/thread.hpp>
32
-
33
- using namespace std;
34
- using namespace boost;
35
- using namespace Passenger;
36
-
37
- // CachedMultiFileStat is written in C++, with a C wrapper API around it.
38
- // I'm not going to reinvent my own linked list and hash table in C when I
39
- // can just use the STL.
40
- struct CachedMultiFileStat {
41
- struct Item {
42
- string filename;
43
- CachedFileStat cstat;
44
-
45
- Item(const string &filename)
46
- : cstat(filename)
47
- {
48
- this->filename = filename;
49
- }
50
- };
51
-
52
- typedef shared_ptr<Item> ItemPtr;
53
- typedef list<ItemPtr> ItemList;
54
- typedef map<string, ItemList::iterator> ItemMap;
30
+ struct CachedFileStat {
31
+ Passenger::CachedFileStat cfs;
55
32
 
56
- unsigned int maxSize;
57
- ItemList items;
58
- ItemMap cache;
59
- boost::mutex lock;
60
-
61
- CachedMultiFileStat(unsigned int maxSize) {
62
- this->maxSize = maxSize;
63
- }
64
-
65
- int stat(const string &filename, struct stat *buf, unsigned int throttleRate = 0) {
66
- boost::unique_lock<boost::mutex> l(lock);
67
- ItemMap::iterator it(cache.find(filename));
68
- ItemPtr item;
69
- int ret;
70
-
71
- if (it == cache.end()) {
72
- // Filename not in cache.
73
- // If cache is full, remove the least recently used
74
- // cache entry.
75
- if (cache.size() == maxSize) {
76
- ItemList::iterator listEnd(items.end());
77
- listEnd--;
78
- string filename((*listEnd)->filename);
79
- items.pop_back();
80
- cache.erase(filename);
81
- }
82
-
83
- // Add to cache as most recently used.
84
- item = ItemPtr(new Item(filename));
85
- items.push_front(item);
86
- cache[filename] = items.begin();
87
- } else {
88
- // Cache hit.
89
- item = *it->second;
90
-
91
- // Mark this cache item as most recently used.
92
- items.erase(it->second);
93
- items.push_front(item);
94
- cache[filename] = items.begin();
95
- }
96
- ret = item->cstat.refresh(throttleRate);
97
- *buf = item->cstat.info;
98
- return ret;
99
- }
33
+ CachedFileStat(unsigned int maxSize): cfs(maxSize) { }
100
34
  };
101
35
 
102
- CachedMultiFileStat *
103
- cached_multi_file_stat_new(unsigned int max_size) {
104
- return new CachedMultiFileStat(max_size);
36
+ CachedFileStat *
37
+ cached_file_stat_new(unsigned int max_size) {
38
+ return new CachedFileStat(max_size);
105
39
  }
106
40
 
107
41
  void
108
- cached_multi_file_stat_free(CachedMultiFileStat *mstat) {
109
- delete mstat;
42
+ cached_file_stat_free(CachedFileStat *cstat) {
43
+ delete cstat;
110
44
  }
111
45
 
112
46
  int
113
- cached_multi_file_stat_perform(CachedMultiFileStat *mstat,
114
- const char *filename,
115
- struct stat *buf,
116
- unsigned int throttle_rate)
117
- {
118
- return mstat->stat(filename, buf, throttle_rate);
47
+ cached_file_stat_perform(CachedFileStat *cstat,
48
+ const char *filename,
49
+ struct stat *buf,
50
+ unsigned int throttle_rate) {
51
+ try {
52
+ return cstat->cfs.stat(filename, buf, throttle_rate);
53
+ } catch (const Passenger::TimeRetrievalException &e) {
54
+ errno = e.code();
55
+ return -1;
56
+ } catch (const boost::thread_interrupted &) {
57
+ errno = EINTR;
58
+ return -1;
59
+ }
119
60
  }
61
+
62
+ } // extern "C"
@@ -25,141 +25,27 @@
25
25
  #ifndef _PASSENGER_CACHED_FILE_STAT_H_
26
26
  #define _PASSENGER_CACHED_FILE_STAT_H_
27
27
 
28
- #include <sys/types.h>
29
28
  #include <sys/stat.h>
30
- #include <unistd.h>
31
- #include <time.h>
32
29
 
33
30
  #ifdef __cplusplus
31
+ extern "C" {
32
+ #endif
34
33
 
35
- #include <errno.h>
36
- #include <string>
37
- #include <oxt/system_calls.hpp>
38
-
39
- #include "SystemTime.h"
40
-
41
- namespace Passenger {
42
-
43
- using namespace std;
44
- using namespace oxt;
45
-
46
- /**
47
- * CachedFileStat allows one to stat() a file at a throttled rate, in order
48
- * to minimize stress on the filesystem. It does this by caching the old stat
49
- * data for a specified amount of time.
50
- */
51
- class CachedFileStat {
52
- private:
53
- /** The last return value of stat(). */
54
- int last_result;
55
-
56
- /** The errno set by the last stat() call. */
57
- int last_errno;
58
-
59
- /** The filename of the file to stat. */
60
- string filename;
61
-
62
- /** The last time a stat() was performed. */
63
- time_t last_time;
64
-
65
- /**
66
- * Checks whether <em>interval</em> seconds have elapsed since <em>begin</em>
67
- * The current time is returned via the <tt>currentTime</tt> argument,
68
- * so that the caller doesn't have to call time() again if it needs the current
69
- * time.
70
- *
71
- * @pre begin <= time(NULL)
72
- * @return Whether <tt>interval</tt> seconds have elapsed since <tt>begin</tt>.
73
- * @throws SystemException Something went wrong while retrieving the time.
74
- * @throws boost::thread_interrupted
75
- */
76
- bool expired(time_t begin, unsigned int interval, time_t &currentTime) {
77
- currentTime = SystemTime::get();
78
- return (unsigned int) (currentTime - begin) >= interval;
79
- }
80
-
81
- public:
82
- /** The cached stat info. */
83
- struct stat info;
84
-
85
- /**
86
- * Creates a new CachedFileStat object. The file will not be
87
- * stat()ted until you call refresh().
88
- *
89
- * @param filename The file to stat.
90
- */
91
- CachedFileStat(const string &filename) {
92
- memset(&info, 0, sizeof(struct stat));
93
- last_result = -1;
94
- last_errno = 0;
95
- this->filename = filename;
96
- last_time = 0;
97
- }
98
-
99
- /**
100
- * Re-stat() the file, if necessary. If <tt>throttleRate</tt> seconds have
101
- * passed since the last time stat() was called, then the file will be
102
- * re-stat()ted.
103
- *
104
- * The stat information, which may either be the result of a new stat() call
105
- * or just the old cached information, is be available in the <tt>info</tt>
106
- * member.
107
- *
108
- * @return 0 if the stat() call succeeded or if no stat() was performed,
109
- * -1 if something went wrong while statting the file. In the latter
110
- * case, <tt>errno</tt> will be populated with an appropriate error code.
111
- * @throws SystemException Something went wrong while retrieving the
112
- * system time. stat() errors will <em>not</em> result in SystemException
113
- * being thrown.
114
- * @throws boost::thread_interrupted
115
- */
116
- int refresh(unsigned int throttleRate) {
117
- time_t currentTime;
118
-
119
- if (expired(last_time, throttleRate, currentTime)) {
120
- last_result = syscalls::stat(filename.c_str(), &info);
121
- last_errno = errno;
122
- last_time = currentTime;
123
- return last_result;
124
- } else {
125
- errno = last_errno;
126
- return last_result;
127
- }
128
- }
129
- };
130
34
 
131
- } // namespace Passenger
35
+ /** C bindings for Passenger::CachedFileStat. */
132
36
 
133
- #endif /* __cplusplus */
37
+ typedef struct CachedFileStat CachedFileStat;
134
38
 
39
+ CachedFileStat *cached_file_stat_new(unsigned int max_size);
40
+ void cached_file_stat_free(CachedFileStat *cstat);
41
+ int cached_file_stat_perform(CachedFileStat *cstat,
42
+ const char *filename,
43
+ struct stat *buf,
44
+ unsigned int throttle_rate);
135
45
 
136
- #ifdef __cplusplus
137
- extern "C" {
138
- #endif
139
-
140
- /**
141
- * CachedMultiFileStat allows one to stat() files at a throttled rate, in order
142
- * to minimize stress on the filesystem. It does this by caching the old stat
143
- * data for a specified amount of time.
144
- *
145
- * Unlike CachedFileStat, which can only stat() one specific file per
146
- * CachedFileStat object, CachedMultiFileStat can stat() any file. The
147
- * number of cached stat() information is limited by the given cache size.
148
- *
149
- * This class is fully thread-safe.
150
- */
151
- typedef struct CachedMultiFileStat CachedMultiFileStat;
152
-
153
- CachedMultiFileStat *cached_multi_file_stat_new(unsigned int max_size);
154
- void cached_multi_file_stat_free(CachedMultiFileStat *mstat);
155
- int cached_multi_file_stat_perform(CachedMultiFileStat *mstat,
156
- const char *filename,
157
- struct stat *buf,
158
- unsigned int throttle_rate);
159
46
 
160
47
  #ifdef __cplusplus
161
- }
48
+ }
162
49
  #endif
163
50
 
164
51
  #endif /* _PASSENGER_CACHED_FILE_STAT_H_ */
165
-