branch with improvemnts
Fork of M2XStreamClient by
Diff: M2XStreamClient.cpp
- Revision:
- 8:bd39886d72fb
- Parent:
- 6:e6d66d99dd6f
--- a/M2XStreamClient.cpp Thu Nov 14 15:14:54 2013 +0000 +++ b/M2XStreamClient.cpp Fri Jan 03 11:55:17 2014 +0000 @@ -6,15 +6,31 @@ #include "LocationParseFunctions.h" const char* M2XStreamClient::kDefaultM2XHost = "api-m2x.att.com"; -const char* kUserAgentLine = "User-Agent: M2X Arduino Client/0.1"; int print_encoded_string(Print* print, const char* str); +int tolower(int ch); + +#if defined(ARDUINO_PLATFORM) || defined(MBED_PLATFORM) +int tolower(int ch) +{ + // Arduino and mbed use ASCII table, so we can simplify the implementation + if ((ch >= 'A') && (ch <= 'Z')) { + return (ch + 32); + } + return ch; +} +#else +// For other platform, we use libc's tolower by default +#include <ctype.h> +#endif M2XStreamClient::M2XStreamClient(Client* client, const char* key, + int case_insensitive, const char* host, int port) : _client(client), _key(key), + _case_insensitive(case_insensitive), _host(host), _port(port), _null_print() { @@ -123,7 +139,7 @@ } void M2XStreamClient::writeHttpHeader(int contentLength) { - _client->println(kUserAgentLine); + _client->println(USER_AGENT); _client->print("X-M2X-KEY: "); _client->println(_key); @@ -156,8 +172,14 @@ char c = _client->read(); DBG("%c", c); - if ((str[currentIndex] == '*') || - (c == str[currentIndex])) { + int cmp; + if (_case_insensitive) { + cmp = tolower(c) - tolower(str[currentIndex]); + } else { + cmp = c - str[currentIndex]; + } + + if ((str[currentIndex] == '*') || (cmp == 0)) { currentIndex++; if (str[currentIndex] == '\0') { return E_OK;