aboutsummaryrefslogtreecommitdiffstats
path: root/src/manager/lib/response.h
blob: 50d0eacc1e785f077bea9befa862e674089ab263 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
 * @file response.h
 * 
 * @brief Interface of response_t.
 * 
 */

/*
 * Copyright (C) 2007 Martin Willi
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#ifndef RESPONSE_H_
#define RESPONSE_H_


#include <fcgiapp.h>

typedef struct response_t response_t;

/**
 * @brief A HTTP response, wraps response functionality around FCGX_Request.
 *
 */
struct response_t {
	
	/**
	 * @brief Write a string to the client.
	 *
	 * @param str			string to write
	 */
	void (*print)(response_t *this, char *str);
	
	/**
	 * @brief Write a printf like format string to client.
	 *
	 * @param format		printf like format string
	 * @param ...			variable argument list
	 */
	void (*printf)(response_t *this, char *format, ...);
	
	/**
	 * @brief Add a custom header to the response.
	 *
	 * @param name			name of the header
	 * @param value			value of the header
	 */
	void (*add_header)(response_t *this, char *name, char *value);
	
	/**
	 * @brief Set the content type (Content-Type header).
	 *
	 * @param type			content type (e.g. text/html)
	 */
	void (*set_content_type)(response_t *this, char *type);
	
	/**
	 * @brief Add a cookie to the response (Set-Cookie header).
	 *
	 * @param name			name of the cookie to set
	 * @param value			value of the cookie
	 */
	void (*add_cookie)(response_t *this, char *name, char *value);
	
	/**
	 * @brief Redirect the client to another location.
	 *
	 * @param location		location to redirect to
	 */
	void (*redirect)(response_t *this, char *location);
	
	/**
	 * @brief Get the base path of the application.
	 *
	 * @return			base path
	 */
	char* (*get_base)(response_t *this);
		
	/**
	 * @brief Destroy a response_t.
	 */
	void (*destroy) (response_t *this);
};

/**
 * @brief Create a response.
 *
 * @param request		the FCGI request structure
 */
response_t *response_create(FCGX_Request *request);

#endif /* RESPONSE_H_ */