Integrating the ublox LISA C200 modem
Fork of SprintUSBModemHTTPClientTest by
HTTPClient/data/HTTPText.cpp@5:3f93dd1d4cb3, 2013-09-26 (annotated)
- Committer:
- sam_grove
- Date:
- Thu Sep 26 00:44:20 2013 -0500
- Revision:
- 5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 5:3f93dd1d4cb3 | 1 | /* HTTPText.cpp */ |
sam_grove | 5:3f93dd1d4cb3 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
sam_grove | 5:3f93dd1d4cb3 | 3 | * |
sam_grove | 5:3f93dd1d4cb3 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
sam_grove | 5:3f93dd1d4cb3 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
sam_grove | 5:3f93dd1d4cb3 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
sam_grove | 5:3f93dd1d4cb3 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
sam_grove | 5:3f93dd1d4cb3 | 8 | * furnished to do so, subject to the following conditions: |
sam_grove | 5:3f93dd1d4cb3 | 9 | * |
sam_grove | 5:3f93dd1d4cb3 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
sam_grove | 5:3f93dd1d4cb3 | 11 | * substantial portions of the Software. |
sam_grove | 5:3f93dd1d4cb3 | 12 | * |
sam_grove | 5:3f93dd1d4cb3 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
sam_grove | 5:3f93dd1d4cb3 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
sam_grove | 5:3f93dd1d4cb3 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
sam_grove | 5:3f93dd1d4cb3 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
sam_grove | 5:3f93dd1d4cb3 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
sam_grove | 5:3f93dd1d4cb3 | 18 | */ |
sam_grove | 5:3f93dd1d4cb3 | 19 | |
sam_grove | 5:3f93dd1d4cb3 | 20 | #include "HTTPText.h" |
sam_grove | 5:3f93dd1d4cb3 | 21 | |
sam_grove | 5:3f93dd1d4cb3 | 22 | #include <cstring> |
sam_grove | 5:3f93dd1d4cb3 | 23 | |
sam_grove | 5:3f93dd1d4cb3 | 24 | #define OK 0 |
sam_grove | 5:3f93dd1d4cb3 | 25 | |
sam_grove | 5:3f93dd1d4cb3 | 26 | using std::memcpy; |
sam_grove | 5:3f93dd1d4cb3 | 27 | using std::strncpy; |
sam_grove | 5:3f93dd1d4cb3 | 28 | using std::strlen; |
sam_grove | 5:3f93dd1d4cb3 | 29 | |
sam_grove | 5:3f93dd1d4cb3 | 30 | #define MIN(x,y) (((x)<(y))?(x):(y)) |
sam_grove | 5:3f93dd1d4cb3 | 31 | |
sam_grove | 5:3f93dd1d4cb3 | 32 | HTTPText::HTTPText(char* str) : m_str(str), m_pos(0) |
sam_grove | 5:3f93dd1d4cb3 | 33 | { |
sam_grove | 5:3f93dd1d4cb3 | 34 | m_size = strlen(str) + 1; |
sam_grove | 5:3f93dd1d4cb3 | 35 | } |
sam_grove | 5:3f93dd1d4cb3 | 36 | |
sam_grove | 5:3f93dd1d4cb3 | 37 | HTTPText::HTTPText(char* str, size_t size) : m_str(str), m_size(size), m_pos(0) |
sam_grove | 5:3f93dd1d4cb3 | 38 | { |
sam_grove | 5:3f93dd1d4cb3 | 39 | |
sam_grove | 5:3f93dd1d4cb3 | 40 | } |
sam_grove | 5:3f93dd1d4cb3 | 41 | |
sam_grove | 5:3f93dd1d4cb3 | 42 | //IHTTPDataIn |
sam_grove | 5:3f93dd1d4cb3 | 43 | /*virtual*/ void HTTPText::readReset() |
sam_grove | 5:3f93dd1d4cb3 | 44 | { |
sam_grove | 5:3f93dd1d4cb3 | 45 | m_pos = 0; |
sam_grove | 5:3f93dd1d4cb3 | 46 | } |
sam_grove | 5:3f93dd1d4cb3 | 47 | |
sam_grove | 5:3f93dd1d4cb3 | 48 | /*virtual*/ int HTTPText::read(char* buf, size_t len, size_t* pReadLen) |
sam_grove | 5:3f93dd1d4cb3 | 49 | { |
sam_grove | 5:3f93dd1d4cb3 | 50 | *pReadLen = MIN(len, m_size - 1 - m_pos); |
sam_grove | 5:3f93dd1d4cb3 | 51 | memcpy(buf, m_str + m_pos, *pReadLen); |
sam_grove | 5:3f93dd1d4cb3 | 52 | m_pos += *pReadLen; |
sam_grove | 5:3f93dd1d4cb3 | 53 | return OK; |
sam_grove | 5:3f93dd1d4cb3 | 54 | } |
sam_grove | 5:3f93dd1d4cb3 | 55 | |
sam_grove | 5:3f93dd1d4cb3 | 56 | /*virtual*/ int HTTPText::getDataType(char* type, size_t maxTypeLen) //Internet media type for Content-Type header |
sam_grove | 5:3f93dd1d4cb3 | 57 | { |
sam_grove | 5:3f93dd1d4cb3 | 58 | strncpy(type, "text/plain", maxTypeLen-1); |
sam_grove | 5:3f93dd1d4cb3 | 59 | type[maxTypeLen-1] = '\0'; |
sam_grove | 5:3f93dd1d4cb3 | 60 | return OK; |
sam_grove | 5:3f93dd1d4cb3 | 61 | } |
sam_grove | 5:3f93dd1d4cb3 | 62 | |
sam_grove | 5:3f93dd1d4cb3 | 63 | /*virtual*/ bool HTTPText::getIsChunked() //For Transfer-Encoding header |
sam_grove | 5:3f93dd1d4cb3 | 64 | { |
sam_grove | 5:3f93dd1d4cb3 | 65 | return false; |
sam_grove | 5:3f93dd1d4cb3 | 66 | } |
sam_grove | 5:3f93dd1d4cb3 | 67 | |
sam_grove | 5:3f93dd1d4cb3 | 68 | /*virtual*/ size_t HTTPText::getDataLen() //For Content-Length header |
sam_grove | 5:3f93dd1d4cb3 | 69 | { |
sam_grove | 5:3f93dd1d4cb3 | 70 | return m_size - 1; |
sam_grove | 5:3f93dd1d4cb3 | 71 | } |
sam_grove | 5:3f93dd1d4cb3 | 72 | |
sam_grove | 5:3f93dd1d4cb3 | 73 | //IHTTPDataOut |
sam_grove | 5:3f93dd1d4cb3 | 74 | /*virtual*/ void HTTPText::writeReset() |
sam_grove | 5:3f93dd1d4cb3 | 75 | { |
sam_grove | 5:3f93dd1d4cb3 | 76 | m_pos = 0; |
sam_grove | 5:3f93dd1d4cb3 | 77 | } |
sam_grove | 5:3f93dd1d4cb3 | 78 | |
sam_grove | 5:3f93dd1d4cb3 | 79 | /*virtual*/ int HTTPText::write(const char* buf, size_t len) |
sam_grove | 5:3f93dd1d4cb3 | 80 | { |
sam_grove | 5:3f93dd1d4cb3 | 81 | size_t writeLen = MIN(len, m_size - 1 - m_pos); |
sam_grove | 5:3f93dd1d4cb3 | 82 | memcpy(m_str + m_pos, buf, writeLen); |
sam_grove | 5:3f93dd1d4cb3 | 83 | m_pos += writeLen; |
sam_grove | 5:3f93dd1d4cb3 | 84 | m_str[m_pos] = '\0'; |
sam_grove | 5:3f93dd1d4cb3 | 85 | return OK; |
sam_grove | 5:3f93dd1d4cb3 | 86 | } |
sam_grove | 5:3f93dd1d4cb3 | 87 | |
sam_grove | 5:3f93dd1d4cb3 | 88 | /*virtual*/ void HTTPText::setDataType(const char* type) //Internet media type from Content-Type header |
sam_grove | 5:3f93dd1d4cb3 | 89 | { |
sam_grove | 5:3f93dd1d4cb3 | 90 | |
sam_grove | 5:3f93dd1d4cb3 | 91 | } |
sam_grove | 5:3f93dd1d4cb3 | 92 | |
sam_grove | 5:3f93dd1d4cb3 | 93 | /*virtual*/ void HTTPText::setIsChunked(bool chunked) //From Transfer-Encoding header |
sam_grove | 5:3f93dd1d4cb3 | 94 | { |
sam_grove | 5:3f93dd1d4cb3 | 95 | |
sam_grove | 5:3f93dd1d4cb3 | 96 | } |
sam_grove | 5:3f93dd1d4cb3 | 97 | |
sam_grove | 5:3f93dd1d4cb3 | 98 | /*virtual*/ void HTTPText::setDataLen(size_t len) //From Content-Length header, or if the transfer is chunked, next chunk length |
sam_grove | 5:3f93dd1d4cb3 | 99 | { |
sam_grove | 5:3f93dd1d4cb3 | 100 | |
sam_grove | 5:3f93dd1d4cb3 | 101 | } |
sam_grove | 5:3f93dd1d4cb3 | 102 | |
sam_grove | 5:3f93dd1d4cb3 | 103 | |
sam_grove | 5:3f93dd1d4cb3 | 104 |