|
balde
master
A microframework for C based on GLib.
|
Go to the documentation of this file.
14 #ifdef WITH_UNIX_SOCKETS
15 #include <gio/gunixsocketaddress.h>
30 #define BALDE_LOG_DOMAIN "balde"
32 #define balde_log_critical(...) \
33 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
35 #define balde_log_warning(...) \
36 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__)
38 #define balde_log_message(...) \
39 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__)
41 #define balde_log_info(...) \
42 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
44 #define balde_log_debug(...) \
45 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__)
58 BALDE_HTTP_OPTIONS = 1 << 0,
59 BALDE_HTTP_GET = 1 << 1,
60 BALDE_HTTP_HEAD = 1 << 2,
61 BALDE_HTTP_POST = 1 << 3,
62 BALDE_HTTP_PUT = 1 << 4,
63 BALDE_HTTP_PATCH = 1 << 5,
64 BALDE_HTTP_DELETE = 1 << 6,
65 BALDE_HTTP_ANY = 0xFF,
79 BALDE_HTTP_MULTIPLE_CHOICES = 300,
80 BALDE_HTTP_MOVED_PERMANENTLY = 301,
81 BALDE_HTTP_FOUND = 302,
82 BALDE_HTTP_SEE_OTHER = 303,
83 BALDE_HTTP_NOT_MODIFIED = 304,
84 BALDE_HTTP_USE_PROXY = 305,
85 BALDE_HTTP_TEMPORARY_REDIRECT = 307,
86 BALDE_HTTP_BAD_REQUEST = 400,
87 BALDE_HTTP_UNAUTHORIZED = 401,
88 BALDE_HTTP_FORBIDDEN = 403,
89 BALDE_HTTP_NOT_FOUND = 404,
90 BALDE_HTTP_METHOD_NOT_ALLOWED = 405,
91 BALDE_HTTP_NOT_ACCEPTABLE = 406,
92 BALDE_HTTP_REQUEST_TIMEOUT = 408,
93 BALDE_HTTP_CONFLICT = 409,
94 BALDE_HTTP_GONE = 410,
95 BALDE_HTTP_LENGTH_REQUIRED = 411,
96 BALDE_HTTP_PRECONDITION_FAILED = 412,
97 BALDE_HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
98 BALDE_HTTP_REQUEST_URI_TOO_LONG = 414,
99 BALDE_HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
100 BALDE_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
101 BALDE_HTTP_EXPECTATION_FAILED = 417,
102 BALDE_HTTP_I_M_A_TEAPOT = 418,
103 BALDE_HTTP_UNPROCESSABLE_ENTITY = 422,
104 BALDE_HTTP_PRECONDITION_REQUIRED = 428,
105 BALDE_HTTP_TOO_MANY_REQUESTS = 429,
106 BALDE_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
107 BALDE_HTTP_INTERNAL_SERVER_ERROR = 500,
108 BALDE_HTTP_NOT_IMPLEMENTED = 501,
109 BALDE_HTTP_BAD_GATEWAY = 502,
110 BALDE_HTTP_SERVICE_UNAVAILABLE = 503,
134 struct _balde_app_private_t *
priv;
255 struct _balde_request_private_t *
priv;
280 struct _balde_response_private_t *
priv;
331 const gchar *env_name, gboolean silent);
371 GDestroyNotify destroy_func);
423 const gchar *endpoint, gboolean external, ...);
466 const gchar *content);
474 const gchar *content,
const gssize len);
549 const gchar *value,
const gint max_age,
const gint64 expires,
550 const gchar *path,
const gchar *domain,
const gboolean secure,
551 const gboolean http_only);
562 const gchar *path,
const gchar *domain);
744 const gchar *endpoint, gboolean external, ...);
const gchar * balde_request_get_header(balde_request_t *request, const gchar *name)
Gets a request header.
void balde_app_set_user_data_destroy_func(balde_app_t *app, GDestroyNotify destroy_func)
Sets user data destroy function.
void balde_session_delete(balde_request_t *request, const gchar *key)
Deletes a value from an HTTP session context.
void balde_response_truncate_body(balde_response_t *response)
Truncate response's body.
void balde_app_add_url_rule(balde_app_t *app, const gchar *endpoint, const gchar *rule, const balde_http_method_t method, balde_view_func_t view_func)
Adds a view to the balde application.
void balde_abort_set_error_with_description(balde_app_t *app, const balde_http_exception_code_t code, const gchar *description)
Sets application error with an HTTP status code and custom description.
void balde_response_delete_cookie(balde_response_t *response, const gchar *name, const gchar *path, const gchar *domain)
Deletes a cookie from client.
void balde_app_free_user_data(balde_app_t *app)
Free memory allocated for user data.
void balde_session_save(balde_request_t *request, balde_response_t *response)
Saves an HTTP session context and attaches it to a response context.
gpointer balde_app_get_user_data(balde_app_t *app)
Gets user data.
const balde_file_t * balde_request_get_file(balde_request_t *request, const gchar *name)
Gets a file uploaded.
struct _balde_app_private_t * priv
Private structure.
Definition: balde.h:134
void balde_response_set_cookie(balde_response_t *response, const gchar *name, const gchar *value, const gint max_age, const gint64 expires, const gchar *path, const gchar *domain, const gboolean secure, const gboolean http_only)
Sets a cookie.
balde_response_t * balde_abort(balde_app_t *app, const balde_http_exception_code_t code)
Returns a response context that represents an HTTP status code.
GString * content
File content.
Definition: balde.h:199
void balde_session_open(balde_app_t *app, balde_request_t *request)
Initializes an HTTP session context.
const GString * balde_request_get_body(balde_request_t *request)
Gets the request body.
balde HTTP request context
Definition: balde.h:212
void balde_app_set_config_from_envvar(balde_app_t *app, const gchar *name, const gchar *env_name, gboolean silent)
Sets a configuration parameter with the value of an environment variable.
balde_http_method_t
Supported HTTP methods.
Definition: balde.h:56
balde_http_exception_code_t
Supported HTTP status codes.
Definition: balde.h:77
void balde_app_set_config(balde_app_t *app, const gchar *name, const gchar *value)
Sets a configuration parameter.
gchar * balde_file_save_to_disk(const balde_file_t *file, const gchar *destdir, const gchar *name)
Saves a file to disk.
const gchar * type
File type.
Definition: balde.h:193
const gchar * balde_request_get_form(balde_request_t *request, const gchar *name)
Gets a form input value.
const gchar * balde_response_get_tmpl_var_or_empty(balde_response_t *response, const gchar *name)
Gets a template variable and returns an empty string, if not found.
struct _balde_response_private_t * priv
Private structure.
Definition: balde.h:280
const gchar * balde_request_get_view_arg(balde_request_t *request, const gchar *name)
Gets a view argument.
void(* balde_before_request_func_t)(balde_app_t *, balde_request_t *)
"Before request" hook type definition
Definition: balde.h:300
balde_response_t *(* balde_view_func_t)(balde_app_t *, balde_request_t *)
View type definition.
Definition: balde.h:292
const gchar * script_name
Request script name.
Definition: balde.h:230
const gchar * balde_request_get_arg(balde_request_t *request, const gchar *name)
Gets a query string argument.
balde HTTP response context
Definition: balde.h:268
const gchar * name
File name.
Definition: balde.h:187
void balde_session_set(balde_request_t *request, const gchar *key, const gchar *value)
Sets a value into an HTTP session context.
void balde_app_add_before_request(balde_app_t *app, balde_before_request_func_t hook_func)
Adds a "before request" hook to the balde application.
void balde_response_set_etag_header(balde_response_t *response, gboolean weak)
Sets a response ETag header for the current content of the response.
void balde_response_set_tmpl_var(balde_response_t *response, const gchar *name, const gchar *value)
Sets a template variable.
void balde_abort_set_error(balde_app_t *app, const balde_http_exception_code_t code)
Sets application error with an HTTP status code.
GError * error
Application error context.
Definition: balde.h:128
gboolean copy
Private field.
Definition: balde.h:140
void balde_app_free(balde_app_t *app)
Free application context memory.
const gchar * username
User name.
Definition: balde.h:160
balde_response_t * balde_make_response_len(const gchar *content, const gssize len)
Initialize a response context with specific length.
const gchar * balde_request_get_cookie(balde_request_t *request, const gchar *name)
Gets a cookie.
gchar * balde_app_url_for(balde_app_t *app, balde_request_t *request, const gchar *endpoint, gboolean external,...)
Helper function to get the URL for a given endpoint.
balde HTTP authorization context.
Definition: balde.h:154
void balde_response_append_body_len(balde_response_t *response, const gchar *content, const gssize len)
Appends a string to the response body, with specific length.
balde file representation.
Definition: balde.h:181
void balde_app_run(balde_app_t *app, gint argc, gchar **argv)
Application main loop.
void balde_resources_load(balde_app_t *app, GResource *resources)
Load static resources.
const gchar * password
User password.
Definition: balde.h:166
gchar * balde_tmpl_url_for(balde_app_t *app, balde_request_t *request, const gchar *endpoint, gboolean external,...)
Template helper to get the URL for a given endpoint.
const gchar * balde_app_get_config(balde_app_t *app, const gchar *name)
Gets a configuration parameter.
struct _balde_request_private_t * priv
Private structure.
Definition: balde.h:255
void balde_response_append_body(balde_response_t *response, const gchar *content)
Appends a nul-terminated string to the response body.
const gchar * path
Request path.
Definition: balde.h:236
void balde_app_set_user_data(balde_app_t *app, gpointer user_data)
Sets user data.
void balde_response_set_header(balde_response_t *response, const gchar *name, const gchar *value)
Sets a response header.
balde_http_method_t method
Request HTTP method.
Definition: balde.h:243
balde_http_exception_code_t status_code
HTTP response status code.
Definition: balde.h:274
balde_response_t * balde_abort_with_description(balde_app_t *app, const balde_http_exception_code_t code, const gchar *description)
Returns a response context that represents an HTTP status code with custom description.
balde_app_t * balde_app_init(void)
Initializes the application context.
void balde_response_etag_matching(balde_request_t *request, balde_response_t *response)
Check if response matches a sent etag header and change response to be blank and change response code...
const gchar * server_name
Request server name.
Definition: balde.h:224
const gchar * balde_response_get_tmpl_var(balde_response_t *response, const gchar *name)
Gets a template variable.
balde_response_t * balde_make_response(const gchar *content)
Initialize a response context.
balde_authorization_t * authorization
A structure that stores the authorization data received from the client.
Definition: balde.h:218
balde application context
Definition: balde.h:122
const gchar * balde_session_get(balde_request_t *request, const gchar *key)
Gets a value from an HTTP session context.
gboolean https
Request using encrypted connection.
Definition: balde.h:249