Annotation of embedaddon/mpd/src/contrib/libpdel/http/http_server.h, revision 1.1

1.1     ! misho       1: 
        !             2: /*
        !             3:  * Copyright (c) 2001-2002 Packet Design, LLC.
        !             4:  * All rights reserved.
        !             5:  * 
        !             6:  * Subject to the following obligations and disclaimer of warranty,
        !             7:  * use and redistribution of this software, in source or object code
        !             8:  * forms, with or without modifications are expressly permitted by
        !             9:  * Packet Design; provided, however, that:
        !            10:  * 
        !            11:  *    (i)  Any and all reproductions of the source or object code
        !            12:  *         must include the copyright notice above and the following
        !            13:  *         disclaimer of warranties; and
        !            14:  *    (ii) No rights are granted, in any manner or form, to use
        !            15:  *         Packet Design trademarks, including the mark "PACKET DESIGN"
        !            16:  *         on advertising, endorsements, or otherwise except as such
        !            17:  *         appears in the above copyright notice or in the software.
        !            18:  * 
        !            19:  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
        !            20:  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
        !            21:  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
        !            22:  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
        !            23:  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
        !            24:  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
        !            25:  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
        !            26:  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
        !            27:  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
        !            28:  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
        !            29:  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
        !            30:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
        !            31:  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
        !            32:  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
        !            33:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
        !            35:  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
        !            36:  * THE POSSIBILITY OF SUCH DAMAGE.
        !            37:  *
        !            38:  * Author: Archie Cobbs <archie@freebsd.org>
        !            39:  */
        !            40: 
        !            41: #ifndef _PDEL_HTTP_HTTP_SERVER_H_
        !            42: #define _PDEL_HTTP_HTTP_SERVER_H_
        !            43: 
        !            44: struct http_connection;
        !            45: struct http_request;
        !            46: struct http_response;
        !            47: struct http_servlet;
        !            48: struct mime_multipart;
        !            49: struct mime_part;
        !            50: struct pevent_ctx;
        !            51: 
        !            52: #ifndef __FreeBSD__
        !            53: #define __printflike(x,y)
        !            54: #endif
        !            55: 
        !            56: /*
        !            57:  * SSL info supplied by the application
        !            58:  */
        !            59: struct http_server_ssl {
        !            60:        const char      *cert_path;     /* path to certificate file */
        !            61:        const char      *pkey_path;     /* path to private key file */
        !            62:        const char      *pkey_password; /* private key password, if needed */
        !            63: };
        !            64: 
        !            65: /*
        !            66:  * Special "headers" from the first line
        !            67:  * of an HTTP request or HTTP response.
        !            68:  */
        !            69: #define        HDR_REQUEST_METHOD      ((const char *)1)
        !            70: #define        HDR_REQUEST_URI         ((const char *)2)
        !            71: #define        HDR_REQUEST_VERSION     ((const char *)3)
        !            72: #define        HDR_REPLY_VERSION       ((const char *)1)
        !            73: #define        HDR_REPLY_STATUS        ((const char *)2)
        !            74: #define        HDR_REPLY_REASON        ((const char *)3)
        !            75: 
        !            76: /*
        !            77:  * User callback types
        !            78:  */
        !            79: typedef void   http_logger_t(int sev, const char *fmt, ...);
        !            80: typedef void   http_proxy_t(void *arg, struct http_request *req,
        !            81:                         struct http_response *resp);
        !            82: 
        !            83: /*
        !            84:  * Should return 0 to proceed, or -1 and set errno to abort.
        !            85:  * The handler should NOT close the stream and should NOT free "part".
        !            86:  */
        !            87: typedef int    http_mime_handler_t(void *arg,
        !            88:                        struct mime_part *part, FILE *fp);
        !            89: 
        !            90: __BEGIN_DECLS
        !            91: 
        !            92: /*
        !            93:  * Server functions
        !            94:  */
        !            95: extern struct  http_server *http_server_start(struct pevent_ctx *ctx,
        !            96:                        struct in_addr ip, u_int16_t port,
        !            97:                        const struct http_server_ssl *ssl,
        !            98:                        const char *server_name, http_logger_t *logger);
        !            99: extern void    http_server_stop(struct http_server **serverp);
        !           100: extern int     http_server_register_servlet(struct http_server *serv,
        !           101:                        struct http_servlet *servlet, const char *vhost,
        !           102:                        const char *urlpat, int order);
        !           103: extern void    http_server_destroy_servlet(struct http_servlet **servletp);
        !           104: extern void    http_server_set_proxy_handler(struct http_server *serv,
        !           105:                        http_proxy_t *handler, void *arg);
        !           106: 
        !           107: /*
        !           108:  * Client functions
        !           109:  */
        !           110: extern struct  http_client *http_client_create(struct pevent_ctx *ctx,
        !           111:                        const char *user_agent, u_int max_conn, u_int max_cache,
        !           112:                        u_int max_cache_idle, http_logger_t *logger);
        !           113: extern int     http_client_destroy(struct http_client **clientp);
        !           114: 
        !           115: extern struct  http_client_connection *http_client_connect(
        !           116:                        struct http_client *client, struct in_addr ip,
        !           117:                        u_int16_t port, int https);
        !           118: extern struct  in_addr http_client_get_local_ip(
        !           119:                        struct http_client_connection *cc);
        !           120: extern u_int16_t http_client_get_local_port(struct http_client_connection *cc);
        !           121: extern struct  http_request *http_client_get_request(
        !           122:                        struct http_client_connection *client);
        !           123: extern struct  http_response *http_client_get_response(
        !           124:                        struct http_client_connection *client);
        !           125: extern void    http_client_close(struct http_client_connection **cconp);
        !           126: extern const   char *http_client_get_reason(
        !           127:                        struct http_client_connection *ccon);
        !           128: 
        !           129: /*
        !           130:  * Request functions
        !           131:  */
        !           132: extern const   char *http_request_get_query_string(struct http_request *req);
        !           133: extern const   char *http_request_get_method(struct http_request *req);
        !           134: extern int     http_request_set_method(struct http_request *req,
        !           135:                        const char *method);
        !           136: extern const   char *http_request_get_uri(struct http_request *req);
        !           137: extern const   char *http_request_get_version(struct http_request *req);
        !           138: extern const   char *http_request_get_path(struct http_request *req);
        !           139: extern int     http_request_set_path(struct http_request *req,
        !           140:                        const char *path);
        !           141: extern SSL_CTX *http_request_get_ssl(struct http_request *req);
        !           142: extern const   char *http_request_get_header(struct http_request *req,
        !           143:                        const char *name);
        !           144: extern int     http_request_num_headers(struct http_request *req);
        !           145: extern int     http_request_get_header_by_index(struct http_request *req,
        !           146:                        u_int index, const char **namep, const char **valuep);
        !           147: extern void    http_request_set_proxy(struct http_request *req, int whether);
        !           148: extern int     http_request_set_header(struct http_request *req,
        !           149:                        int append, const char *name, const char *valfmt, ...)
        !           150:                        __printflike(4, 5);
        !           151: extern int     http_request_remove_header(struct http_request *req,
        !           152:                        const char *name);
        !           153: extern int     http_request_send_headers(struct http_request *req);
        !           154: extern FILE    *http_request_get_input(struct http_request *req);
        !           155: extern FILE    *http_request_get_output(struct http_request *req, int buffer);
        !           156: extern const   char *http_request_get_username(struct http_request *req);
        !           157: extern const   char *http_request_get_password(struct http_request *req);
        !           158: extern const   char *http_request_get_host(struct http_request *req);
        !           159: extern struct  in_addr http_request_get_remote_ip(struct http_request *req);
        !           160: extern u_int16_t http_request_get_remote_port(struct http_request *req);
        !           161: extern const   char *http_request_get_value(struct http_request *req,
        !           162:                        const char *name, int instance);
        !           163: extern int     http_request_set_value(struct http_request *req,
        !           164:                        const char *name, const char *value);
        !           165: extern int     http_request_get_num_values(struct http_request *req);
        !           166: extern int     http_request_get_value_by_index(struct http_request *req,
        !           167:                        int index, const char **name, const char **value);
        !           168: extern int     http_request_set_query_from_values(struct http_request *req);
        !           169: extern int     http_request_read_url_encoded_values(struct http_request *req);
        !           170: extern int     http_request_write_url_encoded_values(struct http_request *req);
        !           171: 
        !           172: extern int     http_request_get_mime_multiparts(struct http_request *req,
        !           173:                        http_mime_handler_t *handler, void *arg);
        !           174: extern struct  mime_multipart *http_request_read_mime_multipart(
        !           175:                        struct http_request *req);
        !           176: extern int     http_request_file_upload(struct http_request *req,
        !           177:                        const char *field, FILE *fp, size_t max);
        !           178: 
        !           179: extern time_t  http_request_parse_time(const char *string);
        !           180: extern void    http_request_url_decode(const char *s, char *t);
        !           181: extern char    *http_request_url_encode(const char *mtype, const char *string);
        !           182: extern char    *http_request_encode_basic_auth(const char *mtype,
        !           183:                        const char *username, const char *password);
        !           184: extern int     http_request_get_raw_socket(struct http_request *req);
        !           185: 
        !           186: /*
        !           187:  * mime_multipart methods
        !           188:  */
        !           189: extern u_int   http_mime_multipart_get_count(struct mime_multipart *mp);
        !           190: extern struct  mime_part *http_mime_multipart_get_part(
        !           191:                        struct mime_multipart *mp, u_int index);
        !           192: extern void    http_mime_multipart_free(struct mime_multipart **mpp);
        !           193: 
        !           194: /*
        !           195:  * mime_part methods
        !           196:  */
        !           197: extern const   char *http_mime_part_get_header(struct mime_part *part,
        !           198:                        const char *name);
        !           199: extern u_int   http_mime_part_get_length(struct mime_part *part);
        !           200: extern u_char  *http_mime_part_get_data(struct mime_part *part);
        !           201: 
        !           202: /*
        !           203:  * Response functions
        !           204:  */
        !           205: extern SSL_CTX *http_response_get_ssl(struct http_response *resp);
        !           206: extern const   char *http_response_get_header(struct http_response *resp,
        !           207:                        const char *name);
        !           208: extern int     http_response_num_headers(struct http_response *req);
        !           209: extern int     http_response_get_header_by_index(struct http_response *resp,
        !           210:                        u_int index, const char **namep, const char **valuep);
        !           211: extern int     http_response_set_header(struct http_response *resp,
        !           212:                        int append, const char *name, const char *valfmt, ...)
        !           213:                        __printflike(4, 5);
        !           214: extern int     http_response_remove_header(struct http_response *resp,
        !           215:                        const char *name);
        !           216: extern int     http_response_send_headers(struct http_response *resp,
        !           217:                        int unbuffer);
        !           218: extern int     http_response_get_code(struct http_response *resp);
        !           219: extern FILE    *http_response_get_input(struct http_response *resp);
        !           220: extern FILE    *http_response_get_output(struct http_response *resp, int bufr);
        !           221: extern struct  in_addr http_response_get_remote_ip(struct http_response *resp);
        !           222: extern u_int16_t http_response_get_remote_port(struct http_response *resp);
        !           223: extern void    http_response_guess_mime(const char *path, const char **ctype,
        !           224:                        const char **cencs, int maxenc);
        !           225: extern void    http_response_send_redirect(struct http_response *resp,
        !           226:                        const char *url);
        !           227: extern void    http_response_send_basic_auth(struct http_response *resp,
        !           228:                        const char *realm);
        !           229: extern void    http_response_send_error(struct http_response *resp,
        !           230:                        int code, const char *fmt, ...);
        !           231: extern void    http_response_send_errno_error(struct http_response *resp);
        !           232: 
        !           233: extern int     http_response_no_body(int code);
        !           234: extern const   char *http_response_status_msg(int code);
        !           235: extern int     http_response_get_raw_socket(struct http_response *resp);
        !           236: 
        !           237: __END_DECLS
        !           238: 
        !           239: #endif /* _PDEL_HTTP_HTTP_SERVER_H_ */
        !           240: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>