From 9bb25bf6983f11cb5680183a3e0423eb7cd6fe89 Mon Sep 17 00:00:00 2001 From: Achim Kraus Date: Fri, 17 Apr 2015 12:56:51 +0200 Subject: [PATCH] Adjust implementation for "alt path" and "delete all. Signed-off-by: Achim Kraus --- core/uri.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/core/uri.c b/core/uri.c index f07e0238e..cf5b92d0f 100755 --- a/core/uri.c +++ b/core/uri.c @@ -105,21 +105,15 @@ lwm2m_uri_t * lwm2m_decode_uri(char * altPath, memset(uriP, 0, sizeof(lwm2m_uri_t)); - if (uriPath->len == 0) - { - uriP->flag |= LWM2M_URI_FLAG_DELETE_ALL; - return uriP; - } - // Read object ID - if (URI_REGISTRATION_SEGMENT_LEN == uriPath->len + if (NULL != uriPath && URI_REGISTRATION_SEGMENT_LEN == uriPath->len && 0 == strncmp(URI_REGISTRATION_SEGMENT, uriPath->data, uriPath->len)) { uriP->flag |= LWM2M_URI_FLAG_REGISTRATION; uriPath = uriPath->next; if (uriPath == NULL) return uriP; } - else if (URI_BOOTSTRAP_SEGMENT_LEN == uriPath->len + else if (NULL != uriPath && URI_BOOTSTRAP_SEGMENT_LEN == uriPath->len && 0 == strncmp(URI_BOOTSTRAP_SEGMENT, uriPath->data, uriPath->len)) { uriP->flag |= LWM2M_URI_FLAG_BOOTSTRAP; @@ -128,20 +122,32 @@ lwm2m_uri_t * lwm2m_decode_uri(char * altPath, return uriP; } - // Read altPath if any - if (altPath != NULL) + if ((uriP->flag & LWM2M_URI_MASK_TYPE) != LWM2M_URI_FLAG_REGISTRATION) { - int i; - - for (i = 0 ; i < uriPath->len ; i++) + // Read altPath if any + if (altPath != NULL) { - if (uriPath->data[i] != altPath[i+1]) + int i; + if (NULL == uriPath) { lwm2m_free(uriP); return NULL; } + for (i = 0 ; i < uriPath->len ; i++) + { + if (uriPath->data[i] != altPath[i+1]) + { + lwm2m_free(uriP); + return NULL; + } + } + uriPath = uriPath->next; + } + if (NULL == uriPath || uriPath->len == 0) + { + uriP->flag |= LWM2M_URI_FLAG_DELETE_ALL; + return uriP; } - uriPath = uriPath->next; } readNum = prv_get_number(uriPath->data, uriPath->len);