mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-19 22:19:05 +03:00
Deprecate coap_new_uri() as it might waste storage
This commit is contained in:
1 parent
3cb5a81c16
commit
940b372554
2 files changed
+21
-5
No files matched your search
@@ -17,7 +17,7 @@
|
||||
#include "uri.h"
|
||||
|
||||
int
|
||||
coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) {
|
||||
coap_split_uri(const unsigned char *str_var, size_t len, coap_uri_t *uri) {
|
||||
unsigned char *p, *q;
|
||||
int secure = 0, res = 0;
|
||||
|
||||
@@ -303,14 +303,26 @@ coap_split_path_impl(unsigned char *s, size_t length, int is_path,
|
||||
|
||||
coap_uri_t *
|
||||
coap_new_uri(const unsigned char *uri, unsigned int length) {
|
||||
unsigned char *result = coap_malloc(length + 1 + sizeof(coap_uri_t));
|
||||
if ( !result )
|
||||
unsigned char *result;
|
||||
|
||||
/**
|
||||
* @bug Some additional storage is needed to split path and query
|
||||
* into segments. Unfortunately, we do not know in advance, how
|
||||
* many segments we will get. A quick hack is to assume that every
|
||||
* segment will have 4 characters in average and hope for the best.
|
||||
*/
|
||||
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 */
|
||||
|
||||
coap_split_uri( URI_DATA(result), length, (coap_uri_t *)result );
|
||||
if (coap_split_uri(URI_DATA(result), length, (coap_uri_t *)result) < 0) {
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
return (coap_uri_t *)result;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ typedef struct {
|
||||
* @return @c 0 on success, or < 0 on error.
|
||||
*/
|
||||
int
|
||||
coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri);
|
||||
coap_split_uri(const unsigned char *str_var, size_t len, coap_uri_t *uri);
|
||||
|
||||
/**
|
||||
* Splits the given string into segments. You should call one of the
|
||||
@@ -86,6 +86,10 @@ int coap_split_path_impl(unsigned char *s, size_t length, int is_path,
|
||||
* @param uri The URI path to copy.
|
||||
* @para length The length of uri.
|
||||
* @return New URI object or NULL on error.
|
||||
*
|
||||
* @depreated This function has inconvenient storage allocation
|
||||
* characteristics to split URI path and query. Better do that
|
||||
* manually.
|
||||
*/
|
||||
coap_uri_t *coap_new_uri(const unsigned char *uri, unsigned int length);
|
||||
|
||||
|
||||
Reference in new issue
Block a user