1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// $Id: parse_http_response.cpp 80826 2008-03-04 14:51:23Z wotte $
#include "HTTPU/parse_http_response.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_stdlib.h"
Parse_HTTP_Response::Parse_HTTP_Response (const char *response)
: code_ (200),
code_str_ (0),
major_version_ (0),
minor_version_ (9),
version_ (0),
response_ (0),
error_ (0)
{
if (response != 0)
this->init (response);
}
Parse_HTTP_Response::~Parse_HTTP_Response (void)
{
if (this->response_)
ACE_OS::free (this->response_);
this->response_ = 0;
this->code_str_ = 0;
this->version_ = 0;
}
void
Parse_HTTP_Response::init (const char *response)
{
this->response_ = ACE_OS::strdup (response);
if (this->response_ == 0)
{
this->error_ = NO_MEMORY;
return;
}
int n = ::sscanf (this->response_, "HTTP/%d.%d %d %*s",
&(this->major_version_),
&(this->minor_version_),
&(this->code_));
if (n == 3)
{
char *p = this->response_;
while (*p == ' ' || *p == '\t')
p++;
this->version_ = p++;
while (*p != ' ' && *p != '\t')
p++;
*p++ = '\0';
while (*p == ' ' || *p == '\t')
p++;
this->code_str_ = p;
while (*p && !ACE_OS::strchr (" \t\r\n", *p))
p++;
*p++ = '\0';
}
else
this->error_ = BAD_RESPONSE;
}
#if !defined (ACE_HAS_INLINED_OSCALLS)
# include "HTTPU/parse_http_response.inl"
#endif /* ACE_HAS_INLINED_OSCALLS */
|