Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / apps / JAWS2 / HTTPU / parse_http_request.cpp
blobcd1eb9ec8f4dbfff2c85ca89f59659cb55de8350
1 #include "HTTPU/parse_http_request.h"
3 Parse_HTTP_Request::Parse_HTTP_Request (const char *request)
4 : method_ (0),
5 major_version_ (-1),
6 minor_version_ (-1),
7 version_ (0),
8 url_ (0),
9 request_ (0),
10 error_ (0)
12 if (request != 0)
13 this->init (request);
16 Parse_HTTP_Request::~Parse_HTTP_Request ()
18 if (this->request_)
19 ACE_OS::free (this->request_);
20 this->request_ = 0;
21 this->version_ = 0;
22 this->url_ = 0;
25 void
26 Parse_HTTP_Request::dump ()
28 ACE_DEBUG ((LM_DEBUG, "%s %s %s\n",
29 this->method_str (), this->url (), this->version ()));
32 void
33 Parse_HTTP_Request::init (const char *request)
35 char *method;
37 this->request_ = ACE_OS::strdup (request);
38 if (this->request_ == 0)
40 this->error_ = NO_MEMORY;
41 return;
44 char buf[BUFSIZ];
45 int n = ::sscanf (this->request_, "%s %*s HTTP/%d.%d",
46 buf,
47 &(this->major_version_),
48 &(this->minor_version_));
50 if (n == 1 || n == 3)
52 char *p = this->request_;
54 while (*p == ' ' || *p == '\t')
55 p++;
57 method = p++;
59 while (*p != ' ' && *p != '\t')
60 p++;
62 *p++ = '\0';
64 while (*p == ' ' || *p == '\t')
65 p++;
67 this->url_ = p;
69 while (*p && !ACE_OS::strchr (" \t\r\n", *p))
70 p++;
72 *p++ = '\0';
74 if (n == 1)
76 this->major_version_ = 0;
77 this->minor_version_ = 9;
79 else
81 while (*p == ' ' || *p == '\t')
82 p++;
84 this->version_ = p;
86 while (*p && !ACE_OS::strchr (" \t\r\n", *p))
87 p++;
89 *p++ = '\0';
92 if (ACE_OS::strcmp (method, "GET") == 0)
93 this->method_ = &GET;
94 else if (ACE_OS::strcmp (method, "HEAD") == 0)
95 this->method_ = &HEAD;
96 else if (ACE_OS::strcmp (method, "POST") == 0)
97 this->method_ = &POST;
98 else if (ACE_OS::strcmp (method, "PUT") == 0)
99 this->method_ = &PUT;
100 else if (ACE_OS::strcmp (method, "QUIT") == 0)
101 this->method_ = &QUIT;
102 else
104 this->method_ = &DUNNO;
105 this->error_ = NOT_IMPLEMENTED;
108 else
109 this->error_ = BAD_REQUEST;
112 #if !defined (ACE_HAS_INLINED_OSCALLS)
113 # include "HTTPU/parse_http_request.inl"
114 #endif /* ACE_HAS_INLINED_OSCALLS */