ENGINE-9: forgot to add resource_id.* ENGINE-9
authorKrista Bennett <krista@pep-project.org>
Wed, 21 Jun 2017 13:20:50 +0200
branchENGINE-9
changeset 1880e2c2680bba23
parent 1879 8b28ba5fbeb0
child 1881 facb0b5b0bce
ENGINE-9: forgot to add resource_id.*
src/resource_id.c
src/resource_id.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/resource_id.c	Wed Jun 21 13:20:50 2017 +0200
     1.3 @@ -0,0 +1,53 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#include "pEp_internal.h"
     1.8 +#include "resource_id.h"
     1.9 +
    1.10 +pEp_rid_list_t* new_rid_node(pEp_resource_id_type type, const char* resource) {
    1.11 +    pEp_rid_list_t* retval = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t));
    1.12 +    retval->rid_type = type;
    1.13 +    retval->rid = strdup(resource);
    1.14 +    return retval;
    1.15 +}
    1.16 +
    1.17 +void free_rid_list(pEp_rid_list_t* list) {
    1.18 +    while (list) {
    1.19 +        pEp_rid_list_t* nextptr = list->next;
    1.20 +        free(list->rid);
    1.21 +        free(list);
    1.22 +        list = nextptr;
    1.23 +    }
    1.24 +}
    1.25 +
    1.26 +const char* get_resource_ptr_noown(const char* uri) {
    1.27 +    char* uri_delim = strstr(uri, "://");
    1.28 +    if (!uri_delim)
    1.29 +        return uri;
    1.30 +    else
    1.31 +        return uri + 3;
    1.32 +}
    1.33 +
    1.34 +char* get_resource(char* uri) {
    1.35 +    const char* resource_ptr = get_resource_ptr_noown(uri);
    1.36 +    char* resource_str = NULL;
    1.37 +    if (resource_ptr)
    1.38 +        resource_str = strdup(resource_ptr);
    1.39 +    return resource_str;
    1.40 +}
    1.41 +
    1.42 +bool is_file_uri(char* str) {
    1.43 +    return(!str ? false : strncmp(str, "file://", 7) == 0);
    1.44 +}
    1.45 +
    1.46 +bool is_cid_uri(const char* str) {
    1.47 +    return(!str ? false : strncmp(str, "cid://", 6) == 0);
    1.48 +}
    1.49 +
    1.50 +pEp_rid_list_t* parse_uri(const char* uri) {
    1.51 +    if (!uri)
    1.52 +        return NULL;
    1.53 +    pEp_resource_id_type type = (is_cid_uri(uri) ? PEP_RID_CID : PEP_RID_FILENAME);
    1.54 +    const char* resource = get_resource_ptr_noown(uri);
    1.55 +    return new_rid_node(type, resource);
    1.56 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/resource_id.h	Wed Jun 21 13:20:50 2017 +0200
     2.3 @@ -0,0 +1,32 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#pragma once
     2.8 +
     2.9 +/* structs to contain info about parsed resource ids (filenames, uids) */
    2.10 +typedef enum _resource_id_type {
    2.11 +    PEP_RID_FILENAME,
    2.12 +    PEP_RID_CID
    2.13 +} pEp_resource_id_type;
    2.14 +
    2.15 +typedef struct pEp_rid_list_t pEp_rid_list_t;
    2.16 +
    2.17 +struct pEp_rid_list_t {
    2.18 +    pEp_resource_id_type rid_type;
    2.19 +    char* rid;
    2.20 +    pEp_rid_list_t* next;    
    2.21 +};
    2.22 +
    2.23 +pEp_rid_list_t* new_rid_node(pEp_resource_id_type type, const char* resource);
    2.24 +
    2.25 +void free_rid_list(pEp_rid_list_t* list);
    2.26 +
    2.27 +pEp_rid_list_t* parse_uri(const char* uri);
    2.28 +
    2.29 +const char* get_resource_ptr_noown(const char* uri);
    2.30 +
    2.31 +char* get_resource(char* uri);
    2.32 +
    2.33 +bool is_file_uri(char* str);
    2.34 +
    2.35 +bool is_cid_uri(const char* str);