diff -r 30e51941a673 -r e3ae779232a9 src/server/httprequest.c --- a/src/server/httprequest.c Thu Dec 29 18:51:23 2011 +0100 +++ b/src/server/httprequest.c Fri Dec 30 14:06:56 2011 +0100 @@ -268,6 +268,10 @@ } case NSAPIObjectType: { printf(">>> ObjectType\n"); + r = nsapi_objecttype(sn, rq); + if(r != REQ_PROCEED) { + break; + } rq->phase++; nsapi_context_next_stage(&rq->context); } @@ -378,6 +382,73 @@ return REQ_PROCEED; } +int nsapi_objecttype(NSAPISession *sn, NSAPIRequest *rq) { + printf("nsapi_objecttype\n"); + httpd_objset *objset = rq->rq.os; + + if(NCX_OI(rq) == -1) { + /* object index is undefined -> define correct object index */ + NCX_OI(rq) = objset->pos - 1; + } + + int ret = rq->context.last_req_code; + for(int i=NCX_OI(rq);i>=0;i--) { + httpd_object *obj = objset->obj[i]; + dtable *dt = object_get_dtable(obj, NSAPIObjectType); + + // execute directives + for(int j=0;jndir;j++) { + directive *d = dt->dirs[j]; + + ret = d->func->func(d->param, (Session*)sn, (Request*)rq); + switch(ret) { + case REQ_PROCEED: { + char *type = pblock_findkeyval( + pb_key_content_type, + rq->rq.srvhdrs); + if(type == NULL) { + ret = REQ_NOACTION; + break; + } + return ret; + } + case REQ_PROCESSING: { + /* save nsapi context */ + rq->context.objset_index = i; + + /* add +1 to start next round with next function */ + rq->context.dtable_index = j + 1; + return ret; + } + case REQ_NOACTION: { + break; + } + default: { + return ret; + } + } + } + } + + /* + * No function returned with REQ_PROCEED, but we need a content type. + * If the path ends with a '/', we set the content type to + * 'internal/directory' so that 'index-common' can serve the content. + * Otherwise we set the content type to text/plain + */ + sstr_t path = sstr(pblock_findkeyval(pb_key_ppath, rq->rq.vars)); + sstr_t ct; + if(path.ptr[path.length - 1] == '/') { + /* directory */ + ct = sstrn("internal/directory", 18); + } else { + ct = sstrn("text/plain", 10); + } + pblock_kvinsert(pb_key_content_type, ct.ptr, ct.length, rq->rq.srvhdrs); + + return REQ_PROCEED; +} + int nsapi_service(NSAPISession *sn, NSAPIRequest *rq) { printf("nsapi_service\n"); httpd_objset *objset = rq->rq.os; @@ -425,10 +496,22 @@ char *path) { /* first, add all objects with a matching path */ + /* TODO */ /* add object with object with matching name */ - + if(name == NULL) { + return REQ_PROCEED; + } + + for(int i=0;inobj;i++) { + httpd_object *obj = objs->objects[i]; + + if(obj->name && !strcmp(name, obj->name)) { + printf("name is %s -> add object %s\n", name, obj->name); + objset_add_object(sn->sn.pool, os, obj); + } + } return REQ_PROCEED; }