Esempio n. 1
0
JsonNode * JsonNode_createChild(JsonNode * node, String name, int type)
{
    JsonNode * child = (JsonNode *)cpo_array_push(node->m_childs);
    child->m_type = type;
    child->m_parent = node;
    child->m_name = (name != NULL) ? strdup(name) : NULL;
    child->m_pairs = cpo_array_create(4, sizeof(JsonPair));
    child->m_childs = cpo_array_create(4, sizeof(JsonNode));
    return child;
}
Esempio 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;
}
Esempio n. 3
0
int calipso_reply_send_writev(calipso_reply_t *reply)
{
    struct iovec *iovv, iov[IOV_MAX];
    cpo_array_t arr;

    dllist_t *l;
    struct chunk_ctx *cc;
    chunks_t *cf = reply->out_filter;
    calipso_client_t *client;
    int prev_send, sent = 0;
    int send = 0;

    //int complete = 0;
    int nw, block;

    arr.elem_size = sizeof(struct iovec);
    arr.max = IOV_MAX;
    arr.v = iov;

    client = calipso_reply_get_client(reply);

    for (;;) {
        arr.num = 0;
        iovv = NULL;
        prev_send = send;

        for (l = cf->list; l && (cc = l->data); l = l->next) {
            if (arr.num == IOV_MAX) {
                break;
            }

            if (cc->size) {
                send += cc->size;
                iovv = cpo_array_push(&arr);
                iovv->iov_base = cc->b;
                iovv->iov_len = cc->size;
            }
        }

#ifdef USE_SSL

        if (client->ssl)
            nw = SSL_writev(client->ssl, arr.v, arr.num);
        else

#endif
            nw = writev(client->csocket, arr.v, arr.num);

        if (nw < 0) {
            if (nw == -1 && errno == EWOULDBLOCK) {
                break;
            } else {
                reply->bytes_to_send = reply->bytes_sent;
                reply->out_filter->total_bytes = 0;
                TRACE("writev error %s\n", strerror(errno));
                cpo_log_error(calipso->log, "writev error %s\n",
                              strerror(errno));
                break;
            }
        }

        sent = nw > 0 ? nw : 0;

        if (send - prev_send == sent) {
            printf("Complete %d\n", send - prev_send);
            //complete =1;
        }

        //printf("nwritten %d bytes_sent %d\n", nw , reply->bytes_sent);
        reply->bytes_sent += sent;
        reply->out_filter->total_bytes -= sent;

        if (!reply->out_filter->total_bytes) {
            //printf("Break loop\n");
            break;
        }

        block = 0;

        FOREACH_CHUNK_CTX(l,cf,cc) {
            //dllist_t *ll = l;

            block += cc->size;
            if (block <= sent) {

                cc->b += cc->size;
                cc->size -= cc->size;

                //ll = dllist_find_release(ll, cc);
                //l = ll;
            }
            if (block > sent) {
                int last = block - sent;
                int len = cc->size - last;

                cc->b += len;
                cc->size -= len;
                reply->out_filter = cf;
                return 1;
            }
        }

    } //for;;
Esempio n. 4
0
void JsonNode_setPair(JsonNode * node, const String key, const String value )
{
    JsonPair *a = (JsonPair*)cpo_array_push( node->m_pairs );
    a->key = strdup(key);
    a->value = strdup(value);
}