expel / cdf6cf5 include / ubik / uri.h

Tree @cdf6cf5 (Download .tar.gz)

uri.h @cdf6cf5raw · history · blame

 * uri.h: expel content identifiers
 * Copyright (C) 2015, Haldean Brown
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#pragma once
#include <stdbool.h>
#include <stdint.h>

#include "ubik/expel.h"

/* Identifies values in the expel substrate */
struct xl_uri {
        xl_tag    tag;
        xl_word   hash;

        char      *name;
        size_t    name_len;
        char      *source;
        size_t    source_len;
        xl_word   version;
        xl_word   scope;

        uint64_t  refcount;

        /* The value representation of the URI. Generated and cached by
         * xl_uri_attach_value. */
        struct xl_value *as_value;

/* Creates a URI for a resource of unknown scope. */
no_ignore xl_error
        struct xl_uri *uri,
        char *name);

/* Creates a URI for a local resource. */
no_ignore xl_error
        struct xl_uri *uri,
        char *name);

/* Creates a URI for a package-scoped resource. */
no_ignore xl_error
        struct xl_uri *uri,
        char *package,
        char *name);

/* Creates a URI for a global, runtime-provided resource. */
no_ignore xl_error
        struct xl_uri *uri,
        char *name);

/* Creates a URI struct from a value-encoded URI. */
no_ignore xl_error
xl_uri_from_value(struct xl_uri *uri, struct xl_value *uri_val);

/* Returns true if the provided URIs are equal. */
xl_uri_eq(struct xl_uri *u0, struct xl_uri *u1);

/* Generates a value representation for the URI and stores it in the URI's
 * as_value field. If the field is already initialized, this function is a
 * no-op. */
no_ignore xl_error
xl_uri_attach_value(struct xl_uri *uri);

/* Parses a URI string into a URI struct. Returns struct has no references;
 * caller must take a reference to it. */
no_ignore xl_error
xl_uri_parse(struct xl_uri *uri, char *str);

/* Creates a string representation of a URI. */
char *
xl_uri_explain(struct xl_uri *uri);