Forgot to include mongoose (new shttpd name)
[platform/upstream/libzypp.git] / vendor / mongoose / mongoose.h
1 /*\r
2  * Copyright (c) 2004-2009 Sergey Lyubka\r
3  *\r
4  * Permission is hereby granted, free of charge, to any person obtaining a copy\r
5  * of this software and associated documentation files (the "Software"), to deal\r
6  * in the Software without restriction, including without limitation the rights\r
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
8  * copies of the Software, and to permit persons to whom the Software is\r
9  * furnished to do so, subject to the following conditions:\r
10  *\r
11  * The above copyright notice and this permission notice shall be included in\r
12  * all copies or substantial portions of the Software.\r
13  *\r
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
20  * THE SOFTWARE.\r
21  *\r
22  * $Id$\r
23  */\r
24 \r
25 #ifndef MONGOOSE_HEADER_INCLUDED\r
26 #define MONGOOSE_HEADER_INCLUDED\r
27 \r
28 #ifdef __cplusplus\r
29 extern "C" {\r
30 #endif /* __cplusplus */\r
31 \r
32 struct mg_context;      /* Handle for the HTTP service itself   */\r
33 struct mg_connection;   /* Handle for the individual connection */\r
34 \r
35 /*\r
36  * This structure contains full information about the HTTP request.\r
37  * It is passed to the user-specified callback function as a parameter.\r
38  */\r
39 struct mg_request_info {\r
40         char    *request_method;        /* "GET", "POST", etc   */\r
41         char    *uri;                   /* Normalized URI       */\r
42         char    *query_string;          /* \0 - terminated      */\r
43         char    *post_data;             /* POST data buffer     */\r
44         char    *remote_user;           /* Authenticated user   */\r
45         long    remote_ip;              /* Client's IP address  */\r
46         int     remote_port;            /* Client's port        */\r
47         int     post_data_len;          /* POST buffer length   */\r
48         int     http_version_major;\r
49         int     http_version_minor;\r
50         int     status_code;            /* HTTP status code     */\r
51         int     num_headers;            /* Number of headers    */\r
52 #define MAX_HTTP_HEADERS        64\r
53         struct mg_header {\r
54                 char    *name;          /* HTTP header name     */\r
55                 char    *value;         /* HTTP header value    */\r
56         } http_headers[MAX_HTTP_HEADERS];\r
57 };\r
58 \r
59 /*\r
60  * Mongoose configuration option.\r
61  * Array of those is returned by mg_get_option_list().\r
62  */\r
63 struct mg_option {\r
64         char    *name;\r
65         char    *description;\r
66         char    *default_value;\r
67 };\r
68 \r
69 /*\r
70  * Functions dealing with initialization, starting and stopping Mongoose\r
71  *\r
72  * mg_start             Start serving thread. Return server context.\r
73  * mg_stop              Stop server thread, and release the context.\r
74  * mg_set_option        Set an option for the running context.\r
75  * mg_get_option        Get an option for the running context.\r
76  * mg_get_option_list   Get a list of all known options.\r
77  * mg_handle_uri        Associate user function with paticular URI.\r
78  *                      '*' in regex matches zero or more characters.\r
79  * mg_handle_error_code Associate user function with HTTP error code.\r
80  *                      Passing 0 as error code binds function to all codes.\r
81  *                      Error code is passed as status_code in request info.\r
82  * mg_protect_uri       Similar to "protect" option, but uses a user\r
83  *                      specified function instead of the passwords file.\r
84  *                      User specified function is usual callback, which\r
85  *                      does use its third argument to pass the result back.\r
86  */\r
87 \r
88 struct mg_context *mg_start(void);\r
89 void mg_stop(struct mg_context *);\r
90 const struct mg_option *mg_get_option_list(void);\r
91 const char *mg_get_option(struct mg_context *, const char *);\r
92 int mg_set_option(struct mg_context *, const char *, const char *);\r
93 \r
94 typedef void (*mg_callback_t)(struct mg_connection *,\r
95                 const struct mg_request_info *info, void *user_data);\r
96 \r
97 void mg_bind_to_uri(struct mg_context *ctx, const char *uri_regex,\r
98                 mg_callback_t func, void *user_data);\r
99 void mg_bind_to_error_code(struct mg_context *ctx, int error_code,\r
100                 mg_callback_t func, void *user_data);\r
101 void mg_protect_uri(struct mg_context *ctx, const char *uri_regex,\r
102                 mg_callback_t func, void *user_data);\r
103 \r
104 /*\r
105  * Needed only if SSL certificate asks for a password.\r
106  * Instead of prompting for a password, specified function will be called.\r
107  */\r
108 typedef int (*mg_spcb_t)(char *buf, int num, int w, void *key);\r
109 void mg_set_ssl_password_callback(struct mg_context *ctx, mg_spcb_t func);\r
110 \r
111 /*\r
112  * Functions that can be used within the user URI callback\r
113  *\r
114  * mg_write     Send data to the remote end.\r
115  * mg_printf    Send data, using printf() semantics.\r
116  * mg_get_header Helper function to get HTTP header value\r
117  * mg_get_var   Helper function to get form variable value.\r
118  *              Returned value must be free-d by the caller.\r
119  */\r
120 int mg_write(struct mg_connection *, const void *buf, int len);\r
121 int mg_printf(struct mg_connection *, const char *fmt, ...);\r
122 const char *mg_get_header(const struct mg_connection *, const char *hdr_name);\r
123 char *mg_get_var(const struct mg_connection *, const char *var_name);\r
124 \r
125 /*\r
126  * General helper functions\r
127  * mg_version   Return current version.\r
128  * mg_md5       Helper function. buf must be 33 bytes in size. Expects\r
129  *              a NULL terminated list of asciz strings.\r
130  *              Fills buf with stringified \0 terminated MD5 hash.\r
131  */\r
132 const char *mg_version(void);\r
133 void mg_md5(char *buf, ...);\r
134 \r
135 #ifdef __cplusplus\r
136 }\r
137 #endif /* __cplusplus */\r
138 \r
139 #endif /* MONGOOSE_HEADER_INCLUDED */\r