void CAParseURI(const char* uriInfo, coap_list_t **optlist) { OIC_LOG(DEBUG, TAG, "parse URI"); unsigned char portbuf[2]; unsigned char _buf[CA_BUFSIZE]; unsigned char *buf = _buf; coap_uri_t uri; size_t buflen; uint32_t res; OIC_LOG_V(DEBUG, TAG, "url : %s", uriInfo); /* split arg into Uri-* options */ coap_split_uri((unsigned char *) uriInfo, strlen(uriInfo), &uri); if (uri.port != COAP_DEFAULT_PORT) { coap_insert(optlist, CACreateNewOptionNode(COAP_OPTION_URI_PORT, coap_encode_var_bytes(portbuf, uri.port), portbuf), CAOrderOpts); } if (uri.path.length) { buflen = CA_BUFSIZE; res = coap_split_path(uri.path.s, uri.path.length, buf, &buflen); while (res--) { coap_insert(optlist, CACreateNewOptionNode(COAP_OPTION_URI_PATH, COAP_OPT_LENGTH(buf), COAP_OPT_VALUE(buf)), CAOrderOpts); buf += COAP_OPT_SIZE(buf); } } if (uri.query.length) { buflen = CA_BUFSIZE; buf = _buf; res = coap_split_query(uri.query.s, uri.query.length, buf, &buflen); while (res--) { coap_insert(optlist, CACreateNewOptionNode(COAP_OPTION_URI_QUERY, COAP_OPT_LENGTH(buf), COAP_OPT_VALUE(buf)), CAOrderOpts); buf += COAP_OPT_SIZE(buf); } } }
coap_uri_t * coap_new_uri(const unsigned char *uri, unsigned int length) { unsigned char *result; result = coap_malloc(length + 1 + sizeof(coap_uri_t)); if (!result) return NULL; memcpy(URI_DATA(result), uri, length); URI_DATA(result)[length] = '\0'; /* make it zero-terminated */ if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) { free(result); return NULL; } return (coap_uri_t *)result; }
CAResult_t CAParseURI(const char *uriInfo, coap_list_t **optlist) { OIC_LOG(DEBUG, TAG, "IN"); if (NULL == uriInfo) { OIC_LOG(ERROR, TAG, "uriInfo is null"); return CA_STATUS_INVALID_PARAM; } OIC_LOG_V(DEBUG, TAG, "url : %s", uriInfo); if (NULL == optlist) { OIC_LOG(ERROR, TAG, "optlist is null"); return CA_STATUS_INVALID_PARAM; } /* split arg into Uri-* options */ coap_uri_t uri; coap_split_uri((unsigned char *) uriInfo, strlen(uriInfo), &uri); if (uri.port != COAP_DEFAULT_PORT) { unsigned char portbuf[CA_PORT_BUFFER_SIZE] = { 0 }; int ret = coap_insert(optlist, CACreateNewOptionNode(COAP_OPTION_URI_PORT, coap_encode_var_bytes(portbuf, uri.port), (char *)portbuf), CAOrderOpts); if (ret <= 0) { return CA_STATUS_INVALID_PARAM; } } if (uri.path.s && uri.path.length) { CAResult_t ret = CAParseUriPartial(uri.path.s, uri.path.length, COAP_OPTION_URI_PATH, optlist); if (CA_STATUS_OK != ret) { OIC_LOG(ERROR, TAG, "CAParseUriPartial failed(uri path)"); return ret; } } if (uri.query.s && uri.query.length) { CAResult_t ret = CAParseUriPartial(uri.query.s, uri.query.length, COAP_OPTION_URI_QUERY, optlist); if (CA_STATUS_OK != ret) { OIC_LOG(ERROR, TAG, "CAParseUriPartial failed(uri query)"); return ret; } } OIC_LOG(DEBUG, TAG, "OUT"); return CA_STATUS_OK; }