Ejemplo n.º 1
0
JsonPair * JsonNode_getPair(JsonNode *node, asize_t index)
{
    return (JsonPair *)cpo_array_get_at(node->m_pairs, index);
}
Ejemplo n.º 2
0
static int mod_autoind_make_index_table(calipso_reply_t * reply, const char *uri, int prop)
{
    DIR *dir;
    struct stat sb;
    struct tm tm;
    char date[26];
    struct dirent *ent;

    cpo_array_t arr;
    cpo_autoind_entry_t *entry;
    int i,dname_len;
    char *dname;
    const char * directory = calipso_resource_get_path(reply->resource);

    struct chunk_ctx * cb  = chunk_ctx_alloc(reply->pool);

    arr.elem_size = sizeof(cpo_autoind_entry_t);
    arr.v = calloc(40 , sizeof(cpo_autoind_entry_t) );
    arr.num = 0;
    arr.max = 32;


    if ((dir = opendir(directory)) == NULL) {

        calipso_reply_set_status(reply, HTTP_FORBIDDEN);
        return CPO_ERR;
    }

    while ((ent = readdir(dir)) != NULL) {

        if(!strncmp(ent->d_name, ".", 1)) {
            continue;
        }

        if( stat(ent->d_name , &sb) != -1) {

            entry = cpo_array_push(&arr);
            entry->name  = cpo_pool_strdup(reply->pool, ent->d_name);
            entry->mtime = sb.st_mtime;
            entry->size =  sb.st_size;
            entry->is_dir =  S_ISDIR(sb.st_mode);
        }
    }

    closedir(dir);

    cpo_array_qsort(&arr, mod_autoindex_cmp_entries);

    chunk_ctx_printf(reply->pool, cb, indheadfoot[0], uri, uri);

    if(strcmp(uri,"/") ) {
        char dir[FILENAME_MAX];
        strncpy(dir, uri, sizeof(dir));

        chunk_ctx_printf(reply->pool, cb, "<a href=\"%s\">%s</a>%s %40s\n",
                         dirname(dir), PARENT_DIR_NAME, add_space(PARENT_DIR_NAME,
                                 sizeof(PARENT_DIR_NAME), SPACE_CHAR), "-");
    }

    for(i =0; i < arr.num; i++)
    {
        entry = cpo_array_get_at(&arr, i);
        dname_len = cpo_strlen(entry->name);

        if(ETALON_SPACE < dname_len) {
            int dots;
            dname = cpo_pool_strdup(reply->pool, entry->name);

            for(dots = 4; dots >= 1; dots--) {
                dname[ETALON_SPACE-dots] = ((dots == 1) ? '>' : '.');
            }

            dname[ETALON_SPACE]='\0';
            dname_len = ETALON_SPACE;
        } else {
            dname = entry->name;
        }

        if(dname) {

            cpo_gmtime(&tm, &entry->mtime);

            cpo_snprintf(date, sizeof(date), "%02d-%s-%d %02d:%02d ",
                         tm.tm_mday, months[tm.tm_mon ],	tm.tm_year, tm.tm_hour, tm.tm_min);

            if(entry->is_dir) {

                chunk_ctx_printf(reply->pool, cb, "<a href=\"%s%s/\">%s/</a>%s%10s %20s\n",
                                 uri, entry->name , dname, add_space(dname, dname_len, SPACE_CHAR), date, "-");
            } else {

                chunk_ctx_printf(reply->pool, cb, "<a href=\"%s%s\">%s</a>%s %s %20.llu\n",
                                 uri, entry->name , dname, add_space(dname, dname_len ,SPACE_CHAR), date, (uintmax_t) entry->size);
            }
            //free dname
        }
    }

    chunk_ctx_printf(reply->pool, cb, indheadfoot[1], "");

    CNUNKS_ADD_TAIL_CTX(reply->out_filter, cb);

    free(arr.v);

    return CPO_OK;
}
Ejemplo n.º 3
0
JsonNode * JsonNode_getChild(JsonNode *node, asize_t index)
{
    return (JsonNode *)cpo_array_get_at(node->m_childs, index);
}