Exemple #1
0
static struct mk_list *mk_dirhtml_create_list(DIR * dir, char *path,
                                              unsigned long *list_len)
{
    char full_path[PATH_MAX];
    struct mk_list *list;
    struct dirent *ent;
    struct mk_f_list *entry = 0;

    list = mk_api->mem_alloc(sizeof(struct mk_list));
    mk_list_init(list);

    while ((ent = readdir(dir)) != NULL) {
        if ((ent->d_name[0] == '.') && (strcmp(ent->d_name, "..") != 0))
            continue;

        /* Look just for files and dirs */
        if (ent->d_type != DT_REG && ent->d_type != DT_DIR
            && ent->d_type != DT_LNK && ent->d_type != DT_UNKNOWN) {
            continue;
        }

        snprintf(full_path, PATH_MAX, "%s%s", path, ent->d_name);
        entry = mk_dirhtml_create_element(ent->d_name,
                                          ent->d_type, full_path, list_len);
        if (!entry) {
            continue;
        }

        mk_list_add(&entry->_head, list);
    }

    return list;
}
Exemple #2
0
static struct mk_f_list *mk_dirhtml_create_list(DIR * dir, char *path,
                                         unsigned long *list_len)
{
    unsigned long len;
    char *full_path = NULL;
    struct dirent *ent;
    struct mk_f_list *list = 0, *entry = 0, *last = 0;

    /* Before to send the information, we need to build
     * the list of entries, this really sucks because the user
     * always will want to have the information sorted, why we don't
     * add some spec to the HTTP protocol in order to send the information
     * in a generic way and let the client choose how to show it
     * as they does browsing a FTP server ???, we can save bandweight,
     * let the cool firefox developers create different templates and
     * we are going to have a more happy end users.
     *
     * that kind of ideas comes when you are in an airport just waiting :)
     */

    while ((ent = readdir(dir)) != NULL) {
        if ((ent->d_name[0] == '.') && (strcmp(ent->d_name, "..") != 0))
            continue;

        /* Look just for files and dirs */
        if (ent->d_type != DT_REG && ent->d_type != DT_DIR
            && ent->d_type != DT_LNK && ent->d_type != DT_UNKNOWN) {
            continue;
        }

        mk_api->str_build(&full_path, &len, "%s%s", path, ent->d_name);
        entry = mk_dirhtml_create_element(ent->d_name,
                                          ent->d_type, full_path, list_len);

        mk_api->mem_free(full_path);
        full_path = NULL;

        if (!entry) {
            continue;
        }

        if (!list) {
            list = entry;
        }
        else {
            last->next = entry;
        }
        last = entry;
    }

    return list;
}