Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
util/SmartRestConf.cpp
- Committer:
- xinlei
- Date:
- 2015-04-13
- Revision:
- 92:0acd11870c6a
- Child:
- 93:61d44636f020
File content as of revision 92:0acd11870c6a:
#include <string.h> #include "b64.h" const char* _username = NULL; const char* _password = NULL; char _authStr[100] = {0}; const char *_identifier = "com_cumulocity_MbedAgent_1.5.2"; const char _host[] = "developer.cumulocity.com"; // const char _host[] = "management.m2m-devicecloud.com" const int _port = 80; const char* getAuthStr() { return _authStr; } void setAuthStr(const char* p1, const char* p2) { memset(_authStr, 0, sizeof(_authStr)); size_t ul = strlen(p1); size_t pl = strlen(p2); unsigned char input[3], output[5]; int inputOffset = 0; for (size_t i = 0; i < (ul+1+pl); i++) { if (i < ul) input[inputOffset++] = p1[i]; else if (i == ul) input[inputOffset++] = ':'; else input[inputOffset++] = p2[i-(ul+1)]; if ((inputOffset == 3) || (i == ul+pl)) { b64_encode(input, inputOffset, output, 4); output[4] = '\0'; strcat(_authStr, (char*)output); inputOffset = 0; } } } const char* getIdentifier() { return _identifier; } void setIdentifier(const char* id) { if (id) _identifier = id; } const char* getUsername() { return _username; } void setUsername(const char* username) { _username = username; } const char* getPassword() { return _password; } void setPassword(const char* password) { _password = password; } void setAuth(const char* username, const char* password) { setUsername(username); setPassword(password); setAuthStr(username, password); } const char* getHost() { return _host; } int getPort() { return _port; }