mirror of https://github.com/grpc/grpc.git
commit
2877d7398e
1588 changed files with 19356 additions and 12798 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@ |
||||
Plugin for creating insecure channels using chttp2 |
@ -0,0 +1 @@ |
||||
Plugin for creating secure channels using chttp2 |
@ -0,0 +1 @@ |
||||
Plugin for creating insecure servers using chttp2 |
@ -0,0 +1 @@ |
||||
Plugin for creating secure servers using chttp2 |
@ -0,0 +1,4 @@ |
||||
chttp2 transport plugin - implements grpc over http2 |
||||
|
||||
Used by chttp2/{client,server}/{insecure,secure} plugins to implement most of |
||||
their functionality |
@ -0,0 +1,105 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015-2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/ext/transport/chttp2/transport/huffsyms.h" |
||||
|
||||
/* Constants pulled from the HPACK spec, and converted to C using the vim
|
||||
command: |
||||
:%s/.* \([0-9a-f]\+\) \[ *\([0-9]\+\)\]/{0x\1, \2},/g */ |
||||
const grpc_chttp2_huffsym grpc_chttp2_huffsyms[GRPC_CHTTP2_NUM_HUFFSYMS] = { |
||||
{0x1ff8, 13}, {0x7fffd8, 23}, {0xfffffe2, 28}, {0xfffffe3, 28}, |
||||
{0xfffffe4, 28}, {0xfffffe5, 28}, {0xfffffe6, 28}, {0xfffffe7, 28}, |
||||
{0xfffffe8, 28}, {0xffffea, 24}, {0x3ffffffc, 30}, {0xfffffe9, 28}, |
||||
{0xfffffea, 28}, {0x3ffffffd, 30}, {0xfffffeb, 28}, {0xfffffec, 28}, |
||||
{0xfffffed, 28}, {0xfffffee, 28}, {0xfffffef, 28}, {0xffffff0, 28}, |
||||
{0xffffff1, 28}, {0xffffff2, 28}, {0x3ffffffe, 30}, {0xffffff3, 28}, |
||||
{0xffffff4, 28}, {0xffffff5, 28}, {0xffffff6, 28}, {0xffffff7, 28}, |
||||
{0xffffff8, 28}, {0xffffff9, 28}, {0xffffffa, 28}, {0xffffffb, 28}, |
||||
{0x14, 6}, {0x3f8, 10}, {0x3f9, 10}, {0xffa, 12}, |
||||
{0x1ff9, 13}, {0x15, 6}, {0xf8, 8}, {0x7fa, 11}, |
||||
{0x3fa, 10}, {0x3fb, 10}, {0xf9, 8}, {0x7fb, 11}, |
||||
{0xfa, 8}, {0x16, 6}, {0x17, 6}, {0x18, 6}, |
||||
{0x0, 5}, {0x1, 5}, {0x2, 5}, {0x19, 6}, |
||||
{0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6}, |
||||
{0x1e, 6}, {0x1f, 6}, {0x5c, 7}, {0xfb, 8}, |
||||
{0x7ffc, 15}, {0x20, 6}, {0xffb, 12}, {0x3fc, 10}, |
||||
{0x1ffa, 13}, {0x21, 6}, {0x5d, 7}, {0x5e, 7}, |
||||
{0x5f, 7}, {0x60, 7}, {0x61, 7}, {0x62, 7}, |
||||
{0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, |
||||
{0x67, 7}, {0x68, 7}, {0x69, 7}, {0x6a, 7}, |
||||
{0x6b, 7}, {0x6c, 7}, {0x6d, 7}, {0x6e, 7}, |
||||
{0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, |
||||
{0xfc, 8}, {0x73, 7}, {0xfd, 8}, {0x1ffb, 13}, |
||||
{0x7fff0, 19}, {0x1ffc, 13}, {0x3ffc, 14}, {0x22, 6}, |
||||
{0x7ffd, 15}, {0x3, 5}, {0x23, 6}, {0x4, 5}, |
||||
{0x24, 6}, {0x5, 5}, {0x25, 6}, {0x26, 6}, |
||||
{0x27, 6}, {0x6, 5}, {0x74, 7}, {0x75, 7}, |
||||
{0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, |
||||
{0x2b, 6}, {0x76, 7}, {0x2c, 6}, {0x8, 5}, |
||||
{0x9, 5}, {0x2d, 6}, {0x77, 7}, {0x78, 7}, |
||||
{0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x7ffe, 15}, |
||||
{0x7fc, 11}, {0x3ffd, 14}, {0x1ffd, 13}, {0xffffffc, 28}, |
||||
{0xfffe6, 20}, {0x3fffd2, 22}, {0xfffe7, 20}, {0xfffe8, 20}, |
||||
{0x3fffd3, 22}, {0x3fffd4, 22}, {0x3fffd5, 22}, {0x7fffd9, 23}, |
||||
{0x3fffd6, 22}, {0x7fffda, 23}, {0x7fffdb, 23}, {0x7fffdc, 23}, |
||||
{0x7fffdd, 23}, {0x7fffde, 23}, {0xffffeb, 24}, {0x7fffdf, 23}, |
||||
{0xffffec, 24}, {0xffffed, 24}, {0x3fffd7, 22}, {0x7fffe0, 23}, |
||||
{0xffffee, 24}, {0x7fffe1, 23}, {0x7fffe2, 23}, {0x7fffe3, 23}, |
||||
{0x7fffe4, 23}, {0x1fffdc, 21}, {0x3fffd8, 22}, {0x7fffe5, 23}, |
||||
{0x3fffd9, 22}, {0x7fffe6, 23}, {0x7fffe7, 23}, {0xffffef, 24}, |
||||
{0x3fffda, 22}, {0x1fffdd, 21}, {0xfffe9, 20}, {0x3fffdb, 22}, |
||||
{0x3fffdc, 22}, {0x7fffe8, 23}, {0x7fffe9, 23}, {0x1fffde, 21}, |
||||
{0x7fffea, 23}, {0x3fffdd, 22}, {0x3fffde, 22}, {0xfffff0, 24}, |
||||
{0x1fffdf, 21}, {0x3fffdf, 22}, {0x7fffeb, 23}, {0x7fffec, 23}, |
||||
{0x1fffe0, 21}, {0x1fffe1, 21}, {0x3fffe0, 22}, {0x1fffe2, 21}, |
||||
{0x7fffed, 23}, {0x3fffe1, 22}, {0x7fffee, 23}, {0x7fffef, 23}, |
||||
{0xfffea, 20}, {0x3fffe2, 22}, {0x3fffe3, 22}, {0x3fffe4, 22}, |
||||
{0x7ffff0, 23}, {0x3fffe5, 22}, {0x3fffe6, 22}, {0x7ffff1, 23}, |
||||
{0x3ffffe0, 26}, {0x3ffffe1, 26}, {0xfffeb, 20}, {0x7fff1, 19}, |
||||
{0x3fffe7, 22}, {0x7ffff2, 23}, {0x3fffe8, 22}, {0x1ffffec, 25}, |
||||
{0x3ffffe2, 26}, {0x3ffffe3, 26}, {0x3ffffe4, 26}, {0x7ffffde, 27}, |
||||
{0x7ffffdf, 27}, {0x3ffffe5, 26}, {0xfffff1, 24}, {0x1ffffed, 25}, |
||||
{0x7fff2, 19}, {0x1fffe3, 21}, {0x3ffffe6, 26}, {0x7ffffe0, 27}, |
||||
{0x7ffffe1, 27}, {0x3ffffe7, 26}, {0x7ffffe2, 27}, {0xfffff2, 24}, |
||||
{0x1fffe4, 21}, {0x1fffe5, 21}, {0x3ffffe8, 26}, {0x3ffffe9, 26}, |
||||
{0xffffffd, 28}, {0x7ffffe3, 27}, {0x7ffffe4, 27}, {0x7ffffe5, 27}, |
||||
{0xfffec, 20}, {0xfffff3, 24}, {0xfffed, 20}, {0x1fffe6, 21}, |
||||
{0x3fffe9, 22}, {0x1fffe7, 21}, {0x1fffe8, 21}, {0x7ffff3, 23}, |
||||
{0x3fffea, 22}, {0x3fffeb, 22}, {0x1ffffee, 25}, {0x1ffffef, 25}, |
||||
{0xfffff4, 24}, {0xfffff5, 24}, {0x3ffffea, 26}, {0x7ffff4, 23}, |
||||
{0x3ffffeb, 26}, {0x7ffffe6, 27}, {0x3ffffec, 26}, {0x3ffffed, 26}, |
||||
{0x7ffffe7, 27}, {0x7ffffe8, 27}, {0x7ffffe9, 27}, {0x7ffffea, 27}, |
||||
{0x7ffffeb, 27}, {0xffffffe, 28}, {0x7ffffec, 27}, {0x7ffffed, 27}, |
||||
{0x7ffffee, 27}, {0x7ffffef, 27}, {0x7fffff0, 27}, {0x3ffffee, 26}, |
||||
{0x3fffffff, 30}, |
||||
}; |
@ -1,211 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/httpcli/parser.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/useful.h> |
||||
|
||||
static int handle_response_line(grpc_httpcli_parser *parser) { |
||||
uint8_t *beg = parser->cur_line; |
||||
uint8_t *cur = beg; |
||||
uint8_t *end = beg + parser->cur_line_length; |
||||
|
||||
if (cur == end || *cur++ != 'H') goto error; |
||||
if (cur == end || *cur++ != 'T') goto error; |
||||
if (cur == end || *cur++ != 'T') goto error; |
||||
if (cur == end || *cur++ != 'P') goto error; |
||||
if (cur == end || *cur++ != '/') goto error; |
||||
if (cur == end || *cur++ != '1') goto error; |
||||
if (cur == end || *cur++ != '.') goto error; |
||||
if (cur == end || *cur < '0' || *cur++ > '1') goto error; |
||||
if (cur == end || *cur++ != ' ') goto error; |
||||
if (cur == end || *cur < '1' || *cur++ > '9') goto error; |
||||
if (cur == end || *cur < '0' || *cur++ > '9') goto error; |
||||
if (cur == end || *cur < '0' || *cur++ > '9') goto error; |
||||
parser->r.status = |
||||
(cur[-3] - '0') * 100 + (cur[-2] - '0') * 10 + (cur[-1] - '0'); |
||||
if (cur == end || *cur++ != ' ') goto error; |
||||
|
||||
/* we don't really care about the status code message */ |
||||
|
||||
return 1; |
||||
|
||||
error: |
||||
gpr_log(GPR_ERROR, "Failed parsing response line"); |
||||
return 0; |
||||
} |
||||
|
||||
static char *buf2str(void *buffer, size_t length) { |
||||
char *out = gpr_malloc(length + 1); |
||||
memcpy(out, buffer, length); |
||||
out[length] = 0; |
||||
return out; |
||||
} |
||||
|
||||
static int add_header(grpc_httpcli_parser *parser) { |
||||
uint8_t *beg = parser->cur_line; |
||||
uint8_t *cur = beg; |
||||
uint8_t *end = beg + parser->cur_line_length; |
||||
grpc_httpcli_header hdr = {NULL, NULL}; |
||||
|
||||
GPR_ASSERT(cur != end); |
||||
|
||||
if (*cur == ' ' || *cur == '\t') { |
||||
gpr_log(GPR_ERROR, "Continued header lines not supported yet"); |
||||
goto error; |
||||
} |
||||
|
||||
while (cur != end && *cur != ':') { |
||||
cur++; |
||||
} |
||||
if (cur == end) { |
||||
gpr_log(GPR_ERROR, "Didn't find ':' in header string"); |
||||
goto error; |
||||
} |
||||
GPR_ASSERT(cur >= beg); |
||||
hdr.key = buf2str(beg, (size_t)(cur - beg)); |
||||
cur++; /* skip : */ |
||||
|
||||
while (cur != end && (*cur == ' ' || *cur == '\t')) { |
||||
cur++; |
||||
} |
||||
GPR_ASSERT(end - cur >= 2); |
||||
hdr.value = buf2str(cur, (size_t)(end - cur) - 2); |
||||
|
||||
if (parser->r.hdr_count == parser->hdr_capacity) { |
||||
parser->hdr_capacity = |
||||
GPR_MAX(parser->hdr_capacity + 1, parser->hdr_capacity * 3 / 2); |
||||
parser->r.hdrs = gpr_realloc( |
||||
parser->r.hdrs, parser->hdr_capacity * sizeof(*parser->r.hdrs)); |
||||
} |
||||
parser->r.hdrs[parser->r.hdr_count++] = hdr; |
||||
return 1; |
||||
|
||||
error: |
||||
gpr_free(hdr.key); |
||||
gpr_free(hdr.value); |
||||
return 0; |
||||
} |
||||
|
||||
static int finish_line(grpc_httpcli_parser *parser) { |
||||
switch (parser->state) { |
||||
case GRPC_HTTPCLI_INITIAL_RESPONSE: |
||||
if (!handle_response_line(parser)) { |
||||
return 0; |
||||
} |
||||
parser->state = GRPC_HTTPCLI_HEADERS; |
||||
break; |
||||
case GRPC_HTTPCLI_HEADERS: |
||||
if (parser->cur_line_length == 2) { |
||||
parser->state = GRPC_HTTPCLI_BODY; |
||||
break; |
||||
} |
||||
if (!add_header(parser)) { |
||||
return 0; |
||||
} |
||||
break; |
||||
case GRPC_HTTPCLI_BODY: |
||||
GPR_UNREACHABLE_CODE(return 0); |
||||
} |
||||
|
||||
parser->cur_line_length = 0; |
||||
return 1; |
||||
} |
||||
|
||||
static int addbyte(grpc_httpcli_parser *parser, uint8_t byte) { |
||||
switch (parser->state) { |
||||
case GRPC_HTTPCLI_INITIAL_RESPONSE: |
||||
case GRPC_HTTPCLI_HEADERS: |
||||
if (parser->cur_line_length >= GRPC_HTTPCLI_MAX_HEADER_LENGTH) { |
||||
gpr_log(GPR_ERROR, "HTTP client max line length (%d) exceeded", |
||||
GRPC_HTTPCLI_MAX_HEADER_LENGTH); |
||||
return 0; |
||||
} |
||||
parser->cur_line[parser->cur_line_length] = byte; |
||||
parser->cur_line_length++; |
||||
if (parser->cur_line_length >= 2 && |
||||
parser->cur_line[parser->cur_line_length - 2] == '\r' && |
||||
parser->cur_line[parser->cur_line_length - 1] == '\n') { |
||||
return finish_line(parser); |
||||
} else { |
||||
return 1; |
||||
} |
||||
GPR_UNREACHABLE_CODE(return 0); |
||||
case GRPC_HTTPCLI_BODY: |
||||
if (parser->r.body_length == parser->body_capacity) { |
||||
parser->body_capacity = GPR_MAX(8, parser->body_capacity * 3 / 2); |
||||
parser->r.body = |
||||
gpr_realloc((void *)parser->r.body, parser->body_capacity); |
||||
} |
||||
parser->r.body[parser->r.body_length] = (char)byte; |
||||
parser->r.body_length++; |
||||
return 1; |
||||
} |
||||
GPR_UNREACHABLE_CODE(return 0); |
||||
} |
||||
|
||||
void grpc_httpcli_parser_init(grpc_httpcli_parser *parser) { |
||||
memset(parser, 0, sizeof(*parser)); |
||||
parser->state = GRPC_HTTPCLI_INITIAL_RESPONSE; |
||||
parser->r.status = 500; |
||||
} |
||||
|
||||
void grpc_httpcli_parser_destroy(grpc_httpcli_parser *parser) { |
||||
size_t i; |
||||
gpr_free(parser->r.body); |
||||
for (i = 0; i < parser->r.hdr_count; i++) { |
||||
gpr_free(parser->r.hdrs[i].key); |
||||
gpr_free(parser->r.hdrs[i].value); |
||||
} |
||||
gpr_free(parser->r.hdrs); |
||||
} |
||||
|
||||
int grpc_httpcli_parser_parse(grpc_httpcli_parser *parser, gpr_slice slice) { |
||||
size_t i; |
||||
|
||||
for (i = 0; i < GPR_SLICE_LENGTH(slice); i++) { |
||||
if (!addbyte(parser, GPR_SLICE_START_PTR(slice)[i])) { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
return 1; |
||||
} |
||||
|
||||
int grpc_httpcli_parser_eof(grpc_httpcli_parser *parser) { |
||||
return parser->state == GRPC_HTTPCLI_BODY; |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue