source: cheroxy/trunk/src/CRXHttpRequest.cpp@ 6

Last change on this file since 6 was 6, checked in by cheese, 12 years ago

#1 개발버전 게시

File size: 2.4 KB
Line 
1/**
2 * CRXHttpRequest.cpp
3 */
4#ifdef _WIN32
5# pragma warning (disable:4996)
6#endif
7
8#include "CRXHttpRequest.h"
9
10#include <iostream>
11#include <stdio.h>
12#include <stdlib.h>
13
14CRXHttpRequest::CRXHttpRequest (void)
15 : mMethod (""),
16 mUrl (""),
17 mHttpVersion (""),
18 mProtocol (""),
19 mHost (""),
20 mPort (0)
21{
22}
23
24void
25CRXHttpRequest::SetRequest (const char * aHttpRequest)
26{
27 SetMessage (aHttpRequest);
28}
29
30std::string
31CRXHttpRequest::GetRequest (void) const
32{
33 return GetMessage ();
34}
35
36std::string
37CRXHttpRequest::GetURL (void) const
38{
39 return mUrl;
40}
41
42std::string
43CRXHttpRequest::GetHost (void) const
44{
45 return mHost;
46}
47
48int
49CRXHttpRequest::GetPort (void) const
50{
51 return mPort;
52}
53
54CRXHttpRequest &
55CRXHttpRequest::operator = (const char * aHttpMessage)
56{
57 SetRequest (aHttpMessage);
58 return *this;
59}
60
61void
62CRXHttpRequest::Parse (void)
63{
64 std::string aHttpRequestUri = "";
65
66 char aMethod[64] = {0x00, };
67 char aUrl[1024] = {0x00, };
68 char aHttpVersion[64] = {0x00, };
69
70 char aProtocol[32] = {0x00, };
71 char aHostBuffer[512] = {0x00, };
72 char aHost[512] = {0x00, };
73 char aPortBuffer[32] = {0x00, };
74 int aPort = 0;
75
76 /*----------------------------------------------------------------*/
77 aHttpRequestUri = GetRequest ().substr (0, mHttpMessage.find ('\r'));
78
79 /*----------------------------------------------------------------
80 * 1. separate first line to <METHOD>, <URL> and <VERSION>
81 *----------------------------------------------------------------*/
82 sscanf (aHttpRequestUri.c_str (), "%[^ ] %[^ ] %[^ ]\r\n", aMethod, aUrl, aHttpVersion);
83 mMethod.assign (aMethod);
84 mUrl.assign (aUrl);
85 mHttpVersion.assign (aHttpVersion);
86
87 /*----------------------------------------------------------------
88 * 2. separate <URL> to <PROTOCOL> and <HOST>
89 *----------------------------------------------------------------*/
90 sscanf (mUrl.c_str (), "%[^://]://%[^/]", aProtocol, aHostBuffer);
91 mProtocol.assign (aProtocol);
92
93 /*----------------------------------------------------------------
94 * 3. separate <HOST> to <HOSTNAME>:<PORT>
95 *----------------------------------------------------------------*/
96 sscanf (aHostBuffer, "%[^:]:%s", aHost, aPortBuffer);
97 mHost.assign (aHost);
98 aPort = atoi (aPortBuffer);
99
100 mPort = aPort == 0 ? 80 : aPort;
101 /*----------------------------------------------------------------*/
102}
Note: See TracBrowser for help on using the repository browser.