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