int lwm2m_stringToUri(char * buffer, size_t len, lwm2m_uri_t * uriP) { int head; int readNum; int buffer_len = len; if (buffer == NULL || buffer_len == 0 || uriP == NULL) return 0; // Skip any white space head = 0; while (head < buffer_len && isspace(buffer[head])) { head++; } if (head == buffer_len) return 0; // Read object ID readNum = prv_parse_number(buffer, buffer_len, &head); if (readNum < 0 || readNum > LWM2M_MAX_ID) return 0; uriP->objectId = (uint16_t)readNum; if (head >= buffer_len) return head; // Read object instance if (buffer[head] == '/') { // default instance head++; } else { readNum = prv_parse_number(buffer, buffer_len, &head); if (readNum < 0 || readNum >= LWM2M_MAX_ID) return 0; uriP->instanceId = (uint16_t)readNum; uriP->flag |= LWM2M_URI_FLAG_INSTANCE_ID; } if (head >= buffer_len) return head; // Read ressource ID if (buffer[head] == '/') { // no ID head++; } else { readNum = prv_parse_number(buffer, buffer_len, &head); if (readNum < 0 || readNum >= LWM2M_MAX_ID) return 0; uriP->resourceId = (uint16_t)readNum; uriP->flag |= LWM2M_URI_FLAG_RESOURCE_ID; } return head; }
int lwm2m_stringToUri(const char * buffer, size_t buffer_len, lwm2m_uri_t * uriP) { size_t head; int readNum; if (buffer == NULL || buffer_len == 0 || uriP == NULL) return 0; memset(uriP, 0, sizeof(lwm2m_uri_t)); // Skip any white space head = 0; while (head < buffer_len && isspace(buffer[head]&0xFF)) { head++; } if (head == buffer_len) return 0; // Check the URI start with a '/' if (buffer[head] != '/') return 0; head++; if (head == buffer_len) return 0; // Read object ID readNum = prv_parse_number((uint8_t *)buffer, buffer_len, &head); if (readNum < 0 || readNum > LWM2M_MAX_ID) return 0; uriP->objectId = (uint16_t)readNum; uriP->flag |= LWM2M_URI_FLAG_OBJECT_ID; if (buffer[head] == '/') head += 1; if (head >= buffer_len) return head; readNum = prv_parse_number((uint8_t *)buffer, buffer_len, &head); if (readNum < 0 || readNum >= LWM2M_MAX_ID) return 0; uriP->instanceId = (uint16_t)readNum; uriP->flag |= LWM2M_URI_FLAG_INSTANCE_ID; if (buffer[head] == '/') head += 1; if (head >= buffer_len) return head; readNum = prv_parse_number((uint8_t *)buffer, buffer_len, &head); if (readNum < 0 || readNum >= LWM2M_MAX_ID) return 0; uriP->resourceId = (uint16_t)readNum; uriP->flag |= LWM2M_URI_FLAG_RESOURCE_ID; if (head != buffer_len) return 0; return head; }
int prv_get_number(const char * uriString, size_t uriLength) { int index = 0; return prv_parse_number(uriString, uriLength, &index); }
int prv_get_number(uint8_t * uriString, size_t uriLength) { size_t index = 0; return prv_parse_number(uriString, uriLength, &index); }