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 45 of file HttpPutSocket.h.


Constructor & Destructor Documentation

HttpPutSocket::HttpPutSocket ( ISocketHandler h  ) 

Definition at line 51 of file HttpPutSocket.cpp.

00051                                               : HttpClientSocket(h)
00052 {
00053 }

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

client constructor,

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

Definition at line 56 of file HttpPutSocket.cpp.

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

HttpPutSocket::~HttpPutSocket (  ) 

Definition at line 61 of file HttpPutSocket.cpp.

00062 {
00063 }

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

Definition at line 67 of file HttpPutSocket.h.

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


Member Function Documentation

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

Set filename to send.

Definition at line 66 of file HttpPutSocket.cpp.

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

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

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

Set mimetype of file to send.

Definition at line 82 of file HttpPutSocket.cpp.

References m_content_type.

00083 {
00084         m_content_type = type;
00085 }

void HttpPutSocket::Open (  ) 

connect to host:port derived from url in constructor

Definition at line 89 of file HttpPutSocket.cpp.

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

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

void HttpPutSocket::OnConnect (  )  [virtual]

http put client implemented in OnConnect

Reimplemented from Socket.

Definition at line 96 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().

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

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

Definition at line 68 of file HttpPutSocket.h.

00068 { return *this; } // assignment operator


Member Data Documentation

std::string HttpPutSocket::m_filename [private]

Filename to write response to.

Reimplemented from HttpClientSocket.

Definition at line 70 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 71 of file HttpPutSocket.h.

Referenced by OnConnect(), and SetContentType().

Content-length header received from remote.

Reimplemented from HttpClientSocket.

Definition at line 72 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