1 | /**
|
---|
2 | * CRXHttpResponse.cpp
|
---|
3 | */
|
---|
4 | #ifdef _WIN32
|
---|
5 | # pragma warning (disable:4996)
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #include "CRXHttpResponse.h"
|
---|
9 |
|
---|
10 | #include <iostream>
|
---|
11 | #include <stdio.h>
|
---|
12 | #include <stdlib.h>
|
---|
13 |
|
---|
14 | CRXHttpResponse::CRXHttpResponse (void)
|
---|
15 | : mStatusCode (0)
|
---|
16 | {
|
---|
17 | }
|
---|
18 |
|
---|
19 | void
|
---|
20 | CRXHttpResponse::SetResponse (const char * aHttpResponse)
|
---|
21 | {
|
---|
22 | SetMessage (aHttpResponse);
|
---|
23 | }
|
---|
24 |
|
---|
25 | std::string
|
---|
26 | CRXHttpResponse::GetResponse (void) const
|
---|
27 | {
|
---|
28 | return GetMessage ();
|
---|
29 | }
|
---|
30 |
|
---|
31 | CRXHttpResponse &
|
---|
32 | CRXHttpResponse::operator = (const char * aHttpMessage)
|
---|
33 | {
|
---|
34 | SetMessage (aHttpMessage);
|
---|
35 | return *this;
|
---|
36 | }
|
---|
37 |
|
---|
38 | void
|
---|
39 | CRXHttpResponse::Parse (void)
|
---|
40 | {
|
---|
41 | std::string aHttpStatus = "";
|
---|
42 |
|
---|
43 | char aStatusCode[64] = {0x00, };
|
---|
44 | char aStatusString[64] = {0x00, };
|
---|
45 | char aHttpVersion[64] = {0x00, };
|
---|
46 |
|
---|
47 | /*----------------------------------------------------------------*/
|
---|
48 | aHttpStatus = GetResponse ().substr (0, mHttpMessage.find ('\r'));
|
---|
49 |
|
---|
50 | /*----------------------------------------------------------------
|
---|
51 | * 1. separate first line to <METHOD>, <URL> and <VERSION>
|
---|
52 | *----------------------------------------------------------------*/
|
---|
53 | sscanf (aHttpStatus.c_str (), "%[^ ] %[^ ] %[^ ]\r\n", aHttpVersion, aStatusCode, aStatusString);
|
---|
54 | mHttpVersion.assign (aHttpVersion);
|
---|
55 | mStatusString.assign (aStatusString);
|
---|
56 | mStatusCode = atoi (aStatusCode);
|
---|
57 |
|
---|
58 | /*----------------------------------------------------------------*/
|
---|
59 | }
|
---|
60 |
|
---|
61 | int
|
---|
62 | CRXHttpResponse::GetStatusCode (void) const
|
---|
63 | {
|
---|
64 | return mStatusCode;
|
---|
65 | } |
---|