Ejemplo n.º 1
0
static int init_add_plugin(void *obj, int (*init)(struct hFILE_plugin *),
                           const char *pluginname)
{
    struct hFILE_plugin_list *p = malloc (sizeof (struct hFILE_plugin_list));
    if (p == NULL) abort();

    p->plugin.api_version = 1;
    p->plugin.obj = obj;
    p->plugin.name = NULL;
    p->plugin.destroy = NULL;

    int ret = (*init)(&p->plugin);

    if (ret != 0) {
        hts_log_debug("Initialisation failed for plugin \"%s\": %d", pluginname, ret);
        free(p);
        return ret;
    }

    hts_log_debug("Loaded \"%s\"", pluginname);

    p->next = plugins, plugins = p;
    return 0;
}
Ejemplo n.º 2
0
static ssize_t multipart_read(hFILE *fpv, void *buffer, size_t nbytes)
{
    hFILE_multipart *fp = (hFILE_multipart *) fpv;
    size_t n;

open_next:
    if (fp->currentfp == NULL) {
        if (fp->current < fp->nparts) {
            const hfile_part *p = &fp->parts[fp->current];
            hts_log_debug("Opening part #%zu of %zu: \"%.120s%s\"",
                fp->current+1, fp->nparts, p->url,
                (strlen(p->url) > 120)? "..." : "");

            fp->currentfp = p->headers?
                  hopen(p->url, "r:", "httphdr:v", p->headers, NULL)
                : hopen(p->url, "r");

            if (fp->currentfp == NULL) return -1;
        }
        else return 0;  // No more parts, so we're truly at EOF
    }

    n = fp->currentfp->mobile?
          fp->currentfp->backend->read(fp->currentfp, buffer, nbytes)
        : hread(fp->currentfp, buffer, nbytes);

    if (n == 0) {
        // We're at EOF on this part, so set up the next part
        hFILE *prevfp = fp->currentfp;
        free_part(&fp->parts[fp->current]);
        fp->current++;
        fp->currentfp = NULL;
        if (hclose(prevfp) < 0) return -1;
        goto open_next;
    }

    return n;  // Number of bytes read by (or an error from) fp->currentfp
}