src/server/daemon/httprequest.h

Tue, 19 Apr 2022 19:14:49 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 19 Apr 2022 19:14:49 +0200
branch
webdav
changeset 301
2bc514931612
parent 272
f210681d9dd0
child 415
d938228c382e
permissions
-rw-r--r--

add function for registering webdav backends

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2013 Olaf Wintermann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef HTTPREQUEST_H
#define	HTTPREQUEST_H

#include <ucx/string.h>

#include "sessionhandler.h"
#include "../public/nsapi.h"
#include "../util/pool.h"
#include "session.h"
#include "request.h"

#ifdef	__cplusplus
extern "C" {
#endif

typedef struct _http_request   HTTPRequest;
typedef struct _header         Header;
typedef struct _header_array   HeaderArray;

struct _http_request {
    Connection     *connection;
    sstr_t         request_line;
    sstr_t         method;
    sstr_t         uri;
    sstr_t         httpv;
    HeaderArray    *headers;
    netbuf         *netbuf;
    time_t         req_start;
};

struct _header {
    sstr_t name;
    sstr_t value;
};

struct _header_array {
    HeaderArray *next;
    Header      *headers;
    int         len;
    int         alloc;
};

void http_request_init(HTTPRequest *req);
void http_request_cleanup(HTTPRequest *req);

sstr_t http_request_get_abspath(HTTPRequest *req);


NSAPISession* nsapisession_create(pool_handle_t *pool);
int nsapisession_setconnection(NSAPISession *sn, Connection *conn, netbuf *inbuf, IOStream **io);

/*
 * starts request processing after reading the request header
 * 
 * request: request object
 * pool:    current thread pool or NULL
 */
int handle_request(HTTPRequest *request, threadpool_t *pool, EventHandler *ev);



void header_add(HeaderArray *hd, sstr_t name, sstr_t value);
void header_array_free(HeaderArray *hd);

int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq);
int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq);

void request_free_resources(NSAPISession *sn, NSAPIRequest *rq);

int nsapi_authtrans(NSAPISession *sn, NSAPIRequest *rq);
int nsapi_nametrans(NSAPISession *sn, NSAPIRequest *rq);
int nsapi_pathcheck(NSAPISession *sn, NSAPIRequest *rq);
int nsapi_objecttype(NSAPISession *sn, NSAPIRequest *rq);
int nsapi_service(NSAPISession *sn, NSAPIRequest *rq);
int nsapi_error(NSAPISession *sn, NSAPIRequest *rq);
int nsapi_addlog(NSAPISession *sn, NSAPIRequest *rq);

int nsapi_exec(directive *d, NSAPISession *sn, NSAPIRequest *rq);

int nsapi_exec_tp(
        directive *d,
        NSAPISession *sn,
        NSAPIRequest *rq,
        threadpool_t *pool);

//void nsapi_function_return(Session *sn, Request *rq, int ret);

void nsapi_change_threadpool(
        NSAPISession *sn,
        NSAPIRequest *rq,
        threadpool_t *thrpool);

void* thrpool_exec(void *d);

void* thrpool_change(void *data);


int add_objects(
        HTTPObjectConfig *objs,
        httpd_objset *os,
        NSAPISession *sn,
        NSAPIRequest *rq,
        char *name,
        char *path);

int method_match(char *cmp, char *method);
int contenttype_match(sstr_t cmp, sstr_t ctype);

/* request.h functions */
int request_initialize(
        pool_handle_t *pool,
        HTTPRequest *hrq,
        NSAPIRequest *nrq);

#ifdef	__cplusplus
}
#endif

#endif	/* HTTPREQUEST_H */

mercurial