Ejemplo n.º 1
0
void parsing_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *flags)
{
    if (NULL == uri)
    {
        printf("parameter is null\n");
        return;
    }

    // parse uri
    // #1. check prefix
    uint8_t startIndex = 0;
    if (strncmp(COAPS_PREFIX, uri, COAPS_PREFIX_LEN) == 0)
    {
        printf("uri has '%s' prefix\n", COAPS_PREFIX);
        startIndex = COAPS_PREFIX_LEN;
        *flags = CA_SECURE;
    }
    else if (strncmp(COAP_PREFIX, uri, COAP_PREFIX_LEN) == 0)
    {
        printf("uri has '%s' prefix\n", COAP_PREFIX);
        startIndex = COAP_PREFIX_LEN;
    }
    else if (strncmp(COAP_TCP_PREFIX, uri, COAP_TCP_PREFIX_LEN) == 0)
    {
        printf("uri has '%s' prefix\n", COAP_TCP_PREFIX);
        startIndex = COAP_TCP_PREFIX_LEN;
    }

    // #2. copy uri for parse
    int32_t len = strlen(uri) - startIndex;

    if (len <= 0)
    {
        printf("uri length is 0!\n");
        return;
    }

    char *cloneUri = (char *) calloc(len + 1, sizeof(char));
    if (NULL == cloneUri)
    {
        printf("Out of memory\n");
        return;
    }

    memcpy(cloneUri, &uri[startIndex], sizeof(char) * len);
    cloneUri[len] = '\0';

    char *pAddress = cloneUri;
    printf("pAddress : %s\n", pAddress);

    if (!get_address_set(pAddress, address))
    {
        printf("address parse error\n");
    }

    free(cloneUri);
    return;
}
Ejemplo n.º 2
0
void parse_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *flags)
{
    if (NULL == uri)
    {
        printf("parameter is null\n");
        return;
    }

    // parse uri
    // #1. check prefix
    uint8_t startIndex = 0;
    if (strncmp(COAPS_PREFIX, uri, COAPS_PREFIX_LEN) == 0)
    {
        printf("uri has '%s' prefix\n", COAPS_PREFIX);
        startIndex = COAPS_PREFIX_LEN;
        *flags = CA_SECURE;
    }
    else if (strncmp(COAP_PREFIX, uri, COAP_PREFIX_LEN) == 0)
    {
        printf("uri has '%s' prefix\n", COAP_PREFIX);
        startIndex = COAP_PREFIX_LEN;
        *flags = CA_IPV4;
    }
    else if (strncmp(COAP_TCP_PREFIX, uri, COAP_TCP_PREFIX_LEN) == 0)
    {
        printf("uri has '%s' prefix\n", COAP_TCP_PREFIX);
        startIndex = COAP_TCP_PREFIX_LEN;
        *flags = CA_IPV4;
    }

    // #2. copy uri for parse
    int32_t len = strlen(uri) - startIndex;

    if (len <= 0)
    {
        printf("uri length is 0!\n");
        return;
    }

    int res = get_address_set(uri + startIndex, address);
    if (res == -1)
    {
        printf("address parse error\n");
        return;
    }

    return;
}
Ejemplo n.º 3
0
void parsing_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *flags)
{
    if (NULL == uri || NULL == address)
    {
        LOGE("parameter is null");
        return;
    }

    // parse uri
    // #1. check prefix
    uint8_t startIndex = 0;
    if (strncmp(COAPS_PREFIX, uri, COAPS_PREFIX_LEN) == 0)
    {
        LOGI("uri has '%s' prefix", COAPS_PREFIX);
        startIndex = COAPS_PREFIX_LEN;
        *flags = CA_SECURE;
    }
    else if (strncmp(COAP_PREFIX, uri, COAP_PREFIX_LEN) == 0)
    {
        LOGI("uri has '%s' prefix", COAP_PREFIX);
        startIndex = COAP_PREFIX_LEN;
        *flags = CA_IPV4;
    }

    // #2. copy uri for parse
    size_t len = strlen(uri) - startIndex;

    if (len <= 0)
    {
        LOGE("uri length is 0!");
        return;
    }

    char *cloneUri = (char *) calloc(len + 1, sizeof(char));
    if (NULL == cloneUri)
    {
        LOGE("Out of memory");
        return;
    }

    OICStrcpy(cloneUri, len+1, &uri[startIndex]);

    char *pstr = NULL;
    //filter out the resource uri
    char *pUrl = strtok_r(cloneUri, "/", &pstr);

    if (pUrl)
    {
        LOGI("pAddress : %s", pUrl);
        int res = get_address_set(pUrl, address);
        if (res == -1)
        {
            LOGE("address parse error");

            return;
        }
    }
    else
    {
        LOGE("strtok_r error, could not get the address");
    }

    return;
}