passenger 5.0.30 → 5.1.0

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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +30 -1
  3. data/CONTRIBUTING.md +1 -1
  4. data/CONTRIBUTORS +2 -0
  5. data/bin/passenger-install-nginx-module +18 -13
  6. data/build/agent.rb +1 -0
  7. data/build/basics.rb +1 -0
  8. data/build/cxx_tests.rb +6 -1
  9. data/build/misc.rb +3 -0
  10. data/build/packaging.rb +5 -17
  11. data/build/support/cxx_dependency_map.rb +100 -0
  12. data/build/support/vendor/cxxcodebuilder/lib/cxxcodebuilder/builder.rb +4 -1
  13. data/build/test_basics.rb +12 -2
  14. data/dev/ci/run_travis.sh +6 -2
  15. data/doc/Users guide Apache.html +7 -2
  16. data/doc/Users guide Apache.txt +4 -0
  17. data/resources/templates/error_layout.css +70 -84
  18. data/resources/templates/error_layout.html.template +84 -93
  19. data/resources/templates/standalone/http.erb +17 -13
  20. data/resources/templates/standalone/server.erb +2 -1
  21. data/resources/templates/undisclosed_error.html.template +52 -51
  22. data/resources/update_check_client_cert.p12 +0 -0
  23. data/resources/update_check_client_cert.pem +89 -0
  24. data/resources/update_check_server_pubkey.pem +14 -0
  25. data/src/agent/Core/ApplicationPool/ErrorRenderer.h +15 -1
  26. data/src/agent/Core/Controller.h +3 -2
  27. data/src/agent/Core/Controller/CheckoutSession.cpp +5 -4
  28. data/src/agent/Core/Controller/ForwardResponse.cpp +1 -1
  29. data/src/agent/Core/Controller/InitRequest.cpp +2 -0
  30. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +1 -0
  31. data/src/agent/Core/Controller/Request.h +1 -0
  32. data/src/agent/Core/CoreMain.cpp +99 -2
  33. data/src/agent/Core/OptionParser.h +18 -1
  34. data/src/agent/Core/SecurityUpdateChecker.h +559 -0
  35. data/src/agent/Shared/Base.cpp +6 -1
  36. data/src/agent/TempDirToucher/TempDirToucherMain.cpp +52 -0
  37. data/src/agent/Watchdog/InstanceDirToucher.cpp +1 -2
  38. data/src/agent/Watchdog/WatchdogMain.cpp +31 -40
  39. data/src/apache2_module/Configuration.cpp +12 -0
  40. data/src/apache2_module/Configuration.hpp +5 -0
  41. data/src/apache2_module/ConfigurationCommands.cpp +19 -19
  42. data/src/apache2_module/ConfigurationCommands.cpp.cxxcodebuilder +2 -2
  43. data/src/apache2_module/ConfigurationFields.hpp +19 -19
  44. data/src/apache2_module/ConfigurationFields.hpp.cxxcodebuilder +2 -2
  45. data/src/apache2_module/ConfigurationSetters.cpp +19 -19
  46. data/src/apache2_module/ConfigurationSetters.cpp.cxxcodebuilder +2 -2
  47. data/src/apache2_module/CreateDirConfig.cpp +19 -19
  48. data/src/apache2_module/CreateDirConfig.cpp.cxxcodebuilder +2 -2
  49. data/src/apache2_module/Hooks.cpp +10 -1
  50. data/src/apache2_module/MergeDirConfig.cpp +19 -19
  51. data/src/apache2_module/MergeDirConfig.cpp.cxxcodebuilder +2 -2
  52. data/src/apache2_module/SetHeaders.cpp +19 -19
  53. data/src/apache2_module/SetHeaders.cpp.cxxcodebuilder +2 -2
  54. data/src/cxx_supportlib/Constants.h +22 -22
  55. data/src/cxx_supportlib/Constants.h.cxxcodebuilder +4 -1
  56. data/src/cxx_supportlib/Crypto.cpp +977 -0
  57. data/src/cxx_supportlib/Crypto.h +147 -0
  58. data/src/cxx_supportlib/InstanceDirectory.h +55 -2
  59. data/src/cxx_supportlib/Utils/Curl.h +24 -10
  60. data/src/cxx_supportlib/Utils/JsonUtils.h +1 -1
  61. data/src/cxx_supportlib/oxt/detail/spin_lock_darwin.hpp +2 -0
  62. data/src/cxx_supportlib/vendor-modified/boost/system/error_code.hpp +3 -3
  63. data/src/cxx_supportlib/vendor-modified/jsoncpp/json-forwards.h +167 -92
  64. data/src/cxx_supportlib/vendor-modified/jsoncpp/json.h +1827 -1542
  65. data/src/cxx_supportlib/vendor-modified/jsoncpp/jsoncpp.cpp +4705 -3652
  66. data/src/cxx_supportlib/vendor-modified/libev/Changes +46 -15
  67. data/src/cxx_supportlib/vendor-modified/libev/LICENSE +1 -1
  68. data/src/cxx_supportlib/vendor-modified/libev/Makefile.in +215 -128
  69. data/src/cxx_supportlib/vendor-modified/libev/aclocal.m4 +466 -275
  70. data/src/cxx_supportlib/vendor-modified/libev/config.guess +312 -418
  71. data/src/cxx_supportlib/vendor-modified/libev/config.sub +246 -105
  72. data/src/cxx_supportlib/vendor-modified/libev/configure +276 -72
  73. data/src/cxx_supportlib/vendor-modified/libev/configure.ac +2 -1
  74. data/src/cxx_supportlib/vendor-modified/libev/depcomp +346 -185
  75. data/src/cxx_supportlib/vendor-modified/libev/ev++.h +1 -1
  76. data/src/cxx_supportlib/vendor-modified/libev/ev.c +530 -190
  77. data/src/cxx_supportlib/vendor-modified/libev/ev.h +23 -14
  78. data/src/cxx_supportlib/vendor-modified/libev/ev_epoll.c +12 -6
  79. data/src/cxx_supportlib/vendor-modified/libev/ev_kqueue.c +9 -5
  80. data/src/cxx_supportlib/vendor-modified/libev/ev_poll.c +6 -3
  81. data/src/cxx_supportlib/vendor-modified/libev/ev_port.c +8 -4
  82. data/src/cxx_supportlib/vendor-modified/libev/ev_select.c +4 -2
  83. data/src/cxx_supportlib/vendor-modified/libev/ev_vars.h +3 -2
  84. data/src/cxx_supportlib/vendor-modified/libev/ev_win32.c +3 -4
  85. data/src/cxx_supportlib/vendor-modified/libev/install-sh +433 -219
  86. data/src/cxx_supportlib/vendor-modified/libev/libev.m4 +6 -6
  87. data/src/cxx_supportlib/vendor-modified/libev/ltmain.sh +2 -2
  88. data/src/cxx_supportlib/vendor-modified/libev/missing +167 -288
  89. data/src/cxx_supportlib/vendor-modified/libev/mkinstalldirs +72 -21
  90. data/src/cxx_supportlib/vendor-modified/modp_b64.cpp +4 -106
  91. data/src/cxx_supportlib/vendor-modified/modp_b64_data.h +37 -1
  92. data/src/cxx_supportlib/vendor-modified/modp_b64_strict_aliasing.cpp +119 -0
  93. data/src/helper-scripts/node-loader.js +72 -1
  94. data/src/nginx_module/CacheLocationConfig.c +52 -19
  95. data/src/nginx_module/CacheLocationConfig.c.cxxcodebuilder +2 -2
  96. data/src/nginx_module/Configuration.c +26 -1
  97. data/src/nginx_module/Configuration.h +2 -0
  98. data/src/nginx_module/ConfigurationCommands.c +35 -19
  99. data/src/nginx_module/ConfigurationCommands.c.cxxcodebuilder +2 -2
  100. data/src/nginx_module/ContentHandler.c +1 -1
  101. data/src/nginx_module/CreateLocationConfig.c +22 -19
  102. data/src/nginx_module/CreateLocationConfig.c.cxxcodebuilder +2 -2
  103. data/src/nginx_module/LocationConfig.h +21 -19
  104. data/src/nginx_module/LocationConfig.h.cxxcodebuilder +2 -2
  105. data/src/nginx_module/MergeLocationConfig.c +25 -19
  106. data/src/nginx_module/MergeLocationConfig.c.cxxcodebuilder +2 -2
  107. data/src/nginx_module/ngx_http_passenger_module.c +8 -4
  108. data/src/ruby_supportlib/phusion_passenger.rb +9 -4
  109. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +2 -2
  110. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance_registry.rb +1 -1
  111. data/src/ruby_supportlib/phusion_passenger/common_library.rb +13 -0
  112. data/src/ruby_supportlib/phusion_passenger/config/nginx_engine_compiler.rb +5 -2
  113. data/src/ruby_supportlib/phusion_passenger/constants.rb +1 -1
  114. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +15 -3
  115. data/src/ruby_supportlib/phusion_passenger/platform_info/crypto.rb +51 -0
  116. data/src/ruby_supportlib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +7 -0
  117. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +17 -0
  118. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +4 -2
  119. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +4 -0
  120. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +5 -0
  121. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/app.rb +19 -10
  122. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/base.rb +25 -0
  123. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/gdb_controller.rb +38 -103
  124. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/lldb_controller.rb +178 -0
  125. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/utils.rb +94 -0
  126. data/src/ruby_supportlib/phusion_passenger/vendor/crash_watch/version.rb +2 -2
  127. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +2 -2
  128. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
  129. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +5 -3
  130. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +9 -7
  131. metadata +14 -4
@@ -1,21 +1,36 @@
1
1
  #! /bin/sh
2
2
  # mkinstalldirs --- make directory hierarchy
3
- # Author: Noah Friedman <friedman@prep.ai.mit.edu>
3
+
4
+ scriptversion=2009-04-28.21; # UTC
5
+
6
+ # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
4
7
  # Created: 1993-05-16
5
- # Public domain
8
+ # Public domain.
9
+ #
10
+ # This file is maintained in Automake, please report
11
+ # bugs to <bug-automake@gnu.org> or send patches to
12
+ # <automake-patches@gnu.org>.
6
13
 
14
+ nl='
15
+ '
16
+ IFS=" "" $nl"
7
17
  errstatus=0
8
- dirmode=""
18
+ dirmode=
9
19
 
10
20
  usage="\
11
- Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
21
+ Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
22
+
23
+ Create each directory DIR (with mode MODE, if specified), including all
24
+ leading file name components.
25
+
26
+ Report bugs to <bug-automake@gnu.org>."
12
27
 
13
28
  # process command line arguments
14
29
  while test $# -gt 0 ; do
15
30
  case $1 in
16
31
  -h | --help | --h*) # -h for help
17
- echo "$usage" 1>&2
18
- exit 0
32
+ echo "$usage"
33
+ exit $?
19
34
  ;;
20
35
  -m) # -m PERM arg
21
36
  shift
@@ -23,6 +38,10 @@ while test $# -gt 0 ; do
23
38
  dirmode=$1
24
39
  shift
25
40
  ;;
41
+ --version)
42
+ echo "$0 $scriptversion"
43
+ exit $?
44
+ ;;
26
45
  --) # stop option processing
27
46
  shift
28
47
  break
@@ -50,30 +69,58 @@ case $# in
50
69
  0) exit 0 ;;
51
70
  esac
52
71
 
72
+ # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
73
+ # mkdir -p a/c at the same time, both will detect that a is missing,
74
+ # one will create a, then the other will try to create a and die with
75
+ # a "File exists" error. This is a problem when calling mkinstalldirs
76
+ # from a parallel make. We use --version in the probe to restrict
77
+ # ourselves to GNU mkdir, which is thread-safe.
53
78
  case $dirmode in
54
79
  '')
55
- if mkdir -p -- . 2>/dev/null; then
80
+ if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
56
81
  echo "mkdir -p -- $*"
57
82
  exec mkdir -p -- "$@"
83
+ else
84
+ # On NextStep and OpenStep, the 'mkdir' command does not
85
+ # recognize any option. It will interpret all options as
86
+ # directories to create, and then abort because '.' already
87
+ # exists.
88
+ test -d ./-p && rmdir ./-p
89
+ test -d ./--version && rmdir ./--version
58
90
  fi
59
91
  ;;
60
92
  *)
61
- if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
93
+ if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
94
+ test ! -d ./--version; then
62
95
  echo "mkdir -m $dirmode -p -- $*"
63
96
  exec mkdir -m "$dirmode" -p -- "$@"
97
+ else
98
+ # Clean up after NextStep and OpenStep mkdir.
99
+ for d in ./-m ./-p ./--version "./$dirmode";
100
+ do
101
+ test -d $d && rmdir $d
102
+ done
64
103
  fi
65
104
  ;;
66
105
  esac
67
106
 
68
107
  for file
69
108
  do
70
- set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
109
+ case $file in
110
+ /*) pathcomp=/ ;;
111
+ *) pathcomp= ;;
112
+ esac
113
+ oIFS=$IFS
114
+ IFS=/
115
+ set fnord $file
71
116
  shift
117
+ IFS=$oIFS
72
118
 
73
- pathcomp=
74
119
  for d
75
120
  do
76
- pathcomp="$pathcomp$d"
121
+ test "x$d" = x && continue
122
+
123
+ pathcomp=$pathcomp$d
77
124
  case $pathcomp in
78
125
  -*) pathcomp=./$pathcomp ;;
79
126
  esac
@@ -84,21 +131,21 @@ do
84
131
  mkdir "$pathcomp" || lasterr=$?
85
132
 
86
133
  if test ! -d "$pathcomp"; then
87
- errstatus=$lasterr
134
+ errstatus=$lasterr
88
135
  else
89
- if test ! -z "$dirmode"; then
136
+ if test ! -z "$dirmode"; then
90
137
  echo "chmod $dirmode $pathcomp"
91
- lasterr=""
92
- chmod "$dirmode" "$pathcomp" || lasterr=$?
138
+ lasterr=
139
+ chmod "$dirmode" "$pathcomp" || lasterr=$?
93
140
 
94
- if test ! -z "$lasterr"; then
95
- errstatus=$lasterr
96
- fi
97
- fi
141
+ if test ! -z "$lasterr"; then
142
+ errstatus=$lasterr
143
+ fi
144
+ fi
98
145
  fi
99
146
  fi
100
147
 
101
- pathcomp="$pathcomp/"
148
+ pathcomp=$pathcomp/
102
149
  done
103
150
  done
104
151
 
@@ -107,5 +154,9 @@ exit $errstatus
107
154
  # Local Variables:
108
155
  # mode: shell-script
109
156
  # sh-indentation: 2
157
+ # eval: (add-hook 'write-file-hooks 'time-stamp)
158
+ # time-stamp-start: "scriptversion="
159
+ # time-stamp-format: "%:y-%02m-%02d.%02H"
160
+ # time-stamp-time-zone: "UTC"
161
+ # time-stamp-end: "; # UTC"
110
162
  # End:
111
- # mkinstalldirs ends here
@@ -43,44 +43,11 @@
43
43
  * </PRE>
44
44
  */
45
45
 
46
- #ifdef __cplusplus
47
- #include <boost/cstdint.hpp>
48
- typedef boost::uint8_t modp_uint8_t;
49
- typedef boost::uint32_t modp_uint32_t;
50
- #else
51
- #include <stdint.h>
52
- typedef uint8_t modp_uint8_t;
53
- typedef uint32_t modp_uint32_t;
54
- #endif
55
-
56
- #ifndef MODP_B64_DONT_INCLUDE_BOOST_ENDIANNESS_HEADERS
57
- #include <boost/detail/endian.hpp>
58
- #endif
46
+ #include "modp_b64_data.h"
59
47
 
60
48
  /* public header */
61
49
  #include "modp_b64.h"
62
50
 
63
- #include "modp_b64_data.h"
64
-
65
- #define B64_BADCHAR 0x01FFFFFF
66
-
67
- /**
68
- * you can control if we use padding by commenting out this
69
- * next line. However, I highly recommend you use padding and not
70
- * using it should only be for compatability with a 3rd party.
71
- * Also, 'no padding' is not tested!
72
- */
73
- #define B64_DOPAD 1
74
-
75
- /*
76
- * if we aren't doing padding
77
- * set the pad character to NULL
78
- */
79
- #ifndef B64_DOPAD
80
- #undef B64_CHARPAD
81
- #define B64_CHARPAD '\0'
82
- #endif
83
-
84
51
  size_t modp_b64_encode(char* dest, const char* str, size_t len)
85
52
  {
86
53
  size_t i = 0;
@@ -123,77 +90,8 @@ size_t modp_b64_encode(char* dest, const char* str, size_t len)
123
90
  *p = '\0';
124
91
  return (size_t)(p - (modp_uint8_t*)dest);
125
92
  }
126
-
127
- #ifdef BOOST_BIG_ENDIAN /* BIG ENDIAN -- SUN / IBM / MOTOROLA */
128
- size_t modp_b64_decode(char* dest, const char* src, size_t len)
129
- {
130
- size_t i;
131
- if (len == 0) return 0;
132
-
133
- #ifdef B64_DOPAD
134
- /* if padding is used, then the message must be at least
135
- 4 chars and be a multiple of 4.
136
- there can be at most 2 pad chars at the end */
137
- if (len < 4 || (len % 4 != 0)) return -1;
138
- if (src[len-1] == B64_CHARPAD) {
139
- len--;
140
- if (src[len -1] == B64_CHARPAD) {
141
- len--;
142
- }
143
- }
144
- #endif /* B64_DOPAD */
145
-
146
- size_t leftover = len % 4;
147
- size_t chunks = (leftover == 0) ? len / 4 - 1 : len /4;
148
-
149
- modp_uint8_t* p = (modp_uint8_t*) dest;
150
- modp_uint32_t x = 0;
151
- modp_uint32_t* destInt = (modp_uint32_t*) p;
152
- modp_uint32_t* srcInt = (modp_uint32_t*) src;
153
- modp_uint32_t y = *srcInt++;
154
- for (i = 0; i < chunks; ++i) {
155
- x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] |
156
- d2[y >> 8 & 0xff] | d3[y & 0xff];
157
-
158
- if (x >= B64_BADCHAR) return -1;
159
- *destInt = x << 8;
160
- p += 3;
161
- destInt = (modp_uint32_t*)p;
162
- y = *srcInt++;
163
- }
164
-
165
- switch (leftover) {
166
- case 0:
167
- x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] |
168
- d2[y >> 8 & 0xff] | d3[y & 0xff];
169
- if (x >= B64_BADCHAR) return -1;
170
- *p++ = ((modp_uint8_t*)&x)[1];
171
- *p++ = ((modp_uint8_t*)&x)[2];
172
- *p = ((modp_uint8_t*)&x)[3];
173
- return (chunks+1)*3;
174
- #ifndef B64_DOPAD
175
- case 1: /* with padding this is an impossible case */
176
- x = d3[y >> 24];
177
- *p = (modp_uint8_t)x;
178
- break;
179
- #endif
180
- case 2:
181
- x = d3[y >> 24] *64 + d3[(y >> 16) & 0xff];
182
- *p = (modp_uint8_t)(x >> 4);
183
- break;
184
- default: /* case 3 */
185
- x = (d3[y >> 24] *64 + d3[(y >> 16) & 0xff])*64 +
186
- d3[(y >> 8) & 0xff];
187
- *p++ = (modp_uint8_t) (x >> 10);
188
- *p = (modp_uint8_t) (x >> 2);
189
- break;
190
- }
191
-
192
- if (x >= B64_BADCHAR) return -1;
193
- return 3*chunks + (6*leftover)/8;
194
- }
195
-
196
- #else /* LITTLE ENDIAN -- INTEL AND FRIENDS */
93
+ #if defined(__x86_64__) || defined(__x86__)
94
+ /* INTEL & AMD */
197
95
 
198
96
  size_t modp_b64_decode(char* dest, const char* src, size_t len)
199
97
  {
@@ -289,4 +187,4 @@ size_t modp_b64_decode(char* dest, const char* src, size_t len)
289
187
  return 3*chunks + (6*leftover)/8;
290
188
  }
291
189
 
292
- #endif /* if bigendian / else / endif */
190
+ #endif
@@ -1,6 +1,41 @@
1
+ #ifndef MODP_B64_DATA_H
2
+ #define MODP_B64_DATA_H
3
+
4
+ #ifdef __cplusplus
5
+ #include <boost/cstdint.hpp>
6
+ typedef boost::uint8_t modp_uint8_t;
7
+ typedef boost::uint32_t modp_uint32_t;
8
+ #else
9
+ #include <stdint.h>
10
+ typedef uint8_t modp_uint8_t;
11
+ typedef uint32_t modp_uint32_t;
12
+ #endif
13
+
14
+ #ifndef MODP_B64_DONT_INCLUDE_BOOST_ENDIANNESS_HEADERS
15
+ #include <boost/detail/endian.hpp>
16
+ #endif
17
+
18
+ /**
19
+ * you can control if we use padding by commenting out this
20
+ * next line. However, I highly recommend you use padding and not
21
+ * using it should only be for compatability with a 3rd party.
22
+ * Also, 'no padding' is not tested!
23
+ */
24
+ #define B64_DOPAD 1
25
+ #define B64_BADCHAR 0x01FFFFFF
1
26
  #define B64_CHAR62 '+'
2
27
  #define B64_CHAR63 '/'
3
28
  #define B64_CHARPAD '='
29
+
30
+ /*
31
+ * if we aren't doing padding
32
+ * set the pad character to NULL
33
+ */
34
+ #ifndef B64_DOPAD
35
+ #undef B64_CHARPAD
36
+ #define B64_CHARPAD '\0'
37
+ #endif
38
+
4
39
  static const modp_uint8_t e0[256] = {
5
40
  'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C',
6
41
  'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E',
@@ -90,7 +125,7 @@ static const modp_uint8_t e2[256] = {
90
125
 
91
126
 
92
127
 
93
- #ifdef BOOST_BIG_ENDIAN
128
+ #if !defined(__x86_64__) && !defined(__x86__)
94
129
 
95
130
 
96
131
  /* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */
@@ -477,3 +512,4 @@ static const modp_uint32_t d3[256] = {
477
512
 
478
513
 
479
514
  #endif
515
+ #endif
@@ -0,0 +1,119 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2014-2015 Phusion Holding B.V.
4
+ *
5
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
+ * trademarks of Phusion Holding B.V.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ #include "modp_b64_data.h"
28
+
29
+ /* public header */
30
+ #include "modp_b64.h"
31
+
32
+ #if !defined(__x86_64__) && !defined(__x86__)
33
+
34
+ size_t modp_b64_decode(char* dest, const char* src, size_t len)
35
+ {
36
+ size_t i;
37
+ if (len == 0) return 0;
38
+
39
+ #ifdef B64_DOPAD
40
+ /* if padding is used, then the message must be at least
41
+ 4 chars and be a multiple of 4.
42
+ there can be at most 2 pad chars at the end */
43
+ if (len < 4 || (len % 4 != 0)) return -1;
44
+ if (src[len-1] == B64_CHARPAD) {
45
+ len--;
46
+ if (src[len -1] == B64_CHARPAD) {
47
+ len--;
48
+ }
49
+ }
50
+ #endif /* B64_DOPAD */
51
+
52
+ size_t leftover = len % 4;
53
+ size_t chunks = (leftover == 0) ? len / 4 - 1 : len /4;
54
+
55
+ modp_uint8_t* p = (modp_uint8_t*) dest;
56
+ modp_uint32_t x = 0;
57
+ const modp_uint8_t* srcInt = (modp_uint8_t*) src;
58
+ modp_uint8_t y[4];
59
+
60
+ y[3]=srcInt[0];
61
+ y[2]=srcInt[1];
62
+ y[1]=srcInt[2];
63
+ y[0]=srcInt[3];
64
+ srcInt+=4;
65
+
66
+ for (i = 0; i < chunks; ++i) {
67
+ x = d0[y[3]] | d1[y[2]] | d2[y[1]] | d3[y[0]];
68
+
69
+ if (x >= B64_BADCHAR) return -1;
70
+ modp_uint32_t tmp_x = (x << 8);
71
+ p[0] = (tmp_x >> 3*8) & 0xFF;
72
+ p[1] = (tmp_x >> 2*8) & 0xFF;
73
+ p[2] = (tmp_x >> 1*8) & 0xFF;
74
+ p[3] = (tmp_x >> 0*8) & 0xFF;
75
+ p += 3;
76
+
77
+ y[3]=srcInt[0];
78
+ y[2]=srcInt[1];
79
+ y[1]=srcInt[2];
80
+ y[0]=srcInt[3];
81
+ srcInt+=4;
82
+ }
83
+
84
+ switch (leftover) {
85
+ case 0:
86
+ x = d0[y[3]] | d1[y[2]] | d2[y[1]] | d3[y[0]];
87
+ if (x >= B64_BADCHAR) return -1;
88
+ #ifdef BOOST_BIG_ENDIAN
89
+ *p++ = ((modp_uint8_t*)&x)[1];
90
+ *p++ = ((modp_uint8_t*)&x)[2];
91
+ *p = ((modp_uint8_t*)&x)[3];
92
+ #else
93
+ *p++ = ((modp_uint8_t*)&x)[2];
94
+ *p++ = ((modp_uint8_t*)&x)[1];
95
+ *p = ((modp_uint8_t*)&x)[0];
96
+ #endif
97
+ return (chunks+1)*3;
98
+ #ifndef B64_DOPAD
99
+ case 1: /* with padding this is an impossible case */
100
+ x = d3[y[3]];
101
+ *p = (modp_uint8_t)x;
102
+ break;
103
+ #endif
104
+ case 2:
105
+ x = d3[y[3]] *64 + d3[y[2]];
106
+ *p = (modp_uint8_t)(x >> 4);
107
+ break;
108
+ default: /* case 3 */
109
+ x = (d3[y[3]] *64 + d3[y[2]])*64 + d3[y[1]];
110
+ *p++ = (modp_uint8_t) (x >> 10);
111
+ *p = (modp_uint8_t) (x >> 2);
112
+ break;
113
+ }
114
+
115
+ if (x >= B64_BADCHAR) return -1;
116
+ return 3*chunks + (6*leftover)/8;
117
+ }
118
+
119
+ #endif