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
HTTPTransport.cpp@37:1588ba3af6d1, 2014-03-01 (annotated)
- Committer:
- ansond
- Date:
- Sat Mar 01 05:57:50 2014 +0000
- Revision:
- 37:1588ba3af6d1
- Parent:
- 36:73e343ddca7f
- Child:
- 39:4b9165d242f4
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 30:bf56ef794ba6 | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 30:bf56ef794ba6 | 2 | * |
ansond | 30:bf56ef794ba6 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 30:bf56ef794ba6 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 30:bf56ef794ba6 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 30:bf56ef794ba6 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 30:bf56ef794ba6 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 30:bf56ef794ba6 | 8 | * |
ansond | 30:bf56ef794ba6 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 30:bf56ef794ba6 | 10 | * substantial portions of the Software. |
ansond | 30:bf56ef794ba6 | 11 | * |
ansond | 30:bf56ef794ba6 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 30:bf56ef794ba6 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 30:bf56ef794ba6 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 30:bf56ef794ba6 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 30:bf56ef794ba6 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 30:bf56ef794ba6 | 17 | */ |
ansond | 30:bf56ef794ba6 | 18 | |
ansond | 30:bf56ef794ba6 | 19 | #include "HTTPTransport.h" |
ansond | 30:bf56ef794ba6 | 20 | |
ansond | 30:bf56ef794ba6 | 21 | // Endpoint Support |
ansond | 30:bf56ef794ba6 | 22 | #include "MBEDEndpoint.h" |
ansond | 31:7a4bb4742e69 | 23 | |
ansond | 30:bf56ef794ba6 | 24 | // HTTP Client |
ansond | 30:bf56ef794ba6 | 25 | HTTPClient _http; |
ansond | 30:bf56ef794ba6 | 26 | |
ansond | 30:bf56ef794ba6 | 27 | // default constructor |
ansond | 30:bf56ef794ba6 | 28 | HTTPTransport::HTTPTransport(ErrorHandler *error_handler,void *endpoint) : Transport(error_handler,endpoint) { |
ansond | 30:bf56ef794ba6 | 29 | this->m_http = &_http; |
ansond | 30:bf56ef794ba6 | 30 | this->m_connected = true; |
ansond | 30:bf56ef794ba6 | 31 | } |
ansond | 30:bf56ef794ba6 | 32 | |
ansond | 30:bf56ef794ba6 | 33 | // default destructor |
ansond | 30:bf56ef794ba6 | 34 | HTTPTransport::~HTTPTransport() { |
ansond | 30:bf56ef794ba6 | 35 | } |
ansond | 37:1588ba3af6d1 | 36 | |
ansond | 30:bf56ef794ba6 | 37 | // HTTP Get |
ansond | 30:bf56ef794ba6 | 38 | bool HTTPTransport::httpGet(char *url,char *result,int result_length) { |
ansond | 36:73e343ddca7f | 39 | this->logger()->blinkTransportTxLED(); |
ansond | 30:bf56ef794ba6 | 40 | int status = this->m_http->get(url,result,result_length); |
ansond | 36:73e343ddca7f | 41 | this->logger()->blinkTransportRxLED(); |
ansond | 30:bf56ef794ba6 | 42 | this->logger()->log("httpGet: Status: %d",status); |
ansond | 30:bf56ef794ba6 | 43 | return (status == 0); |
ansond | 30:bf56ef794ba6 | 44 | } |
ansond | 30:bf56ef794ba6 | 45 | |
ansond | 30:bf56ef794ba6 | 46 | // HTTP Put |
ansond | 30:bf56ef794ba6 | 47 | bool HTTPTransport::httpPut(char *url,char *data,int data_length,char *result,int result_length) { |
ansond | 30:bf56ef794ba6 | 48 | HTTPText output(data,data_length); |
ansond | 30:bf56ef794ba6 | 49 | HTTPText input(result,result_length); |
ansond | 30:bf56ef794ba6 | 50 | this->m_http->basicAuth(IOC_USERNAME,IOC_PASSWORD); |
ansond | 36:73e343ddca7f | 51 | this->logger()->blinkTransportTxLED(); |
ansond | 30:bf56ef794ba6 | 52 | int status = this->m_http->put(url,output,&input); |
ansond | 36:73e343ddca7f | 53 | this->logger()->blinkTransportRxLED(); |
ansond | 30:bf56ef794ba6 | 54 | this->logger()->log("httpPut: Status: %d",status); |
ansond | 30:bf56ef794ba6 | 55 | return (status == 0); |
ansond | 30:bf56ef794ba6 | 56 | } |
ansond | 30:bf56ef794ba6 | 57 | |
ansond | 30:bf56ef794ba6 | 58 | // HTTP Post |
ansond | 30:bf56ef794ba6 | 59 | bool HTTPTransport::httpPost(char *url,char *data,int data_length,char *result,int result_length) { |
ansond | 30:bf56ef794ba6 | 60 | HTTPText output(data,data_length); |
ansond | 30:bf56ef794ba6 | 61 | HTTPText input(result,result_length); |
ansond | 30:bf56ef794ba6 | 62 | this->m_http->basicAuth(IOC_USERNAME,IOC_PASSWORD); |
ansond | 36:73e343ddca7f | 63 | this->logger()->blinkTransportTxLED(); |
ansond | 30:bf56ef794ba6 | 64 | int status = this->m_http->post(url,output,&input); |
ansond | 36:73e343ddca7f | 65 | this->logger()->blinkTransportRxLED(); |
ansond | 30:bf56ef794ba6 | 66 | this->logger()->log("httpPost: Status: %d",status); |
ansond | 30:bf56ef794ba6 | 67 | return (status == 0); |
ansond | 30:bf56ef794ba6 | 68 | } |
ansond | 30:bf56ef794ba6 | 69 | |
ansond | 30:bf56ef794ba6 | 70 | // HTTP Delete |
ansond | 30:bf56ef794ba6 | 71 | bool HTTPTransport::httpDelete(char *url,char *data,int data_length) { |
ansond | 30:bf56ef794ba6 | 72 | HTTPText input(data,data_length); |
ansond | 36:73e343ddca7f | 73 | this->logger()->blinkTransportTxLED(); |
ansond | 30:bf56ef794ba6 | 74 | int status = this->m_http->del(url,&input); |
ansond | 36:73e343ddca7f | 75 | this->logger()->blinkTransportRxLED(); |
ansond | 30:bf56ef794ba6 | 76 | this->logger()->log("httpDelete: Status: %d",status); |
ansond | 30:bf56ef794ba6 | 77 | return (status == 0); |
ansond | 30:bf56ef794ba6 | 78 | } |