Exemplo n.º 1
0
static int extract_archive(struct vt_options* opt, vaht_archive* archive, char* out)
{
    uint16_t resource_types_count = vaht_archive_get_resource_types(archive);
    unsigned int t;
    for (t = 0; t < resource_types_count; t++)
    {
        const char* type = vaht_archive_get_resource_type(archive, t);
        
        /* check if we pass the type filter */
        if (opt->filter_type != NULL && strcmp(opt->filter_type, type) != 0)
        {
            /* we have failed the type filter! */
            continue;
        }

        /* if we're converting, but there's no extension for this type,
         * skip it
         */
        if (opt->convert && get_ext(opt, type) == NULL)
            continue;
        
        char* newdir = path_join(out, type);
        if (create_directory(opt, newdir))
        {
            free(newdir);
            return 1;
        }
        
        free(newdir);
        
        vaht_resource** resources = vaht_resources_open(archive, type);
        
        unsigned int r;
        for (r = 0; resources[r] != NULL; r++)
        {
            /* check if we pass the id filter */
            if (opt->filter_id != -1 && opt->filter_id != vaht_resource_id(resources[r]))
            {
                /* we failed the resource id filter! */
                continue;
            }
            
            char* ext = get_ext(opt, type);
            char* path = construct_path(resources[r], out, ext);
            
            if (write_resource(opt, resources[r], path))
            {
                vaht_resources_close(resources);
                free(path);
                return 1;
            }
            
            free(path);
        }
        
        vaht_resources_close(resources);
    }
    
    return 0;
}
Exemplo n.º 2
0
static void create_request(struct location *location)
{
    struct headers *header = config_opts.headers;
    char *p;
    location->rlen = request_length(location);
    p = malloc(location->rlen + 1);
    memset(p, 0, location->rlen + 1);
    location->request = p;
    p += write_resource(location->uri, p);
    while (1) {
        if (header->value)
            p += sprintf(p, "%s: %s\r\n", header->header, header->value);
        if (header->next == config_opts.headers)
            break;
        header = header->next;
    }
    p += sprintf(p, "Host: %s\r\n\r\n", location->uri->hostname);
}