HTTP Client with hardcoded authorization for supertweet proxy server.

Dependents:   twitterCoffeeMakerFinal iCoffee

Fork of HTTPClientAuthAndPathExtension by Joseph Lind

Committer:
tlisowski3
Date:
Wed Apr 23 18:37:32 2014 +0000
Revision:
18:da79dd7e9df2
Parent:
17:951bf897ba01
HTTP Client with authorization hardcoded in

Who changed what in which revision?

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