passenger 3.0.7 → 3.0.8

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 (439) hide show
  1. data/NEWS +27 -0
  2. data/README +1 -1
  3. data/bin/passenger-install-nginx-module +3 -1
  4. data/build/config.rb +2 -1
  5. data/build/cxx_tests.rb +7 -3
  6. data/build/documentation.rb +5 -40
  7. data/build/nginx.rb +0 -1
  8. data/build/packaging.rb +0 -6
  9. data/build/rake_extensions.rb +5 -0
  10. data/doc/Architectural overview.html +344 -77
  11. data/doc/Security of user switching support.html +338 -71
  12. data/doc/Users guide Apache with comments.html +4830 -0
  13. data/doc/Users guide Apache.html +695 -428
  14. data/doc/Users guide Apache.idmap.txt +80 -0
  15. data/doc/Users guide Apache.txt +5 -5
  16. data/doc/Users guide Nginx.html +591 -313
  17. data/doc/Users guide Nginx.txt +9 -3
  18. data/doc/Users guide Standalone.html +344 -77
  19. data/ext/boost/src/pthread/thread.cpp +1 -1
  20. data/ext/common/AccountsDatabase.h +1 -1
  21. data/ext/common/Constants.h +2 -2
  22. data/ext/common/Logging.h +2 -1
  23. data/ext/common/LoggingAgent/FilterSupport.h +107 -3
  24. data/ext/common/Session.h +1 -1
  25. data/ext/common/Utils.cpp +2 -0
  26. data/ext/common/Utils/Dechunker.h +232 -0
  27. data/ext/common/Utils/HttpHeaderBufferer.h +165 -0
  28. data/ext/common/Utils/StrIntUtils.cpp +51 -15
  29. data/ext/common/Utils/StrIntUtils.h +3 -0
  30. data/ext/common/Utils/StreamBoyerMooreHorspool.h +506 -0
  31. data/ext/nginx/Configuration.c +36 -282
  32. data/ext/nginx/ContentHandler.c +17 -0
  33. data/ext/nginx/HelperAgent.cpp +397 -39
  34. data/ext/oxt/tracable_exception.cpp +3 -1
  35. data/ext/ruby/extconf.rb +1 -0
  36. data/ext/ruby/passenger_native_support.c +3 -0
  37. data/helper-scripts/prespawn +113 -31
  38. data/lib/phusion_passenger.rb +2 -2
  39. data/lib/phusion_passenger/standalone/runtime_installer.rb +3 -2
  40. data/lib/phusion_passenger/standalone/start_command.rb +12 -12
  41. data/test/cxx/DechunkerTest.cpp +216 -0
  42. data/test/cxx/FilterSupportTest.cpp +31 -4
  43. data/test/cxx/HttpHeaderBuffererTest.cpp +203 -0
  44. data/test/cxx/UtilsTest.cpp +46 -3
  45. data/test/integration_tests/hello_world_rack_spec.rb +7 -0
  46. data/test/stub/rack/config.ru +6 -1
  47. data/test/stub/rails_apps/1.2/empty/public/dispatch.cgi +1 -1
  48. data/test/stub/rails_apps/1.2/empty/public/dispatch.fcgi +1 -1
  49. data/test/stub/rails_apps/1.2/empty/public/dispatch.rb +1 -1
  50. data/test/stub/rails_apps/2.0/empty/public/dispatch.cgi +1 -1
  51. data/test/stub/rails_apps/2.0/empty/public/dispatch.fcgi +1 -1
  52. data/test/stub/rails_apps/2.0/empty/public/dispatch.rb +1 -1
  53. data/test/stub/rails_apps/2.2/empty/public/dispatch.cgi +1 -1
  54. data/test/stub/rails_apps/2.2/empty/public/dispatch.fcgi +1 -1
  55. data/test/stub/rails_apps/2.2/empty/public/dispatch.rb +1 -1
  56. metadata +20 -403
  57. data/doc/Doxyfile +0 -241
  58. data/doc/cxxapi/AbstractSpawnManager_8h_source.html +0 -141
  59. data/doc/cxxapi/Account_8h_source.html +0 -206
  60. data/doc/cxxapi/AccountsDatabase_8h_source.html +0 -161
  61. data/doc/cxxapi/AgentBase_8h_source.html +0 -70
  62. data/doc/cxxapi/AgentsStarter_8h_source.html +0 -112
  63. data/doc/cxxapi/BCrypt_8h_source.html +0 -104
  64. data/doc/cxxapi/Blowfish_8h_source.html +0 -134
  65. data/doc/cxxapi/Bucket_8h_source.html +0 -118
  66. data/doc/cxxapi/Constants_8h_source.html +0 -79
  67. data/doc/cxxapi/ContentHandler_8h_source.html +0 -95
  68. data/doc/cxxapi/DirectoryMapper_8h_source.html +0 -311
  69. data/doc/cxxapi/EventedClient_8h_source.html +0 -733
  70. data/doc/cxxapi/EventedMessageServer_8h_source.html +0 -358
  71. data/doc/cxxapi/EventedServer_8h_source.html +0 -326
  72. data/doc/cxxapi/Exceptions_8h_source.html +0 -393
  73. data/doc/cxxapi/FileDescriptor_8h_source.html +0 -324
  74. data/doc/cxxapi/Hooks_8h_source.html +0 -76
  75. data/doc/cxxapi/HttpStatusExtractor_8h_source.html +0 -382
  76. data/doc/cxxapi/IniFile_8h_source.html +0 -527
  77. data/doc/cxxapi/Logging_8h_source.html +0 -796
  78. data/doc/cxxapi/MessageChannel_8h_source.html +0 -776
  79. data/doc/cxxapi/MessageClient_8h_source.html +0 -328
  80. data/doc/cxxapi/MessageReadersWriters_8h_source.html +0 -539
  81. data/doc/cxxapi/MessageServer_8h_source.html +0 -612
  82. data/doc/cxxapi/PoolOptions_8h_source.html +0 -549
  83. data/doc/cxxapi/Process_8h_source.html +0 -286
  84. data/doc/cxxapi/RandomGenerator_8h_source.html +0 -191
  85. data/doc/cxxapi/ResourceLocator_8h_source.html +0 -166
  86. data/doc/cxxapi/SafeLibev_8h_source.html +0 -180
  87. data/doc/cxxapi/ScgiRequestParser_8h_source.html +0 -406
  88. data/doc/cxxapi/ServerInstanceDir_8h_source.html +0 -378
  89. data/doc/cxxapi/Session_8h_source.html +0 -501
  90. data/doc/cxxapi/SpawnManager_8h_source.html +0 -647
  91. data/doc/cxxapi/StaticContentHandler_8h_source.html +0 -69
  92. data/doc/cxxapi/StaticString_8h_source.html +0 -329
  93. data/doc/cxxapi/StringListCreator_8h_source.html +0 -114
  94. data/doc/cxxapi/Utils_8h_source.html +0 -469
  95. data/doc/cxxapi/annotated.html +0 -87
  96. data/doc/cxxapi/apache2_2Configuration_8h_source.html +0 -82
  97. data/doc/cxxapi/classAgentWatcher-members.html +0 -54
  98. data/doc/cxxapi/classAgentWatcher.html +0 -419
  99. data/doc/cxxapi/classClient-members.html +0 -38
  100. data/doc/cxxapi/classClient.html +0 -123
  101. data/doc/cxxapi/classHooks-members.html +0 -40
  102. data/doc/cxxapi/classHooks.html +0 -153
  103. data/doc/cxxapi/classPassenger_1_1AbstractSpawnManager-members.html +0 -40
  104. data/doc/cxxapi/classPassenger_1_1AbstractSpawnManager.html +0 -187
  105. data/doc/cxxapi/classPassenger_1_1AbstractSpawnManager__inherit__graph.map +0 -3
  106. data/doc/cxxapi/classPassenger_1_1AbstractSpawnManager__inherit__graph.md5 +0 -1
  107. data/doc/cxxapi/classPassenger_1_1AbstractSpawnManager__inherit__graph.png +0 -0
  108. data/doc/cxxapi/classPassenger_1_1ArgumentException-members.html +0 -36
  109. data/doc/cxxapi/classPassenger_1_1ArgumentException.html +0 -56
  110. data/doc/cxxapi/classPassenger_1_1ArrayMessage-members.html +0 -37
  111. data/doc/cxxapi/classPassenger_1_1ArrayMessage.html +0 -113
  112. data/doc/cxxapi/classPassenger_1_1BufferedUpload-members.html +0 -38
  113. data/doc/cxxapi/classPassenger_1_1BufferedUpload.html +0 -112
  114. data/doc/cxxapi/classPassenger_1_1BusyException-members.html +0 -36
  115. data/doc/cxxapi/classPassenger_1_1BusyException.html +0 -54
  116. data/doc/cxxapi/classPassenger_1_1ConfigurationException-members.html +0 -36
  117. data/doc/cxxapi/classPassenger_1_1ConfigurationException.html +0 -51
  118. data/doc/cxxapi/classPassenger_1_1DirectoryMapper-members.html +0 -41
  119. data/doc/cxxapi/classPassenger_1_1DirectoryMapper.html +0 -223
  120. data/doc/cxxapi/classPassenger_1_1EOFException-members.html +0 -36
  121. data/doc/cxxapi/classPassenger_1_1EOFException.html +0 -61
  122. data/doc/cxxapi/classPassenger_1_1EOFException__inherit__graph.map +0 -3
  123. data/doc/cxxapi/classPassenger_1_1EOFException__inherit__graph.md5 +0 -1
  124. data/doc/cxxapi/classPassenger_1_1EOFException__inherit__graph.png +0 -0
  125. data/doc/cxxapi/classPassenger_1_1EventFd-members.html +0 -36
  126. data/doc/cxxapi/classPassenger_1_1EventFd.html +0 -52
  127. data/doc/cxxapi/classPassenger_1_1EventedClient-members.html +0 -59
  128. data/doc/cxxapi/classPassenger_1_1EventedClient.html +0 -531
  129. data/doc/cxxapi/classPassenger_1_1EventedMessageServer-members.html +0 -37
  130. data/doc/cxxapi/classPassenger_1_1EventedMessageServer.html +0 -59
  131. data/doc/cxxapi/classPassenger_1_1EventedMessageServer__inherit__graph.map +0 -3
  132. data/doc/cxxapi/classPassenger_1_1EventedMessageServer__inherit__graph.md5 +0 -1
  133. data/doc/cxxapi/classPassenger_1_1EventedMessageServer__inherit__graph.png +0 -0
  134. data/doc/cxxapi/classPassenger_1_1EventedServer-members.html +0 -37
  135. data/doc/cxxapi/classPassenger_1_1EventedServer.html +0 -93
  136. data/doc/cxxapi/classPassenger_1_1EventedServer__inherit__graph.map +0 -3
  137. data/doc/cxxapi/classPassenger_1_1EventedServer__inherit__graph.md5 +0 -1
  138. data/doc/cxxapi/classPassenger_1_1EventedServer__inherit__graph.png +0 -0
  139. data/doc/cxxapi/classPassenger_1_1FileDescriptor-members.html +0 -41
  140. data/doc/cxxapi/classPassenger_1_1FileDescriptor.html +0 -178
  141. data/doc/cxxapi/classPassenger_1_1FileDescriptorPair-members.html +0 -36
  142. data/doc/cxxapi/classPassenger_1_1FileDescriptorPair.html +0 -52
  143. data/doc/cxxapi/classPassenger_1_1FileNotFoundException-members.html +0 -36
  144. data/doc/cxxapi/classPassenger_1_1FileNotFoundException.html +0 -58
  145. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.map +0 -3
  146. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.md5 +0 -1
  147. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.png +0 -0
  148. data/doc/cxxapi/classPassenger_1_1FileSystemException-members.html +0 -41
  149. data/doc/cxxapi/classPassenger_1_1FileSystemException.html +0 -66
  150. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.map +0 -3
  151. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.md5 +0 -1
  152. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.png +0 -0
  153. data/doc/cxxapi/classPassenger_1_1HttpStatusExtractor-members.html +0 -39
  154. data/doc/cxxapi/classPassenger_1_1HttpStatusExtractor.html +0 -128
  155. data/doc/cxxapi/classPassenger_1_1IOException-members.html +0 -36
  156. data/doc/cxxapi/classPassenger_1_1IOException.html +0 -61
  157. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.map +0 -4
  158. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.md5 +0 -1
  159. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.png +0 -0
  160. data/doc/cxxapi/classPassenger_1_1MessageChannel-members.html +0 -57
  161. data/doc/cxxapi/classPassenger_1_1MessageChannel.html +0 -839
  162. data/doc/cxxapi/classPassenger_1_1MessageServer-members.html +0 -49
  163. data/doc/cxxapi/classPassenger_1_1MessageServer.html +0 -407
  164. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1ClientContext-members.html +0 -36
  165. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1ClientContext.html +0 -58
  166. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1ClientContext__inherit__graph.map +0 -3
  167. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1ClientContext__inherit__graph.md5 +0 -1
  168. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1ClientContext__inherit__graph.png +0 -0
  169. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1CommonClientContext-members.html +0 -41
  170. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1CommonClientContext.html +0 -165
  171. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1CommonClientContext__inherit__graph.map +0 -3
  172. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1CommonClientContext__inherit__graph.md5 +0 -1
  173. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1CommonClientContext__inherit__graph.png +0 -0
  174. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1Handler-members.html +0 -39
  175. data/doc/cxxapi/classPassenger_1_1MessageServer_1_1Handler.html +0 -173
  176. data/doc/cxxapi/classPassenger_1_1Process-members.html +0 -44
  177. data/doc/cxxapi/classPassenger_1_1Process.html +0 -290
  178. data/doc/cxxapi/classPassenger_1_1RandomGenerator-members.html +0 -37
  179. data/doc/cxxapi/classPassenger_1_1RandomGenerator.html +0 -79
  180. data/doc/cxxapi/classPassenger_1_1ResourceLocator-members.html +0 -36
  181. data/doc/cxxapi/classPassenger_1_1ResourceLocator.html +0 -51
  182. data/doc/cxxapi/classPassenger_1_1RuntimeException-members.html +0 -36
  183. data/doc/cxxapi/classPassenger_1_1RuntimeException.html +0 -54
  184. data/doc/cxxapi/classPassenger_1_1SafeLibev-members.html +0 -36
  185. data/doc/cxxapi/classPassenger_1_1SafeLibev.html +0 -51
  186. data/doc/cxxapi/classPassenger_1_1ScalarMessage-members.html +0 -37
  187. data/doc/cxxapi/classPassenger_1_1ScalarMessage.html +0 -76
  188. data/doc/cxxapi/classPassenger_1_1ScgiRequestParser-members.html +0 -50
  189. data/doc/cxxapi/classPassenger_1_1ScgiRequestParser.html +0 -285
  190. data/doc/cxxapi/classPassenger_1_1SecurityException-members.html +0 -36
  191. data/doc/cxxapi/classPassenger_1_1SecurityException.html +0 -56
  192. data/doc/cxxapi/classPassenger_1_1Session-members.html +0 -53
  193. data/doc/cxxapi/classPassenger_1_1Session.html +0 -556
  194. data/doc/cxxapi/classPassenger_1_1Session__inherit__graph.map +0 -3
  195. data/doc/cxxapi/classPassenger_1_1Session__inherit__graph.md5 +0 -1
  196. data/doc/cxxapi/classPassenger_1_1Session__inherit__graph.png +0 -0
  197. data/doc/cxxapi/classPassenger_1_1SpawnException-members.html +0 -39
  198. data/doc/cxxapi/classPassenger_1_1SpawnException.html +0 -101
  199. data/doc/cxxapi/classPassenger_1_1SpawnManager-members.html +0 -42
  200. data/doc/cxxapi/classPassenger_1_1SpawnManager.html +0 -292
  201. data/doc/cxxapi/classPassenger_1_1SpawnManager__inherit__graph.map +0 -3
  202. data/doc/cxxapi/classPassenger_1_1SpawnManager__inherit__graph.md5 +0 -1
  203. data/doc/cxxapi/classPassenger_1_1SpawnManager__inherit__graph.png +0 -0
  204. data/doc/cxxapi/classPassenger_1_1StandardSession-members.html +0 -54
  205. data/doc/cxxapi/classPassenger_1_1StandardSession.html +0 -394
  206. data/doc/cxxapi/classPassenger_1_1StandardSession__inherit__graph.map +0 -3
  207. data/doc/cxxapi/classPassenger_1_1StandardSession__inherit__graph.md5 +0 -1
  208. data/doc/cxxapi/classPassenger_1_1StandardSession__inherit__graph.png +0 -0
  209. data/doc/cxxapi/classPassenger_1_1StaticString-members.html +0 -36
  210. data/doc/cxxapi/classPassenger_1_1StaticString.html +0 -56
  211. data/doc/cxxapi/classPassenger_1_1SyntaxError-members.html +0 -36
  212. data/doc/cxxapi/classPassenger_1_1SyntaxError.html +0 -54
  213. data/doc/cxxapi/classPassenger_1_1SystemException-members.html +0 -40
  214. data/doc/cxxapi/classPassenger_1_1SystemException.html +0 -155
  215. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.map +0 -4
  216. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.md5 +0 -1
  217. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.png +0 -0
  218. data/doc/cxxapi/classPassenger_1_1TimeRetrievalException-members.html +0 -40
  219. data/doc/cxxapi/classPassenger_1_1TimeRetrievalException.html +0 -61
  220. data/doc/cxxapi/classPassenger_1_1TimeRetrievalException__inherit__graph.map +0 -3
  221. data/doc/cxxapi/classPassenger_1_1TimeRetrievalException__inherit__graph.md5 +0 -1
  222. data/doc/cxxapi/classPassenger_1_1TimeRetrievalException__inherit__graph.png +0 -0
  223. data/doc/cxxapi/classPassenger_1_1TimeoutException-members.html +0 -36
  224. data/doc/cxxapi/classPassenger_1_1TimeoutException.html +0 -54
  225. data/doc/cxxapi/classPassenger_1_1Uint16Message-members.html +0 -36
  226. data/doc/cxxapi/classPassenger_1_1Uint16Message.html +0 -51
  227. data/doc/cxxapi/classPassenger_1_1Uint32Message-members.html +0 -36
  228. data/doc/cxxapi/classPassenger_1_1Uint32Message.html +0 -51
  229. data/doc/cxxapi/classServer-members.html +0 -36
  230. data/doc/cxxapi/classServer.html +0 -49
  231. data/doc/cxxapi/classServerInstanceDirToucher-members.html +0 -36
  232. data/doc/cxxapi/classServerInstanceDirToucher.html +0 -47
  233. data/doc/cxxapi/classes.html +0 -52
  234. data/doc/cxxapi/definitions_8h_source.html +0 -36
  235. data/doc/cxxapi/doxygen.css +0 -532
  236. data/doc/cxxapi/doxygen.png +0 -0
  237. data/doc/cxxapi/files.html +0 -76
  238. data/doc/cxxapi/ftv2blank.png +0 -0
  239. data/doc/cxxapi/ftv2doc.png +0 -0
  240. data/doc/cxxapi/ftv2folderclosed.png +0 -0
  241. data/doc/cxxapi/ftv2folderopen.png +0 -0
  242. data/doc/cxxapi/ftv2lastnode.png +0 -0
  243. data/doc/cxxapi/ftv2link.png +0 -0
  244. data/doc/cxxapi/ftv2mlastnode.png +0 -0
  245. data/doc/cxxapi/ftv2mnode.png +0 -0
  246. data/doc/cxxapi/ftv2node.png +0 -0
  247. data/doc/cxxapi/ftv2plastnode.png +0 -0
  248. data/doc/cxxapi/ftv2pnode.png +0 -0
  249. data/doc/cxxapi/ftv2vertline.png +0 -0
  250. data/doc/cxxapi/functions.html +0 -103
  251. data/doc/cxxapi/functions_0x62.html +0 -82
  252. data/doc/cxxapi/functions_0x63.html +0 -102
  253. data/doc/cxxapi/functions_0x64.html +0 -102
  254. data/doc/cxxapi/functions_0x65.html +0 -88
  255. data/doc/cxxapi/functions_0x66.html +0 -100
  256. data/doc/cxxapi/functions_0x67.html +0 -167
  257. data/doc/cxxapi/functions_0x68.html +0 -88
  258. data/doc/cxxapi/functions_0x69.html +0 -96
  259. data/doc/cxxapi/functions_0x6b.html +0 -80
  260. data/doc/cxxapi/functions_0x6c.html +0 -88
  261. data/doc/cxxapi/functions_0x6d.html +0 -88
  262. data/doc/cxxapi/functions_0x6e.html +0 -86
  263. data/doc/cxxapi/functions_0x6f.html +0 -94
  264. data/doc/cxxapi/functions_0x70.html +0 -94
  265. data/doc/cxxapi/functions_0x72.html +0 -110
  266. data/doc/cxxapi/functions_0x73.html +0 -171
  267. data/doc/cxxapi/functions_0x74.html +0 -85
  268. data/doc/cxxapi/functions_0x75.html +0 -85
  269. data/doc/cxxapi/functions_0x77.html +0 -92
  270. data/doc/cxxapi/functions_0x7e.html +0 -79
  271. data/doc/cxxapi/functions_enum.html +0 -49
  272. data/doc/cxxapi/functions_eval.html +0 -67
  273. data/doc/cxxapi/functions_func.html +0 -531
  274. data/doc/cxxapi/functions_vars.html +0 -278
  275. data/doc/cxxapi/graph_legend.dot +0 -22
  276. data/doc/cxxapi/graph_legend.html +0 -92
  277. data/doc/cxxapi/graph_legend.png +0 -0
  278. data/doc/cxxapi/group__Core.html +0 -46
  279. data/doc/cxxapi/group__Core.map +0 -3
  280. data/doc/cxxapi/group__Core.png +0 -0
  281. data/doc/cxxapi/group__Exceptions.html +0 -53
  282. data/doc/cxxapi/group__Hooks.html +0 -42
  283. data/doc/cxxapi/group__Hooks.map +0 -3
  284. data/doc/cxxapi/group__Hooks.png +0 -0
  285. data/doc/cxxapi/group__Support.html +0 -538
  286. data/doc/cxxapi/hierarchy.html +0 -101
  287. data/doc/cxxapi/index.html +0 -16
  288. data/doc/cxxapi/inherit__graph__0.map +0 -3
  289. data/doc/cxxapi/inherit__graph__0.md5 +0 -1
  290. data/doc/cxxapi/inherit__graph__0.png +0 -0
  291. data/doc/cxxapi/inherit__graph__1.map +0 -3
  292. data/doc/cxxapi/inherit__graph__1.md5 +0 -1
  293. data/doc/cxxapi/inherit__graph__1.png +0 -0
  294. data/doc/cxxapi/inherit__graph__10.map +0 -3
  295. data/doc/cxxapi/inherit__graph__10.md5 +0 -1
  296. data/doc/cxxapi/inherit__graph__10.png +0 -0
  297. data/doc/cxxapi/inherit__graph__11.map +0 -4
  298. data/doc/cxxapi/inherit__graph__11.md5 +0 -1
  299. data/doc/cxxapi/inherit__graph__11.png +0 -0
  300. data/doc/cxxapi/inherit__graph__12.map +0 -3
  301. data/doc/cxxapi/inherit__graph__12.md5 +0 -1
  302. data/doc/cxxapi/inherit__graph__12.png +0 -0
  303. data/doc/cxxapi/inherit__graph__13.map +0 -3
  304. data/doc/cxxapi/inherit__graph__13.md5 +0 -1
  305. data/doc/cxxapi/inherit__graph__13.png +0 -0
  306. data/doc/cxxapi/inherit__graph__14.map +0 -3
  307. data/doc/cxxapi/inherit__graph__14.md5 +0 -1
  308. data/doc/cxxapi/inherit__graph__14.png +0 -0
  309. data/doc/cxxapi/inherit__graph__15.map +0 -3
  310. data/doc/cxxapi/inherit__graph__15.md5 +0 -1
  311. data/doc/cxxapi/inherit__graph__15.png +0 -0
  312. data/doc/cxxapi/inherit__graph__16.map +0 -5
  313. data/doc/cxxapi/inherit__graph__16.md5 +0 -1
  314. data/doc/cxxapi/inherit__graph__16.png +0 -0
  315. data/doc/cxxapi/inherit__graph__17.map +0 -3
  316. data/doc/cxxapi/inherit__graph__17.md5 +0 -1
  317. data/doc/cxxapi/inherit__graph__17.png +0 -0
  318. data/doc/cxxapi/inherit__graph__18.map +0 -3
  319. data/doc/cxxapi/inherit__graph__18.md5 +0 -1
  320. data/doc/cxxapi/inherit__graph__18.png +0 -0
  321. data/doc/cxxapi/inherit__graph__19.map +0 -4
  322. data/doc/cxxapi/inherit__graph__19.md5 +0 -1
  323. data/doc/cxxapi/inherit__graph__19.png +0 -0
  324. data/doc/cxxapi/inherit__graph__2.map +0 -3
  325. data/doc/cxxapi/inherit__graph__2.md5 +0 -1
  326. data/doc/cxxapi/inherit__graph__2.png +0 -0
  327. data/doc/cxxapi/inherit__graph__20.map +0 -3
  328. data/doc/cxxapi/inherit__graph__20.md5 +0 -1
  329. data/doc/cxxapi/inherit__graph__20.png +0 -0
  330. data/doc/cxxapi/inherit__graph__21.map +0 -3
  331. data/doc/cxxapi/inherit__graph__21.md5 +0 -1
  332. data/doc/cxxapi/inherit__graph__21.png +0 -0
  333. data/doc/cxxapi/inherit__graph__22.map +0 -3
  334. data/doc/cxxapi/inherit__graph__22.md5 +0 -1
  335. data/doc/cxxapi/inherit__graph__22.png +0 -0
  336. data/doc/cxxapi/inherit__graph__23.map +0 -3
  337. data/doc/cxxapi/inherit__graph__23.md5 +0 -1
  338. data/doc/cxxapi/inherit__graph__23.png +0 -0
  339. data/doc/cxxapi/inherit__graph__24.map +0 -3
  340. data/doc/cxxapi/inherit__graph__24.md5 +0 -1
  341. data/doc/cxxapi/inherit__graph__24.png +0 -0
  342. data/doc/cxxapi/inherit__graph__25.map +0 -3
  343. data/doc/cxxapi/inherit__graph__25.md5 +0 -1
  344. data/doc/cxxapi/inherit__graph__25.png +0 -0
  345. data/doc/cxxapi/inherit__graph__26.map +0 -3
  346. data/doc/cxxapi/inherit__graph__26.md5 +0 -1
  347. data/doc/cxxapi/inherit__graph__26.png +0 -0
  348. data/doc/cxxapi/inherit__graph__27.map +0 -3
  349. data/doc/cxxapi/inherit__graph__27.md5 +0 -1
  350. data/doc/cxxapi/inherit__graph__27.png +0 -0
  351. data/doc/cxxapi/inherit__graph__28.map +0 -3
  352. data/doc/cxxapi/inherit__graph__28.md5 +0 -1
  353. data/doc/cxxapi/inherit__graph__28.png +0 -0
  354. data/doc/cxxapi/inherit__graph__29.map +0 -3
  355. data/doc/cxxapi/inherit__graph__29.md5 +0 -1
  356. data/doc/cxxapi/inherit__graph__29.png +0 -0
  357. data/doc/cxxapi/inherit__graph__3.map +0 -4
  358. data/doc/cxxapi/inherit__graph__3.md5 +0 -1
  359. data/doc/cxxapi/inherit__graph__3.png +0 -0
  360. data/doc/cxxapi/inherit__graph__30.map +0 -3
  361. data/doc/cxxapi/inherit__graph__30.md5 +0 -1
  362. data/doc/cxxapi/inherit__graph__30.png +0 -0
  363. data/doc/cxxapi/inherit__graph__31.map +0 -4
  364. data/doc/cxxapi/inherit__graph__31.md5 +0 -1
  365. data/doc/cxxapi/inherit__graph__31.png +0 -0
  366. data/doc/cxxapi/inherit__graph__32.map +0 -3
  367. data/doc/cxxapi/inherit__graph__32.md5 +0 -1
  368. data/doc/cxxapi/inherit__graph__32.png +0 -0
  369. data/doc/cxxapi/inherit__graph__33.map +0 -3
  370. data/doc/cxxapi/inherit__graph__33.md5 +0 -1
  371. data/doc/cxxapi/inherit__graph__33.png +0 -0
  372. data/doc/cxxapi/inherit__graph__34.map +0 -3
  373. data/doc/cxxapi/inherit__graph__34.md5 +0 -1
  374. data/doc/cxxapi/inherit__graph__34.png +0 -0
  375. data/doc/cxxapi/inherit__graph__35.map +0 -3
  376. data/doc/cxxapi/inherit__graph__35.md5 +0 -1
  377. data/doc/cxxapi/inherit__graph__35.png +0 -0
  378. data/doc/cxxapi/inherit__graph__36.map +0 -5
  379. data/doc/cxxapi/inherit__graph__36.md5 +0 -1
  380. data/doc/cxxapi/inherit__graph__36.png +0 -0
  381. data/doc/cxxapi/inherit__graph__37.map +0 -3
  382. data/doc/cxxapi/inherit__graph__37.md5 +0 -1
  383. data/doc/cxxapi/inherit__graph__37.png +0 -0
  384. data/doc/cxxapi/inherit__graph__38.map +0 -3
  385. data/doc/cxxapi/inherit__graph__38.md5 +0 -1
  386. data/doc/cxxapi/inherit__graph__38.png +0 -0
  387. data/doc/cxxapi/inherit__graph__39.map +0 -3
  388. data/doc/cxxapi/inherit__graph__39.md5 +0 -1
  389. data/doc/cxxapi/inherit__graph__39.png +0 -0
  390. data/doc/cxxapi/inherit__graph__4.map +0 -3
  391. data/doc/cxxapi/inherit__graph__4.md5 +0 -1
  392. data/doc/cxxapi/inherit__graph__4.png +0 -0
  393. data/doc/cxxapi/inherit__graph__40.map +0 -3
  394. data/doc/cxxapi/inherit__graph__40.md5 +0 -1
  395. data/doc/cxxapi/inherit__graph__40.png +0 -0
  396. data/doc/cxxapi/inherit__graph__41.map +0 -3
  397. data/doc/cxxapi/inherit__graph__41.md5 +0 -1
  398. data/doc/cxxapi/inherit__graph__41.png +0 -0
  399. data/doc/cxxapi/inherit__graph__5.map +0 -3
  400. data/doc/cxxapi/inherit__graph__5.md5 +0 -1
  401. data/doc/cxxapi/inherit__graph__5.png +0 -0
  402. data/doc/cxxapi/inherit__graph__6.map +0 -3
  403. data/doc/cxxapi/inherit__graph__6.md5 +0 -1
  404. data/doc/cxxapi/inherit__graph__6.png +0 -0
  405. data/doc/cxxapi/inherit__graph__7.map +0 -3
  406. data/doc/cxxapi/inherit__graph__7.md5 +0 -1
  407. data/doc/cxxapi/inherit__graph__7.png +0 -0
  408. data/doc/cxxapi/inherit__graph__8.map +0 -3
  409. data/doc/cxxapi/inherit__graph__8.md5 +0 -1
  410. data/doc/cxxapi/inherit__graph__8.png +0 -0
  411. data/doc/cxxapi/inherit__graph__9.map +0 -3
  412. data/doc/cxxapi/inherit__graph__9.md5 +0 -1
  413. data/doc/cxxapi/inherit__graph__9.png +0 -0
  414. data/doc/cxxapi/inherits.html +0 -165
  415. data/doc/cxxapi/main.html +0 -28
  416. data/doc/cxxapi/modules.html +0 -36
  417. data/doc/cxxapi/namespacePassenger.html +0 -585
  418. data/doc/cxxapi/namespacemembers.html +0 -190
  419. data/doc/cxxapi/namespacemembers_enum.html +0 -48
  420. data/doc/cxxapi/namespacemembers_eval.html +0 -57
  421. data/doc/cxxapi/namespacemembers_func.html +0 -114
  422. data/doc/cxxapi/namespacemembers_type.html +0 -54
  423. data/doc/cxxapi/namespaces.html +0 -37
  424. data/doc/cxxapi/nginx_2Configuration_8h_source.html +0 -126
  425. data/doc/cxxapi/ngx__http__passenger__module_8h_source.html +0 -95
  426. data/doc/cxxapi/structPassenger_1_1MessageServer_1_1DisconnectEventBroadcastGuard-members.html +0 -36
  427. data/doc/cxxapi/structPassenger_1_1MessageServer_1_1DisconnectEventBroadcastGuard.html +0 -51
  428. data/doc/cxxapi/structPassenger_1_1PoolOptions-members.html +0 -67
  429. data/doc/cxxapi/structPassenger_1_1PoolOptions.html +0 -647
  430. data/doc/cxxapi/structPassenger_1_1StaticString_1_1Hash-members.html +0 -36
  431. data/doc/cxxapi/structPassenger_1_1StaticString_1_1Hash.html +0 -51
  432. data/doc/cxxapi/tab_b.gif +0 -0
  433. data/doc/cxxapi/tab_l.gif +0 -0
  434. data/doc/cxxapi/tab_r.gif +0 -0
  435. data/doc/cxxapi/tabs.css +0 -105
  436. data/doc/cxxapi/tree.html +0 -249
  437. data/doc/template/horo.rb +0 -613
  438. data/ext/libev/config.h +0 -122
  439. data/ext/nginx/HttpStatusExtractor.h +0 -351
@@ -0,0 +1,165 @@
1
+ /*
2
+ * Phusion Passenger - http://www.modrails.com/
3
+ * Copyright (c) 2011 Phusion
4
+ *
5
+ * "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ */
25
+ #ifndef _PASSENGER_HTTP_HEADER_BUFFERER_
26
+ #define _PASSENGER_HTTP_HEADER_BUFFERER_
27
+
28
+ #include <string>
29
+ #include <algorithm>
30
+ #include <cstddef>
31
+ #include <cassert>
32
+ #include <StaticString.h>
33
+ #include <Utils/StreamBoyerMooreHorspool.h>
34
+
35
+ namespace Passenger {
36
+
37
+ using namespace std;
38
+
39
+ /**
40
+ * Buffers an entire HTTP header, including terminating "\r\n\r\n".
41
+ *
42
+ * Feed data until acceptingInput() is false. The entire HTTP header
43
+ * will become available through getData(). Non-HTTP header data is
44
+ * not consumed and will not be included in getData().
45
+ *
46
+ * This class has zero-copy support. If the first feed already contains
47
+ * an entire HTTP header getData() will point to the fed data. Otherwise
48
+ * this class will put data in an internal buffer, and getData() will
49
+ * point to the internal buffer.
50
+ *
51
+ * This class also supports size checking through setMax(). If the HTTP
52
+ * header exceeds this size then this bufferer will enter an error state.
53
+ * The default max size is 128 KB.
54
+ */
55
+ class HttpHeaderBufferer {
56
+ private:
57
+ struct StaticData {
58
+ StreamBMH_Occ occ;
59
+
60
+ StaticData() {
61
+ sbmh_init(NULL, &occ, (const unsigned char *) "\r\n\r\n", 4);
62
+ }
63
+ };
64
+
65
+ static StaticData staticData;
66
+
67
+ string buffer;
68
+ StaticString data;
69
+ unsigned int max;
70
+ enum {
71
+ WORKING,
72
+ DONE,
73
+ ERROR
74
+ } state;
75
+ union {
76
+ struct StreamBMH terminatorFinder;
77
+ char padding[SBMH_SIZE(4)];
78
+ } u;
79
+
80
+ public:
81
+ HttpHeaderBufferer() {
82
+ sbmh_init(&u.terminatorFinder,
83
+ &staticData.occ,
84
+ (const unsigned char *) "\r\n\r\n",
85
+ 4);
86
+ max = 1024 * 128;
87
+ reset();
88
+ }
89
+
90
+ void setMax(unsigned int value) {
91
+ max = value;
92
+ }
93
+
94
+ void reset() {
95
+ buffer.clear();
96
+ data = StaticString("", 0);
97
+ sbmh_reset(&u.terminatorFinder);
98
+ state = WORKING;
99
+ }
100
+
101
+ size_t feed(const char *data, size_t size) {
102
+ if (state == DONE || state == ERROR) {
103
+ return 0;
104
+ }
105
+
106
+ size_t accepted, feedSize;
107
+
108
+ if (buffer.empty()) {
109
+ feedSize = std::min<size_t>(size, max);
110
+ accepted = sbmh_feed(&u.terminatorFinder,
111
+ &staticData.occ,
112
+ (const unsigned char *) "\r\n\r\n",
113
+ 4,
114
+ (const unsigned char *) data,
115
+ feedSize);
116
+ if (u.terminatorFinder.found) {
117
+ state = DONE;
118
+ this->data = StaticString(data, accepted);
119
+ } else if (feedSize == max) {
120
+ state = ERROR;
121
+ this->data = StaticString(data, accepted);
122
+ } else {
123
+ assert(accepted == size);
124
+ buffer.append(data, size);
125
+ this->data = buffer;
126
+ }
127
+ } else {
128
+ feedSize = std::min<size_t>(size, max - buffer.size());
129
+ accepted = sbmh_feed(&u.terminatorFinder,
130
+ &staticData.occ,
131
+ (const unsigned char *) "\r\n\r\n",
132
+ 4,
133
+ (const unsigned char *) data,
134
+ feedSize);
135
+ buffer.append(data, accepted);
136
+ this->data = buffer;
137
+ if (u.terminatorFinder.found) {
138
+ state = DONE;
139
+ } else if (buffer.size() == (size_t) max) {
140
+ state = ERROR;
141
+ }
142
+ }
143
+
144
+ return accepted;
145
+ }
146
+
147
+ bool acceptingInput() const {
148
+ return state == WORKING;
149
+ }
150
+
151
+ bool hasError() const {
152
+ return state == ERROR;
153
+ }
154
+
155
+ /**
156
+ * Get the data that has been fed so far.
157
+ */
158
+ StaticString getData() const {
159
+ return data;
160
+ }
161
+ };
162
+
163
+ } // namespace Passenger
164
+
165
+ #endif /* _PASSENGER_HTTP_HEADER_BUFFERER_ */
@@ -79,7 +79,8 @@ split(const StaticString &str, char sep, vector<StaticString> &output) {
79
79
  _split(str, sep, output);
80
80
  }
81
81
 
82
- string toString(const vector<string> &vec) {
82
+ string
83
+ toString(const vector<string> &vec) {
83
84
  vector<StaticString> vec2;
84
85
  vec2.reserve(vec.size());
85
86
  for (vector<string>::const_iterator it = vec.begin(); it != vec.end(); it++) {
@@ -88,7 +89,8 @@ string toString(const vector<string> &vec) {
88
89
  return toString(vec2);
89
90
  }
90
91
 
91
- string toString(const vector<StaticString> &vec) {
92
+ string
93
+ toString(const vector<StaticString> &vec) {
92
94
  string result = "[";
93
95
  vector<StaticString>::const_iterator it;
94
96
  unsigned int i;
@@ -128,9 +130,10 @@ pointerToIntString(void *pointer) {
128
130
  }
129
131
  }
130
132
 
131
- unsigned long long
132
- stringToULL(const StaticString &str) {
133
- unsigned long long result = 0;
133
+ template<typename Numeric>
134
+ static Numeric
135
+ stringToUnsignedNumeric(const StaticString &str) {
136
+ Numeric result = 0;
134
137
  string::size_type i = 0;
135
138
  const char *data = str.data();
136
139
 
@@ -145,9 +148,20 @@ stringToULL(const StaticString &str) {
145
148
  return result;
146
149
  }
147
150
 
148
- long long
149
- stringToLL(const StaticString &str) {
150
- long long result = 0;
151
+ unsigned long long
152
+ stringToULL(const StaticString &str) {
153
+ return stringToUnsignedNumeric<unsigned long long>(str);
154
+ }
155
+
156
+ unsigned int
157
+ stringToUint(const StaticString &str) {
158
+ return stringToUnsignedNumeric<unsigned int>(str);
159
+ }
160
+
161
+ template<typename Numeric>
162
+ static Numeric
163
+ stringToSignedNumeric(const StaticString &str) {
164
+ Numeric result = 0;
151
165
  string::size_type i = 0;
152
166
  const char *data = str.data();
153
167
  bool minus = false;
@@ -171,14 +185,26 @@ stringToLL(const StaticString &str) {
171
185
  }
172
186
  }
173
187
 
174
- unsigned long long
175
- hexToULL(const StaticString &hex) {
176
- unsigned long long result = 0;
177
- string::size_type i = 0;
188
+ long long
189
+ stringToLL(const StaticString &str) {
190
+ return stringToSignedNumeric<long long>(str);
191
+ }
192
+
193
+ int
194
+ stringToInt(const StaticString &str) {
195
+ return stringToSignedNumeric<int>(str);
196
+ }
197
+
198
+ template<typename Numeric>
199
+ static Numeric
200
+ hexToUnsignedNumeric(const StaticString &hex) {
201
+ const char *pos = hex.data();
202
+ const char *end = hex.data() + hex.size();
203
+ Numeric result = 0;
178
204
  bool done = false;
179
205
 
180
- while (i < hex.size() && !done) {
181
- char c = hex[i];
206
+ while (pos < end && !done) {
207
+ char c = *pos;
182
208
  if (c >= '0' && c <= '9') {
183
209
  result *= 16;
184
210
  result += c - '0';
@@ -191,11 +217,21 @@ hexToULL(const StaticString &hex) {
191
217
  } else {
192
218
  done = true;
193
219
  }
194
- i++;
220
+ pos++;
195
221
  }
196
222
  return result;
197
223
  }
198
224
 
225
+ unsigned long long
226
+ hexToULL(const StaticString &hex) {
227
+ return hexToUnsignedNumeric<unsigned long long>(hex);
228
+ }
229
+
230
+ unsigned int
231
+ hexToUint(const StaticString &hex) {
232
+ return hexToUnsignedNumeric<unsigned int>(hex);
233
+ }
234
+
199
235
  unsigned long long
200
236
  hexatriToULL(const StaticString &str) {
201
237
  unsigned long long result = 0;
@@ -92,16 +92,19 @@ string pointerToIntString(void *pointer);
92
92
  * Converts the given integer string to an unsigned long long integer.
93
93
  */
94
94
  unsigned long long stringToULL(const StaticString &str);
95
+ unsigned int stringToUint(const StaticString &str);
95
96
 
96
97
  /**
97
98
  * Converts the given integer string to a long long integer.
98
99
  */
99
100
  long long stringToLL(const StaticString &str);
101
+ int stringToInt(const StaticString &str);
100
102
 
101
103
  /**
102
104
  * Converts the given hexadecimal string to an unsigned long long integer.
103
105
  */
104
106
  unsigned long long hexToULL(const StaticString &str);
107
+ unsigned int hexToUint(const StaticString &str);
105
108
 
106
109
  /**
107
110
  * Converts the given hexatridecimal (base 36) string to an unsigned long long integer.
@@ -0,0 +1,506 @@
1
+ /*
2
+ * Copyright (c) 2010 Phusion v.o.f.
3
+ * https://github.com/FooBarWidget/boyer-moore-horspool
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ */
23
+ #ifndef _STREAM_BOYER_MOORE_HORSPOOL_
24
+ #define _STREAM_BOYER_MOORE_HORSPOOL_
25
+
26
+ /*
27
+ * Boyer-Moore-Horspool string search algorithm implementation with streaming support.
28
+ * Most string search algorithm implementations require the entire haystack data to
29
+ * be in memory. In contrast, this implementation allows one to feed the haystack data
30
+ * piece-of-piece in a "streaming" manner.
31
+ *
32
+ * This implementation is optimized for both speed and memory usage.
33
+ * Other than the memory needed for the context structure, it does not perform any
34
+ * additional memory allocations (except for minimal usage of the stack). The context
35
+ * structure, which contains the Boyer-Moore-Horspool occurance table and various
36
+ * state information, is is organized in such a way that it can be allocated with a
37
+ * single memory allocation action, regardless of the length of the needle.
38
+ * Its inner loop also deviates a little bit from the original algorithm: the original
39
+ * algorithm matches data right-to-left, but this implementation first matches the
40
+ * rightmost character, then matches the data left-to-right, thereby incorporating
41
+ * some ideas from "Tuning the Boyer-Moore-Horspool String Searching Algorithm" by
42
+ * Timo Raita, 1992. It uses memcmp() for this left-to-right match which is typically
43
+ * heavily optimized.
44
+ *
45
+ * A few more notes:
46
+ * - This code can be used for searching an arbitrary binary needle in an arbitrary binary
47
+ * haystack. It is not limited to text.
48
+ * - Boyer-Moore-Horspool works best for long needles. Generally speaking, the longer the
49
+ * needle the faster the algorithm becomes. Thus, this implementation makes no effort
50
+ * at being fast at searching single-character needles or even short needles (say,
51
+ * less than 5 characters). You should just use memchr() and memmem() for that; those
52
+ * functions are usually heavily optimized (e.g. by using tricks like searching 4 bytes
53
+ * at the same time by treating data as an array of integers) and will probably be
54
+ * *much* faster than this code at searching short needles.
55
+ * - You can further tweak this code to favor either memory usage or performance.
56
+ * See the typedef for sbmh_size_t for more information.
57
+ *
58
+ *
59
+ * == Basic usage
60
+ *
61
+ * 1. Allocate a StreamBMH structure either on the stack (alloca) or on the heap.
62
+ * It must be at least SBMH_SIZE(needle_len) bytes big.
63
+ * The maximum supported needle size depends on the definition of sbmh_size_t. See
64
+ * its typedef for more information.
65
+ *
66
+ * This structure contains haystack search state information and callback
67
+ * information. The section 'Reuse' explains why this is important.
68
+ *
69
+ * 2. Allocate a StreamBMH_Occ structure somewhere.
70
+ * This structure contains the Boyer-Moore-Horspool occurrance table. The secion
71
+ * 'Reuse' explains why this is important.
72
+ *
73
+ * 3. Initialize both structures with sbmh_init(). The structures are now usable for
74
+ * searching the given needle, and only the given needle.
75
+ * You must ensure that the StreamBMH structure has at least SBMH_SIZE(needle_len)
76
+ * bytes of space, otherwise sbmh_init() will overwrite too much memory.
77
+ * sbmh_init() does NOT make a copy of the needle data.
78
+ *
79
+ * 4. Feed haystack data using sbmh_feed(). You must pass it the same needle that you
80
+ * passed to sbmh_init(), and the same StreamBMH and StreamBMH_Occ structures.
81
+ * This library does not store a pointer to the needle passed to
82
+ * sbmh_init() for memory efficiency reasons: the caller already has a pointer
83
+ * to the needle data so there's no need for us to store it.
84
+ *
85
+ * sbmh_feed() returns the number of bytes that has been analyzed:
86
+ *
87
+ * - If the needle has now been found then the position of the last needle character
88
+ * in the currently fed data will be returned: all data until the end of the needle
89
+ * has been analyzed, but no more. Additionally, the 'found' field in the context
90
+ * structure will be set to true.
91
+ * - If the needle hasn't been found yet, then the size of the currently fed data
92
+ * will be returned: all fed data has been analyzed.
93
+ * - If the needle was already found, then any additional call to sbmh_feed()
94
+ * will cause it to return 0: nothing in the fed data is analyzed.
95
+ *
96
+ * There's no need deinitialize the StreamBMH/StreamBMH_Occ structures. Just free their
97
+ * memory.
98
+ *
99
+ *
100
+ * == Convenience
101
+ *
102
+ * There's a convenience macro, SBMH_ALLOC_AND_INIT(), for combining steps 1 and 2.
103
+ * It accepts a NULL-terminated needle and allocates the StreamBMH structure using
104
+ * malloc():
105
+ *
106
+ * struct StreamBMH *ctx;
107
+ * SBMH_ALLOC_AND_INIT(ctx, "my needle");
108
+ * if (ctx == NULL) {
109
+ * // error...
110
+ * }
111
+ * ...
112
+ * free(ctx);
113
+ *
114
+ *
115
+ * == Reusing: finding the same needle in a different haystack
116
+ *
117
+ * You can reuse the StreamBMH structure and the StreamBMH_Occ structure for
118
+ * finding the same needle in a different haystack.
119
+ *
120
+ * StreamBMH contains the haystack search state. It must be reset every time
121
+ * you want to search in a new haystack. Call sbmh_reset() to do so.
122
+ *
123
+ * The StreamBMH_Occ structure must not be changed because it only contains
124
+ * needle-specific preparation data, not haystack-specific state. You can
125
+ * just reuse the old StreamBMH_Occ structure.
126
+ *
127
+ * You can then call sbmh_feed() to analyze haystack data.
128
+ *
129
+ *
130
+ * == Reusing: finding a different needle
131
+ *
132
+ * You can reuse an existing StreamBMH/StreamBMH_Occ structure for finding a
133
+ * *different* needle as well. Call sbmh_init() to re-initialize both structures
134
+ * for use with a different needle.
135
+ * However you must make sure that the StreamBMH structure is at least
136
+ * SBMH_SIZE(new_needle_len) bytes big.
137
+ *
138
+ *
139
+ * == Multithreading
140
+ *
141
+ * Once initialized, it is safe to share a StreamBMH_Occ structure and the
142
+ * needle among multiple threads as long as they don't modify either of these.
143
+ * Each thread must however have its own StreamBMH structure.
144
+ *
145
+ *
146
+ * == Recognition of non-needle data
147
+ *
148
+ * The 'callback' field in the StreamBMH structure can be used for recognizing non-needle
149
+ * data. This is especially useful for things like multipart MIME parsers where you're
150
+ * interested in all data except for the needle.
151
+ *
152
+ * This callback is initially set to NULL by sbmh_init(). sbmh_reset() does not set it.
153
+ * When set, sbmh_feed() will call this callback with any data that is determined to not
154
+ * contain the needle. StreamBMH also has a 'user_data' field. You can set it to any
155
+ * value for your own use; this code do not use it at all.
156
+ *
157
+ * The data passed to the callback can be either part of the data in sbmh_feed()'s
158
+ * 'data' argument, or it can be part of the StreamBMH lookbehind buffer. If the latter
159
+ * is the case, then consider the data only valid within the callback: once the
160
+ * callback has finished, this code can do arbitrary things to the lookbehind buffer,
161
+ * so to preserve that data you must make your own copy.
162
+ */
163
+
164
+ /* This implementation is based on sample code originally written by Joel
165
+ * Yliluoma <joel.yliluoma@iki.fi>, licensed under MIT.
166
+ */
167
+
168
+ // We assume that other compilers support the 'restrict' keyword.
169
+ #ifdef __GNUC__
170
+ #ifndef G_GNUC_RESTRICT
171
+ #if defined (__GNUC__) && (__GNUC__ >= 4)
172
+ #define G_GNUC_RESTRICT __restrict__
173
+ #else
174
+ #define G_GNUC_RESTRICT
175
+ #endif
176
+ #endif
177
+ #ifndef restrict
178
+ #define restrict G_GNUC_RESTRICT
179
+ #endif
180
+ #endif
181
+
182
+ #ifndef likely
183
+ #ifdef __GNUC__
184
+ #define likely(expr) __builtin_expect((expr), 1)
185
+ #define unlikely(expr) __builtin_expect((expr), 0)
186
+ #else
187
+ #define likely(expr) expr
188
+ #define unlikely(expr) expr
189
+ #endif
190
+ #endif
191
+
192
+
193
+ #include <cstddef>
194
+ #include <cstring>
195
+ #include <cassert>
196
+ #include <algorithm>
197
+
198
+
199
+ namespace Passenger {
200
+
201
+ struct StreamBMH;
202
+
203
+ /*
204
+ * sbmh_size_t is a type for representing the needle length. It should be unsigned;
205
+ * it makes no sense for it not to be.
206
+ * By default it's typedef'ed to 'unsigned short', which is a 16-bit integer on most
207
+ * platforms, allowing us to support needles up to about 64 KB. This ough to be enough
208
+ * for most people. In the odd situation that you're dealing with extremely large
209
+ * needles, you can typedef this to 'unsigned int' or even 'unsigned long long'.
210
+ *
211
+ * Its typedef slightly affects performance. Benchmarks on OS X Snow Leopard (x86_64)
212
+ * have shown that typedeffing this to size_t (64-bit integer) makes the benchmark
213
+ * 4-8% faster at the cost of 4 times more memory usage per StreamBMH structure.
214
+ * Consider changing the typedef depending on your needs.
215
+ */
216
+ typedef unsigned char sbmh_size_t;
217
+
218
+ typedef void (*sbmh_data_cb)(const struct StreamBMH *ctx, const unsigned char *data, size_t len);
219
+
220
+ struct StreamBMH_Occ {
221
+ sbmh_size_t occ[256];
222
+ };
223
+
224
+ struct StreamBMH {
225
+ /***** Public but read-only fields *****/
226
+ bool found;
227
+
228
+ /***** Public fields; feel free to populate *****/
229
+ sbmh_data_cb callback;
230
+ void *user_data;
231
+
232
+ /***** Internal fields, do not access. *****/
233
+ sbmh_size_t lookbehind_size;
234
+ // Algorithm uses at most needle_len - 1 bytes of space in lookbehind buffer.
235
+ unsigned char lookbehind[];
236
+ };
237
+
238
+ #define SBMH_SIZE(needle_len) (sizeof(struct StreamBMH) + (needle_len) - 1)
239
+ #define SBMH_ALLOC_AND_INIT(sbmh, needle) \
240
+ do { \
241
+ size_t needle_len = strlen((const char *) needle); \
242
+ sbmh = (struct StreamBMH *) malloc(SBMH_SIZE(needle_len)); \
243
+ sbmh_init(sbmh, (const unsigned char *) needle, needle_len); \
244
+ } while (false)
245
+
246
+ #if 0
247
+ #include <string>
248
+ #include <cstdio>
249
+
250
+ #define SBMH_DEBUG(format) printf(format)
251
+ #define SBMH_DEBUG1(format, arg1) printf(format, arg1)
252
+ #define SBMH_DEBUG2(format, arg1, arg2) printf(format, arg1, arg2)
253
+ #else
254
+ #define SBMH_DEBUG(format) do { /* nothing */ } while (false)
255
+ #define SBMH_DEBUG1(format, arg1) do { /* nothing */ } while (false)
256
+ #define SBMH_DEBUG2(format, arg1, arg2) do { /* nothing */ } while (false)
257
+ #endif
258
+
259
+
260
+ inline void
261
+ sbmh_reset(struct StreamBMH *restrict ctx) {
262
+ ctx->found = false;
263
+ ctx->lookbehind_size = 0;
264
+ }
265
+
266
+ inline void
267
+ sbmh_init(struct StreamBMH *restrict ctx, struct StreamBMH_Occ *restrict occ,
268
+ const unsigned char *restrict needle, sbmh_size_t needle_len)
269
+ {
270
+ sbmh_size_t i;
271
+ unsigned int j;
272
+
273
+ if (ctx != NULL) {
274
+ sbmh_reset(ctx);
275
+ ctx->callback = NULL;
276
+ ctx->user_data = NULL;
277
+ }
278
+
279
+ if (occ != NULL) {
280
+ assert(needle_len > 0);
281
+
282
+ /* Initialize occurrance table. */
283
+ for (j = 0; j < 256; j++) {
284
+ occ->occ[j] = needle_len;
285
+ }
286
+
287
+ /* Populate occurance table with analysis of the needle,
288
+ * ignoring last letter.
289
+ */
290
+ if (needle_len >= 1) {
291
+ for (i = 0; i < needle_len - 1; i++) {
292
+ occ->occ[needle[i]] = needle_len - 1 - i;
293
+ }
294
+ }
295
+ }
296
+ }
297
+
298
+ inline char
299
+ sbmh_lookup_char(const struct StreamBMH *restrict ctx,
300
+ const unsigned char *restrict data, ssize_t pos)
301
+ {
302
+ if (pos < 0) {
303
+ return ctx->lookbehind[ctx->lookbehind_size + pos];
304
+ } else {
305
+ return data[pos];
306
+ }
307
+ }
308
+
309
+ inline bool
310
+ sbmh_memcmp(const struct StreamBMH *restrict ctx,
311
+ const unsigned char *restrict needle,
312
+ const unsigned char *restrict data,
313
+ ssize_t pos, sbmh_size_t len)
314
+ {
315
+ ssize_t i = 0;
316
+
317
+ while (i < ssize_t(len)) {
318
+ unsigned char data_ch = sbmh_lookup_char(ctx, data, pos + i);
319
+ unsigned char needle_ch = needle[i];
320
+
321
+ if (data_ch == needle_ch) {
322
+ i++;
323
+ } else {
324
+ return false;
325
+ }
326
+ }
327
+ return true;
328
+ }
329
+
330
+ inline size_t
331
+ sbmh_feed(struct StreamBMH *restrict ctx, const struct StreamBMH_Occ *restrict occtable,
332
+ const unsigned char *restrict needle, sbmh_size_t needle_len,
333
+ const unsigned char *restrict data, size_t len)
334
+ {
335
+ SBMH_DEBUG1("\n[sbmh] feeding: (%s)\n", std::string((const char *) data, len).c_str());
336
+
337
+ if (ctx->found) {
338
+ return 0;
339
+ }
340
+
341
+ /* Positive: points to a position in 'data'
342
+ * pos == 3 points to data[3]
343
+ * Negative: points to a position in the lookbehind buffer
344
+ * pos == -2 points to lookbehind[lookbehind_size - 2]
345
+ */
346
+ ssize_t pos = -ctx->lookbehind_size;
347
+ unsigned char last_needle_char = needle[needle_len - 1];
348
+ const sbmh_size_t *occ = occtable->occ;
349
+
350
+ if (pos < 0) {
351
+ SBMH_DEBUG2("[sbmh] considering lookbehind: (%s)(%s)\n",
352
+ std::string((const char *) ctx->lookbehind, ctx->lookbehind_size).c_str(),
353
+ std::string((const char *) data, len).c_str());
354
+
355
+ /* Lookbehind buffer is not empty. Perform Boyer-Moore-Horspool
356
+ * search with character lookup code that considers both the
357
+ * lookbehind buffer and the current round's haystack data.
358
+ *
359
+ * Loop until
360
+ * there is a match.
361
+ * or until
362
+ * we've moved past the position that requires the
363
+ * lookbehind buffer. In this case we switch to the
364
+ * optimized loop.
365
+ * or until
366
+ * the character to look at lies outside the haystack.
367
+ */
368
+ while (pos < 0 && pos <= ssize_t(len) - ssize_t(needle_len)) {
369
+ unsigned char ch = sbmh_lookup_char(ctx, data,
370
+ pos + needle_len - 1);
371
+
372
+ if (ch == last_needle_char
373
+ && sbmh_memcmp(ctx, needle, data, pos, needle_len - 1)) {
374
+ ctx->found = true;
375
+ ctx->lookbehind_size = 0;
376
+ if (pos > -ctx->lookbehind_size && ctx->callback != NULL) {
377
+ ctx->callback(ctx, ctx->lookbehind,
378
+ ctx->lookbehind_size + pos);
379
+ }
380
+ SBMH_DEBUG1("[sbmh] found using lookbehind; end = %d\n",
381
+ int(pos + needle_len));
382
+ return pos + needle_len;
383
+ } else {
384
+ pos += occ[ch];
385
+ }
386
+ }
387
+
388
+ // No match.
389
+
390
+ if (pos < 0) {
391
+ /* There's too few data for Boyer-Moore-Horspool to run,
392
+ * so let's use a different algorithm to skip as much as
393
+ * we can.
394
+ * Forward pos until
395
+ * the trailing part of lookbehind + data
396
+ * looks like the beginning of the needle
397
+ * or until
398
+ * pos == 0
399
+ */
400
+ SBMH_DEBUG1("[sbmh] inconclusive; pos = %d\n", (int) pos);
401
+ while (pos < 0 && !sbmh_memcmp(ctx, needle, data, pos, len - pos)) {
402
+ pos++;
403
+ }
404
+ SBMH_DEBUG1("[sbmh] managed to skip to pos = %d\n", (int) pos);
405
+ }
406
+
407
+ if (pos >= 0) {
408
+ /* Discard lookbehind buffer. */
409
+ SBMH_DEBUG("[sbmh] no match; discarding lookbehind\n");
410
+ if (ctx->callback != NULL) {
411
+ ctx->callback(ctx, ctx->lookbehind, ctx->lookbehind_size);
412
+ }
413
+ ctx->lookbehind_size = 0;
414
+ } else {
415
+ /* Cut off part of the lookbehind buffer that has
416
+ * been processed and append the entire haystack
417
+ * into it.
418
+ */
419
+ sbmh_size_t bytesToCutOff = sbmh_size_t(ssize_t(ctx->lookbehind_size) + pos);
420
+
421
+ if (bytesToCutOff > 0 && ctx->callback != NULL) {
422
+ // The cut off data is guaranteed not to contain the needle.
423
+ ctx->callback(ctx, ctx->lookbehind, bytesToCutOff);
424
+ }
425
+
426
+ memmove(ctx->lookbehind,
427
+ ctx->lookbehind + bytesToCutOff,
428
+ ctx->lookbehind_size - bytesToCutOff);
429
+ ctx->lookbehind_size -= bytesToCutOff;
430
+
431
+ assert(ssize_t(ctx->lookbehind_size + len) < ssize_t(needle_len));
432
+ memcpy(ctx->lookbehind + ctx->lookbehind_size,
433
+ data, len);
434
+ ctx->lookbehind_size += len;
435
+
436
+ SBMH_DEBUG1("[sbmh] update lookbehind -> (%s)\n",
437
+ std::string((const char *) ctx->lookbehind, ctx->lookbehind_size).c_str());
438
+ return len;
439
+ }
440
+ }
441
+
442
+ assert(pos >= 0);
443
+ assert(ctx->lookbehind_size == 0);
444
+
445
+ SBMH_DEBUG1("[sbmh] starting from pos = %d\n", (int) pos);
446
+
447
+ /* Lookbehind buffer is now empty. Perform Boyer-Moore-Horspool
448
+ * search with optimized character lookup code that only considers
449
+ * the current round's haystack data.
450
+ */
451
+ while (likely( pos <= ssize_t(len) - ssize_t(needle_len) )) {
452
+ unsigned char ch = data[pos + needle_len - 1];
453
+
454
+ if (unlikely(
455
+ unlikely( ch == last_needle_char )
456
+ && unlikely( *(data + pos) == needle[0] )
457
+ && unlikely( memcmp(needle, data + pos, needle_len - 1) == 0 )
458
+ )) {
459
+ SBMH_DEBUG1("[sbmh] found at position %d\n", (int) pos);
460
+ ctx->found = true;
461
+ if (pos > 0 && ctx->callback != NULL) {
462
+ ctx->callback(ctx, data, pos);
463
+ }
464
+ return pos + needle_len;
465
+ } else {
466
+ pos += occ[ch];
467
+ }
468
+ }
469
+
470
+ /* There was no match. If there's trailing haystack data that we cannot
471
+ * match yet using the Boyer-Moore-Horspool algorithm (because the trailing
472
+ * data is less than the needle size) then match using a modified
473
+ * algorithm that starts matching from the beginning instead of the end.
474
+ * Whatever trailing data is left after running this algorithm is added to
475
+ * the lookbehind buffer.
476
+ */
477
+ SBMH_DEBUG("[sbmh] no match\n");
478
+ if (size_t(pos) < len) {
479
+ while (size_t(pos) < len
480
+ && (
481
+ data[pos] != needle[0]
482
+ || memcmp(data + pos, needle, len - pos) != 0
483
+ )) {
484
+ pos++;
485
+ }
486
+ if (size_t(pos) < len) {
487
+ memcpy(ctx->lookbehind, data + pos, len - pos);
488
+ ctx->lookbehind_size = len - pos;
489
+ SBMH_DEBUG2("[sbmh] adding %d trailing bytes to lookbehind -> (%s)\n",
490
+ int(len - pos),
491
+ std::string((const char *) ctx->lookbehind,
492
+ ctx->lookbehind_size).c_str());
493
+ }
494
+ }
495
+
496
+ /* Everything until pos is guaranteed not to contain needle data. */
497
+ if (pos > 0 && ctx->callback != NULL) {
498
+ ctx->callback(ctx, data, std::min(size_t(pos), len));
499
+ }
500
+
501
+ return len;
502
+ }
503
+
504
+ } // namespace Passenger
505
+
506
+ #endif /* _STREAM_BOYER_MOORE_HORSPOOL_ */