Core Base Classes for the Light Endpoints
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
Diff: HTTPTransport.cpp
- Revision:
- 37:1588ba3af6d1
- Parent:
- 36:73e343ddca7f
- Child:
- 39:4b9165d242f4
diff -r 73e343ddca7f -r 1588ba3af6d1 HTTPTransport.cpp --- a/HTTPTransport.cpp Sat Mar 01 05:31:26 2014 +0000 +++ b/HTTPTransport.cpp Sat Mar 01 05:57:50 2014 +0000 @@ -33,65 +33,7 @@ // default destructor 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); - } - - // create the IOC load URL - char *HTTPTransport::createIOCLoadURL() { return this->createIOCUpdateURL(0); } - - // create the IOC update URL - 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; - } - - // connect up HTTP - bool HTTPTransport::connect() { return this->m_connected; } - - // disconnect from HTTP - bool HTTPTransport::disconnect() { return true; } - + // HTTP Get bool HTTPTransport::httpGet(char *url,char *result,int result_length) { this->logger()->blinkTransportTxLED();