Пример #1
0
static int mod_autoind_translate(calipso_request_t *request)
{
    calipso_reply_t *reply = calipso_request_get_reply(request);
    calipso_resource_t *resource = calipso_reply_get_resource(reply);
    int http_status  = calipso_reply_get_status(reply);
    char * uri, *directory;
    int i;

    if( calipso_http_status_is_error(http_status) ) {
        return NOK;
    }

    uri = calipso_request_get_uri(request);
    directory = calipso_resource_get_path(resource);

    if( cpo_strlen( strrchr(uri,'/') ) == 1 )
    {
        chdir(directory);

        for(i=0; i < (sizeof(indexes) / sizeof(indexes[0])); i++ )
        {
            if( access(indexes[i], F_OK) == 0 ) {
                strcat(directory, indexes[i]);
                calipso_resource_set_path(resource, directory);
                break;
            }
        }
    }

    return OK;
}
Пример #2
0
static int mod_autoind_resource(calipso_request_t *request)
{
    char *uri;
    calipso_reply_t *reply = calipso_request_get_reply(request);
    calipso_resource_t *resource = calipso_reply_get_resource(reply);
    int http_status  = calipso_reply_get_status(reply);

    if (!calipso_resource_is_directory(resource)
            ||( calipso_http_status_is_error(http_status)
                && http_status != HTTP_FORBIDDEN )) {
        return NOK;
    }

    if(calipso_resource_is_directory(reply->resource))  {

        uri = calipso_request_get_uri(request);

        if( cpo_strlen( strrchr(uri,'/') ) == 1 ) {
            calipso_reply_set_status(reply, HTTP_OK);
        } else {
            calipso_reply_set_status(reply, HTTP_MOVED_PERMANENTLY);
        }

        mod_autoind_reply(request);
    }

    return OK;
}
Пример #3
0
void chunks_printf(chunks_t *c, char *fmt, ...)
{
    char *buf;
    va_list ap;

    va_start(ap, fmt);
    cpo_pool_vasprintf(c->pool, &buf, fmt, ap);
    va_end(ap);

    chunks_add_tail(c, buf, cpo_strlen(buf));
}
Пример #4
0
char *
calipso_request_get_header_value(calipso_request_t *request, char *header)
{
    char *key, *val = NULL;

    calipso_pool_t *pool = calipso_request_get_pool(request);
    int keylen = cpo_strlen(header);

    if (pool && keylen) {
        key = cpo_pool_strndup_lower(pool, header, keylen);
        val = hash_table_get_data(request->header, key);
        cpo_pool_free(pool, key);
    }

    return val;
}
Пример #5
0
char *
calipso_reply_get_header_value(calipso_reply_t *reply, char *header)
{
    char *key, *val = NULL;
    size_t keylen;
    calipso_pool_t *pool;

    pool = reply->request->pool; //calipso_reply_get_pool(reply);
    keylen = cpo_strlen(header);

    if (pool && keylen) {
        key = cpo_pool_strndup_lower(pool, header, keylen);
        val = hash_table_get_data(reply->header, key);
	cpo_pool_free(pool, key);
    }

    return val;
}
Пример #6
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;
}