• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

HttpSessionAccept.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #if !defined (_HttpSessionAccept_h_)
00025 #define _HttpSessionAccept_h_
00026 
00027 #include "libts.h"
00028 #include "P_EventSystem.h"
00029 #include "HttpConfig.h"
00030 #include "HTTP.h"
00031 #include "I_Net.h"
00032 #include <records/I_RecHttp.h>
00033 
00034 namespace detail {
00035   /** Options for @c HttpSessionAccept.
00036 
00037       @internal This is done as a separate class for two reasons.
00038 
00039       The first is that in current usage many instances are created
00040       with the same options so (for the client) this is easier and
00041       more efficient than passing options directly to the @c
00042       HttpSessionAccept or calling setters.
00043 
00044       The second is that @c HttpSessionAccept is not provided with any thread
00045       safety because it is intended as an immutable object. Putting
00046       the setters here and not there makes that clearer.
00047 
00048       We don't do this directly as nested class because we want to
00049       inherit the data members rather than duplicate the declarations
00050       and initializations.
00051    */
00052   class HttpSessionAcceptOptions {
00053   private:
00054     typedef HttpSessionAcceptOptions self; ///< Self reference type.
00055   public:
00056     HttpSessionAcceptOptions();
00057 
00058     // Connection type (HttpProxyPort::TransportType)
00059     int transport_type;
00060     /// Set the transport type.
00061     self& setTransportType(int);
00062     /// Local address to bind for outbound connections.
00063     IpAddr outbound_ip4;
00064     /// Local address to bind for outbound connections.
00065     IpAddr outbound_ip6;
00066     /// Set the outbound IP address to @a ip.
00067     self& setOutboundIp(IpAddr& ip);
00068     /// Set the outbound IP address to @a ip.
00069     self& setOutboundIp(IpEndpoint* ip);
00070     /// Local port for outbound connection.
00071     uint16_t outbound_port;
00072     /// Set outbound port.
00073     self& setOutboundPort(uint16_t);
00074     /// Outbound transparent.
00075     bool f_outbound_transparent;
00076     /// Set outbound transparency.
00077     self& setOutboundTransparent(bool);
00078     /// Transparent pass-through.
00079     bool f_transparent_passthrough;
00080     /// Set transparent passthrough.
00081     self& setTransparentPassthrough(bool);
00082     /// Accepting backdoor connections.
00083     bool backdoor;
00084     /// Set backdoor accept.
00085     self& setBackdoor(bool);
00086     /// Host address resolution preference order.
00087     HostResPreferenceOrder host_res_preference;
00088     /// Set the host query preference.
00089     self& setHostResPreference(HostResPreferenceOrder const);
00090     /// Acceptable session protocols.
00091     SessionProtocolSet session_protocol_preference;
00092     /// Set the session protocol preference.
00093     self& setSessionProtocolPreference(SessionProtocolSet const&);
00094   };
00095 
00096   inline HttpSessionAcceptOptions::HttpSessionAcceptOptions()
00097     : transport_type(0)
00098     , outbound_port(0)
00099     , f_outbound_transparent(false)
00100     , f_transparent_passthrough(false)
00101     , backdoor(false)
00102   {
00103     memcpy(host_res_preference, host_res_default_preference_order, sizeof(host_res_preference));
00104   }
00105 
00106   inline HttpSessionAcceptOptions&
00107   HttpSessionAcceptOptions::setTransportType(int type) {
00108     transport_type =  type;
00109     return *this;
00110   }
00111 
00112   inline HttpSessionAcceptOptions&
00113   HttpSessionAcceptOptions::setOutboundIp(IpAddr& ip) {
00114     if (ip.isIp4()) outbound_ip4 = ip;
00115     else if (ip.isIp6()) outbound_ip6 = ip;
00116     return *this;
00117   }
00118 
00119   inline HttpSessionAcceptOptions&
00120   HttpSessionAcceptOptions::setOutboundIp(IpEndpoint* ip) {
00121     if (ip->isIp4()) outbound_ip4 = *ip;
00122     else if (ip->isIp6()) outbound_ip6 = *ip;
00123     return *this;
00124   }
00125 
00126   inline HttpSessionAcceptOptions&
00127   HttpSessionAcceptOptions::setOutboundPort(uint16_t port) {
00128     outbound_port = port;
00129     return *this;
00130   }
00131 
00132   inline HttpSessionAcceptOptions&
00133   HttpSessionAcceptOptions::setOutboundTransparent(bool flag) {
00134     f_outbound_transparent = flag;
00135     return *this;
00136   }
00137 
00138   inline HttpSessionAcceptOptions&
00139   HttpSessionAcceptOptions::setTransparentPassthrough(bool flag) {
00140     f_transparent_passthrough = flag;
00141     return *this;
00142   }
00143 
00144  inline HttpSessionAcceptOptions&
00145   HttpSessionAcceptOptions::setBackdoor(bool flag) {
00146     backdoor = flag;
00147     return *this;
00148   }
00149 
00150   inline HttpSessionAcceptOptions&
00151   HttpSessionAcceptOptions::setHostResPreference(HostResPreferenceOrder const order) {
00152     memcpy(host_res_preference, order, sizeof(host_res_preference));
00153     return *this;
00154   }
00155 
00156   inline HttpSessionAcceptOptions&
00157   HttpSessionAcceptOptions::setSessionProtocolPreference(SessionProtocolSet const& sp_set) {
00158     session_protocol_preference = sp_set;
00159     return *this;
00160   }
00161 }
00162 
00163 /**
00164    The continuation mutex is NULL to allow parellel accepts in NT. No
00165    state is recorded by the handler and values are required to be set
00166    during construction via the @c Options struct and never changed. So
00167    a NULL mutex is safe.
00168 
00169    Most of the state is simply passed on to the @c ClientSession after
00170    an accept. It is done here because this is the least bad pathway
00171    from the top level configuration to the HTTP session.
00172 */
00173 
00174 class HttpSessionAccept: public SessionAccept, private detail::HttpSessionAcceptOptions
00175 {
00176 private:
00177   typedef HttpSessionAccept self; ///< Self reference type.
00178 public:
00179   /** Construction options.
00180       Provide an easier to remember typedef for clients.
00181   */
00182   typedef detail::HttpSessionAcceptOptions Options;
00183 
00184   /** Default constructor.
00185       @internal We don't use a static default options object because of
00186       initialization order issues. It is important to pick up data that is read
00187       from the config file and a static is initialized long before that point.
00188   */
00189   HttpSessionAccept(Options const& opt = Options())
00190     : SessionAccept(NULL)
00191     , detail::HttpSessionAcceptOptions(opt) // copy these.
00192   {
00193     SET_HANDLER(&HttpSessionAccept::mainEvent);
00194     return;
00195   }
00196 
00197   ~HttpSessionAccept()
00198   {
00199     return;
00200   }
00201 
00202   void accept(NetVConnection *, MIOBuffer *, IOBufferReader *);
00203   int mainEvent(int event, void *netvc);
00204 
00205 private:
00206     HttpSessionAccept(const HttpSessionAccept &);
00207     HttpSessionAccept & operator =(const HttpSessionAccept &);
00208 };
00209 
00210 #endif

Generated by  doxygen 1.7.1