Logo
~Sockets~
~Examples~
~Contact~


HttpRequest Class Reference

#include <HttpRequest.h>

Inheritance diagram for HttpRequest:
Collaboration diagram for HttpRequest:

List of all members.


Public Member Functions

 HttpRequest ()
 HttpRequest (const HttpRequest &src)
 ~HttpRequest ()
HttpRequestoperator= (const HttpRequest &src)
void SetHttpMethod (const std::string &value)
 Get, Post.
const std::string & HttpMethod () const
void SetHttpVersion (const std::string &value)
 HTTP/1.x.
const std::string & HttpVersion () const
void SetUri (const std::string &value)
const std::string & Uri () const
void SetRemoteAddr (const std::string &value)
const std::string & RemoteAddr () const
void SetRemoteHost (const std::string &value)
const std::string & RemoteHost () const
void SetServerName (const std::string &value)
const std::string & ServerName () const
void SetServerPort (int value)
int ServerPort () const
void SetIsSsl (bool value)
bool IsSsl () const
void SetAttribute (const std::string &key, const std::string &value)
 Set / Read attribute value.
void SetAttribute (const std::string &key, long value)
const std::string & Attribute (const std::string &key) const
const Utility::ncmap
< std::string > & 
Attributes () const
void AddCookie (const std::string &)
 Cookies.
const Utility::ncmap
< std::string > & 
CookieMap () const
void InitBody (size_t sz)
 Open file for body data.
void Write (const char *buf, size_t sz)
 Write body data.
void CloseBody ()
 No more writing.
void ParseBody ()
const HttpdFormForm () const
const HttpdCookiesCookies () const
const IFileBodyFile () const
void Reset ()

Private Attributes

std::string m_method
std::string m_protocol
std::string m_req_uri
std::string m_remote_addr
std::string m_remote_host
std::string m_server_name
int m_server_port
bool m_is_ssl
Utility::ncmap< std::string > m_attribute
std::string m_null
std::auto_ptr< IFilem_body_file
std::auto_ptr< HttpdFormm_form
HttpdCookies m_cookies
Utility::ncmap< std::string > m_cookie

Detailed Description

Definition at line 47 of file HttpRequest.h.


Constructor & Destructor Documentation

HttpRequest::HttpRequest (  ) 

Definition at line 54 of file HttpRequest.cpp.

00054                          : HttpTransaction()
00055 , m_server_port(0)
00056 , m_is_ssl(false)
00057 , m_body_file(NULL)
00058 , m_form(NULL)
00059 {
00060 }

HttpRequest::HttpRequest ( const HttpRequest src  ) 

Definition at line 64 of file HttpRequest.cpp.

00064                                                : HttpTransaction(src)
00065 , m_method(src.m_method)
00066 , m_protocol(src.m_protocol)
00067 , m_req_uri(src.m_req_uri)
00068 , m_remote_addr(src.m_remote_addr)
00069 , m_remote_host(src.m_remote_host)
00070 , m_server_name(src.m_server_name)
00071 , m_server_port(src.m_server_port)
00072 , m_is_ssl(src.m_is_ssl)
00073 , m_attribute(src.m_attribute)
00074 , m_null(src.m_null)
00075 , m_body_file(src.m_body_file)
00076 , m_form(src.m_form)
00077 , m_cookies(src.m_cookies)
00078 , m_cookie(src.m_cookie)
00079 {
00080 }

HttpRequest::~HttpRequest (  ) 

Definition at line 84 of file HttpRequest.cpp.

00085 {
00086 }


Member Function Documentation

HttpRequest & HttpRequest::operator= ( const HttpRequest src  ) 

Definition at line 90 of file HttpRequest.cpp.

References m_attribute, m_body_file, m_cookie, m_cookies, m_form, m_is_ssl, m_method, m_null, m_protocol, m_remote_addr, m_remote_host, m_req_uri, m_server_name, and m_server_port.

00091 {
00092         m_method = src.m_method;
00093         m_protocol = src.m_protocol;
00094         m_req_uri = src.m_req_uri;
00095         m_remote_addr = src.m_remote_addr;
00096         m_remote_host = src.m_remote_host;
00097         m_server_name = src.m_server_name;
00098         m_server_port = src.m_server_port;
00099         m_is_ssl = src.m_is_ssl;
00100         m_attribute = src.m_attribute;
00101         m_null = src.m_null;
00102         m_body_file = src.m_body_file;
00103         m_form = src.m_form;
00104         m_cookies = src.m_cookies;
00105         m_cookie = src.m_cookie;
00106 
00107         HttpTransaction::operator=(src);
00108 
00109         return *this;
00110 }

void HttpRequest::SetHttpMethod ( const std::string &  value  ) 

Get, Post.

Definition at line 114 of file HttpRequest.cpp.

References m_method.

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00115 {
00116         m_method = value;
00117 }

const std::string & HttpRequest::HttpMethod (  )  const

Definition at line 120 of file HttpRequest.cpp.

References m_method.

00121 {
00122         return m_method;
00123 }

void HttpRequest::SetHttpVersion ( const std::string &  value  ) 

HTTP/1.x.

Definition at line 128 of file HttpRequest.cpp.

References m_protocol.

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00129 {
00130         m_protocol = value;
00131 }

const std::string & HttpRequest::HttpVersion (  )  const

Definition at line 134 of file HttpRequest.cpp.

References m_protocol.

Referenced by HttpBaseSocket::Execute().

00135 {
00136         return m_protocol;
00137 }

void HttpRequest::SetUri ( const std::string &  value  ) 

Definition at line 142 of file HttpRequest.cpp.

References m_req_uri, and Utility::rfc1738_decode().

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00143 {
00144         m_req_uri = Utility::rfc1738_decode(value);
00145 }

const std::string & HttpRequest::Uri (  )  const

Definition at line 148 of file HttpRequest.cpp.

References m_req_uri.

00149 {
00150         return m_req_uri;
00151 }

void HttpRequest::SetRemoteAddr ( const std::string &  value  ) 

Definition at line 156 of file HttpRequest.cpp.

References m_remote_addr.

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00157 {
00158         m_remote_addr = value;
00159 }

const std::string & HttpRequest::RemoteAddr (  )  const

Definition at line 162 of file HttpRequest.cpp.

References m_remote_addr.

00163 {
00164         return m_remote_addr;
00165 }

void HttpRequest::SetRemoteHost ( const std::string &  value  ) 

Definition at line 170 of file HttpRequest.cpp.

References m_remote_host.

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00171 {
00172         m_remote_host = value;
00173 }

const std::string & HttpRequest::RemoteHost (  )  const

Definition at line 176 of file HttpRequest.cpp.

References m_remote_host.

00177 {
00178         return m_remote_host;
00179 }

void HttpRequest::SetServerName ( const std::string &  value  ) 

Definition at line 184 of file HttpRequest.cpp.

References m_server_name.

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00185 {
00186         m_server_name = value;
00187 }

const std::string & HttpRequest::ServerName (  )  const

Definition at line 190 of file HttpRequest.cpp.

References m_server_name.

00191 {
00192         return m_server_name;
00193 }

void HttpRequest::SetServerPort ( int  value  ) 

Definition at line 198 of file HttpRequest.cpp.

References m_server_port.

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00199 {
00200         m_server_port = value;
00201 }

int HttpRequest::ServerPort (  )  const

Definition at line 204 of file HttpRequest.cpp.

References m_server_port.

00205 {
00206         return m_server_port;
00207 }

void HttpRequest::SetIsSsl ( bool  value  ) 

Definition at line 212 of file HttpRequest.cpp.

References m_is_ssl.

Referenced by Ajp13Socket::ReceiveForwardRequest().

00213 {
00214         m_is_ssl = value;
00215 }

bool HttpRequest::IsSsl (  )  const

Definition at line 218 of file HttpRequest.cpp.

References m_is_ssl.

00219 {
00220         return m_is_ssl;
00221 }

void HttpRequest::SetAttribute ( const std::string &  key,
const std::string &  value 
)

Set / Read attribute value.

Definition at line 226 of file HttpRequest.cpp.

References m_attribute.

Referenced by HttpBaseSocket::OnFirst(), and Ajp13Socket::ReceiveForwardRequest().

00227 {
00228         m_attribute[key] = value;
00229 }

void HttpRequest::SetAttribute ( const std::string &  key,
long  value 
)

Definition at line 232 of file HttpRequest.cpp.

References Utility::l2string(), and m_attribute.

00233 {
00234         m_attribute[key] = Utility::l2string(value);
00235 }

const std::string & HttpRequest::Attribute ( const std::string &  key  )  const

Definition at line 238 of file HttpRequest.cpp.

References m_attribute, and m_null.

00239 {
00240         Utility::ncmap<std::string>::const_iterator it;
00241         if ( (it = m_attribute.find(key)) != m_attribute.end())
00242                 return it -> second;
00243         return m_null;
00244 }

const Utility::ncmap< std::string > & HttpRequest::Attributes (  )  const

Definition at line 248 of file HttpRequest.cpp.

References m_attribute.

00249 {
00250         return m_attribute;
00251 }

void HttpRequest::AddCookie ( const std::string &  str  ) 

Cookies.

Definition at line 255 of file HttpRequest.cpp.

References HttpdCookies::add(), DEB, Parse::getword(), m_cookie, and m_cookies.

Referenced by HttpBaseSocket::OnHeader(), and Ajp13Socket::ReceiveForwardRequest().

00256 {
00257         m_cookies.add( str );
00258         Parse pa(str, ";");
00259         std::string lstr = pa.getword();
00260         while (!lstr.empty())
00261         {
00262                 Parse pa2(lstr, "=");
00263                 std::string name = pa2.getword();
00264                 m_cookie[name] = lstr;
00265 DEB(fprintf(stderr, " *** AddCookie '%s' = '%s'\n", name.c_str(), lstr.c_str());)
00266                 lstr = pa.getword();
00267         }
00268 }

const Utility::ncmap<std::string>& HttpRequest::CookieMap (  )  const [inline]

Definition at line 91 of file HttpRequest.h.

00091 { return m_cookie; }

void HttpRequest::InitBody ( size_t  sz  ) 

Open file for body data.

Definition at line 272 of file HttpRequest.cpp.

References DEB, and m_body_file.

Referenced by HttpBaseSocket::OnHeaderComplete(), and Ajp13Socket::ReceiveForwardRequest().

00273 {
00274         if (!m_body_file.get())
00275                 m_body_file = std::auto_ptr<IFile>(new MemFile);
00276 DEB(    else
00277                 fprintf(stderr, "Body data file already opened\n");)
00278 }

void HttpRequest::Write ( const char *  buf,
size_t  sz 
)

Write body data.

Definition at line 282 of file HttpRequest.cpp.

References DEB, and m_body_file.

Referenced by HttpBaseSocket::OnData(), and Ajp13Socket::ReceiveBody().

00283 {
00284         if (m_body_file.get())
00285                 m_body_file -> fwrite(buf, 1, sz);
00286 DEB(    else
00287                 fprintf(stderr, "Write: Body data file not open\n");)
00288 }

void HttpRequest::CloseBody (  ) 

No more writing.

Definition at line 292 of file HttpRequest.cpp.

References DEB, and m_body_file.

Referenced by HttpBaseSocket::OnData(), and Ajp13Socket::ReceiveBody().

00293 {
00294         if (m_body_file.get())
00295                 m_body_file -> fclose();
00296 DEB(    else
00297                 fprintf(stderr, "CloseBody: File not open\n");)
00298 }

void HttpRequest::ParseBody (  ) 

Definition at line 302 of file HttpRequest.cpp.

References HttpTransaction::ContentLength(), HttpTransaction::ContentType(), m_attribute, m_body_file, and m_form.

Referenced by HttpBaseSocket::Execute(), and Ajp13Socket::Execute().

00303 {
00304         Utility::ncmap<std::string>::const_iterator it;
00305         if ( (it = m_attribute.find("query_string")) != m_attribute.end())
00306         {
00307                 std::string qs = it -> second;
00308                 m_form = std::auto_ptr<HttpdForm>(new HttpdForm( qs, qs.size() ));
00309         }
00310         else
00311         if (m_body_file.get())
00312         {
00313                 m_form = std::auto_ptr<HttpdForm>(new HttpdForm( m_body_file.get(), ContentType(), ContentLength() ));
00314         }
00315         else
00316         {
00317                 // dummy
00318                 m_form = std::auto_ptr<HttpdForm>(new HttpdForm( "", 0 ));
00319         }
00320 }

const HttpdForm & HttpRequest::Form (  )  const

Definition at line 324 of file HttpRequest.cpp.

References m_form.

00325 {
00326         if (!m_form.get())
00327                 throw Exception("Form not available");
00328         return *m_form;
00329 }

const HttpdCookies & HttpRequest::Cookies (  )  const

Definition at line 333 of file HttpRequest.cpp.

References m_cookies.

00334 {
00335         return m_cookies;
00336 }

const IFile* HttpRequest::BodyFile (  )  const [inline]

Definition at line 107 of file HttpRequest.h.

00107 { return m_body_file.get(); }

void HttpRequest::Reset (  )  [virtual]

Reimplemented from HttpTransaction.

Definition at line 340 of file HttpRequest.cpp.

References m_attribute, m_body_file, m_cookie, m_cookies, m_form, m_is_ssl, m_method, m_protocol, m_remote_addr, m_remote_host, m_req_uri, m_server_name, m_server_port, HttpdCookies::Reset(), and HttpTransaction::Reset().

Referenced by HttpBaseSocket::Execute().

00341 {
00342         HttpTransaction::Reset();
00343         m_method = "";
00344         m_protocol = "";
00345         m_req_uri = "";
00346         m_remote_addr = "";
00347         m_remote_host = "";
00348         m_server_name = "";
00349         m_server_port = 0;
00350         m_is_ssl = false;
00351         while (!m_attribute.empty())
00352         {
00353                 m_attribute.erase(m_attribute.begin());
00354         }
00355         m_body_file = std::auto_ptr<IFile>(NULL);
00356         m_form = std::auto_ptr<HttpdForm>(NULL);
00357         m_cookies.Reset();
00358         while (!m_cookie.empty())
00359         {
00360                 m_cookie.erase(m_cookie.begin());
00361         }
00362 }


Member Data Documentation

std::string HttpRequest::m_method [private]

Definition at line 112 of file HttpRequest.h.

Referenced by HttpMethod(), operator=(), Reset(), and SetHttpMethod().

std::string HttpRequest::m_protocol [private]

Definition at line 113 of file HttpRequest.h.

Referenced by HttpVersion(), operator=(), Reset(), and SetHttpVersion().

std::string HttpRequest::m_req_uri [private]

Definition at line 114 of file HttpRequest.h.

Referenced by operator=(), Reset(), SetUri(), and Uri().

std::string HttpRequest::m_remote_addr [private]

Definition at line 115 of file HttpRequest.h.

Referenced by operator=(), RemoteAddr(), Reset(), and SetRemoteAddr().

std::string HttpRequest::m_remote_host [private]

Definition at line 116 of file HttpRequest.h.

Referenced by operator=(), RemoteHost(), Reset(), and SetRemoteHost().

std::string HttpRequest::m_server_name [private]

Definition at line 117 of file HttpRequest.h.

Referenced by operator=(), Reset(), ServerName(), and SetServerName().

Definition at line 118 of file HttpRequest.h.

Referenced by operator=(), Reset(), ServerPort(), and SetServerPort().

bool HttpRequest::m_is_ssl [private]

Definition at line 119 of file HttpRequest.h.

Referenced by IsSsl(), operator=(), Reset(), and SetIsSsl().

Utility::ncmap<std::string> HttpRequest::m_attribute [private]

Definition at line 120 of file HttpRequest.h.

Referenced by Attribute(), Attributes(), operator=(), ParseBody(), Reset(), and SetAttribute().

std::string HttpRequest::m_null [private]

Reimplemented from HttpTransaction.

Definition at line 121 of file HttpRequest.h.

Referenced by Attribute(), and operator=().

std::auto_ptr<IFile> HttpRequest::m_body_file [mutable, private]

Definition at line 122 of file HttpRequest.h.

Referenced by CloseBody(), InitBody(), operator=(), ParseBody(), Reset(), and Write().

std::auto_ptr<HttpdForm> HttpRequest::m_form [mutable, private]

Definition at line 123 of file HttpRequest.h.

Referenced by Form(), operator=(), ParseBody(), and Reset().

Definition at line 124 of file HttpRequest.h.

Referenced by AddCookie(), Cookies(), operator=(), and Reset().

Utility::ncmap<std::string> HttpRequest::m_cookie [private]

Definition at line 125 of file HttpRequest.h.

Referenced by AddCookie(), operator=(), and Reset().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4