#include <HTTP_Handler.h>
Inheritance diagram for TAO_HTTP_Reader:
Public Member Functions | |
TAO_HTTP_Reader (ACE_Message_Block *mb, ACE_TCHAR *filename, const char *request_prefix="GET", const char *request_suffix="HTTP/1.0\r\nAccept: HTTP/1.0\r\n\r\n") | |
Private Member Functions | |
int | send_request (void) |
int | receive_reply (void) |
Private Attributes | |
const char * | request_prefix_ |
const char * | request_suffix_ |
Definition at line 80 of file HTTP_Handler.h.
TAO_HTTP_Reader::TAO_HTTP_Reader | ( | ACE_Message_Block * | mb, | |
ACE_TCHAR * | filename, | |||
const char * | request_prefix = "GET" , |
|||
const char * | request_suffix = "HTTP/1.0\r\nAccept: HTTP/1.0\r\n\r\n" | |||
) |
Definition at line 72 of file HTTP_Handler.cpp.
00075 : 00076 TAO_HTTP_Handler (mb, filename), 00077 request_prefix_ (request_prefix), 00078 request_suffix_ (request_suffix) 00079 { 00080 }
int TAO_HTTP_Reader::receive_reply | ( | void | ) | [private, virtual] |
Reimplemented from TAO_HTTP_Handler.
Definition at line 104 of file HTTP_Handler.cpp.
References ACE_ERROR_RETURN, ACE_NEW_RETURN, TAO_HTTP_Handler::bytecount_, ACE_Message_Block::cont(), ACE_Message_Block::copy(), LM_ERROR, TAO_HTTP_Handler::mb_, TAO_HTTP_Handler::MTU, ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer(), recv_n(), ACE_Message_Block::space(), ACE_OS::strstr(), and ACE_Message_Block::wr_ptr().
00105 { 00106 size_t num_recvd = 0; 00107 char buf [MTU+1]; 00108 char *buf_ptr = 0; 00109 size_t bytes_read = 0; 00110 00111 // Receive the first MTU bytes and strip the header off. 00112 // Note that we assume that the header will fit into MTU bytes. 00113 if (peer ().recv_n (buf, MTU, 0, &num_recvd) >= 0) 00114 { 00115 //Make sure that response type is 200 OK 00116 if (ACE_OS::strstr (buf,"200 OK") == 0) 00117 ACE_ERROR_RETURN ((LM_ERROR, 00118 "TAO (%P|%t) - HTTP_Reader::receive_reply, Response is not 200 OK\n" ), -1); 00119 00120 // Search for the header termination string "\r\n\r\n", or "\n\n". If 00121 // found, move past it to get to the data portion. 00122 if ((buf_ptr = ACE_OS::strstr (buf,"\r\n\r\n")) != 0) 00123 buf_ptr += 4; 00124 else if ((buf_ptr = ACE_OS::strstr (buf, "\n\n")) != 0) //for compatibility with JAWS 00125 buf_ptr += 2; 00126 else 00127 buf_ptr = buf; 00128 00129 // Determine number of data bytes read. This is equal to the 00130 // total bytes read minus number of header bytes. 00131 bytes_read = num_recvd - (buf_ptr - buf); 00132 00133 } 00134 else 00135 { 00136 ACE_ERROR_RETURN ((LM_ERROR, 00137 "TAO (%P|%t) - HTTP_Reader::receive_reply, error while reading header\n"), -1); 00138 } 00139 00140 // *************************************************************** 00141 // At this point, we have stripped off the header and are ready to 00142 // process data. buf_ptr points to the data 00143 00144 ACE_Message_Block* temp = 0; 00145 ACE_Message_Block* curr = this->mb_; 00146 00147 ACE_NEW_RETURN (temp, 00148 ACE_Message_Block (bytes_read), 00149 -1); 00150 curr->cont (temp); 00151 curr = curr->cont (); 00152 00153 // Copy over all the data bytes into our message buffer. 00154 if (curr->copy (buf_ptr, bytes_read) == -1) 00155 { 00156 ACE_ERROR_RETURN ((LM_ERROR, "TAO (%P|%t) - HTTP_Reader::receive_reply, error copying data into Message_Block\n"), -1); 00157 } 00158 00159 // read the rest of the data into a number of ACE_Message_Blocks and 00160 // chain them together in a link list fashion 00161 num_recvd = 0; 00162 00163 do 00164 { 00165 if (curr->space () == 0) 00166 { 00167 ACE_NEW_RETURN (temp, 00168 ACE_Message_Block (MTU), 00169 -1); 00170 curr->cont (temp); 00171 curr = curr->cont (); 00172 } 00173 00174 if (peer ().recv_n (curr->wr_ptr (), curr->space (), 0, &num_recvd) >= 0) 00175 { 00176 // Move the write pointer 00177 curr->wr_ptr (num_recvd); 00178 00179 // Increment bytes_read 00180 bytes_read += num_recvd; 00181 00182 } 00183 else 00184 { 00185 ACE_ERROR_RETURN ((LM_ERROR, 00186 "TAO (%P|%t) - HTTP_Reader::receive_reply, Error while reading header\n"), -1); 00187 } 00188 } while (num_recvd != 0); 00189 00190 // Set the byte count to number of bytes received 00191 this->bytecount_ = bytes_read; 00192 00193 return 0; 00194 }
int TAO_HTTP_Reader::send_request | ( | void | ) | [private, virtual] |
Reimplemented from TAO_HTTP_Handler.
Definition at line 83 of file HTTP_Handler.cpp.
References ACE_ERROR_RETURN, TAO_HTTP_Handler::filename_, LM_ERROR, TAO_HTTP_Handler::MAX_HEADER_SIZE, ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer(), request_prefix_, request_suffix_, send_n(), ACE_OS::sprintf(), and ACE_OS::strlen().
00084 { 00085 char mesg [MAX_HEADER_SIZE]; 00086 00087 // Check to see if the request is too big 00088 if (MAX_HEADER_SIZE < (ACE_OS::strlen (request_prefix_) 00089 + ACE_OS::strlen (filename_) 00090 + ACE_OS::strlen (request_suffix_) + 4)) 00091 ACE_ERROR_RETURN((LM_ERROR,"TAO (%P|%t) - HTTP_Reader::send_request, request too large!"), -1); 00092 00093 // Create a message to send to the server requesting retrieval of the file 00094 int const len = ACE_OS::sprintf (mesg, "%s %s %s", request_prefix_, filename_, request_suffix_); 00095 00096 // Send the message to server 00097 if (peer ().send_n (mesg, len) != len) 00098 ACE_ERROR_RETURN((LM_ERROR,"TAO (%P|%t) - HTTP_Reader::send_request, error sending request\n"), -1); 00099 00100 return 0; 00101 }
const char* TAO_HTTP_Reader::request_prefix_ [private] |
const char* TAO_HTTP_Reader::request_suffix_ [private] |