1 /** @file
2 
3   SessionAccept
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "I_Net.h"
27 #include "I_VConnection.h"
28 
29 struct AclRecord;
30 struct HttpProxyPort;
31 /**
32    The base class SessionAccept can not be used directly. The inherited class of
33    SessionAccept (ex. HttpSessionAccept) is designed to:
34 
35      - Check IPAllow policy.
36      - Create ClientSession.
37      - Pass NetVC and MIOBuffer by call ClientSession::new_connection().
38 
39    nullptr mutex:
40 
41      - One specific protocol has ONLY one inherited class of SessionAccept.
42      - The object of this class is shared by all incoming request / NetVC that
43        identified as the protocol by ProtocolSessionProbe.
44      - The inherited class of SessionAccept is non-blocking to allow parallel accepts/
45 
46    To implement a inherited class of SessionAccept:
47 
48      - No state is recorded by the handler.
49      - Values are required to be set during construction and never changed.
50      - Can not put into EventSystem.
51 
52    So a nullptr mutex is safe for the continuation.
53 */
54 
55 class SessionAccept : public Continuation
56 {
57 public:
SessionAccept(ProxyMutex * amutex)58   SessionAccept(ProxyMutex *amutex) : Continuation(amutex) { SET_HANDLER(&SessionAccept::mainEvent); }
~SessionAccept()59   ~SessionAccept() override {}
60   /**
61     Accept a new connection on this session.
62 
63     If the session accepts the connection by returning true, it
64     takes ownership of all the arguments.
65 
66     If the session rejects the connection by returning false, the
67     arguments are unmodified and the caller retains ownership.
68     Typically in this case, the caller would simply destroy all the
69     arguments.
70 
71    */
72   virtual bool accept(NetVConnection *, MIOBuffer *, IOBufferReader *) = 0;
73   /// The proxy port on which this session arrived.
74   HttpProxyPort *proxyPort = nullptr;
75 
76 private:
77   virtual int mainEvent(int event, void *netvc) = 0;
78 };
79