Logo
~Sockets~
~Examples~
~Contact~


HttpPutSocket Class Reference
[HTTP Sockets]

Put http page. More...

#include <HttpPutSocket.h>

Inheritance diagram for HttpPutSocket:

Inheritance graph
[legend]
Collaboration diagram for HttpPutSocket:

Collaboration graph
[legend]
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  ) 

Definition at line 50 of file HttpPutSocket.cpp.

00050                                               : HttpClientSocket(h)
00051 {
00052 }

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

client constructor,

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

Definition at line 55 of file HttpPutSocket.cpp.

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

HttpPutSocket::~HttpPutSocket (  ) 

Definition at line 60 of file HttpPutSocket.cpp.

00061 {
00062 }

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 &   ) 

Set filename to send.

Definition at line 65 of file HttpPutSocket.cpp.

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

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

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

Set mimetype of file to send.

Definition at line 81 of file HttpPutSocket.cpp.

References m_content_type.

00082 {
00083         m_content_type = type;
00084 }

void HttpPutSocket::Open (  ) 

connect to host:port derived from url in constructor

Definition at line 88 of file HttpPutSocket.cpp.

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

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

void HttpPutSocket::OnConnect (  )  [virtual]

http put client implemented in OnConnect

Reimplemented from Socket.

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

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

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