* replaced __thread with pthread_key_t/pthread_setspecific
[strongswan.git] / src / manager / lib / request.h
1 /**
2 * @file request.h
3 *
4 * @brief Interface of request_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2007 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef REQUEST_H_
24 #define REQUEST_H_
25
26 #include <fcgiapp.h>
27 #include <library.h>
28
29 typedef struct request_t request_t;
30
31 /**
32 * @brief A HTTP request, encapsulates FCGX_Request.
33 *
34 */
35 struct request_t {
36
37 /**
38 * @brief Add a cookie to the reply (Set-Cookie header).
39 *
40 * @param name name of the cookie to set
41 * @param value value of the cookie
42 */
43 void (*add_cookie)(request_t *this, char *name, char *value);
44
45 /**
46 * @brief Get a cookie the client sent in the request.
47 *
48 * @param name name of the cookie
49 * @return cookie value, NULL if no such cookie found
50 */
51 char* (*get_cookie)(request_t *this, char *name);
52
53 /**
54 * @brief Get the request path relative to the application.
55 *
56 * @return path
57 */
58 char* (*get_path)(request_t *this);
59
60 /**
61 * @brief Get the base path of the application.
62 *
63 * @return base path
64 */
65 char* (*get_base)(request_t *this);
66
67 /**
68 * @brief Get a post/get variable included in the request.
69 *
70 * @param name name of the POST/GET variable
71 * @return value, NULL if not found
72 */
73 char* (*get_query_data)(request_t *this, char *name);
74
75 /**
76 * @brief Redirect the client to another location.
77 *
78 * @param fmt location format string
79 * @param ... variable argument for fmt
80 */
81 void (*redirect)(request_t *this, char *fmt, ...);
82
83 /**
84 * @brief Set a template value.
85 *
86 * @param key key to set
87 * @param value value to set key to
88 */
89 void (*set)(request_t *this, char *key, char *value);
90
91 /**
92 * @brief Set a template value using format strings.
93 *
94 * Format string is in the form "key=value", where printf like format
95 * substitution occurs over the whole string.
96 *
97 * @param format printf like format string
98 * @param ... variable argument list
99 */
100 void (*setf)(request_t *this, char *format, ...);
101
102 /**
103 * @brief Render a template.
104 *
105 * The render() function additionally sets a HDF variable "base"
106 * which points to the root of the web application and allows to point to
107 * other targets without to worry about path location.
108 *
109 * @param template clearsilver template file location
110 */
111 void (*render)(request_t *this, char *template);
112
113 /**
114 * @brief Serve a request with headers and a body.
115 *
116 * @param headers HTTP headers, \n separated
117 * @param chunk body to write to output
118 */
119 void (*serve)(request_t *this, char *headers, chunk_t chunk);
120
121 /**
122 * @brief Destroy the request_t.
123 */
124 void (*destroy) (request_t *this);
125 };
126
127 /**
128 * @brief Create a request from the fastcgi struct.
129 *
130 * @param request the FCGI request
131 * @param debug no stripping, no compression, timing information
132 */
133 request_t *request_create(FCGX_Request *request, bool debug);
134
135 #endif /* REQUEST_H_ */