Logo
~Sockets~
~Examples~
~Contact~


HttpPutSocket Class Reference
[HTTP Sockets]

Put http page. More...

#include <HttpPutSocket.h>

Inheritance diagram for HttpPutSocket:
Collaboration diagram for HttpPutSocket:

List of all members.


Public Member Functions

 HttpPutSocket (ISocketHandler &)
 HttpPutSocket (ISocketHandler &, const std::string &url_in)
 client constructor,
 ~HttpPutSocket ()
void SetFile (const std::string &)
 Set filename to send.
void SetContentType (const std::string &)
 Set mimetype of file to send.
void Open ()
 connect to host:port derived from url in constructor
void OnConnect ()
 http put client implemented in OnConnect

Private Member Functions

 HttpPutSocket (const HttpPutSocket &s)
HttpPutSocketoperator= (const HttpPutSocket &)

Private Attributes

std::string m_filename
 Filename to write response to.
std::string m_content_type
 Content-type: header from response.
long m_content_length
 Content-length header received from remote.

Detailed Description

Put http page.

Definition at line 47 of file HttpPutSocket.h.


Constructor & Destructor Documentation

HttpPutSocket::HttpPutSocket ( ISocketHandler h  ) 

Definition at line 52 of file HttpPutSocket.cpp.

00052                                               : HttpClientSocket(h)
00053 {
00054 }

HttpPutSocket::HttpPutSocket ( ISocketHandler h,
const std::string &  url_in 
)

client constructor,

Parameters:
url_in = 'http://host:port/resource'

Definition at line 57 of file HttpPutSocket.cpp.

00057                                                                       : HttpClientSocket(h, url_in)
00058 {
00059 }

HttpPutSocket::~HttpPutSocket (  ) 

Definition at line 62 of file HttpPutSocket.cpp.

00063 {
00064 }

HttpPutSocket::HttpPutSocket ( const HttpPutSocket s  )  [inline, private]

Definition at line 69 of file HttpPutSocket.h.

00069 : HttpClientSocket(s) {} // copy constructor


Member Function Documentation

void HttpPutSocket::SetFile ( const std::string &  file  ) 

Set filename to send.

Definition at line 67 of file HttpPutSocket.cpp.

References Errno, Socket::Handler(), LOG_LEVEL_FATAL, ISocketHandler::LogError(), m_content_length, m_filename, Socket::SetCloseAndDelete(), and StrError.

00068 {
00069         struct stat st;
00070         if (!stat(file.c_str(), &st))
00071         {
00072                 m_filename = file;
00073                 m_content_length = st.st_size;
00074         }
00075         else
00076         {
00077                 Handler().LogError(this, "SetFile", Errno, StrError(Errno), LOG_LEVEL_FATAL);
00078                 SetCloseAndDelete();
00079         }
00080 }

void HttpPutSocket::SetContentType ( const std::string &  type  ) 

Set mimetype of file to send.

Definition at line 83 of file HttpPutSocket.cpp.

References m_content_type.

00084 {
00085         m_content_type = type;
00086 }

void HttpPutSocket::Open (  ) 

connect to host:port derived from url in constructor

Definition at line 90 of file HttpPutSocket.cpp.

References HttpClientSocket::GetUrlHost(), HttpClientSocket::GetUrlPort(), and TcpSocket::Open().

00091 {
00092         // why do I have to specify TcpSocket:: to get to the Open() method??
00093         TcpSocket::Open(GetUrlHost(), GetUrlPort());
00094 }

void HttpPutSocket::OnConnect (  )  [virtual]

http put client implemented in OnConnect

Reimplemented from Socket.

Definition at line 97 of file HttpPutSocket.cpp.

References HTTPSocket::AddResponseHeader(), HttpClientSocket::GetUrlHost(), Utility::l2string(), m_content_length, m_content_type, m_filename, HTTPSocket::MyUseragent(), TcpSocket::SendBuf(), HTTPSocket::SendRequest(), HTTPSocket::SetHttpVersion(), and HTTPSocket::SetMethod().

00098 {
00099         SetMethod( "PUT" );
00100         SetHttpVersion( "HTTP/1.1" );
00101         AddResponseHeader( "Host", GetUrlHost() );
00102         AddResponseHeader( "Content-type", m_content_type );
00103         AddResponseHeader( "Content-length", Utility::l2string(m_content_length) );
00104         AddResponseHeader( "User-agent", MyUseragent() );
00105         SendRequest();
00106 
00107         std::auto_ptr<IFile> fil = std::auto_ptr<IFile>(new File);
00108         if (fil -> fopen(m_filename, "rb"))
00109         {
00110                 size_t n;
00111                 char buf[32768];
00112                 while ((n = fil -> fread(buf, 1, 32768)) > 0)
00113                 {
00114                         SendBuf(buf, n);
00115                 }
00116                 fil -> fclose();
00117         }
00118 }

HttpPutSocket& HttpPutSocket::operator= ( const HttpPutSocket  )  [inline, private]

Definition at line 70 of file HttpPutSocket.h.

00070 { return *this; } // assignment operator


Member Data Documentation

std::string HttpPutSocket::m_filename [private]

Filename to write response to.

Reimplemented from HttpClientSocket.

Definition at line 72 of file HttpPutSocket.h.

Referenced by OnConnect(), and SetFile().

std::string HttpPutSocket::m_content_type [private]

Content-type: header from response.

Reimplemented from HttpClientSocket.

Definition at line 73 of file HttpPutSocket.h.

Referenced by OnConnect(), and SetContentType().

Content-length header received from remote.

Reimplemented from HttpClientSocket.

Definition at line 74 of file HttpPutSocket.h.

Referenced by OnConnect(), and SetFile().


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