Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027 C12832 EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed
Diff: HTTPTransport.cpp
- Revision:
- 21:d1ce325d1d32
- Parent:
- 20:4d7321f7579d
- Child:
- 23:793b2898522e
--- a/HTTPTransport.cpp Thu Feb 27 15:20:30 2014 +0000
+++ b/HTTPTransport.cpp Thu Feb 27 22:07:45 2014 +0000
@@ -37,15 +37,33 @@
HTTPTransport::~HTTPTransport() {
}
+ // package up data
+ char *HTTPTransport::packageData(char *verb,char *data,int ioc_id) {
+ char buffer[IOC_PAYLOAD_LEN+1];
+ memset(buffer,0,IOC_PAYLOAD_LEN+1);
+ if (USE_GW_HTTP_REDIRECTOR == false) {
+ // just use the data
+ return data;
+ }
+ else {
+ // repackage into format: VERB;USER;PASS;AUTHDOMAIN;CONTENTTYPE;JSON;URL
+ sprintf(buffer,"%s;%s;%s;_none_;%s;%s;%s ",verb,IOC_USERNAME,IOC_PASSWORD,"application/json",data,this->createIOCUpdateURL(ioc_id,false));
+ memcpy(data,buffer,strlen(buffer));
+ return data;
+ }
+ }
+
// Load up our endpoint into the IOC
bool HTTPTransport::loadEndpoint(char *data,int data_length,char *result,int result_length) {
this->logger()->log("loadEndpoint: %s",data);
+ data = this->packageData("POST",data,0);
return this->httpPost(this->createIOCLoadURL(),data,strlen(data),result,result_length);
}
// update our endpoint with the IOC
bool HTTPTransport::updateEndpoint(int ioc_id,char *data,int data_length,char *result,int result_length) {
this->logger()->log("updateEndpoint: %s",data);
+ data = this->packageData("PUT",data,ioc_id);
return this->httpPut(this->createIOCUpdateURL(ioc_id),data,strlen(data),result,result_length);
}
@@ -53,12 +71,21 @@
char *HTTPTransport::createIOCLoadURL() { return this->createIOCUpdateURL(0); }
// create the IOC update URL
- char *HTTPTransport::createIOCUpdateURL(int ioc_id) {
- char ioc_id_str[IOC_IOC_ID_LEN+1];
- memset(ioc_id_str,0,IOC_IOC_ID_LEN+1);
- if (ioc_id > 0) sprintf(ioc_id_str,"/%d",ioc_id);
- memset(this->m_url_buffer,0,IOC_REST_URL_LEN+1);
- sprintf(this->m_url_buffer,IOC_REST_URL,IOC_HOST_NAME,IOC_DATASOURCE_ID,ioc_id_str);
+ char *HTTPTransport::createIOCUpdateURL(int ioc_id) { return this->createIOCUpdateURL(ioc_id,USE_GW_HTTP_REDIRECTOR); }
+ char *HTTPTransport::createIOCUpdateURL(int ioc_id,bool useRedirector) {
+ if (useRedirector == false) {
+ // make HTTP calls directly
+ char ioc_id_str[IOC_IOC_ID_LEN+1];
+ memset(ioc_id_str,0,IOC_IOC_ID_LEN+1);
+ if (ioc_id > 0) sprintf(ioc_id_str,"/%d",ioc_id);
+ memset(this->m_url_buffer,0,IOC_REST_URL_LEN+1);
+ sprintf(this->m_url_buffer,IOC_REST_URL,IOC_HOST_NAME,IOC_DATASOURCE_ID,ioc_id_str);
+ }
+ else {
+ // use the GW HTTP redirector
+ memset(this->m_url_buffer,0,IOC_REST_URL_LEN+1);
+ sprintf(this->m_url_buffer,GW_REDIRECT_URL,GW_IPADDRESS);
+ }
return this->m_url_buffer;
}