transport_common.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_TOOL_TRANSPORT_COMMON_H
16 #define OPENSSL_HEADER_TOOL_TRANSPORT_COMMON_H
17 
18 #include <openssl/ssl.h>
19 #include <string.h>
20 
21 #include <string>
22 
23 // InitSocketLibrary calls the Windows socket init functions, if needed.
24 bool InitSocketLibrary();
25 
26 // Connect sets |*out_sock| to be a socket connected to the destination given
27 // in |hostname_and_port|, which should be of the form "www.example.com:123".
28 // It returns true on success and false otherwise.
29 bool Connect(int *out_sock, const std::string &hostname_and_port);
30 
31 class Listener {
32  public:
33  Listener() {}
34  ~Listener();
35 
36  // Init initializes the listener to listen on |port|, which should be of the
37  // form "123".
38  bool Init(const std::string &port);
39 
40  // Accept sets |*out_sock| to be a socket connected to the listener.
41  bool Accept(int *out_sock);
42 
43  private:
44  int server_sock_ = -1;
45 
46  Listener(const Listener &) = delete;
47  Listener &operator=(const Listener &) = delete;
48 };
49 
50 bool VersionFromString(uint16_t *out_version, const std::string &version);
51 
52 void PrintConnectionInfo(BIO *bio, const SSL *ssl);
53 
54 bool SocketSetNonBlocking(int sock, bool is_non_blocking);
55 
56 // PrintSSLError prints information about the most recent SSL error to stderr.
57 // |ssl_err| must be the output of |SSL_get_error| and the |SSL| object must be
58 // connected to socket from |Connect|.
59 void PrintSSLError(FILE *file, const char *msg, int ssl_err, int ret);
60 
61 bool TransferData(SSL *ssl, int sock);
62 
63 // DoSMTPStartTLS performs the SMTP STARTTLS mini-protocol over |sock|. It
64 // returns true on success and false otherwise.
65 bool DoSMTPStartTLS(int sock);
66 
67 // DoHTTPTunnel sends an HTTP CONNECT request over |sock|. It returns true on
68 // success and false otherwise.
69 bool DoHTTPTunnel(int sock, const std::string &hostname_and_port);
70 
71 #endif // !OPENSSL_HEADER_TOOL_TRANSPORT_COMMON_H
VersionFromString
bool VersionFromString(uint16_t *out_version, const std::string &version)
Definition: transport_common.cc:267
bio_st
Definition: bio.h:822
Connect
bool Connect(int *out_sock, const std::string &hostname_and_port)
Definition: transport_common.cc:142
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
string.h
Listener
Definition: transport_common.h:31
PrintSSLError
void PrintSSLError(FILE *file, const char *msg, int ssl_err, int ret)
Definition: transport_common.cc:659
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
Listener::operator=
Listener & operator=(const Listener &)=delete
Listener::Accept
bool Accept(int *out_sock)
Definition: transport_common.cc:260
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
version
Definition: version.py:1
ssl_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3698
Listener::Init
bool Init(const std::string &port)
Definition: transport_common.cc:214
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
ssl.h
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
PrintConnectionInfo
void PrintConnectionInfo(BIO *bio, const SSL *ssl)
Definition: transport_common.cc:284
InitSocketLibrary
bool InitSocketLibrary()
Definition: transport_common.cc:79
benchmark.FILE
FILE
Definition: benchmark.py:21
TransferData
bool TransferData(SSL *ssl, int sock)
Definition: transport_common.cc:682
DoSMTPStartTLS
bool DoSMTPStartTLS(int sock)
Definition: transport_common.cc:901
DoHTTPTunnel
bool DoHTTPTunnel(int sock, const std::string &hostname_and_port)
Definition: transport_common.cc:958
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
Listener::Listener
Listener()
Definition: transport_common.h:33
SocketSetNonBlocking
bool SocketSetNonBlocking(int sock, bool is_non_blocking)
Definition: transport_common.cc:354
Listener::~Listener
~Listener()
Definition: transport_common.cc:208
Listener::server_sock_
int server_sock_
Definition: transport_common.h:44


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:40