コード例 #1
0
ファイル: request.c プロジェクト: rkarpuzov/calipso
static int request_set_header_vals(calipso_request_t *request)
{
    char *host = calipso_request_get_header_value(request, "host");
    char *clen = calipso_request_get_header_value(request, "content-length");

    if (host) {
        char * p = strrchr(host, ':');
        request->host =
            (p) ? cpo_pool_strndup(request->pool, host, p - host) : cpo_pool_strdup(
                request->pool, host);
    }

    if (clen) {
        request->body_length = cpo_atoi(clen);
    } /*XXX: transfer-coding */
    return CPO_OK;
}
コード例 #2
0
ファイル: mod_autoind.c プロジェクト: nask0/calipso
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;
}
コード例 #3
0
ファイル: request.c プロジェクト: rkarpuzov/calipso
static int request_parse_status_line(calipso_request_t *request, char *line)
{
    char *method = NULL;
    char *uri = NULL;
    char *lastword = NULL;
    char *querystring = NULL;
/*TODO: fix me */
    /* Method */
    method = line;
    calipso_request_set_method(request, method);
    while (*line && !isspace((int )*line) && ++line)
        ;
    if (*line == 0)
        return (1);
    *line++ = 0;

    uri = line;
    if (*uri == 0)
        return (1);

    lastword = NULL;
    while (*line) {
        if (isspace((int)*line) && *(line + 1) && !isspace((int )*(line + 1)))
            lastword = line + 1;
        ++line;
    }

    if (lastword) {
        *(lastword - 1) = 0;
        calipso_request_set_version(request, lastword);

        /* remove tailing spaces */
        while (*lastword && ++lastword)
            ;
        --lastword;
        while (isspace((int)*lastword) && (*lastword-- = 0) == 0)
            ;
    }

    while (*uri && isspace((int )*uri) && ++uri)
        ;

    uri = cpo_strtok(uri, "?");
    querystring = cpo_strtok( NULL, "?");

    if (querystring) {
	char *new_querystring = cpo_pool_strdup(request->pool, querystring);
        calipso_request_set_querystring(request, new_querystring);
    }

    if (uri && *uri == '/') {
    	char *new_uri = cpo_pool_strdup(request->pool, uri);
        calipso_request_set_uri(request, new_uri);
        /* remove tailing spaces */
        /*
         while (*uri && ++uri)
         ;
         --uri;
         while (isspace((int)*uri) && (*uri-- = 0) == 0)
         ;
         */
    } else {
    	calipso_reply_set_status(request->reply,
                                                HTTP_BAD_REQUEST);
    }

    return (1);
}