Beispiel #1
0
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;
}
Beispiel #2
0
coap_uri_t *
coap_clone_uri(const coap_uri_t *uri)
{
    coap_uri_t *result;

    if (!uri)
        return NULL;

    result = (coap_uri_t *) coap_malloc(
            uri->query.length + uri->host.length + uri->path.length + sizeof(coap_uri_t) + 1);

    if (!result)
        return NULL;

    memset(result, 0, sizeof(coap_uri_t));

    result->port = uri->port;

    if (uri->host.length)
    {
        result->host.s = URI_DATA(result);
        result->host.length = uri->host.length;

        memcpy(result->host.s, uri->host.s, uri->host.length);
    }

    if (uri->path.length)
    {
        result->path.s = URI_DATA(result) + uri->host.length;
        result->path.length = uri->path.length;

        memcpy(result->path.s, uri->path.s, uri->path.length);
    }

    if (uri->query.length)
    {
        result->query.s = URI_DATA(result) + uri->host.length + uri->path.length;
        result->query.length = uri->query.length;

        memcpy(result->query.s, uri->query.s, uri->query.length);
    }

    return result;
}