#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 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 } |
|
Reimplemented from TAO_HTTP_Handler. Definition at line 104 of file HTTP_Handler.cpp. References ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_Message_Block::cont(), ACE_Message_Block::copy(), LM_ERROR, ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer(), 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 "HTTP_Reader::receiveReply(): 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 "%p\n", 00138 "HTTP_Reader::receiveReply():Error while reading header\n"), -1); 00139 } 00140 00141 // *************************************************************** 00142 // At this point, we have stripped off the header and are ready to 00143 // process data. buf_ptr points to the data 00144 00145 ACE_Message_Block* temp = 0; 00146 ACE_Message_Block* curr = this->mb_; 00147 00148 ACE_NEW_RETURN (temp, 00149 ACE_Message_Block (bytes_read), 00150 -1); 00151 curr->cont (temp); 00152 curr = curr->cont (); 00153 00154 // Copy over all the data bytes into our message buffer. 00155 if (curr->copy (buf_ptr, bytes_read) == -1) 00156 { 00157 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", 00158 "HTTP_Reader::receiveReply():Error copying data into Message_Block\n" ), -1); 00159 } 00160 00161 // read the rest of the data into a number of ACE_Message_Blocks and 00162 // chain them together in a link list fashion 00163 num_recvd = 0; 00164 00165 do 00166 { 00167 if (curr->space () == 0) 00168 { 00169 ACE_NEW_RETURN (temp, 00170 ACE_Message_Block (MTU), 00171 -1); 00172 curr->cont (temp); 00173 curr = curr->cont (); 00174 } 00175 00176 if (peer ().recv_n (curr->wr_ptr (), curr->space (), 0, &num_recvd) >= 0) 00177 { 00178 // Move the write pointer 00179 curr->wr_ptr (num_recvd); 00180 00181 // Increment bytes_read 00182 bytes_read += num_recvd; 00183 00184 } 00185 else 00186 { 00187 ACE_ERROR_RETURN ((LM_ERROR, 00188 "%p\n", 00189 "TAO_HTTP_Reader::receive_reply(): Error while reading header\n"), -1); 00190 } 00191 } while (num_recvd != 0); 00192 00193 // Set the byte count to number of bytes received 00194 this->bytecount_ = bytes_read; 00195 00196 return 0; 00197 } |
|
Reimplemented from TAO_HTTP_Handler. Definition at line 83 of file HTTP_Handler.cpp. References ACE_ERROR_RETURN, LM_ERROR, ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer(), request_prefix_, request_suffix_, 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,"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,"Error sending request\n"), -1); 00099 00100 return 0; 00101 } |
|
Definition at line 92 of file HTTP_Handler.h. Referenced by send_request(). |
|
Definition at line 93 of file HTTP_Handler.h. Referenced by send_request(). |