NCBI C++ ToolKit
http_proto.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef HTTP_PROTO__HPP
2 #define HTTP_PROTO__HPP
3 
4 /* $Id: http_proto.hpp 97713 2022-08-18 12:53:59Z satskyse $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Dmitri Dmitrienko
30  *
31  * File Description:
32  *
33  */
34 
35 #include <string>
36 using namespace std;
37 
38 #include <h2o.h>
39 
41 
42 class CHttpProto;
43 class CHttpDaemon;
44 class CHttpRequestParser;
45 class CHttpPostParser;
46 class CHttpConnection;
47 class CHttpRequest;
48 class CPSGS_Reply;
49 class CTcpDaemon;
50 class CTcpWorker;
51 
52 void GetSSLSettings(bool & enabled,
53  string & cert_file,
54  string & key_file,
55  string & ciphers);
56 void CheckFDLimit(void);
57 
58 
59 #if H2O_VERSION_MAJOR == 2 && H2O_VERSION_MINOR >= 3
60  h2o_socket_t * Geth2oConnectionSocketForRequest(h2o_req_t * req);
61 #endif
62 
63 
64 using HttpHandlerFunction_t = std::function<void(CHttpRequest & req,
65  shared_ptr<CPSGS_Reply> reply)>;
66 
68 {
70  CTcpDaemon * tcpd,
71  CHttpDaemon * httpd,
72  CHttpRequestParser * get_parser,
73  CHttpPostParser * post_parser)
74  {
75  m_Handler = handler;
76  m_Tcpd = tcpd;
77  m_Httpd = httpd;
78  m_GetParser = get_parser;
79  m_PostParser = post_parser;
80  }
81 
82  struct st_h2o_handler_t m_H2oHandler; // must be first
88 };
89 
90 
92 {
93 public:
95  m_Worker(nullptr),
96  m_Daemon(daemon),
97  m_HttpCtx({0}),
98  m_H2oCtxInitialized(false),
99  m_HttpAcceptCtx({0})
100  {
101  PSG_TRACE("CHttpProto::CHttpProto");
102  x_SetupSSL();
103  }
104 
106  {
107  if (m_HttpAcceptCtx.ssl_ctx) {
108  SSL_CTX_free(m_HttpAcceptCtx.ssl_ctx);
109  }
110 
111  PSG_TRACE("~CHttpProto");
112  }
113 
114  void BeforeStart(void)
115  {}
116 
117  void ThreadStart(uv_loop_t * loop, CTcpWorker * worker);
118  void ThreadStop(void);
119 
120  void OnNewConnection(uv_stream_t * conn,
121  CHttpConnection * http_conn,
122  uv_close_cb close_cb);
123  void OnClientClosedConnection(uv_stream_t * conn,
124  CHttpConnection * http_conn);
125  void WakeWorker(void);
126  void OnTimer(void);
127  void OnAsyncWork(bool cancel);
128 
129  static void DaemonStarted() {}
130  static void DaemonStopped() {}
131 
132  int OnHttpRequest(CHttpGateHandler * rh,
133  h2o_req_t * req,
134  const char * cd_uid);
135 
136 private:
137  void x_SetupSSL(void);
138 
139 private:
142  h2o_context_t m_HttpCtx;
144  h2o_accept_ctx_t m_HttpAcceptCtx;
145 };
146 
147 #endif
148 
h2o_accept_ctx_t m_HttpAcceptCtx
Definition: http_proto.hpp:144
CHttpDaemon & m_Daemon
Definition: http_proto.hpp:141
void BeforeStart(void)
Definition: http_proto.hpp:114
CHttpProto(CHttpDaemon &daemon)
Definition: http_proto.hpp:94
bool m_H2oCtxInitialized
Definition: http_proto.hpp:143
h2o_context_t m_HttpCtx
Definition: http_proto.hpp:142
CTcpWorker * m_Worker
Definition: http_proto.hpp:140
static void DaemonStopped()
Definition: http_proto.hpp:130
static void DaemonStarted()
Definition: http_proto.hpp:129
HTTP request.
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static void Init(void)
Definition: cursor6.c:76
#define daemon(d, c)
Definition: replacements.h:170
void GetSSLSettings(bool &enabled, string &cert_file, string &key_file, string &ciphers)
Definition: http_proto.cpp:47
void CheckFDLimit(void)
Definition: http_proto.cpp:62
std::function< void(CHttpRequest &req, shared_ptr< CPSGS_Reply > reply)> HttpHandlerFunction_t
Definition: http_proto.hpp:65
#define nullptr
Definition: ncbimisc.hpp:45
#define PSG_TRACE(message)
CHttpDaemon * m_Httpd
Definition: http_proto.hpp:85
CHttpPostParser * m_PostParser
Definition: http_proto.hpp:87
CTcpDaemon * m_Tcpd
Definition: http_proto.hpp:84
CHttpRequestParser * m_GetParser
Definition: http_proto.hpp:86
HttpHandlerFunction_t * m_Handler
Definition: http_proto.hpp:83
Modified on Sat May 25 14:22:31 2024 by modify_doxy.py rev. 669887