Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TSaslTransport.h
Go to the documentation of this file.
1 // This file will be removed when the code is accepted into the Thrift library.
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20 
21 #ifndef _THRIFT_TRANSPORT_TSSLTRANSPORT_H_
22 #define _THRIFT_TRANSPORT_TSSLTRANSPORT_H_ 1
23 
24 #include <string>
25 
26 #include <boost/shared_ptr.hpp>
27 #include <boost/scoped_ptr.hpp>
28 #include <thrift/transport/TTransport.h>
29 #include <thrift/transport/TVirtualTransport.h>
30 #include <thrift/transport/TBufferTransports.h>
31 
32 #include "transport/TSasl.h"
33 
34 namespace apache { namespace thrift { namespace transport {
35 
39  TSASL_OK = 2,
40  TSASL_BAD = 3,
43 };
44 
45 static const int MECHANISM_NAME_BYTES = 1;
46 static const int STATUS_BYTES = 1;
47 static const int PAYLOAD_LENGTH_BYTES = 4;
49 
56 class TSaslTransport : public TVirtualTransport<TSaslTransport> {
57  public:
64  TSaslTransport(boost::shared_ptr<TTransport> transport);
65 
70  TSaslTransport(boost::shared_ptr<sasl::TSasl> saslClient,
71  boost::shared_ptr<TTransport> transport);
72 
76  virtual ~TSaslTransport();
77 
81  virtual bool isOpen();
82 
87  virtual bool peek();
88 
94  virtual void open();
95 
99  virtual void close();
100 
109  uint32_t read(uint8_t* buf, uint32_t len);
110 
123  void write(const uint8_t* buf, uint32_t len);
124 
131  virtual void flush();
132 
136  boost::shared_ptr<TTransport> getUnderlyingTransport() {
137  return transport_;
138  }
139 
145  std::string getUsername();
146 
147  protected:
149  boost::shared_ptr<TTransport> transport_;
150 
152  TMemoryBuffer* memBuf_;
153 
156  boost::shared_ptr<sasl::TSasl> sasl_;
157 
160 
162  bool isClient_;
163 
165  boost::scoped_array<uint8_t> protoBuf_;
166 
167  /* store the big endian format int to given buffer */
168  void encodeInt(uint32_t x, uint8_t* buf, uint32_t offset) {
169  *(reinterpret_cast<uint32_t*>(buf + offset)) = htonl(x);
170  }
171 
172  /* load the big endian format int to given buffer */
173  uint32_t decodeInt (uint8_t* buf, uint32_t offset) {
174  return ntohl(*(reinterpret_cast<uint32_t*>(buf + offset)));
175  }
176 
186  uint8_t* receiveSaslMessage(NegotiationStatus* status , uint32_t* length);
187 
194  void sendSaslMessage(const NegotiationStatus status,
195  const uint8_t* payload, const uint32_t length, bool flush = true);
196 
203  uint32_t readLength();
204 
213  void writeLength(uint32_t length);
214  virtual void handleSaslStartMessage() = 0;
215 
218  void shrinkBuffer();
219 };
220 
221 }}} // apache::thrift::transport
222 
223 #endif // #ifndef _THRIFT_TRANSPORT_TSSLTRANSPORT_H_
boost::scoped_array< uint8_t > protoBuf_
Buffer to hold protocol info.
void write(const uint8_t *buf, uint32_t len)
void sendSaslMessage(const NegotiationStatus status, const uint8_t *payload, const uint32_t length, bool flush=true)
bool isClient_
True if this is a client.
uint32_t decodeInt(uint8_t *buf, uint32_t offset)
boost::shared_ptr< sasl::TSasl > sasl_
bool shouldWrap_
IF true we wrap data in encryption.
TMemoryBuffer * memBuf_
Buffer for reading and writing.
boost::shared_ptr< TTransport > transport_
Underlying transport.
static const int HEADER_LENGTH
uint8_t offset[7 *64-sizeof(uint64_t)]
boost::shared_ptr< TTransport > getUnderlyingTransport()
static const int PAYLOAD_LENGTH_BYTES
uint32_t read(uint8_t *buf, uint32_t len)
TSaslTransport(boost::shared_ptr< TTransport > transport)
static const int MECHANISM_NAME_BYTES
void encodeInt(uint32_t x, uint8_t *buf, uint32_t offset)
uint8_t * receiveSaslMessage(NegotiationStatus *status, uint32_t *length)
static const int STATUS_BYTES