aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c59
-rw-r--r--src/core/ngx_conf_file.h1
-rw-r--r--src/core/ngx_output_chain.c4
-rw-r--r--src/core/ngx_string.c95
-rw-r--r--src/core/ngx_string.h3
5 files changed, 133 insertions, 29 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 6d6103c0e..17071c1c5 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -140,6 +140,65 @@ int main(int argc, char *const *argv)
return 1;
}
+{
+ ngx_str_t d, s;
+
+ s.data = "12";
+ s.len = sizeof("12") - 1;
+
+ if (ngx_encode_base64(init_cycle.pool, &s, &d) != NGX_OK) {
+ ngx_log_error(NGX_LOG_ERR, log, 0, "ngx_encode_base64() failed");
+ } else {
+ ngx_log_error(NGX_LOG_NOTICE, log, 0, "BASE64: %d:\"%s\"", d.len, d.data);
+ }
+
+ s.data = "123";
+ s.len = sizeof("123") - 1;
+
+ if (ngx_encode_base64(init_cycle.pool, &s, &d) != NGX_OK) {
+ ngx_log_error(NGX_LOG_ERR, log, 0, "ngx_encode_base64() failed");
+ } else {
+ ngx_log_error(NGX_LOG_NOTICE, log, 0, "BASE64: %d:\"%s\"", d.len, d.data);
+ }
+
+ s.data = "1234";
+ s.len = sizeof("1234") - 1;
+
+ if (ngx_encode_base64(init_cycle.pool, &s, &d) != NGX_OK) {
+ ngx_log_error(NGX_LOG_ERR, log, 0, "ngx_encode_base64() failed");
+ } else {
+ ngx_log_error(NGX_LOG_NOTICE, log, 0, "BASE64: %d:\"%s\"", d.len, d.data);
+ }
+
+ s.data = "12345";
+ s.len = sizeof("12345") - 1;
+
+ if (ngx_encode_base64(init_cycle.pool, &s, &d) != NGX_OK) {
+ ngx_log_error(NGX_LOG_ERR, log, 0, "ngx_encode_base64() failed");
+ } else {
+ ngx_log_error(NGX_LOG_NOTICE, log, 0, "BASE64: %d:\"%s\"", d.len, d.data);
+ }
+
+ s.data = "123456";
+ s.len = sizeof("123456") - 1;
+
+ if (ngx_encode_base64(init_cycle.pool, &s, &d) != NGX_OK) {
+ ngx_log_error(NGX_LOG_ERR, log, 0, "ngx_encode_base64() failed");
+ } else {
+ ngx_log_error(NGX_LOG_NOTICE, log, 0, "BASE64: %d:\"%s\"", d.len, d.data);
+ }
+
+ s.data = "12345678901234567890";
+ s.len = sizeof("12345678901234567890") - 1;
+
+ if (ngx_encode_base64(init_cycle.pool, &s, &d) != NGX_OK) {
+ ngx_log_error(NGX_LOG_ERR, log, 0, "ngx_encode_base64() failed");
+ } else {
+ ngx_log_error(NGX_LOG_NOTICE, log, 0, "BASE64: %d:\"%s\"", d.len, d.data);
+ }
+
+}
+
if (ngx_add_inherited_sockets(&init_cycle) == NGX_ERROR) {
return 1;
}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index c09ee552b..7286dbf41 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -276,7 +276,6 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index db4321bc0..f177076de 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -275,6 +275,10 @@ ngx_int_t ngx_chain_writer(void *data, ngx_chain_t *in)
for (/* void */; in; in = in->next) {
+
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
+ "WRITER buf: %d", ngx_buf_size(in->buf));
+
ngx_alloc_link_and_set_buf(cl, in->buf, ctx->pool, NGX_ERROR);
*ctx->last = cl;
ctx->last = &cl->next;
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index f14040f3f..7231651c0 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -126,7 +126,7 @@ void ngx_md5_text(u_char *text, u_char *md5)
ngx_int_t ngx_encode_base64(ngx_pool_t *pool, ngx_str_t *src, ngx_str_t *dst)
{
u_char *d, *s;
- ngx_uint_t i;
+ size_t len;
static u_char basis64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -136,24 +136,28 @@ ngx_int_t ngx_encode_base64(ngx_pool_t *pool, ngx_str_t *src, ngx_str_t *dst)
dst->data = d;
s = src->data;
+ len = src->len;
- for (i = 0; i < src->len - 2; i += 3) {
- *d++ = basis64[(s[i] >> 2) & 0x3f];
- *d++ = basis64[((s[i] & 3) << 4) | (s[i + 1] >> 4)];
- *d++ = basis64[((s[i + 1] & 0x0f) << 2) | (s[i + 2] >> 6)];
- *d++ = basis64[s[i + 2] & 0x3f];
+ while (len > 2) {
+ *d++ = basis64[(s[0] >> 2) & 0x3f];
+ *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)];
+ *d++ = basis64[((s[1] & 0x0f) << 2) | (s[2] >> 6)];
+ *d++ = basis64[s[2] & 0x3f];
+
+ s += 3;
+ len -= 3;
}
- if (i < src->len) {
- *d++ = basis64[(s[i] >> 2) & 0x3f];
+ if (len) {
+ *d++ = basis64[(s[0] >> 2) & 0x3f];
- if (i == src->len - 1) {
- *d++ = basis64[(s[i] & 3) << 4];
+ if (len == 1) {
+ *d++ = basis64[(s[0] & 3) << 4];
*d++ = '=';
} else {
- *d++ = basis64[((s[i] & 3) << 4) | (s[i + 1] >> 4)];
- *d++ = basis64[(s[i + 1] & 0x0f) << 2];
+ *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)];
+ *d++ = basis64[(s[1] & 0x0f) << 2];
}
*d++ = '=';
@@ -168,34 +172,69 @@ ngx_int_t ngx_encode_base64(ngx_pool_t *pool, ngx_str_t *src, ngx_str_t *dst)
ngx_int_t ngx_decode_base64(ngx_pool_t *pool, ngx_str_t *src, ngx_str_t *dst)
{
- u_char *d, *s, c;
+ size_t len;
+ u_char *d, *s;
+ static u_char basis64[] =
+ { 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,
+ 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77,
+ 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77,
+
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 };
+
+ for (len = 0; len < src->len; len++) {
+ if (src->data[len] == '=') {
+ break;
+ }
+
+ if (basis64[src->data[len]] == 77) {
+ return NGX_ERROR;
+ }
+ }
+
+ if (len % 4 == 1) {
+ return NGX_ERROR;
+ }
- if (!(d = ngx_palloc(pool, ((src->len + 3) / 4) * 3))) {
+ if (!(d = ngx_palloc(pool, ((len + 3) / 4) * 3 + 1))) {
return NGX_ABORT;
}
dst->data = d;
- s = src->data;
-
- if (*s == '+') {
- c = 62;
- } else if (*s == '/') {
- c = 63;
+ s = src->data;
- } else if (*s >= '0' && *s <= '9') {
- c = *s - '0' + 52;
+ while (len > 3) {
+ *d++ = basis64[s[0]] << 2 | basis64[s[1]] >> 4;
+ *d++ = basis64[s[1]] << 4 | basis64[s[2]] >> 2;
+ *d++ = basis64[s[2]] << 6 | basis64[s[3]];
- } else if (*s >= 'A' && *s <= 'Z') {
- c = *s - 'A';
+ s += 4;
+ len -= 4;
+ }
- } else if (*s >= 'a' && *s <= 'z') {
- c = *s - 'a' + 26;
+ if (len > 1) {
+ *d++ = basis64[s[0]] << 2 | basis64[s[1]] >> 4;
+ }
- } else {
- return NGX_ERROR;
+ if (len > 2) {
+ *d++ = basis64[s[1]] << 4 | basis64[s[2]] >> 2;
}
+ dst->len = d - dst->data;
+ *d++ = '\0';
+
return NGX_OK;
}
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index d087e3e96..8a0212685 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -71,6 +71,9 @@ ngx_int_t ngx_hextoi(u_char *line, size_t n);
void ngx_md5_text(u_char *text, u_char *md5);
+ngx_int_t ngx_encode_base64(ngx_pool_t *pool, ngx_str_t *src, ngx_str_t *dst);
+ngx_int_t ngx_decode_base64(ngx_pool_t *pool, ngx_str_t *src, ngx_str_t *dst);
+
#define ngx_qsort qsort