
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 102:ede6611e064e, committed 2015-05-08
- Comitter:
- xinlei
- Date:
- Fri May 08 13:03:41 2015 +0000
- Parent:
- 101:ef2827b2d00a
- Child:
- 103:a3703ca4a4a4
- Commit message:
- hotfix: validate configuration content.
Changed in this revision
--- a/config/ConfigParser.cpp Fri May 08 12:20:50 2015 +0000 +++ b/config/ConfigParser.cpp Fri May 08 13:03:41 2015 +0000 @@ -8,6 +8,7 @@ Token tok; ptrPF = &ConfigParser::parseKey; parseOK = true; + dict.clear(); for (const char*p = buf; *p;) { p = lexConfig(p, tok); (this->*ptrPF)(tok);
--- a/config/ConfigSync.cpp Fri May 08 12:20:50 2015 +0000 +++ b/config/ConfigSync.cpp Fri May 08 13:03:41 2015 +0000 @@ -13,17 +13,17 @@ return d.get(INTERVAL_KEY); } -size_t ConfigSync::read(char *buf, size_t maxLen, char *line, size_t num) +size_t ConfigSync::read(char *buf, size_t maxLen, char *status, size_t num) { static const char *fmt = "130,%ld,%s,%.*s\r\n"; int l = 0; if (changed) { changed = false; - char s[MAX_ITEM_SIZE*(MAX_KEY_LEN+MAX_VALUE_LEN+2)+1]; + char s[(MAX_KEY_LEN+MAX_VALUE_LEN+4)*dict.size()+1]; dict.dump(s); const char *p = dict.get("interval")->value; l = snprintf(buf, maxLen, fmt, deviceID, s, MAX_VALUE_LEN, p); - snprintf(line, num, "%s", "Sync Config"); + snprintf(status, num, "%s", "Sync Config"); } return l; } @@ -35,8 +35,10 @@ dict = cp.dict; changed = true; saveConfiguration(); + return true; + } else { + return false; } - return b; } void ConfigSync::resetConfiguration() @@ -49,7 +51,7 @@ void ConfigSync::loadConfiguration() { - char buf[(MAX_KEY_LEN+MAX_VALUE_LEN)*MAX_ITEM_SIZE+1]; + char buf[(MAX_KEY_LEN+MAX_VALUE_LEN+4)*MAX_ITEM_SIZE+1]; int l = loadConfigFile(buf, sizeof(buf)); if (l > 0) { updateConfiguration(buf); @@ -58,7 +60,7 @@ void ConfigSync::saveConfiguration() const { - char s[dict.size()*(MAX_KEY_LEN+MAX_VALUE_LEN+2)+1]; + char s[(MAX_KEY_LEN+MAX_VALUE_LEN+3)*dict.size()+1]; size_t l = dict.dump(s); if (l) { if (!saveConfigFile(s, l)) {
--- a/io/DeviceMemory.cpp Fri May 08 12:20:50 2015 +0000 +++ b/io/DeviceMemory.cpp Fri May 08 13:03:41 2015 +0000 @@ -11,13 +11,11 @@ char buffer[len*2+3]; int res = pMdm->readFile(CREDENTIALS_FILE, buffer, sizeof(buffer)); if (res < 0) { - printf("Load credentials.\n"); return false; } else { buffer[res] = 0; int l = 0; sscanf(buffer, "%s\n%s\n%n", username, password, &l); - printf("%d:%d\nload: %s\n", res, l, buffer); return res==l; } } @@ -31,7 +29,6 @@ { char buffer[len*2+3]; int res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password); - printf("save: %s\n", buffer); delCredential(); return pMdm->writeFile(CREDENTIALS_FILE, buffer, res)==res; }
--- a/util/dict.h Fri May 08 12:20:50 2015 +0000 +++ b/util/dict.h Fri May 08 13:03:41 2015 +0000 @@ -59,7 +59,7 @@ size_t dump(char* buf) const { size_t l = 0; for (size_t i = 0; i < count; ++i) { - l += sprintf(buf+l, "%s=%s;", items[i].key, items[i].value); + l += sprintf(buf+l, "%s=%s;\r\n", items[i].key, items[i].value); } buf[l] = 0; return l;