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.

Files at this revision

API Documentation at this revision

Comitter:
yangcq88517
Date:
Wed Feb 04 20:37:40 2015 +0000
Parent:
1:fd19bd683e90
Child:
3:90ea1b8b2621
Commit message:
Bug Fix (Payload SetContent)

Changed in this revision

Indication/HTTPResponseIndication.cpp Show annotated file Show diff for this revision Revisions of this file
MuRata.cpp Show annotated file Show diff for this revision Revisions of this file
Payload.cpp Show annotated file Show diff for this revision Revisions of this file
Payload.h Show annotated file Show diff for this revision Revisions of this file
Response/HTTPResponse.cpp Show annotated file Show diff for this revision Revisions of this file
Type/HTTPContent.cpp Show annotated file Show diff for this revision Revisions of this file
Type/HTTPContent.h Show annotated file Show diff for this revision Revisions of this file
--- a/Indication/HTTPResponseIndication.cpp	Wed Feb 04 18:10:30 2015 +0000
+++ b/Indication/HTTPResponseIndication.cpp	Wed Feb 04 20:37:40 2015 +0000
@@ -6,6 +6,7 @@
     : Payload(payload)
 {
     contentLength = (GetData()[2] & 0x7F) << 8 | GetData()[3];
+    GetData()[PAYLOAD_OFFSET + contentLength] = 0x00;
 }
 
 bool HTTPResponseIndication::isMoreDataComing()
--- a/MuRata.cpp	Wed Feb 04 18:10:30 2015 +0000
+++ b/MuRata.cpp	Wed Feb 04 20:37:40 2015 +0000
@@ -748,31 +748,29 @@
 
 HTTPResponse * MuRata::SNIC_SendHTTPRequest(HTTPContent * content, const bool isHTTPS, const bool chunked)
 {
-    SubCommandID _id = isHTTPS ? SNIC_HTTPS_REQ: SNIC_HTTP_REQ;
-
+    SubCommandID _id = (isHTTPS == true) ? SNIC_HTTPS_REQ: SNIC_HTTP_REQ;
 
     _payload.Rewind();
     _payload.SetSubCommandID(_id);
     _payload.SetFrameID(_payload.GetFrameID() + 1);
-    _payload.SetContent((char)(content->GetRemotePort() >> 8));
-    _payload.SetContent((char)content->GetRemotePort());
+    _payload.SetContent(content->GetRemotePort() >> 8);
+    _payload.SetContent(content->GetRemotePort());
     _payload.SetContent((char)content->GetMethod());
     _payload.SetContent(content->GetTimeout());
 
-    _payload.SetContent(content->GetRemoteHost()->c_str(), 0, content->GetRemoteHost()->length());
+    _payload.SetContent(content->GetRemoteHost(), 0, strlen(content->GetRemoteHost()));
     _payload.SetContent(0x00);
 
-    _payload.SetContent(content->GetURI()->c_str(), 0, content->GetURI()->length());
+    _payload.SetContent(content->GetURI(), 0, strlen(content->GetURI()));
     _payload.SetContent(0x00);
 
-    _payload.SetContent(content->GetContentType()->c_str(), 0, content->GetContentType()->length());
+    _payload.SetContent(content->GetContentType(), 0, strlen(content->GetContentType()));
     _payload.SetContent(0x00);
 
-    string * _others = new string();
-    content->GetOtherHeaders(_others);
-    _payload.SetContent(_others->c_str(), 0, _others->length());
+    string _others;
+    content->GetOtherHeaders(&_others);
+    _payload.SetContent(_others.c_str(), 0, _others.length());
     _payload.SetContent(0x00);
-    delete _others;
 
     if (content->GetMethod() == POST) {
         int length = content->GetContentLength();
--- a/Payload.cpp	Wed Feb 04 18:10:30 2015 +0000
+++ b/Payload.cpp	Wed Feb 04 20:37:40 2015 +0000
@@ -15,7 +15,7 @@
     this->position = payload->position;
 }
 
-const char * Payload::GetData()
+char * Payload::GetData()
 {
     return data;
 }
@@ -79,7 +79,7 @@
         return;
 
     if (length > max) {
-        delete data;
+        delete[] data;
         data = new char[length];
     }
 
@@ -94,9 +94,9 @@
 void Payload::SetContent(const char value)
 {
     if (position >= max) {
-        char temp[max + EXPANDSIZE];
+        char * temp = new char[max + EXPANDSIZE];
         memcpy(temp, data, position);
-        delete data;
+        delete[] data;
         data = temp;
     }
 
@@ -105,14 +105,17 @@
 
 void Payload::SetContent(const char * value, const int offset, const int length)
 {
-    if (position + length - offset>= max) {
+    if (length <= 0)
+        return;
+
+    if (position + length >= max) {
         max += EXPANDSIZE * (1 + length / EXPANDSIZE);
-        char temp[max];
+        char * temp = new char[max];
         memcpy(temp, data, position);
-        delete data;
+        delete[] data;
         data = temp;
     }
 
-    memcpy(data + position, value, length);
+    memcpy(data + position, value + offset, length);
     position += length;
 }
\ No newline at end of file
--- a/Payload.h	Wed Feb 04 18:10:30 2015 +0000
+++ b/Payload.h	Wed Feb 04 20:37:40 2015 +0000
@@ -26,7 +26,7 @@
 
     Payload(Payload * payload);
 
-    const char * GetData();
+    char * GetData();
 
     /// <summary>
     /// The first byte of the Payload of the command describes the specific operation to perform for the Command ID, and it contains the Response Flag and Sub-Command ID (RFSCID). The Payload may be a request (REQ) from the host to the module, a response (RSP) from the module to that request, an indication (IND) from the module to the host, and the optional confirmation (CFM) from the host for that indication.
--- a/Response/HTTPResponse.cpp	Wed Feb 04 18:10:30 2015 +0000
+++ b/Response/HTTPResponse.cpp	Wed Feb 04 20:37:40 2015 +0000
@@ -8,8 +8,10 @@
     statusCode = GetData()[2] << 8 | GetData()[3];
     if (statusCode >= 100) {
         contentLength = (GetData()[4] & 0x7F) << 8 | GetData()[5];
-        contentType = string(GetData() + 6);
+        contentType.assign(GetData() + 6);
         payloadOffset = 6 + contentType.length() + 1;
+
+        GetData()[payloadOffset + contentLength] = 0x00;
     }
 }
 
--- a/Type/HTTPContent.cpp	Wed Feb 04 18:10:30 2015 +0000
+++ b/Type/HTTPContent.cpp	Wed Feb 04 20:37:40 2015 +0000
@@ -11,15 +11,10 @@
     SetMethod(method)->SetRemoteHost(remoteHost)->SetRemotePort(remotePort)->SetURI(uri)->SetTimeout(timeout)->SetContentType(contentType);
 }
 
-/*
 HTTPContent::~HTTPContent()
 {
-    delete remoteHost;
-    delete uri;
-    delete contentType;
-    delete body;
+    delete[] body;
 }
-*/
 
 HTTPMethod HTTPContent::GetMethod()
 {
@@ -59,36 +54,39 @@
     return this;
 }
 
-string * HTTPContent::GetRemoteHost()
+const char * HTTPContent::GetRemoteHost()
 {
-    return &remoteHost;
+    return remoteHost.c_str();
 }
 
 HTTPContent * HTTPContent::SetRemoteHost(const char * host)
 {
-    remoteHost = host;
+    remoteHost.assign(host);
     return this;
 }
 
-string * HTTPContent::GetURI()
+const char *  HTTPContent::GetURI()
 {
-    return &uri;
+    return uri.c_str();
 }
 
 HTTPContent * HTTPContent::SetURI(const char * uri)
 {
-    this->uri = uri;
+    this->uri.assign(uri);
     return this;
 }
 
-string * HTTPContent::GetContentType()
+const char * HTTPContent::GetContentType()
 {
-    return &contentType;
+    return contentType.c_str();
 }
 
 HTTPContent * HTTPContent::SetContentType(const char * contentType)
 {
-    this->contentType = string(contentType);
+    if (contentType == NULL)
+        return this;
+
+    this->contentType.assign(contentType);
     return this;
 }
 
@@ -108,10 +106,8 @@
 
 void HTTPContent::GetOtherHeaders(string * headers)
 {
-    for (std::map<const char *, const char *>::iterator it=otherHeaders.begin(); it!=otherHeaders.end(); ++it)
+    for (map<const char *, const char *>::iterator it=otherHeaders.begin(); it!=otherHeaders.end(); ++it)
         headers->append(it->first).append(HEADER_SEPARATE).append(it->second).append(HEADER_TEMINATE);
-
-    headers->append(HEADER_TEMINATE);
 }
 
 const char * HTTPContent::GetBody()
--- a/Type/HTTPContent.h	Wed Feb 04 18:10:30 2015 +0000
+++ b/Type/HTTPContent.h	Wed Feb 04 20:37:40 2015 +0000
@@ -43,7 +43,7 @@
 
     HTTPContent(const HTTPMethod method, const char * remoteHost,const int remotePort,const char * uri,const char timeout, const char * contentType = NULL);
 
-    //~HTTPContent();
+    ~HTTPContent();
 
     HTTPMethod GetMethod();
 
@@ -62,15 +62,15 @@
 
     HTTPContent * SetRemotePort(const int port);
 
-    string * GetRemoteHost() ;
+    const char * GetRemoteHost() ;
 
     HTTPContent * SetRemoteHost(const char * host);
 
-    string * GetURI();
+    const char * GetURI();
 
     HTTPContent * SetURI(const char * uri) ;
 
-    string * GetContentType();
+    const char * GetContentType();
 
     HTTPContent * SetContentType(const char * contentType);