mirror of https://github.com/grpc/grpc.git
Updating moe_db.txt with the latest equivalence since the ruby import changed the exported structure.
Change on 2014/12/01 by nnoble <nnoble@google.com> ------------- new [] file for grpc testing. Change on 2014/12/02 by donnadionne <donnadionne@google.com> ------------- Fix unfinished calls in thread_stress_test. Previously we had an early return if we cancelled a stream part way through a message. Correct this, so that half close and full close signals are propagated up the stack correctly so that higher level state machines can see the termination. Change on 2014/12/02 by ctiller <ctiller@google.com> ------------- Remove dependency on internal C code. Change on 2014/12/02 by ctiller <ctiller@google.com> ------------- Turn off the flaky bit from thread_stress_test. Change on 2014/12/02 by ctiller <ctiller@google.com> ------------- Add test cases of empty request/response, request streaming, response streaming, and half duplex streaming. Bring up the GFE/ESF for mannual test: [] build java/com/google/net/[]/testing/integration/hexa:server_components_env []-bin/java/com/google/net/[]/testing/integration/hexa/server_components_env --manual --rpc_port=25000 --use_autobahn Change on 2014/12/02 by chenw <chenw@google.com> ------------- Make echo/server.c and fling/server.c shutdown cleanly on SIGINT, and update the relevant tests to exercise this mechanism. Now "[] coverage" and the memory leak detector are able to see into the server processes. Change on 2014/12/02 by pmarks <pmarks@google.com> ------------- Allow the # of channels to be configurable in this performance test. The threads will use the channels in statically-defined round-robin order (not based on when RPCs complete on any channel). The interesting cases are #channels=1 or #channels=#threads (we previously only had the latter case) Change on 2014/12/02 by vpai <vpai@google.com> ------------- Fixed a typo and reworded a comment. Change on 2014/12/02 by gnezdo <gnezdo@google.com> ------------- Require the grpc_call in this ClientContext to be NULL before allowing set_call to be invoked. Otherwise, it's an indication of a leak somewhere. Change on 2014/12/02 by vpai <vpai@google.com> ------------- Correctly return status other than ok and add a test for it. Change on 2014/12/02 by yangg <yangg@google.com> ------------- Better C++ guards for grpc_security.h Change on 2014/12/02 by nnoble <nnoble@google.com> ------------- Use nullptr instead of NULL for consistency. Change on 2014/12/02 by vpai <vpai@google.com> ------------- Updates the ruby gRPC service class to require the serialization method to be a static method - this brings it inline with the proto3 ruby API - it adds a monkey patch to allow existing proto (beefcake) to continue working. Change on 2014/12/02 by temiola <temiola@google.com> ------------- Adding a buildable unit to the blue print file. Added the buildable unit as its name will be usesd as tap project id. This test will fail right away in tap until tests are actually added. Change on 2014/12/02 by donnadionne <donnadionne@google.com> ------------- Move interop ESF C++ server from Java to grpc directory. Tests passed: [] test javatests/com/google/net/[]/testing/integration/hexa/... [] test net/grpc/testing/interop/esf_server/... Change on 2014/12/02 by chenw <chenw@google.com> ------------- Return a lame channel as opposed to NULL when secure channel creation fails. - Looks like we're going to need something similar server-side. - I changed the prototype of the lame client channel factory to take an explicit void as I think this is better practice in C. Let me know if you disagree and I will revert these changes. Change on 2014/12/02 by jboeuf <jboeuf@google.com> ------------- Putting ALPN support where it belongs. Change on 2014/12/02 by jboeuf <jboeuf@google.com> ------------- GOAWAY send path. Sends a GOAWAY frame when shutting down. This is not read and understood yet. Change on 2014/12/03 by ctiller <ctiller@google.com> ------------- Adds support for secure channels and servers. - wraps new C apis (credentials, server_credentials) and Server#add_secure_http_port - adds tests to ensure credentials and server credentials can be created - updates client_server_spec to run the client_server wrapper layer end-to-end tests using a secure channel Change on 2014/12/03 by temiola <temiola@google.com> ------------- Fix existing issues regarding out of order events. At the client side, using pluck as the client_metadata_read can happen anytime after invoke. At the server side, allow halfclose_ok and rpc_end to come in reverse order. Change on 2014/12/03 by yangg <yangg@google.com> ------------- Don't track coverage of tests. Change on 2014/12/03 by ctiller <ctiller@google.com> ------------- Change UnaryCall to conform standard test requirement of LargeUnaryCall. Change on 2014/12/03 by yangg <yangg@google.com> ------------- updating alpn version to h2-15 ensure all interop are on the same version and working. Java and go are not ready for h2-16 yet. Change on 2014/12/03 by donnadionne <donnadionne@google.com> ------------- Add config to bring echo server in []. This is used to test production GFE as its bckend. Change on 2014/12/03 by chenw <chenw@google.com> ------------- In preparation for fixing shutdown race issues, change em to take ownership of the file descriptor. Add an API to grpc_tcp to take an already created grpc_em_fd object, and change tcp_client to use that API. This is needed because otherwise an em user's close() of the file descriptor may race with libevent internals. That's not an issue yet because destroy() frees the events inline, but that can't be done safely if there is a concurrent poller. Change on 2014/12/03 by klempner <klempner@google.com> ------------- Fixing TAP opensource build We don't want to compile and run C++ tests in the C target. Change on 2014/12/03 by nnoble <nnoble@google.com> ------------- Move and separate interop tests by languages. Small fixes to the test runner. Improving logging. Change on 2014/12/03 by donnadionne <donnadionne@google.com> ------------- Fixing the opensource build: -) The C/C++ split wasn't done up to the 'dep' target level -) The alpn.c file was missing from build.json Change on 2014/12/03 by nnoble <nnoble@google.com> ------------- Adding blue print files after projects exist Change on 2014/12/03 by donnadionne <donnadionne@google.com> ------------- Refactor StreamContext using the new completion_queue_pluck API. The dedicated the poller thread has been removed. This CL keeps the current behavior to make it short. There is one following to make it usable for both client and server. The tags for pluck is based on the address of this StreamContext object for potential debug use. The Read/Write and Wait cannot be called concurrently now and this might need to be fixed. Change on 2014/12/03 by yangg <yangg@google.com> ------------- Binary encoding utilities. Support base64 encoding, HPACK static huffman encoding, and doing both at once. Change on 2014/12/03 by ctiller <ctiller@google.com> ------------- Enforce Makefile regeneration in presubmits. Change on 2014/12/03 by ctiller <ctiller@google.com> ------------- Make CloseSend() send a real zero-length control message to indicate EOS. Change on 2014/12/03 by zhaoq <zhaoq@google.com> ------------- Prefer to create dualstack sockets for TCP clients and servers, with automatic fallback for environments where IPV6_V6ONLY can't be turned off. Change on 2014/12/03 by pmarks <pmarks@google.com> ------------- Add opensource path to build targets. Ensure that MOE is going to run. Change on 2014/12/03 by ctiller <ctiller@google.com> ------------- Add PingPong test case. Delete FullDuplex test case. The latter is not specified for client in https://docs.google.com/document/d/1dwrPpIu5EqiKVsquZfoOqTj7vP8fa1i49gornJo50Qw/edit# Change on 2014/12/03 by chenw <chenw@google.com> ------------- Make generate_projects.sh check out the generated targets. Change on 2014/12/03 by ctiller <ctiller@google.com> ------------- rspec cleanup - stops declaring specs within the GRPC module - splits Bidi streaming specs into a separate test suite adding tests in the GRPC module was a mistake, it pollutes the module and can affect other tests that run later by the test runner the bidi tests are currently flaky, having them run in their own test suite allows having two separate continuous builds (once ruby gRPC is on GitHub), one that includes bidi where we tolerate flakiness, and another that does not, where there should be no flakiness at all Change on 2014/12/03 by temiola <temiola@google.com> ------------- Adding support for composite and IAM credentials. - For now, we don't do any checks on credentials compatibility in the composite credentials. Maybe we'll add that later. - Refactored the end to end security tests so that we always use the public API (except for the fake security context which is not exposed). Change on 2014/12/03 by jboeuf <jboeuf@google.com> ------------- Make GPR library buildable in Visual Studio 2013. Change on 2014/12/04 by jtattermusch <jtattermusch@google.com> ------------- Adds codegen for ruby This is being added now that ruby's proto and grpc apis are defined and stable Change on 2014/12/04 by temiola <temiola@google.com> ------------- Prevent NewStream() from sending negative or 0 timeout. Change on 2014/12/04 by zhaoq <zhaoq@google.com> ------------- Add a grpc_sockaddr_to_string() function, and use it when logging bind failures. Also improve const-correctness in some earlier code. I'm not certain whether inet_ntop() will need any platform-specific implementations, but for now the compiler offers no complaints. Demo: $ []-bin/net/grpc/c/echo_server 1.2.3.4:80 ... tcp_server.c:139] bind addr=[::ffff:1.2.3.4]:80: Permission denied Change on 2014/12/04 by pmarks <pmarks@google.com> ------------- Refactoring - moves c wrapped classes to a submodule Google::RPC::Core - this allows for an explicit rule when reading through gRPC ruby code for telling when an object is pure ruby or wrapped C Change on 2014/12/04 by temiola <temiola@google.com> ------------- Fixes the bidi_call [] Change on 2014/12/04 by temiola <temiola@google.com> ------------- Fixing dev build when activating surface traces. Change on 2014/12/04 by nnoble <nnoble@google.com> ------------- Updates the tests to reflect that fact that some Credentials compose works. Change on 2014/12/04 by temiola <temiola@google.com> ------------- Making the generate_project_test actually do something. Change on 2014/12/04 by nnoble <nnoble@google.com> ------------- Rename "esf_server" to "[]4_server". Delete "test_sever" from Java directory. Change on 2014/12/04 by chenw <chenw@google.com> ------------- Added PHP client interop tests. Tested large_unary against the C++ server. Change on 2014/12/04 by mlumish <mlumish@google.com> ------------- Refactor grpc_create_dualstack_socket() by pulling the setsockopt into its own function. This separates the magic test flag from the real fallback logic. Change on 2014/12/04 by pmarks <pmarks@google.com> ------------- Fixes the type of the constant used for test cert hostname Change on 2014/12/04 by temiola <temiola@google.com> ------------- Disabling these tests as they're causing flakiness. Change on 2014/12/04 by ctiller <ctiller@google.com> ------------- Change intptr --> uintptr. Handles the case where a void* turns into a negative number, which then gets hashed into a negative bucket and segfaults. Change on 2014/12/04 by ctiller <ctiller@google.com> ------------- Add a test fixture to force parsers to handle one byte at a time. This should expand coverage and hopefully prevent errors at some point (it seems to pass out of the box for now though). Change on 2014/12/04 by ctiller <ctiller@google.com> ------------- The code generator isn't +x. Change on 2014/12/04 by ctiller <ctiller@google.com> ------------- Updates math_client and math_server to allow construction using crednetials By: - Extending rpc_server constructor so that it takes a credentials keyword param - Extending client_stub constructor so that it takes a credentials keyword param Change on 2014/12/04 by temiola <temiola@google.com> ------------- Format output a little more nicely. Print each line of output separately - previously logging.info was truncating this at some maximum length, and logs were getting lost. Change on 2014/12/04 by ctiller <ctiller@google.com> ------------- Up timeout for this test. Under TSAN, if we process one byte at a time, this timeout can be reached - and I think this is the cause of the following flake: [] Change on 2014/12/05 by ctiller <ctiller@google.com> ------------- Adding more error logging for ssl. Change on 2014/12/05 by jboeuf <jboeuf@google.com> ------------- Read path for goaway. Still need to add hooks to deprecate a channel on the client side when goaway is received. Change on 2014/12/05 by ctiller <ctiller@google.com> ------------- Separate accept() into server_accept() and server_end_of_initial_metadata(). This allows servers to initiate reads before finishing writing metadata. Change on 2014/12/05 by ctiller <ctiller@google.com> ------------- Fix for breakage 11512317 - adding missing test files. Change on 2014/12/05 by nnoble <nnoble@google.com> ------------- grpc c++ server side streaming support. This is based on [] There is a lot of room to clean up the internal implementation which may require refactoring of CompletionQueue. The current cl serves as a working implementation with the missing interfaces. The sample generated files are included and will be removed before submitting. Change on 2014/12/05 by yangg <yangg@google.com> ------------- Changed to the latest timeout format again (search "grpc-timeout" in [] for the spec). Change on 2014/12/05 by zhaoq <zhaoq@google.com> ------------- Fixing opensource build. Change on 2014/12/05 by nnoble <nnoble@google.com> ------------- Making absolutely sure we can do the moe export by adding a sh_test for it. Change on 2014/12/05 by nnoble <nnoble@google.com> ------------- Change :scheme psuedo-header from "grpc" to "http" or "https". Change on 2014/12/05 by zhaoq <zhaoq@google.com> ------------- Add server credential wrapping for c++ server. It only wraps ssl and []2 for now. The ServerCredentials class and the factory class are in a similar fashion as client side wrapping. The difference is the factory method returns shared_ptr instead of unique_ptr as the server builder needs to keep a reference to it for actually creating the server later. The integration will happen in a following cl. Change on 2014/12/05 by yangg <yangg@google.com> ------------- Fixed bugs in new_grpc_docker_builder.sh Change on 2014/12/05 by mlumish <mlumish@google.com> ------------- In secure endpoint, hold a refcount for the life of a write callback if the write does not complete immediately. Change on 2014/12/05 by klempner <klempner@google.com> ------------- Add migration support to MOE and have TAP verify it doesn't break. Migration support allows mirroring commits from [] into the git repo, instead of just a dump of the current source. Change on 2014/12/05 by ejona <ejona@google.com> ------------- Change initial window size to 65535 according http2 draft 15. Change on 2014/12/05 by zhaoq <zhaoq@google.com> ------------- Re-enable the flaky cases in dualstack_socket_test, with additional logging to help track down the problem if it surfaces again. This also seems like a good opportunity to make grpc_socket_utils a separate library, as it's not really specific to TCP. Example output: logspam: [], 26570) resolved 2 addrs in 37ms: logspam: [0] [::1]:26570 logspam: [1] 127.0.0.1:26570 Change on 2014/12/05 by pmarks <pmarks@google.com> ------------- Opensource build fixes. -) A function that has a return type should actually return something. -) Don't pass unsigned chars to strlen and strncmp. Change on 2014/12/05 by nnoble <nnoble@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=81458281pull/1/merge
parent
03dc30e76e
commit
0c475f0ad7
148 changed files with 7001 additions and 1914 deletions
@ -0,0 +1,77 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPCPP_SERVER_CREDENTIALS_H_ |
||||
#define __GRPCPP_SERVER_CREDENTIALS_H_ |
||||
|
||||
#include <memory> |
||||
|
||||
#include <grpc++/config.h> |
||||
|
||||
struct grpc_server_credentials; |
||||
|
||||
namespace grpc { |
||||
|
||||
// grpc_server_credentials wrapper class.
|
||||
class ServerCredentials final { |
||||
public: |
||||
~ServerCredentials(); |
||||
|
||||
private: |
||||
explicit ServerCredentials(grpc_server_credentials* c_creds); |
||||
|
||||
grpc_server_credentials* GetRawCreds(); |
||||
|
||||
friend class ServerCredentialsFactory; |
||||
|
||||
grpc_server_credentials* creds_; |
||||
}; |
||||
|
||||
// Options to create ServerCredentials with SSL
|
||||
struct SslServerCredentialsOptions { |
||||
grpc::string pem_root_certs; |
||||
grpc::string pem_private_key; |
||||
grpc::string pem_cert_chain; |
||||
}; |
||||
|
||||
// Factory for building different types of ServerCredentials
|
||||
class ServerCredentialsFactory { |
||||
public: |
||||
// Builds SSL ServerCredentials given SSL specific options
|
||||
static std::shared_ptr<ServerCredentials> SslCredentials( |
||||
const SslServerCredentialsOptions& options); |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // __GRPCPP_SERVER_CREDENTIALS_H_
|
@ -0,0 +1,81 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
/* Posix code for gpr snprintf support. */ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_WIN32 |
||||
|
||||
#include <stdio.h> |
||||
#include <stdarg.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
|
||||
int gpr_asprintf(char **strp, const char *format, ...) { |
||||
va_list args; |
||||
int ret; |
||||
size_t strp_buflen; |
||||
|
||||
/* Determine the length. */ |
||||
va_start(args, format); |
||||
ret = vscprintf(format, args); |
||||
va_end(args); |
||||
if (!(0 <= ret && ret < ~(size_t)0)) { |
||||
*strp = NULL; |
||||
return -1; |
||||
} |
||||
|
||||
/* Allocate a new buffer, with space for the NUL terminator. */ |
||||
strp_buflen = (size_t)ret + 1; |
||||
if ((*strp = gpr_malloc(strp_buflen)) == NULL) { |
||||
/* This shouldn't happen, because gpr_malloc() calls abort(). */ |
||||
return -1; |
||||
} |
||||
|
||||
/* Print to the buffer. */ |
||||
va_start(args, format); |
||||
ret = vsnprintf_s(*strp, strp_buflen, _TRUNCATE, format, args); |
||||
va_end(args); |
||||
if (ret == strp_buflen - 1) { |
||||
return ret; |
||||
} |
||||
|
||||
/* This should never happen. */ |
||||
gpr_free(*strp); |
||||
*strp = NULL; |
||||
return -1; |
||||
} |
||||
|
||||
#endif /* GPR_WIN32 */ |
@ -0,0 +1,45 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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/transport/chttp2/alpn.h" |
||||
|
||||
static const char *const supported_versions[] = {GRPC_CHTTP2_ALPN_VERSION, |
||||
"h2-15", "h2-14"}; |
||||
|
||||
int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size) { |
||||
size_t i; |
||||
for (i = 0; i < sizeof(supported_versions) / sizeof(const char *); i++) { |
||||
if (!strncmp(version, supported_versions[i], size)) return 1; |
||||
} |
||||
return 0; |
||||
} |
@ -0,0 +1,44 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPC_INTERNAL_TRANSPORT_CHTTP2_ALPN_H_ |
||||
#define __GRPC_INTERNAL_TRANSPORT_CHTTP2_ALPN_H_ |
||||
|
||||
#include <string.h> |
||||
|
||||
#define GRPC_CHTTP2_ALPN_VERSION "h2-15" |
||||
|
||||
/* Retuns 1 if the version is supported, 0 otherwise. */ |
||||
int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size); |
||||
|
||||
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_ALPN_H_ */ |
@ -0,0 +1,271 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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/transport/chttp2/bin_encoder.h" |
||||
#include "src/core/transport/chttp2/huffsyms.h" |
||||
#include <grpc/support/log.h> |
||||
|
||||
static const char alphabet[] = |
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
||||
|
||||
typedef struct { |
||||
gpr_uint16 bits; |
||||
gpr_uint8 length; |
||||
} b64_huff_sym; |
||||
|
||||
static const b64_huff_sym huff_alphabet[64] = {{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}, |
||||
{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}, |
||||
{0x0, 5}, |
||||
{0x1, 5}, |
||||
{0x2, 5}, |
||||
{0x19, 6}, |
||||
{0x1a, 6}, |
||||
{0x1b, 6}, |
||||
{0x1c, 6}, |
||||
{0x1d, 6}, |
||||
{0x1e, 6}, |
||||
{0x1f, 6}, |
||||
{0x7fb, 11}, |
||||
{0x18, 6}}; |
||||
|
||||
static const gpr_uint8 tail_xtra[3] = {0, 2, 3}; |
||||
|
||||
gpr_slice grpc_chttp2_base64_encode(gpr_slice input) { |
||||
size_t input_length = GPR_SLICE_LENGTH(input); |
||||
size_t input_triplets = input_length / 3; |
||||
size_t tail_case = input_length % 3; |
||||
size_t output_length = input_triplets * 4 + tail_xtra[tail_case]; |
||||
gpr_slice output = gpr_slice_malloc(output_length); |
||||
gpr_uint8 *in = GPR_SLICE_START_PTR(input); |
||||
gpr_uint8 *out = GPR_SLICE_START_PTR(output); |
||||
size_t i; |
||||
|
||||
/* encode full triplets */ |
||||
for (i = 0; i < input_triplets; i++) { |
||||
out[0] = alphabet[in[0] >> 2]; |
||||
out[1] = alphabet[((in[0] & 0x2) << 4) | (in[1] >> 4)]; |
||||
out[2] = alphabet[((in[1] & 0xf) << 2) | (in[2] >> 6)]; |
||||
out[3] = alphabet[in[2] & 0x3f]; |
||||
out += 4; |
||||
in += 3; |
||||
} |
||||
|
||||
/* encode the remaining bytes */ |
||||
switch (tail_case) { |
||||
case 0: |
||||
break; |
||||
case 1: |
||||
out[0] = alphabet[in[0] >> 2]; |
||||
out[1] = alphabet[(in[0] & 0x2) << 4]; |
||||
out += 2; |
||||
in += 1; |
||||
break; |
||||
case 2: |
||||
out[0] = alphabet[in[0] >> 2]; |
||||
out[1] = alphabet[((in[0] & 0x2) << 4) | (in[1] >> 4)]; |
||||
out[2] = alphabet[(in[1] & 0xf) << 2]; |
||||
out += 3; |
||||
in += 2; |
||||
break; |
||||
} |
||||
|
||||
GPR_ASSERT(out == GPR_SLICE_END_PTR(output)); |
||||
GPR_ASSERT(in == GPR_SLICE_END_PTR(input)); |
||||
return output; |
||||
} |
||||
|
||||
gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) { |
||||
size_t nbits; |
||||
gpr_uint8 *in; |
||||
gpr_uint8 *out; |
||||
gpr_slice output; |
||||
gpr_uint32 temp = 0; |
||||
gpr_uint32 temp_length = 0; |
||||
|
||||
nbits = 0; |
||||
for (in = GPR_SLICE_START_PTR(input); in != GPR_SLICE_END_PTR(input); ++in) { |
||||
nbits += grpc_chttp2_huffsyms[*in].length; |
||||
} |
||||
|
||||
output = gpr_slice_malloc(nbits / 8 + (nbits % 8 != 0)); |
||||
out = GPR_SLICE_START_PTR(output); |
||||
for (in = GPR_SLICE_START_PTR(input); in != GPR_SLICE_END_PTR(input); ++in) { |
||||
int sym = *in; |
||||
temp <<= grpc_chttp2_huffsyms[sym].length; |
||||
temp |= grpc_chttp2_huffsyms[sym].bits; |
||||
temp_length += grpc_chttp2_huffsyms[sym].length; |
||||
|
||||
while (temp_length > 8) { |
||||
temp_length -= 8; |
||||
*out++ = temp >> temp_length; |
||||
} |
||||
} |
||||
|
||||
if (temp_length) { |
||||
*out++ = (temp << (8 - temp_length)) | (0xff >> temp_length); |
||||
} |
||||
|
||||
GPR_ASSERT(out == GPR_SLICE_END_PTR(output)); |
||||
|
||||
return output; |
||||
} |
||||
|
||||
typedef struct { |
||||
gpr_uint32 temp; |
||||
gpr_uint32 temp_length; |
||||
gpr_uint8 *out; |
||||
} huff_out; |
||||
|
||||
static void enc_flush_some(huff_out *out) { |
||||
while (out->temp_length > 8) { |
||||
out->temp_length -= 8; |
||||
*out->out++ = out->temp >> out->temp_length; |
||||
} |
||||
} |
||||
|
||||
static void enc_add2(huff_out *out, gpr_uint8 a, gpr_uint8 b) { |
||||
b64_huff_sym sa = huff_alphabet[a]; |
||||
b64_huff_sym sb = huff_alphabet[b]; |
||||
out->temp = |
||||
(out->temp << (sa.length + sb.length)) | (sa.bits << sb.length) | sb.bits; |
||||
out->temp_length += sa.length + sb.length; |
||||
enc_flush_some(out); |
||||
} |
||||
|
||||
static void enc_add1(huff_out *out, gpr_uint8 a) { |
||||
b64_huff_sym sa = huff_alphabet[a]; |
||||
out->temp = (out->temp << sa.length) | sa.bits; |
||||
out->temp_length += sa.length; |
||||
enc_flush_some(out); |
||||
} |
||||
|
||||
gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) { |
||||
size_t input_length = GPR_SLICE_LENGTH(input); |
||||
size_t input_triplets = input_length / 3; |
||||
size_t tail_case = input_length % 3; |
||||
size_t output_syms = input_triplets * 4 + tail_xtra[tail_case]; |
||||
size_t max_output_bits = 11 * output_syms; |
||||
size_t max_output_length = max_output_bits / 8 + (max_output_bits % 8 != 0); |
||||
gpr_slice output = gpr_slice_malloc(max_output_length); |
||||
gpr_uint8 *in = GPR_SLICE_START_PTR(input); |
||||
gpr_uint8 *start_out = GPR_SLICE_START_PTR(output); |
||||
huff_out out; |
||||
size_t i; |
||||
|
||||
out.temp = 0; |
||||
out.temp_length = 0; |
||||
out.out = start_out; |
||||
|
||||
/* encode full triplets */ |
||||
for (i = 0; i < input_triplets; i++) { |
||||
enc_add2(&out, in[0] >> 2, ((in[0] & 0x2) << 4) | (in[1] >> 4)); |
||||
enc_add2(&out, ((in[1] & 0xf) << 2) | (in[2] >> 6), in[2] & 0x3f); |
||||
in += 3; |
||||
} |
||||
|
||||
/* encode the remaining bytes */ |
||||
switch (tail_case) { |
||||
case 0: |
||||
break; |
||||
case 1: |
||||
enc_add2(&out, in[0] >> 2, (in[0] & 0x2) << 4); |
||||
in += 1; |
||||
break; |
||||
case 2: |
||||
enc_add2(&out, in[0] >> 2, ((in[0] & 0x2) << 4) | (in[1] >> 4)); |
||||
enc_add1(&out, (in[1] & 0xf) << 2); |
||||
in += 2; |
||||
break; |
||||
} |
||||
|
||||
if (out.temp_length) { |
||||
*out.out++ = |
||||
(out.temp << (8 - out.temp_length)) | (0xff >> out.temp_length); |
||||
} |
||||
|
||||
GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output)); |
||||
GPR_SLICE_SET_LENGTH(output, out.out - start_out); |
||||
|
||||
GPR_ASSERT(in == GPR_SLICE_END_PTR(input)); |
||||
return output; |
||||
} |
@ -0,0 +1,54 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPC_INTERNAL_TRANSPORT_CHTTP2_BIN_ENCODER_H_ |
||||
#define __GRPC_INTERNAL_TRANSPORT_CHTTP2_BIN_ENCODER_H_ |
||||
|
||||
#include <grpc/support/slice.h> |
||||
|
||||
/* base64 encode a slice. Returns a new slice, does not take ownership of the
|
||||
input */ |
||||
gpr_slice grpc_chttp2_base64_encode(gpr_slice input); |
||||
|
||||
/* Compress a slice with the static huffman encoder detailed in the hpack
|
||||
standard. Returns a new slice, does not take ownership of the input */ |
||||
gpr_slice grpc_chttp2_huffman_compress(gpr_slice input); |
||||
|
||||
/* equivalent to:
|
||||
gpr_slice x = grpc_chttp2_base64_encode(input); |
||||
gpr_slice y = grpc_chttp2_huffman_compress(x); |
||||
gpr_slice_unref(x); |
||||
return y; */ |
||||
gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input); |
||||
|
||||
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_BIN_ENCODER_H_ */ |
@ -0,0 +1,189 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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/transport/chttp2/frame_goaway.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p) { |
||||
p->debug_data = NULL; |
||||
} |
||||
|
||||
void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p) { |
||||
gpr_free(p->debug_data); |
||||
} |
||||
|
||||
grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame( |
||||
grpc_chttp2_goaway_parser *p, gpr_uint32 length, gpr_uint8 flags) { |
||||
if (length < 8) { |
||||
gpr_log(GPR_ERROR, "goaway frame too short (%d bytes)", length); |
||||
return GRPC_CHTTP2_CONNECTION_ERROR; |
||||
} |
||||
|
||||
gpr_free(p->debug_data); |
||||
p->debug_length = length - 8; |
||||
p->debug_data = gpr_malloc(p->debug_length); |
||||
p->debug_pos = 0; |
||||
p->state = GRPC_CHTTP2_GOAWAY_LSI0; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
|
||||
grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( |
||||
void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, |
||||
int is_last) { |
||||
gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice); |
||||
gpr_uint8 *const end = GPR_SLICE_END_PTR(slice); |
||||
gpr_uint8 *cur = beg; |
||||
grpc_chttp2_goaway_parser *p = parser; |
||||
|
||||
switch (p->state) { |
||||
case GRPC_CHTTP2_GOAWAY_LSI0: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_LSI0; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->last_stream_id = ((gpr_uint32)*cur) << 24; |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_LSI1: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_LSI1; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->last_stream_id |= ((gpr_uint32)*cur) << 16; |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_LSI2: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_LSI2; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->last_stream_id |= ((gpr_uint32)*cur) << 8; |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_LSI3: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_LSI3; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->last_stream_id |= ((gpr_uint32)*cur); |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_ERR0: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_ERR0; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->error_code = ((gpr_uint32)*cur) << 24; |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_ERR1: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_ERR1; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->error_code |= ((gpr_uint32)*cur) << 16; |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_ERR2: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_ERR2; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->error_code |= ((gpr_uint32)*cur) << 8; |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_ERR3: |
||||
if (cur == end) { |
||||
p->state = GRPC_CHTTP2_GOAWAY_ERR3; |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
p->error_code |= ((gpr_uint32)*cur); |
||||
++cur; |
||||
/* fallthrough */ |
||||
case GRPC_CHTTP2_GOAWAY_DEBUG: |
||||
memcpy(p->debug_data + p->debug_pos, cur, end - cur); |
||||
p->debug_pos += end - cur; |
||||
p->state = GRPC_CHTTP2_GOAWAY_DEBUG; |
||||
if (is_last) { |
||||
state->goaway = 1; |
||||
state->goaway_last_stream_index = p->last_stream_id; |
||||
state->goaway_error = p->error_code; |
||||
state->goaway_text = |
||||
gpr_slice_new(p->debug_data, p->debug_length, gpr_free); |
||||
p->debug_data = NULL; |
||||
} |
||||
return GRPC_CHTTP2_PARSE_OK; |
||||
} |
||||
gpr_log(GPR_ERROR, "Should never end up here"); |
||||
abort(); |
||||
return GRPC_CHTTP2_CONNECTION_ERROR; |
||||
} |
||||
|
||||
void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, |
||||
gpr_slice debug_data, |
||||
gpr_slice_buffer *slice_buffer) { |
||||
gpr_slice header = gpr_slice_malloc(9 + 4 + 4); |
||||
gpr_uint8 *p = GPR_SLICE_START_PTR(header); |
||||
gpr_uint32 frame_length = 4 + 4 + GPR_SLICE_LENGTH(debug_data); |
||||
|
||||
/* frame header: length */ |
||||
*p++ = frame_length >> 16; |
||||
*p++ = frame_length >> 8; |
||||
*p++ = frame_length; |
||||
/* frame header: type */ |
||||
*p++ = GRPC_CHTTP2_FRAME_GOAWAY; |
||||
/* frame header: flags */ |
||||
*p++ = 0; |
||||
/* frame header: stream id */ |
||||
*p++ = 0; |
||||
*p++ = 0; |
||||
*p++ = 0; |
||||
*p++ = 0; |
||||
/* payload: last stream id */ |
||||
*p++ = last_stream_id >> 24; |
||||
*p++ = last_stream_id >> 16; |
||||
*p++ = last_stream_id >> 8; |
||||
*p++ = last_stream_id; |
||||
/* payload: error code */ |
||||
*p++ = error_code >> 24; |
||||
*p++ = error_code >> 16; |
||||
*p++ = error_code >> 8; |
||||
*p++ = error_code; |
||||
GPR_ASSERT(p == GPR_SLICE_END_PTR(header)); |
||||
gpr_slice_buffer_add(slice_buffer, header); |
||||
gpr_slice_buffer_add(slice_buffer, debug_data); |
||||
} |
@ -0,0 +1,74 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_GOAWAY_H_ |
||||
#define __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_GOAWAY_H_ |
||||
|
||||
#include "src/core/transport/chttp2/frame.h" |
||||
#include <grpc/support/port_platform.h> |
||||
#include <grpc/support/slice.h> |
||||
#include <grpc/support/slice_buffer.h> |
||||
|
||||
typedef enum { |
||||
GRPC_CHTTP2_GOAWAY_LSI0, |
||||
GRPC_CHTTP2_GOAWAY_LSI1, |
||||
GRPC_CHTTP2_GOAWAY_LSI2, |
||||
GRPC_CHTTP2_GOAWAY_LSI3, |
||||
GRPC_CHTTP2_GOAWAY_ERR0, |
||||
GRPC_CHTTP2_GOAWAY_ERR1, |
||||
GRPC_CHTTP2_GOAWAY_ERR2, |
||||
GRPC_CHTTP2_GOAWAY_ERR3, |
||||
GRPC_CHTTP2_GOAWAY_DEBUG |
||||
} grpc_chttp2_goaway_parse_state; |
||||
|
||||
typedef struct { |
||||
grpc_chttp2_goaway_parse_state state; |
||||
gpr_uint32 last_stream_id; |
||||
gpr_uint32 error_code; |
||||
char *debug_data; |
||||
gpr_uint32 debug_length; |
||||
gpr_uint32 debug_pos; |
||||
} grpc_chttp2_goaway_parser; |
||||
|
||||
void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p); |
||||
void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p); |
||||
grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame( |
||||
grpc_chttp2_goaway_parser *parser, gpr_uint32 length, gpr_uint8 flags); |
||||
grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( |
||||
void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, int is_last); |
||||
|
||||
void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, |
||||
gpr_slice debug_data, |
||||
gpr_slice_buffer *slice_buffer); |
||||
|
||||
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_GOAWAY_H_ */ |
@ -0,0 +1,297 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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/transport/chttp2/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}, |
||||
}; |
@ -0,0 +1,48 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef __GRPC_INTERNAL_TRANSPORT_CHTTP2_HUFFSYMS_H_ |
||||
#define __GRPC_INTERNAL_TRANSPORT_CHTTP2_HUFFSYMS_H_ |
||||
|
||||
/* HPACK static huffman table */ |
||||
|
||||
#define GRPC_CHTTP2_NUM_HUFFSYMS 257 |
||||
|
||||
typedef struct { |
||||
unsigned bits; |
||||
unsigned length; |
||||
} grpc_chttp2_huffsym; |
||||
|
||||
extern const grpc_chttp2_huffsym grpc_chttp2_huffsyms[GRPC_CHTTP2_NUM_HUFFSYMS]; |
||||
|
||||
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_HUFFSYMS_H_ */ |
@ -0,0 +1,62 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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 <grpc/grpc_security.h> |
||||
|
||||
#include <grpc++/server_credentials.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
ServerCredentials::ServerCredentials(grpc_server_credentials* c_creds) |
||||
: creds_(c_creds) {} |
||||
|
||||
ServerCredentials::~ServerCredentials() { |
||||
grpc_server_credentials_release(creds_); |
||||
} |
||||
|
||||
grpc_server_credentials* ServerCredentials::GetRawCreds() { return creds_; } |
||||
|
||||
std::shared_ptr<ServerCredentials> ServerCredentialsFactory::SslCredentials( |
||||
const SslServerCredentialsOptions& options) { |
||||
grpc_server_credentials* c_creds = grpc_ssl_server_credentials_create( |
||||
reinterpret_cast<const unsigned char*>(options.pem_root_certs.c_str()), |
||||
options.pem_root_certs.size(), |
||||
reinterpret_cast<const unsigned char*>(options.pem_private_key.c_str()), |
||||
options.pem_private_key.size(), |
||||
reinterpret_cast<const unsigned char*>(options.pem_cert_chain.c_str()), |
||||
options.pem_cert_chain.size()); |
||||
return std::shared_ptr<ServerCredentials>(new ServerCredentials(c_creds)); |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,301 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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 "rb_credentials.h" |
||||
|
||||
#include <ruby.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
|
||||
#include "rb_grpc.h" |
||||
|
||||
|
||||
/* grpc_rb_credentials wraps a grpc_credentials. It provides a
|
||||
* peer ruby object, 'mark' to minimize copying when a credential is |
||||
* created from ruby. */ |
||||
typedef struct grpc_rb_credentials { |
||||
/* Holder of ruby objects involved in constructing the credentials */ |
||||
VALUE mark; |
||||
|
||||
/* The actual credentials */ |
||||
grpc_credentials *wrapped; |
||||
} grpc_rb_credentials; |
||||
|
||||
/* Destroys the credentials instances. */ |
||||
static void grpc_rb_credentials_free(void *p) { |
||||
grpc_rb_credentials *wrapper = NULL; |
||||
if (p == NULL) { |
||||
return; |
||||
}; |
||||
wrapper = (grpc_rb_credentials *)p; |
||||
|
||||
/* Delete the wrapped object if the mark object is Qnil, which indicates that
|
||||
* no other object is the actual owner. */ |
||||
if (wrapper->wrapped != NULL && wrapper->mark == Qnil) { |
||||
grpc_credentials_release(wrapper->wrapped); |
||||
wrapper->wrapped = NULL; |
||||
} |
||||
|
||||
xfree(p); |
||||
} |
||||
|
||||
/* Protects the mark object from GC */ |
||||
static void grpc_rb_credentials_mark(void *p) { |
||||
grpc_rb_credentials *wrapper = NULL; |
||||
if (p == NULL) { |
||||
return; |
||||
} |
||||
wrapper = (grpc_rb_credentials *)p; |
||||
|
||||
/* If it's not already cleaned up, mark the mark object */ |
||||
if (wrapper->mark != Qnil) { |
||||
rb_gc_mark(wrapper->mark); |
||||
} |
||||
} |
||||
|
||||
/* Allocates Credential instances.
|
||||
|
||||
Provides safe initial defaults for the instance fields. */ |
||||
static VALUE grpc_rb_credentials_alloc(VALUE cls) { |
||||
grpc_rb_credentials *wrapper = ALLOC(grpc_rb_credentials); |
||||
wrapper->wrapped = NULL; |
||||
wrapper->mark = Qnil; |
||||
return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, |
||||
grpc_rb_credentials_free, |
||||
wrapper); |
||||
} |
||||
|
||||
/* Clones Credentials instances.
|
||||
|
||||
Gives Credentials a consistent implementation of Ruby's object copy/dup |
||||
protocol. */ |
||||
static VALUE grpc_rb_credentials_init_copy(VALUE copy, VALUE orig) { |
||||
grpc_rb_credentials *orig_cred = NULL; |
||||
grpc_rb_credentials *copy_cred = NULL; |
||||
|
||||
if (copy == orig) { |
||||
return copy; |
||||
} |
||||
|
||||
/* Raise an error if orig is not a credentials object or a subclass. */ |
||||
if (TYPE(orig) != T_DATA || |
||||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_credentials_free) { |
||||
rb_raise(rb_eTypeError, "not a %s", |
||||
rb_obj_classname(rb_cCredentials)); |
||||
} |
||||
|
||||
Data_Get_Struct(orig, grpc_rb_credentials, orig_cred); |
||||
Data_Get_Struct(copy, grpc_rb_credentials, copy_cred); |
||||
|
||||
/* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
|
||||
* wrapper object. */ |
||||
MEMCPY(copy_cred, orig_cred, grpc_rb_credentials, 1); |
||||
return copy; |
||||
} |
||||
|
||||
/*
|
||||
call-seq: |
||||
creds = Credentials.default() |
||||
|
||||
Creates the default credential instances. */ |
||||
static VALUE grpc_rb_default_credentials_create(VALUE cls) { |
||||
grpc_rb_credentials *wrapper = ALLOC(grpc_rb_credentials); |
||||
wrapper->wrapped = grpc_default_credentials_create(); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, |
||||
"could not create default credentials, not sure why"); |
||||
return Qnil; |
||||
} |
||||
|
||||
wrapper->mark = Qnil; |
||||
return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, |
||||
grpc_rb_credentials_free, wrapper); |
||||
} |
||||
|
||||
/*
|
||||
call-seq: |
||||
creds = Credentials.compute_engine() |
||||
|
||||
Creates the default credential instances. */ |
||||
static VALUE grpc_rb_compute_engine_credentials_create(VALUE cls) { |
||||
grpc_rb_credentials *wrapper = ALLOC(grpc_rb_credentials); |
||||
wrapper->wrapped = grpc_compute_engine_credentials_create(); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, |
||||
"could not create composite engine credentials, not sure why"); |
||||
return Qnil; |
||||
} |
||||
|
||||
wrapper->mark = Qnil; |
||||
return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, |
||||
grpc_rb_credentials_free, wrapper); |
||||
} |
||||
|
||||
/*
|
||||
call-seq: |
||||
creds1 = ... |
||||
creds2 = ... |
||||
creds3 = creds1.add(creds2) |
||||
|
||||
Creates the default credential instances. */ |
||||
static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) { |
||||
grpc_rb_credentials *self_wrapper = NULL; |
||||
grpc_rb_credentials *other_wrapper = NULL; |
||||
grpc_rb_credentials *wrapper = NULL; |
||||
|
||||
Data_Get_Struct(self, grpc_rb_credentials, self_wrapper); |
||||
Data_Get_Struct(other, grpc_rb_credentials, other_wrapper); |
||||
wrapper = ALLOC(grpc_rb_credentials); |
||||
wrapper->wrapped = grpc_composite_credentials_create(self_wrapper->wrapped, |
||||
other_wrapper->wrapped); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, |
||||
"could not create composite credentials, not sure why"); |
||||
return Qnil; |
||||
} |
||||
|
||||
wrapper->mark = Qnil; |
||||
return Data_Wrap_Struct(rb_cCredentials, grpc_rb_credentials_mark, |
||||
grpc_rb_credentials_free, wrapper); |
||||
} |
||||
|
||||
/* The attribute used on the mark object to hold the pem_root_certs. */ |
||||
static ID id_pem_root_certs; |
||||
|
||||
/* The attribute used on the mark object to hold the pem_private_key. */ |
||||
static ID id_pem_private_key; |
||||
|
||||
/* The attribute used on the mark object to hold the pem_private_key. */ |
||||
static ID id_pem_cert_chain; |
||||
|
||||
/*
|
||||
call-seq: |
||||
creds1 = Credentials.new(pem_root_certs) |
||||
... |
||||
creds2 = Credentials.new(pem_root_certs, pem_private_key, |
||||
pem_cert_chain) |
||||
|
||||
pem_root_certs: (required) PEM encoding of the server root certificate |
||||
pem_private_key: (optional) PEM encoding of the client's private key |
||||
pem_cert_chain: (optional) PEM encoding of the client's cert chain |
||||
|
||||
Initializes Credential instances. */ |
||||
static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) { |
||||
VALUE pem_root_certs = Qnil; |
||||
VALUE pem_private_key = Qnil; |
||||
VALUE pem_cert_chain = Qnil; |
||||
grpc_rb_credentials *wrapper = NULL; |
||||
grpc_credentials *creds = NULL; |
||||
/* "12" == 1 mandatory arg, 2 (credentials) is optional */ |
||||
rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key, |
||||
&pem_cert_chain); |
||||
|
||||
Data_Get_Struct(self, grpc_rb_credentials, wrapper); |
||||
if (pem_root_certs == Qnil) { |
||||
rb_raise(rb_eRuntimeError, |
||||
"could not create a credential: nil pem_root_certs"); |
||||
return Qnil; |
||||
} |
||||
if (pem_private_key == Qnil && pem_cert_chain == Qnil) { |
||||
creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), |
||||
RSTRING_LEN(pem_root_certs), NULL, 0, |
||||
NULL, 0); |
||||
} else if (pem_cert_chain == Qnil) { |
||||
creds = grpc_ssl_credentials_create( |
||||
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), |
||||
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key), |
||||
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain)); |
||||
} else if (pem_private_key == Qnil) { |
||||
creds = grpc_ssl_credentials_create( |
||||
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), |
||||
NULL, 0, |
||||
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain)); |
||||
} else { |
||||
creds = grpc_ssl_credentials_create( |
||||
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), |
||||
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key), |
||||
NULL, 0); |
||||
} |
||||
if (creds == NULL) { |
||||
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); |
||||
return Qnil; |
||||
} |
||||
wrapper->wrapped = creds; |
||||
|
||||
/* Add the input objects as hidden fields to preserve them. */ |
||||
rb_ivar_set(self, id_pem_cert_chain, pem_cert_chain); |
||||
rb_ivar_set(self, id_pem_private_key, pem_private_key); |
||||
rb_ivar_set(self, id_pem_root_certs, pem_root_certs); |
||||
|
||||
return self; |
||||
} |
||||
|
||||
/* rb_cCredentials is the ruby class that proxies grpc_credentials. */ |
||||
VALUE rb_cCredentials = Qnil; |
||||
|
||||
void Init_google_rpc_credentials() { |
||||
rb_cCredentials = rb_define_class_under(rb_mGoogleRpcCore, "Credentials", |
||||
rb_cObject); |
||||
|
||||
/* Allocates an object managed by the ruby runtime */ |
||||
rb_define_alloc_func(rb_cCredentials, grpc_rb_credentials_alloc); |
||||
|
||||
/* Provides a ruby constructor and support for dup/clone. */ |
||||
rb_define_method(rb_cCredentials, "initialize", |
||||
grpc_rb_credentials_init, -1); |
||||
rb_define_method(rb_cCredentials, "initialize_copy", |
||||
grpc_rb_credentials_init_copy, 1); |
||||
|
||||
/* Provide static funcs that create new special instances. */ |
||||
rb_define_singleton_method(rb_cCredentials, "default", |
||||
grpc_rb_default_credentials_create, 0); |
||||
|
||||
rb_define_singleton_method(rb_cCredentials, "compute_engine", |
||||
grpc_rb_compute_engine_credentials_create, 0); |
||||
|
||||
/* Provide other methods. */ |
||||
rb_define_method(rb_cCredentials, "compose", |
||||
grpc_rb_composite_credentials_create, 1); |
||||
|
||||
id_pem_cert_chain = rb_intern("__pem_cert_chain"); |
||||
id_pem_private_key = rb_intern("__pem_private_key"); |
||||
id_pem_root_certs = rb_intern("__pem_root_certs"); |
||||
} |
||||
|
||||
/* Gets the wrapped grpc_credentials from the ruby wrapper */ |
||||
grpc_credentials* grpc_rb_get_wrapped_credentials(VALUE v) { |
||||
grpc_rb_credentials *wrapper = NULL; |
||||
Data_Get_Struct(v, grpc_rb_credentials, wrapper); |
||||
return wrapper->wrapped; |
||||
} |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_RB_CREDENTIALS_H_ |
||||
#define GRPC_RB_CREDENTIALS_H_ |
||||
|
||||
#include <ruby.h> |
||||
#include <grpc/grpc_security.h> |
||||
|
||||
/* rb_cCredentials is the ruby class whose instances proxy
|
||||
grpc_credentials. */ |
||||
extern VALUE rb_cCredentials; |
||||
|
||||
/* Initializes the ruby Credentials class. */ |
||||
void Init_google_rpc_credentials(); |
||||
|
||||
/* Gets the wrapped credentials from the ruby wrapper */ |
||||
grpc_credentials* grpc_rb_get_wrapped_credentials(VALUE v); |
||||
|
||||
#endif /* GRPC_RB_CREDENTIALS_H_ */ |
@ -0,0 +1,215 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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 "rb_server_credentials.h" |
||||
|
||||
#include <ruby.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
|
||||
#include "rb_grpc.h" |
||||
|
||||
|
||||
/* grpc_rb_server_credentials wraps a grpc_server_credentials. It provides a
|
||||
peer ruby object, 'mark' to minimize copying when a server credential is |
||||
created from ruby. */ |
||||
typedef struct grpc_rb_server_credentials { |
||||
/* Holder of ruby objects involved in constructing the server credentials */ |
||||
VALUE mark; |
||||
/* The actual server credentials */ |
||||
grpc_server_credentials *wrapped; |
||||
} grpc_rb_server_credentials; |
||||
|
||||
/* Destroys the server credentials instances. */ |
||||
static void grpc_rb_server_credentials_free(void *p) { |
||||
grpc_rb_server_credentials *wrapper = NULL; |
||||
if (p == NULL) { |
||||
return; |
||||
}; |
||||
wrapper = (grpc_rb_server_credentials *)p; |
||||
|
||||
/* Delete the wrapped object if the mark object is Qnil, which indicates that
|
||||
no other object is the actual owner. */ |
||||
if (wrapper->wrapped != NULL && wrapper->mark == Qnil) { |
||||
grpc_server_credentials_release(wrapper->wrapped); |
||||
wrapper->wrapped = NULL; |
||||
} |
||||
|
||||
xfree(p); |
||||
} |
||||
|
||||
/* Protects the mark object from GC */ |
||||
static void grpc_rb_server_credentials_mark(void *p) { |
||||
grpc_rb_server_credentials *wrapper = NULL; |
||||
if (p == NULL) { |
||||
return; |
||||
} |
||||
wrapper = (grpc_rb_server_credentials *)p; |
||||
|
||||
/* If it's not already cleaned up, mark the mark object */ |
||||
if (wrapper->mark != Qnil) { |
||||
rb_gc_mark(wrapper->mark); |
||||
} |
||||
} |
||||
|
||||
/* Allocates ServerCredential instances.
|
||||
|
||||
Provides safe initial defaults for the instance fields. */ |
||||
static VALUE grpc_rb_server_credentials_alloc(VALUE cls) { |
||||
grpc_rb_server_credentials *wrapper = ALLOC(grpc_rb_server_credentials); |
||||
wrapper->wrapped = NULL; |
||||
wrapper->mark = Qnil; |
||||
return Data_Wrap_Struct(cls, grpc_rb_server_credentials_mark, |
||||
grpc_rb_server_credentials_free, |
||||
wrapper); |
||||
} |
||||
|
||||
/* Clones ServerCredentials instances.
|
||||
|
||||
Gives ServerCredentials a consistent implementation of Ruby's object copy/dup |
||||
protocol. */ |
||||
static VALUE grpc_rb_server_credentials_init_copy(VALUE copy, VALUE orig) { |
||||
grpc_rb_server_credentials *orig_ch = NULL; |
||||
grpc_rb_server_credentials *copy_ch = NULL; |
||||
|
||||
if (copy == orig) { |
||||
return copy; |
||||
} |
||||
|
||||
/* Raise an error if orig is not a server_credentials object or a subclass. */ |
||||
if (TYPE(orig) != T_DATA || |
||||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_credentials_free) { |
||||
rb_raise(rb_eTypeError, "not a %s", |
||||
rb_obj_classname(rb_cServerCredentials)); |
||||
} |
||||
|
||||
Data_Get_Struct(orig, grpc_rb_server_credentials, orig_ch); |
||||
Data_Get_Struct(copy, grpc_rb_server_credentials, copy_ch); |
||||
|
||||
/* use ruby's MEMCPY to make a byte-for-byte copy of the server_credentials
|
||||
wrapper object. */ |
||||
MEMCPY(copy_ch, orig_ch, grpc_rb_server_credentials, 1); |
||||
return copy; |
||||
} |
||||
|
||||
|
||||
/* The attribute used on the mark object to hold the pem_root_certs. */ |
||||
static ID id_pem_root_certs; |
||||
|
||||
/* The attribute used on the mark object to hold the pem_private_key. */ |
||||
static ID id_pem_private_key; |
||||
|
||||
/* The attribute used on the mark object to hold the pem_private_key. */ |
||||
static ID id_pem_cert_chain; |
||||
|
||||
/*
|
||||
call-seq: |
||||
creds = ServerCredentials.new(pem_root_certs, pem_private_key, |
||||
pem_cert_chain) |
||||
creds = ServerCredentials.new(nil, pem_private_key, |
||||
pem_cert_chain) |
||||
|
||||
pem_root_certs: (required) PEM encoding of the server root certificate |
||||
pem_private_key: (optional) PEM encoding of the server's private key |
||||
pem_cert_chain: (optional) PEM encoding of the server's cert chain |
||||
|
||||
Initializes ServerCredential instances. */ |
||||
static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs, |
||||
VALUE pem_private_key, |
||||
VALUE pem_cert_chain) { |
||||
grpc_rb_server_credentials *wrapper = NULL; |
||||
grpc_server_credentials *creds = NULL; |
||||
Data_Get_Struct(self, grpc_rb_server_credentials, wrapper); |
||||
if (pem_cert_chain == Qnil) { |
||||
rb_raise(rb_eRuntimeError, |
||||
"could not create a server credential: nil pem_cert_chain"); |
||||
return Qnil; |
||||
} else if (pem_private_key == Qnil) { |
||||
rb_raise(rb_eRuntimeError, |
||||
"could not create a server credential: nil pem_private_key"); |
||||
return Qnil; |
||||
} |
||||
if (pem_root_certs == Qnil) { |
||||
creds = grpc_ssl_server_credentials_create( |
||||
NULL, 0, RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key), |
||||
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain)); |
||||
} else { |
||||
creds = grpc_ssl_server_credentials_create( |
||||
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), |
||||
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key), |
||||
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain)); |
||||
} |
||||
if (creds == NULL) { |
||||
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); |
||||
} |
||||
wrapper->wrapped = creds; |
||||
|
||||
/* Add the input objects as hidden fields to preserve them. */ |
||||
rb_ivar_set(self, id_pem_cert_chain, pem_cert_chain); |
||||
rb_ivar_set(self, id_pem_private_key, pem_private_key); |
||||
rb_ivar_set(self, id_pem_root_certs, pem_root_certs); |
||||
|
||||
return self; |
||||
} |
||||
|
||||
/* rb_cServerCredentials is the ruby class that proxies
|
||||
grpc_server_credentials. */ |
||||
VALUE rb_cServerCredentials = Qnil; |
||||
|
||||
void Init_google_rpc_server_credentials() { |
||||
rb_cServerCredentials = rb_define_class_under(rb_mGoogleRpcCore, |
||||
"ServerCredentials", |
||||
rb_cObject); |
||||
|
||||
/* Allocates an object managed by the ruby runtime */ |
||||
rb_define_alloc_func(rb_cServerCredentials, grpc_rb_server_credentials_alloc); |
||||
|
||||
/* Provides a ruby constructor and support for dup/clone. */ |
||||
rb_define_method(rb_cServerCredentials, "initialize", |
||||
grpc_rb_server_credentials_init, 3); |
||||
rb_define_method(rb_cServerCredentials, "initialize_copy", |
||||
grpc_rb_server_credentials_init_copy, |
||||
1); |
||||
|
||||
id_pem_cert_chain = rb_intern("__pem_cert_chain"); |
||||
id_pem_private_key = rb_intern("__pem_private_key"); |
||||
id_pem_root_certs = rb_intern("__pem_root_certs"); |
||||
} |
||||
|
||||
/* Gets the wrapped grpc_server_credentials from the ruby wrapper */ |
||||
grpc_server_credentials* grpc_rb_get_wrapped_server_credentials(VALUE v) { |
||||
grpc_rb_server_credentials *wrapper = NULL; |
||||
Data_Get_Struct(v, grpc_rb_server_credentials, wrapper); |
||||
return wrapper->wrapped; |
||||
} |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2014, 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_RB_SERVER_CREDENTIALS_H_ |
||||
#define GRPC_RB_SERVER_CREDENTIALS_H_ |
||||
|
||||
#include <ruby.h> |
||||
#include <grpc/grpc_security.h> |
||||
|
||||
/* rb_cServerCredentials is the ruby class whose instances proxy
|
||||
grpc_server_credentials. */ |
||||
extern VALUE rb_cServerCredentials; |
||||
|
||||
/* Initializes the ruby ServerCredentials class. */ |
||||
void Init_google_rpc_server_credentials(); |
||||
|
||||
/* Gets the wrapped server_credentials from the ruby wrapper */ |
||||
grpc_server_credentials* grpc_rb_get_wrapped_server_credentials(VALUE v); |
||||
|
||||
#endif /* GRPC_RB_SERVER_CREDENTIALS_H_ */ |
@ -0,0 +1,62 @@ |
||||
# Copyright 2014, 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. |
||||
|
||||
require 'beefcake' |
||||
|
||||
# Re-open the beefcake message module to add a static encode |
||||
# |
||||
# This is a temporary measure while beefcake is used as the default proto |
||||
# library for developing grpc ruby. Once that changes to the official proto |
||||
# library this can be removed. It's necessary to allow the update the service |
||||
# module to assume a static encode method. |
||||
# |
||||
# TODO(temiola): remove me, once official code generation is available in protoc |
||||
module Beefcake |
||||
module Message |
||||
|
||||
# additional mixin module that adds static encode method when include |
||||
module StaticEncode |
||||
|
||||
# encodes o with its instance#encode method |
||||
def encode(o) |
||||
o.encode |
||||
end |
||||
|
||||
end |
||||
|
||||
# extend self.included in Beefcake::Message to include StaticEncode |
||||
def self.included(o) |
||||
o.extend StaticEncode |
||||
o.extend Dsl |
||||
o.extend Decode |
||||
o.send(:include, Encode) |
||||
end |
||||
|
||||
end |
||||
end |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue