Murata RF modules are designed to simplify wireless development and certification by minimizing the amount of RF expertise you need to wirelessly enable a wide range of applications.

Committer:
yangcq88517
Date:
Mon Feb 15 15:17:50 2016 +0000
Revision:
8:5856c23794b1
Parent:
3:90ea1b8b2621
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangcq88517 0:8e83b9448758 1 #include "HTTPContent.h"
yangcq88517 0:8e83b9448758 2
yangcq88517 0:8e83b9448758 3 using namespace SmartLabMuRata;
yangcq88517 0:8e83b9448758 4
yangcq88517 0:8e83b9448758 5 const char HTTPContent::HEADER_SEPARATE[] = ": ";
yangcq88517 0:8e83b9448758 6 const char HTTPContent::HEADER_TEMINATE[] = "\r\n";
yangcq88517 0:8e83b9448758 7
yangcq88517 0:8e83b9448758 8 HTTPContent::HTTPContent(const HTTPMethod method, const char * remoteHost,const int remotePort,const char * uri, const char timeout, const char * contentType)
yangcq88517 0:8e83b9448758 9 {
yangcq88517 0:8e83b9448758 10 body = NULL;
yangcq88517 0:8e83b9448758 11 SetMethod(method)->SetRemoteHost(remoteHost)->SetRemotePort(remotePort)->SetURI(uri)->SetTimeout(timeout)->SetContentType(contentType);
yangcq88517 0:8e83b9448758 12 }
yangcq88517 0:8e83b9448758 13
yangcq88517 0:8e83b9448758 14 HTTPContent::~HTTPContent()
yangcq88517 0:8e83b9448758 15 {
yangcq88517 3:90ea1b8b2621 16 if (body != NULL)
yangcq88517 8:5856c23794b1 17 delete[] body;
yangcq88517 0:8e83b9448758 18 }
yangcq88517 0:8e83b9448758 19
yangcq88517 0:8e83b9448758 20 HTTPMethod HTTPContent::GetMethod()
yangcq88517 0:8e83b9448758 21 {
yangcq88517 0:8e83b9448758 22 return method;
yangcq88517 0:8e83b9448758 23 }
yangcq88517 0:8e83b9448758 24
yangcq88517 0:8e83b9448758 25 HTTPContent * HTTPContent::SetMethod(const HTTPMethod method)
yangcq88517 0:8e83b9448758 26 {
yangcq88517 0:8e83b9448758 27 this->method = method;
yangcq88517 0:8e83b9448758 28 return this;
yangcq88517 0:8e83b9448758 29 }
yangcq88517 0:8e83b9448758 30
yangcq88517 0:8e83b9448758 31 char HTTPContent::GetTimeout()
yangcq88517 0:8e83b9448758 32 {
yangcq88517 0:8e83b9448758 33 return timeout;
yangcq88517 0:8e83b9448758 34 }
yangcq88517 0:8e83b9448758 35
yangcq88517 0:8e83b9448758 36 /// <summary>
yangcq88517 0:8e83b9448758 37 /// Timeout is in seconds. If Timeout is 0, it means wait forever. A complete HTTP request will block other commands until either a response is received or timeout. So timeout value of 0 is not recommended. If timeout happens, the response status code would be SNIC_TIMEOUT. If it is chunked encoding in the response, the last chunk should be received before Timeout; otherwise, the connection is closed. If the HTTP request has more data to send (POST), it is not considered a complete HTTP request, and other commands are not blocked until the series of SNIC_HTTP_MORE_REQ are finished.
yangcq88517 0:8e83b9448758 38 /// </summary>
yangcq88517 0:8e83b9448758 39 /// <param name="timeout"></param>
yangcq88517 0:8e83b9448758 40 /// <returns></returns>
yangcq88517 0:8e83b9448758 41 HTTPContent * HTTPContent::SetTimeout(const char timeout)
yangcq88517 0:8e83b9448758 42 {
yangcq88517 0:8e83b9448758 43 this->timeout = timeout;
yangcq88517 0:8e83b9448758 44 return this;
yangcq88517 0:8e83b9448758 45 }
yangcq88517 0:8e83b9448758 46
yangcq88517 0:8e83b9448758 47 int HTTPContent::GetRemotePort()
yangcq88517 0:8e83b9448758 48 {
yangcq88517 0:8e83b9448758 49 return remotePort;
yangcq88517 0:8e83b9448758 50 }
yangcq88517 0:8e83b9448758 51
yangcq88517 0:8e83b9448758 52 HTTPContent * HTTPContent::SetRemotePort(const int port)
yangcq88517 0:8e83b9448758 53 {
yangcq88517 0:8e83b9448758 54 this->remotePort = port;
yangcq88517 0:8e83b9448758 55 return this;
yangcq88517 0:8e83b9448758 56 }
yangcq88517 0:8e83b9448758 57
yangcq88517 2:f8e393a81c25 58 const char * HTTPContent::GetRemoteHost()
yangcq88517 0:8e83b9448758 59 {
yangcq88517 2:f8e393a81c25 60 return remoteHost.c_str();
yangcq88517 0:8e83b9448758 61 }
yangcq88517 0:8e83b9448758 62
yangcq88517 0:8e83b9448758 63 HTTPContent * HTTPContent::SetRemoteHost(const char * host)
yangcq88517 0:8e83b9448758 64 {
yangcq88517 2:f8e393a81c25 65 remoteHost.assign(host);
yangcq88517 0:8e83b9448758 66 return this;
yangcq88517 0:8e83b9448758 67 }
yangcq88517 0:8e83b9448758 68
yangcq88517 2:f8e393a81c25 69 const char * HTTPContent::GetURI()
yangcq88517 0:8e83b9448758 70 {
yangcq88517 2:f8e393a81c25 71 return uri.c_str();
yangcq88517 0:8e83b9448758 72 }
yangcq88517 0:8e83b9448758 73
yangcq88517 0:8e83b9448758 74 HTTPContent * HTTPContent::SetURI(const char * uri)
yangcq88517 0:8e83b9448758 75 {
yangcq88517 2:f8e393a81c25 76 this->uri.assign(uri);
yangcq88517 0:8e83b9448758 77 return this;
yangcq88517 0:8e83b9448758 78 }
yangcq88517 0:8e83b9448758 79
yangcq88517 2:f8e393a81c25 80 const char * HTTPContent::GetContentType()
yangcq88517 0:8e83b9448758 81 {
yangcq88517 2:f8e393a81c25 82 return contentType.c_str();
yangcq88517 0:8e83b9448758 83 }
yangcq88517 0:8e83b9448758 84
yangcq88517 0:8e83b9448758 85 HTTPContent * HTTPContent::SetContentType(const char * contentType)
yangcq88517 0:8e83b9448758 86 {
yangcq88517 2:f8e393a81c25 87 if (contentType == NULL)
yangcq88517 2:f8e393a81c25 88 return this;
yangcq88517 2:f8e393a81c25 89
yangcq88517 2:f8e393a81c25 90 this->contentType.assign(contentType);
yangcq88517 0:8e83b9448758 91 return this;
yangcq88517 0:8e83b9448758 92 }
yangcq88517 0:8e83b9448758 93
yangcq88517 0:8e83b9448758 94 /*
yangcq88517 0:8e83b9448758 95 const string * HTTPContent::GetOtherHeader(const string * key)
yangcq88517 0:8e83b9448758 96 {
yangcq88517 0:8e83b9448758 97 if (otherHeaders.count(*key) > 0)
yangcq88517 0:8e83b9448758 98 return otherHeaders[*key];
yangcq88517 0:8e83b9448758 99 else return NULL;
yangcq88517 0:8e83b9448758 100 }*/
yangcq88517 0:8e83b9448758 101
yangcq88517 0:8e83b9448758 102 HTTPContent * HTTPContent::SetOtherHeader(const char * key, const char * value)
yangcq88517 0:8e83b9448758 103 {
yangcq88517 0:8e83b9448758 104 otherHeaders[key] = value;
yangcq88517 0:8e83b9448758 105 return this;
yangcq88517 0:8e83b9448758 106 }
yangcq88517 0:8e83b9448758 107
yangcq88517 0:8e83b9448758 108 void HTTPContent::GetOtherHeaders(string * headers)
yangcq88517 0:8e83b9448758 109 {
yangcq88517 2:f8e393a81c25 110 for (map<const char *, const char *>::iterator it=otherHeaders.begin(); it!=otherHeaders.end(); ++it)
yangcq88517 0:8e83b9448758 111 headers->append(it->first).append(HEADER_SEPARATE).append(it->second).append(HEADER_TEMINATE);
yangcq88517 0:8e83b9448758 112 }
yangcq88517 0:8e83b9448758 113
yangcq88517 0:8e83b9448758 114 const char * HTTPContent::GetBody()
yangcq88517 0:8e83b9448758 115 {
yangcq88517 0:8e83b9448758 116 return body;
yangcq88517 0:8e83b9448758 117 }
yangcq88517 0:8e83b9448758 118
yangcq88517 0:8e83b9448758 119 HTTPContent * HTTPContent::SetBody(char * body, int offset, int length)
yangcq88517 0:8e83b9448758 120 {
yangcq88517 0:8e83b9448758 121 if (body == NULL)
yangcq88517 0:8e83b9448758 122 contentLength = 0;
yangcq88517 0:8e83b9448758 123 else
yangcq88517 0:8e83b9448758 124 contentLength = length - offset;
yangcq88517 0:8e83b9448758 125
yangcq88517 0:8e83b9448758 126 if (this->body != NULL)
yangcq88517 0:8e83b9448758 127 delete[] this->body;
yangcq88517 0:8e83b9448758 128
yangcq88517 0:8e83b9448758 129 this->body = new char[contentLength];
yangcq88517 0:8e83b9448758 130 memcpy(this->body, body + offset, contentLength);
yangcq88517 0:8e83b9448758 131 return this;
yangcq88517 0:8e83b9448758 132 }
yangcq88517 0:8e83b9448758 133
yangcq88517 0:8e83b9448758 134 HTTPContent * HTTPContent::ClearBody()
yangcq88517 0:8e83b9448758 135 {
yangcq88517 0:8e83b9448758 136 contentLength = 0;
yangcq88517 0:8e83b9448758 137 delete[] body;
yangcq88517 0:8e83b9448758 138 body = NULL;
yangcq88517 0:8e83b9448758 139 return this;
yangcq88517 0:8e83b9448758 140 }
yangcq88517 0:8e83b9448758 141
yangcq88517 0:8e83b9448758 142 int HTTPContent::GetContentLength()
yangcq88517 0:8e83b9448758 143 {
yangcq88517 0:8e83b9448758 144 return contentLength;
yangcq88517 0:8e83b9448758 145 }