Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D5C692009D9 for ; Wed, 18 May 2016 04:50:32 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D43FF160A25; Wed, 18 May 2016 02:50:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 864CB160A24 for ; Wed, 18 May 2016 04:50:30 +0200 (CEST) Received: (qmail 54115 invoked by uid 500); 18 May 2016 02:50:29 -0000 Mailing-List: contact commits-help@hawq.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hawq.incubator.apache.org Delivered-To: mailing list commits@hawq.incubator.apache.org Received: (qmail 54106 invoked by uid 99); 18 May 2016 02:50:29 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 May 2016 02:50:29 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 2AE5C1A52D3 for ; Wed, 18 May 2016 02:50:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id sppthP7sDMyr for ; Wed, 18 May 2016 02:50:16 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id 9B5915FBD2 for ; Wed, 18 May 2016 02:50:15 +0000 (UTC) Received: (qmail 53333 invoked by uid 99); 18 May 2016 02:50:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 May 2016 02:50:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 83E42E947B; Wed, 18 May 2016 02:50:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: rlei@apache.org To: commits@hawq.incubator.apache.org Date: Wed, 18 May 2016 02:50:19 -0000 Message-Id: In-Reply-To: <04ef34dcbc8745b3a15238fab69ea80a@git.apache.org> References: <04ef34dcbc8745b3a15238fab69ea80a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/51] [abbrv] [partial] incubator-hawq git commit: HAWQ-735. Import thrift-0.9.3 into depends/thirdparty/thrift folder archived-at: Wed, 18 May 2016 02:50:33 -0000 http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/Makefile.am ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/Makefile.am b/depends/thirdparty/thrift/lib/cpp/Makefile.am new file mode 100755 index 0000000..4742ee0 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/Makefile.am @@ -0,0 +1,276 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +AUTOMAKE_OPTIONS = subdir-objects + +moc_%.cpp: %.h + $(QT_MOC) $(QT_CFLAGS) $< -o $@ + +moc__%.cpp: %.h + $(QT5_MOC) $(QT5_CFLAGS) $< -o $@ + +SUBDIRS = . + +if WITH_TESTS +SUBDIRS += test +endif + +pkgconfigdir = $(libdir)/pkgconfig + +lib_LTLIBRARIES = libthrift.la +pkgconfig_DATA = thrift.pc +libthrift_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) $(OPENSSL_LDFLAGS) + +## We only build the extra libraries if we have the dependencies, +## but we install all of the headers unconditionally. +if AMX_HAVE_LIBEVENT +lib_LTLIBRARIES += libthriftnb.la +pkgconfig_DATA += thrift-nb.pc +endif +if AMX_HAVE_ZLIB +lib_LTLIBRARIES += libthriftz.la +pkgconfig_DATA += thrift-z.pc +endif +if AMX_HAVE_QT +lib_LTLIBRARIES += libthriftqt.la +pkgconfig_DATA += thrift-qt.pc +endif +if AMX_HAVE_QT5 +lib_LTLIBRARIES += libthriftqt5.la +pkgconfig_DATA += thrift-qt5.pc +endif + +AM_CXXFLAGS = -Wall -Wextra -pedantic +AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(OPENSSL_INCLUDES) -I$(srcdir)/src -D__STDC_LIMIT_MACROS +AM_LDFLAGS = $(BOOST_LDFLAGS) $(OPENSSL_LDFLAGS) + +# Define the source files for the module + +libthrift_la_SOURCES = src/thrift/TApplicationException.cpp \ + src/thrift/TOutput.cpp \ + src/thrift/VirtualProfiling.cpp \ + src/thrift/async/TAsyncChannel.cpp \ + src/thrift/async/TConcurrentClientSyncInfo.cpp \ + src/thrift/concurrency/ThreadManager.cpp \ + src/thrift/concurrency/TimerManager.cpp \ + src/thrift/concurrency/Util.cpp \ + src/thrift/processor/PeekProcessor.cpp \ + src/thrift/protocol/TDebugProtocol.cpp \ + src/thrift/protocol/TJSONProtocol.cpp \ + src/thrift/protocol/TBase64Utils.cpp \ + src/thrift/protocol/TMultiplexedProtocol.cpp \ + src/thrift/protocol/TProtocol.cpp \ + src/thrift/transport/TTransportException.cpp \ + src/thrift/transport/TFDTransport.cpp \ + src/thrift/transport/TFileTransport.cpp \ + src/thrift/transport/TSimpleFileTransport.cpp \ + src/thrift/transport/THttpTransport.cpp \ + src/thrift/transport/THttpClient.cpp \ + src/thrift/transport/THttpServer.cpp \ + src/thrift/transport/TSocket.cpp \ + src/thrift/transport/TPipe.cpp \ + src/thrift/transport/TPipeServer.cpp \ + src/thrift/transport/TSSLSocket.cpp \ + src/thrift/transport/TSocketPool.cpp \ + src/thrift/transport/TServerSocket.cpp \ + src/thrift/transport/TSSLServerSocket.cpp \ + src/thrift/transport/TTransportUtils.cpp \ + src/thrift/transport/TBufferTransports.cpp \ + src/thrift/server/TConnectedClient.cpp \ + src/thrift/server/TServer.cpp \ + src/thrift/server/TServerFramework.cpp \ + src/thrift/server/TSimpleServer.cpp \ + src/thrift/server/TThreadPoolServer.cpp \ + src/thrift/server/TThreadedServer.cpp + +if WITH_BOOSTTHREADS +libthrift_la_SOURCES += src/thrift/concurrency/BoostThreadFactory.cpp \ + src/thrift/concurrency/BoostMonitor.cpp \ + src/thrift/concurrency/BoostMutex.cpp +else +libthrift_la_SOURCES += src/thrift/concurrency/Mutex.cpp \ + src/thrift/concurrency/Monitor.cpp \ + src/thrift/concurrency/PosixThreadFactory.cpp +endif + +libthriftnb_la_SOURCES = src/thrift/server/TNonblockingServer.cpp \ + src/thrift/async/TAsyncProtocolProcessor.cpp \ + src/thrift/async/TEvhttpServer.cpp \ + src/thrift/async/TEvhttpClientChannel.cpp + +libthriftz_la_SOURCES = src/thrift/transport/TZlibTransport.cpp + +libthriftqt_la_MOC = src/thrift/qt/moc_TQTcpServer.cpp +nodist_libthriftqt_la_SOURCES = $(libthriftqt_la_MOC) +libthriftqt_la_SOURCES = src/thrift/qt/TQIODeviceTransport.cpp \ + src/thrift/qt/TQTcpServer.cpp +CLEANFILES = $(libthriftqt_la_MOC) + +libthriftqt5_la_MOC = src/thrift/qt/moc__TQTcpServer.cpp +nodist_libthriftqt5_la_SOURCES = $(libthriftqt5_la_MOC) +libthriftqt5_la_SOURCES = src/thrift/qt/TQIODeviceTransport.cpp \ + src/thrift/qt/TQTcpServer.cpp +CLEANFILES += $(libthriftqt5_la_MOC) + +# Flags for the various libraries +libthriftnb_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBEVENT_CPPFLAGS) +libthriftz_la_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CPPFLAGS) +libthriftqt_la_CPPFLAGS = $(AM_CPPFLAGS) $(QT_CFLAGS) +libthriftqt5_la_CPPFLAGS = $(AM_CPPFLAGS) $(QT5_CFLAGS) +if QT5_REDUCE_RELOCATIONS +libthriftqt5_la_CPPFLAGS += -fPIC +endif +libthriftnb_la_CXXFLAGS = $(AM_CXXFLAGS) +libthriftz_la_CXXFLAGS = $(AM_CXXFLAGS) +libthriftqt_la_CXXFLAGS = $(AM_CXXFLAGS) +libthriftqt5_la_CXXFLAGS = $(AM_CXXFLAGS) +libthriftnb_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) +libthriftz_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) +libthriftqt_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) $(QT_LIBS) +libthriftqt5_la_LDFLAGS = -release $(VERSION) $(BOOST_LDFLAGS) $(QT5_LIBS) + +include_thriftdir = $(includedir)/thrift +include_thrift_HEADERS = \ + $(top_builddir)/config.h \ + src/thrift/thrift-config.h \ + src/thrift/TDispatchProcessor.h \ + src/thrift/Thrift.h \ + src/thrift/TOutput.h \ + src/thrift/TProcessor.h \ + src/thrift/TApplicationException.h \ + src/thrift/TLogging.h \ + src/thrift/cxxfunctional.h \ + src/thrift/TToString.h + +include_concurrencydir = $(include_thriftdir)/concurrency +include_concurrency_HEADERS = \ + src/thrift/concurrency/BoostThreadFactory.h \ + src/thrift/concurrency/Exception.h \ + src/thrift/concurrency/Mutex.h \ + src/thrift/concurrency/Monitor.h \ + src/thrift/concurrency/PlatformThreadFactory.h \ + src/thrift/concurrency/PosixThreadFactory.h \ + src/thrift/concurrency/StdMonitor.cpp \ + src/thrift/concurrency/StdMutex.cpp \ + src/thrift/concurrency/StdThreadFactory.cpp \ + src/thrift/concurrency/StdThreadFactory.h \ + src/thrift/concurrency/Thread.h \ + src/thrift/concurrency/ThreadManager.h \ + src/thrift/concurrency/TimerManager.h \ + src/thrift/concurrency/FunctionRunner.h \ + src/thrift/concurrency/Util.h + +include_protocoldir = $(include_thriftdir)/protocol +include_protocol_HEADERS = \ + src/thrift/protocol/TBinaryProtocol.h \ + src/thrift/protocol/TBinaryProtocol.tcc \ + src/thrift/protocol/TCompactProtocol.h \ + src/thrift/protocol/TCompactProtocol.tcc \ + src/thrift/protocol/TDebugProtocol.h \ + src/thrift/protocol/TBase64Utils.h \ + src/thrift/protocol/TJSONProtocol.h \ + src/thrift/protocol/TMultiplexedProtocol.h \ + src/thrift/protocol/TProtocolDecorator.h \ + src/thrift/protocol/TProtocolTap.h \ + src/thrift/protocol/TProtocolException.h \ + src/thrift/protocol/TVirtualProtocol.h \ + src/thrift/protocol/TProtocol.h + +include_transportdir = $(include_thriftdir)/transport +include_transport_HEADERS = \ + src/thrift/transport/PlatformSocket.h \ + src/thrift/transport/TFDTransport.h \ + src/thrift/transport/TFileTransport.h \ + src/thrift/transport/TSimpleFileTransport.h \ + src/thrift/transport/TServerSocket.h \ + src/thrift/transport/TSSLServerSocket.h \ + src/thrift/transport/TServerTransport.h \ + src/thrift/transport/THttpTransport.h \ + src/thrift/transport/THttpClient.h \ + src/thrift/transport/THttpServer.h \ + src/thrift/transport/TSocket.h \ + src/thrift/transport/TPipe.h \ + src/thrift/transport/TPipeServer.h \ + src/thrift/transport/TSSLSocket.h \ + src/thrift/transport/TSocketPool.h \ + src/thrift/transport/TVirtualTransport.h \ + src/thrift/transport/TTransport.h \ + src/thrift/transport/TTransportException.h \ + src/thrift/transport/TTransportUtils.h \ + src/thrift/transport/TBufferTransports.h \ + src/thrift/transport/TShortReadTransport.h \ + src/thrift/transport/TZlibTransport.h + +include_serverdir = $(include_thriftdir)/server +include_server_HEADERS = \ + src/thrift/server/TConnectedClient.h \ + src/thrift/server/TServer.h \ + src/thrift/server/TServerFramework.h \ + src/thrift/server/TSimpleServer.h \ + src/thrift/server/TThreadPoolServer.h \ + src/thrift/server/TThreadedServer.h \ + src/thrift/server/TNonblockingServer.h + +include_processordir = $(include_thriftdir)/processor +include_processor_HEADERS = \ + src/thrift/processor/PeekProcessor.h \ + src/thrift/processor/StatsProcessor.h \ + src/thrift/processor/TMultiplexedProcessor.h + +include_asyncdir = $(include_thriftdir)/async +include_async_HEADERS = \ + src/thrift/async/TAsyncChannel.h \ + src/thrift/async/TAsyncDispatchProcessor.h \ + src/thrift/async/TAsyncProcessor.h \ + src/thrift/async/TAsyncBufferProcessor.h \ + src/thrift/async/TAsyncProtocolProcessor.h \ + src/thrift/async/TConcurrentClientSyncInfo.h \ + src/thrift/async/TEvhttpClientChannel.h \ + src/thrift/async/TEvhttpServer.h + +include_qtdir = $(include_thriftdir)/qt +include_qt_HEADERS = \ + src/thrift/qt/TQIODeviceTransport.h \ + src/thrift/qt/TQTcpServer.h + +THRIFT = $(top_builddir)/compiler/cpp/thrift + +WINDOWS_DIST = \ + src/thrift/windows \ + thrift.sln \ + libthrift.vcxproj \ + libthrift.vcxproj.filters \ + libthriftnb.vcxproj \ + libthriftnb.vcxproj.filters \ + 3rdparty.props + +EXTRA_DIST = \ + CMakeLists.txt \ + coding_standards.md \ + README.md \ + thrift-nb.pc.in \ + thrift.pc.in \ + thrift-z.pc.in \ + thrift-qt.pc.in \ + thrift-qt5.pc.in \ + src/thrift/qt/CMakeLists.txt \ + $(WINDOWS_DIST) + +style-local: + $(CPPSTYLE_CMD) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/README.md ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/README.md b/depends/thirdparty/thrift/lib/cpp/README.md new file mode 100755 index 0000000..2bee2ec --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/README.md @@ -0,0 +1,274 @@ +Thrift C++ Software Library + +# License + +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. + + +# Using Thrift with C++ + +The Thrift C++ libraries are built using the GNU tools. Follow the instructions +in the top-level README.md + +In case you do not want to open another README.md file, do this thrift src: + + ./bootstrap.sh + ./configure (--with-boost=/usr/local) + make + sudo make install + +Thrift is divided into two libraries. + +* libthrift - The core Thrift library contains all the core Thrift code. It requires + boost shared pointers, pthreads, and librt. + +* libthriftnb - This library contains the Thrift nonblocking server, which uses libevent. + To link this library you will also need to link libevent. + +## Linking Against Thrift + +After you build and install Thrift the libraries are installed to +/usr/local/lib by default. Make sure this is in your LDPATH. + +On Linux, the best way to do this is to ensure that /usr/local/lib is in +your /etc/ld.so.conf and then run /sbin/ldconfig. + +Depending upon whether you are linking dynamically or statically and how +your build environment it set up, you may need to include additional +libraries when linking against thrift, such as librt and/or libpthread. If +you are using libthriftnb you will also need libevent. + +## Dependencies + +boost shared pointers +http://www.boost.org/libs/smart_ptr/smart_ptr.htm + +libevent (for libthriftnb only) +http://monkey.org/~provos/libevent/ + +# Using Thrift with C++ on Windows + +You need to define an environment variables for 3rd party components separately: + +BOOST_ROOT : For boost, e.g. D:\boost_1_55_0 +OPENSSL_ROOT_DIR : For OpenSSL, e.g. D:\OpenSSL-Win32 + +only required by libthriftnb: + +LIBEVENT_ROOT_DIR : For Libevent e.g. D:\libevent-2.0.21-stable + +See /3rdparty.user for more details. + +Thrift is divided into two libraries. + +* libthrift - The core Thrift library contains all the core Thrift code. It requires + boost shared pointers, pthreads, and librt. + +* libthriftnb - This library contains the Thrift nonblocking server, which uses libevent. + To link this library you will also need to link libevent. + +## Linking Against Thrift + +You need to link your project that uses thrift against all the thrift +dependencies; in the case of libthrift, boost and for +libthriftnb, libevent. + +In the project properties you must also set HAVE_CONFIG_H as force include +the config header: "windows/confg.h" + +## Dependencies + +boost shared pointers +http://www.boost.org/libs/smart_ptr/smart_ptr.htm + +boost thread +http://www.boost.org/doc/libs/release/doc/html/thread.html + +libevent (for libthriftnb only) +http://monkey.org/~provos/libevent/ + +## Notes on boost thread (static vs shared): + +By default lib/cpp/windows/force_inc.h defines: + + #define BOOST_ALL_NO_LIB 1 + #define BOOST_THREAD_NO_LIB 1 + +This has for effect to have the host application linking against Thrift +to have to link with boost thread as a static library. + +If you wanted instead to link with boost thread as a shared library, +you'll need to uncomment those two lines, and recompile. + +## Windows version compatibility + +The Thrift library targets Windows XP for broadest compatbility. A notable +difference is in the Windows-specific implementation of the socket poll +function. To target Vista, Win7 or other versions, comment out the line + + #define TARGET_WIN_XP. + +## Named Pipes + +Named Pipe transport has been added in the TPipe and TPipeServer classes. This +is currently Windows-only. Named pipe transport for *NIX has not been +implemented. Domain sockets are a better choice for local IPC under non-Windows +OS's. *NIX named pipes only support 1:1 client-server connection. + +# Thrift/SSL + +## Scope + +This SSL only supports blocking mode socket I/O. It can only be used with +TSimpleServer, TThreadedServer, and TThreadPoolServer. + +## Implementation + +There're two main classes TSSLSocketFactory and TSSLSocket. Instances of +TSSLSocket are always created from TSSLSocketFactory. + +PosixSSLThreadFactory creates PosixSSLThread. The only difference from the +PthreadThread type is that it cleanups OpenSSL error queue upon exiting +the thread. Ideally, OpenSSL APIs should only be called from PosixSSLThread. + +## How to use SSL APIs + +This is for demo. In real code, typically only one TSSLSocketFactory +instance is needed. + + shared_ptr getSSLSocketFactory() { + shared_ptr factory(new TSSLSocketFactory()); + // client: load trusted certificates + factory->loadTrustedCertificates("my-trusted-ca-certificates.pem"); + // client: optionally set your own access manager, otherwise, + // the default client access manager will be loaded. + + factory->loadCertificate("my-certificate-signed-by-ca.pem"); + factory->loadPrivateKey("my-private-key.pem"); + // server: optionally setup access manager + // shared_ptr accessManager(new MyAccessManager); + // factory->access(accessManager); + ... + } + + +client code sample + + shared_ptr factory = getSSLSocketFactory(); + shared_ptr socket = factory.createSocket(host, port); + shared_ptr transport(new TBufferedTransport(socket)); + ... + + +server code sample + + shared_ptr factory = getSSLSocketFactory(); + shared_ptr socket(new TSSLServerSocket(port, factory)); + shared_ptr transportFactory(new TBufferedTransportFactory)); + ... + +## AccessManager + +AccessManager defines a callback interface. It has three callback methods: + +(a) Decision verify(const sockaddr_storage& sa); + +(b) Decision verify(const string& host, const char* name, int size); + +(c) Decision verify(const sockaddr_storage& sa, const char* data, int size); + +After SSL handshake completes, additional checks are conducted. Application +is given the chance to decide whether or not to continue the conversation +with the remote. Application is queried through the above three "verify" +method. They are called at different points of the verification process. + +Decisions can be one of ALLOW, DENY, and SKIP. ALLOW and DENY means the +conversation should be continued or disconnected, respectively. ALLOW and +DENY decision stops the verification process. SKIP means there's no decision +based on the given input, continue the verification process. + +First, (a) is called with the remote IP. It is called once at the beginning. +"sa" is the IP address of the remote peer. + +Then, the certificate of remote peer is loaded. SubjectAltName extensions +are extracted and sent to application for verification. When a DNS +subjectAltName field is extracted, (b) is called. When an IP subjectAltName +field is extracted, (c) is called. + +The "host" in (b) is the value from TSocket::getHost() if this is a client +side socket, or TSocket::getPeerHost() if this is a server side socket. The +reason is client side socket initiates the connection. TSocket::getHost() +is the remote host name. On server side, the remote host name is unknown +unless it's retrieved through TSocket::getPeerHost(). Either way, "host" +should be the remote host name. Keep in mind, if TSocket::getPeerHost() +failed, it would return the remote host name in numeric format. + +If all subjectAltName extensions were "skipped", the common name field would +be checked. It is sent to application through (c), where "sa" is the remote +IP address. "data" is the IP address extracted from subjectAltName IP +extension, and "size" is the length of the extension data. + +If any of the above "verify" methods returned a decision ALLOW or DENY, the +verification process would be stopped. + +If any of the above "verify" methods returned SKIP, that decision would be +ignored and the verification process would move on till the last item is +examined. At that point, if there's still no decision, the connection is +terminated. + +Thread safety, an access manager should not store state information if it's +to be used by many SSL sockets. + +## SIGPIPE signal + +Applications running OpenSSL over network connections may crash if SIGPIPE +is not ignored. This happens when they receive a connection reset by remote +peer exception, which somehow triggers a SIGPIPE signal. If not handled, +this signal would kill the application. + +## How to run test client/server in SSL mode + +The server and client expects the followings from the directory /test/ + +- keys/server.crt +- keys/server.key +- keys/CA.pem + +The file names are hard coded in the source code. You need to create these +certificates before you can run the test code in SSL mode. Make sure at least +one of the followings is included in "keys/server.crt", + +- subjectAltName, DNS localhost +- subjectAltName, IP 127.0.0.1 +- common name, localhost + +Run within /test/ folder, + + ./cpp/TestServer --ssl & + ./cpp/TestClient --ssl + +If "-h " is used to run client, the above "localhost" in the above +keys/server.crt has to be replaced with that host name. + +## TSSLSocketFactory::randomize() + +The default implementation of OpenSSLSocketFactory::randomize() simply calls +OpenSSL's RAND_poll() when OpenSSL library is first initialized. + +The PRNG seed is key to the application security. This method should be +overridden if it's not strong enough for you. http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/coding_standards.md ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/coding_standards.md b/depends/thirdparty/thrift/lib/cpp/coding_standards.md new file mode 100644 index 0000000..8018c77 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/coding_standards.md @@ -0,0 +1,4 @@ +Please follow [General Coding Standards](/doc/coding_standards.md) + + * see .clang-format in root dir for settings of accepted format + * clang-format (3.5 or newer) can be used to automaticaly reformat code ('make style' command) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj b/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj new file mode 100644 index 0000000..b4f1c50 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj @@ -0,0 +1,359 @@ + + + + + Debug-mt + Win32 + + + Debug-mt + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release-mt + Win32 + + + Release-mt + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {DD26F57E-60F2-4F37-A616-D219A9BF338F} + Win32Proj + thrift + libthrift + + + + StaticLibrary + true + MultiByte + + + StaticLibrary + true + MultiByte + + + StaticLibrary + true + MultiByte + + + StaticLibrary + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(OPENSSL_ROOT_DIR)\include\;$(IncludePath) + + + + NotUsing + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthrift.pdb + MultiThreadedDebugDLL + + + Windows + true + + + + + NotUsing + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthrift.pdb + MultiThreadedDebug + + + Windows + true + + + + + NotUsing + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + + + + + NotUsing + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthrift.pdb + + + Windows + true + true + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthrift.pdb + MultiThreaded + + + Windows + true + true + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + + + + + + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj.filters ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj.filters b/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj.filters new file mode 100644 index 0000000..ec21886 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/libthrift.vcxproj.filters @@ -0,0 +1,277 @@ + + + + + transport + + + + + windows + + + transport + + + windows + + + concurrency + + + concurrency + + + concurrency + + + protocol + + + protocol + + + protocol + + + protocol + + + transport + + + transport + + + transport + + + transport + + + transport + + + transport + + + transport + + + transport + + + server + + + server + + + server + + + async + + + processor + + + transport + + + transport + + + windows + + + windows + + + concurrency + + + concurrency + + + concurrency + + + concurrency + + + windows + + + transport + + + transport + + + + + transport + + + transport + + + protocol + + + + + + windows + + + windows + + + concurrency + + + transport + + + transport + + + transport + + + windows + + + transport + + + windows + + + protocol + + + protocol + + + server + + + server + + + server + + + server + + + async + + + processor + + + processor + + + transport + + + transport + + + transport + + + transport + + + transport + + + transport + + + transport + + + protocol + + + protocol + + + protocol + + + transport + + + windows + + + windows + + + windows + + + windows + + + concurrency + + + concurrency + + + concurrency + + + windows + + + transport + + + transport + + + + + {07ced19b-b72a-4105-9ffb-6d2bcf64497e} + + + {e9f61404-1148-4103-bd6f-e5869d37fa79} + + + {2814002a-3c68-427e-b0eb-33acd2f406ae} + + + {addd4707-dbaa-4d0c-bef6-fff8be7b495a} + + + {f55a8e9b-6959-487f-a396-c31b4d6c61d6} + + + {d526885b-1b3e-4ee3-8027-e694fe98ad63} + + + {8f428da8-5a83-44fb-9578-de935fb415e1} + + + {eea10406-3380-4f2d-9365-c26fa2875dae} + + + + + protocol + + + windows\tr1 + + + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj b/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj new file mode 100755 index 0000000..259bb20 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj @@ -0,0 +1,293 @@ + + + + + Debug-mt + Win32 + + + Debug-mt + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release-mt + Win32 + + + Release-mt + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + + + + + {D8696CCE-7D46-4659-B432-91754A41DEB0} + Win32Proj + libthriftnb + + + + StaticLibrary + true + MultiByte + + + StaticLibrary + true + MultiByte + + + StaticLibrary + true + MultiByte + + + StaticLibrary + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + StaticLibrary + false + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + $(ProjectDir)\src\;$(ProjectDir)\src\thrift\windows\;$(BOOST_ROOT)\include;$(BOOST_ROOT)\;$(LIBEVENT_ROOT)\WIN32-Code\;$(LIBEVENT_ROOT)\include;$(LIBEVENT_ROOT)\;$(IncludePath) + + + + + + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthriftnb.pdb + + + Windows + true + + + + + + + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthriftnb.pdb + MultiThreadedDebug + + + Windows + true + + + + + + + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + + + + + + + Level3 + Disabled + HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Windows + true + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthriftnb.pdb + + + Windows + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)libthriftnb.pdb + MultiThreaded + + + Windows + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + true + + + + + + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj.filters ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj.filters b/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj.filters new file mode 100644 index 0000000..5245544 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/libthriftnb.vcxproj.filters @@ -0,0 +1,57 @@ + + + + + {bf449d92-4be8-4f6f-a010-c536f57c6f13} + + + {0294d0a6-ce46-4be8-a659-826d6e98ae41} + + + {60fc9e5e-0866-4aba-8662-439bb4a461d3} + + + + + server + + + async + + + async + + + async + + + windows + + + + + server + + + async + + + async + + + async + + + windows + + + windows + + + windows + + + windows + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.cpp ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.cpp b/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.cpp new file mode 100644 index 0000000..2f14653 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.cpp @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include + +namespace apache { +namespace thrift { + +uint32_t TApplicationException::read(apache::thrift::protocol::TProtocol* iprot) { + uint32_t xfer = 0; + std::string fname; + apache::thrift::protocol::TType ftype; + int16_t fid; + + xfer += iprot->readStructBegin(fname); + + while (true) { + xfer += iprot->readFieldBegin(fname, ftype, fid); + if (ftype == apache::thrift::protocol::T_STOP) { + break; + } + switch (fid) { + case 1: + if (ftype == apache::thrift::protocol::T_STRING) { + xfer += iprot->readString(message_); + } else { + xfer += iprot->skip(ftype); + } + break; + case 2: + if (ftype == apache::thrift::protocol::T_I32) { + int32_t type; + xfer += iprot->readI32(type); + type_ = (TApplicationExceptionType)type; + } else { + xfer += iprot->skip(ftype); + } + break; + default: + xfer += iprot->skip(ftype); + break; + } + xfer += iprot->readFieldEnd(); + } + + xfer += iprot->readStructEnd(); + return xfer; +} + +uint32_t TApplicationException::write(apache::thrift::protocol::TProtocol* oprot) const { + uint32_t xfer = 0; + xfer += oprot->writeStructBegin("TApplicationException"); + xfer += oprot->writeFieldBegin("message", apache::thrift::protocol::T_STRING, 1); + xfer += oprot->writeString(message_); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldBegin("type", apache::thrift::protocol::T_I32, 2); + xfer += oprot->writeI32(type_); + xfer += oprot->writeFieldEnd(); + xfer += oprot->writeFieldStop(); + xfer += oprot->writeStructEnd(); + return xfer; +} +} +} // apache::thrift http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.h ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.h b/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.h new file mode 100644 index 0000000..0de5391 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/src/thrift/TApplicationException.h @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_ +#define _THRIFT_TAPPLICATIONEXCEPTION_H_ 1 + +#include + +namespace apache { +namespace thrift { + +namespace protocol { +class TProtocol; +} + +class TApplicationException : public TException { +public: + /** + * Error codes for the various types of exceptions. + */ + enum TApplicationExceptionType { + UNKNOWN = 0, + UNKNOWN_METHOD = 1, + INVALID_MESSAGE_TYPE = 2, + WRONG_METHOD_NAME = 3, + BAD_SEQUENCE_ID = 4, + MISSING_RESULT = 5, + INTERNAL_ERROR = 6, + PROTOCOL_ERROR = 7, + INVALID_TRANSFORM = 8, + INVALID_PROTOCOL = 9, + UNSUPPORTED_CLIENT_TYPE = 10 + }; + + TApplicationException() : TException(), type_(UNKNOWN) {} + + TApplicationException(TApplicationExceptionType type) : TException(), type_(type) {} + + TApplicationException(const std::string& message) : TException(message), type_(UNKNOWN) {} + + TApplicationException(TApplicationExceptionType type, const std::string& message) + : TException(message), type_(type) {} + + virtual ~TApplicationException() throw() {} + + /** + * Returns an error code that provides information about the type of error + * that has occurred. + * + * @return Error code + */ + TApplicationExceptionType getType() { return type_; } + + virtual const char* what() const throw() { + if (message_.empty()) { + switch (type_) { + case UNKNOWN: + return "TApplicationException: Unknown application exception"; + case UNKNOWN_METHOD: + return "TApplicationException: Unknown method"; + case INVALID_MESSAGE_TYPE: + return "TApplicationException: Invalid message type"; + case WRONG_METHOD_NAME: + return "TApplicationException: Wrong method name"; + case BAD_SEQUENCE_ID: + return "TApplicationException: Bad sequence identifier"; + case MISSING_RESULT: + return "TApplicationException: Missing result"; + case INTERNAL_ERROR: + return "TApplicationException: Internal error"; + case PROTOCOL_ERROR: + return "TApplicationException: Protocol error"; + case INVALID_TRANSFORM: + return "TApplicationException: Invalid transform"; + case INVALID_PROTOCOL: + return "TApplicationException: Invalid protocol"; + case UNSUPPORTED_CLIENT_TYPE: + return "TApplicationException: Unsupported client type"; + default: + return "TApplicationException: (Invalid exception type)"; + }; + } else { + return message_.c_str(); + } + } + + uint32_t read(protocol::TProtocol* iprot); + uint32_t write(protocol::TProtocol* oprot) const; + +protected: + /** + * Error code + */ + TApplicationExceptionType type_; +}; +} +} // apache::thrift + +#endif // #ifndef _THRIFT_TAPPLICATIONEXCEPTION_H_ http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/lib/cpp/src/thrift/TDispatchProcessor.h ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/lib/cpp/src/thrift/TDispatchProcessor.h b/depends/thirdparty/thrift/lib/cpp/src/thrift/TDispatchProcessor.h new file mode 100644 index 0000000..fd1dce7 --- /dev/null +++ b/depends/thirdparty/thrift/lib/cpp/src/thrift/TDispatchProcessor.h @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#ifndef _THRIFT_TDISPATCHPROCESSOR_H_ +#define _THRIFT_TDISPATCHPROCESSOR_H_ 1 + +#include + +namespace apache { +namespace thrift { + +/** + * TDispatchProcessor is a helper class to parse the message header then call + * another function to dispatch based on the function name. + * + * Subclasses must implement dispatchCall() to dispatch on the function name. + */ +template +class TDispatchProcessorT : public TProcessor { +public: + virtual bool process(boost::shared_ptr in, + boost::shared_ptr out, + void* connectionContext) { + protocol::TProtocol* inRaw = in.get(); + protocol::TProtocol* outRaw = out.get(); + + // Try to dynamic cast to the template protocol type + Protocol_* specificIn = dynamic_cast(inRaw); + Protocol_* specificOut = dynamic_cast(outRaw); + if (specificIn && specificOut) { + return processFast(specificIn, specificOut, connectionContext); + } + + // Log the fact that we have to use the slow path + T_GENERIC_PROTOCOL(this, inRaw, specificIn); + T_GENERIC_PROTOCOL(this, outRaw, specificOut); + + std::string fname; + protocol::TMessageType mtype; + int32_t seqid; + inRaw->readMessageBegin(fname, mtype, seqid); + + // If this doesn't look like a valid call, log an error and return false so + // that the server will close the connection. + // + // (The old generated processor code used to try to skip a T_STRUCT and + // continue. However, that seems unsafe.) + if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) { + GlobalOutput.printf("received invalid message type %d from client", mtype); + return false; + } + + return this->dispatchCall(inRaw, outRaw, fname, seqid, connectionContext); + } + +protected: + bool processFast(Protocol_* in, Protocol_* out, void* connectionContext) { + std::string fname; + protocol::TMessageType mtype; + int32_t seqid; + in->readMessageBegin(fname, mtype, seqid); + + if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) { + GlobalOutput.printf("received invalid message type %d from client", mtype); + return false; + } + + return this->dispatchCallTemplated(in, out, fname, seqid, connectionContext); + } + + /** + * dispatchCall() methods must be implemented by subclasses + */ + virtual bool dispatchCall(apache::thrift::protocol::TProtocol* in, + apache::thrift::protocol::TProtocol* out, + const std::string& fname, + int32_t seqid, + void* callContext) = 0; + + virtual bool dispatchCallTemplated(Protocol_* in, + Protocol_* out, + const std::string& fname, + int32_t seqid, + void* callContext) = 0; +}; + +/** + * Non-templatized version of TDispatchProcessor, that doesn't bother trying to + * perform a dynamic_cast. + */ +class TDispatchProcessor : public TProcessor { +public: + virtual bool process(boost::shared_ptr in, + boost::shared_ptr out, + void* connectionContext) { + std::string fname; + protocol::TMessageType mtype; + int32_t seqid; + in->readMessageBegin(fname, mtype, seqid); + + if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) { + GlobalOutput.printf("received invalid message type %d from client", mtype); + return false; + } + + return dispatchCall(in.get(), out.get(), fname, seqid, connectionContext); + } + +protected: + virtual bool dispatchCall(apache::thrift::protocol::TProtocol* in, + apache::thrift::protocol::TProtocol* out, + const std::string& fname, + int32_t seqid, + void* callContext) = 0; +}; + +// Specialize TDispatchProcessorT for TProtocol and TDummyProtocol just to use +// the generic TDispatchProcessor. +template <> +class TDispatchProcessorT : public TDispatchProcessor {}; +template <> +class TDispatchProcessorT : public TDispatchProcessor {}; +} +} // apache::thrift + +#endif // _THRIFT_TDISPATCHPROCESSOR_H_