27 #define BALDE_LOG_DOMAIN "balde" 29 #define balde_log_critical(...) \ 30 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __VA_ARGS__) 32 #define balde_log_warning(...) \ 33 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_WARNING, __VA_ARGS__) 35 #define balde_log_message(...) \ 36 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__) 38 #define balde_log_info(...) \ 39 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__) 41 #define balde_log_debug(...) \ 42 g_log(BALDE_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __VA_ARGS__) 55 BALDE_HTTP_OPTIONS = 1 << 0,
56 BALDE_HTTP_GET = 1 << 1,
57 BALDE_HTTP_HEAD = 1 << 2,
58 BALDE_HTTP_POST = 1 << 3,
59 BALDE_HTTP_PUT = 1 << 4,
60 BALDE_HTTP_PATCH = 1 << 5,
61 BALDE_HTTP_DELETE = 1 << 6,
62 BALDE_HTTP_ANY = 0xFF,
76 BALDE_HTTP_MULTIPLE_CHOICES = 300,
77 BALDE_HTTP_MOVED_PERMANENTLY = 301,
78 BALDE_HTTP_FOUND = 302,
79 BALDE_HTTP_SEE_OTHER = 303,
80 BALDE_HTTP_NOT_MODIFIED = 304,
81 BALDE_HTTP_USE_PROXY = 305,
82 BALDE_HTTP_TEMPORARY_REDIRECT = 307,
83 BALDE_HTTP_BAD_REQUEST = 400,
84 BALDE_HTTP_UNAUTHORIZED = 401,
85 BALDE_HTTP_FORBIDDEN = 403,
86 BALDE_HTTP_NOT_FOUND = 404,
87 BALDE_HTTP_METHOD_NOT_ALLOWED = 405,
88 BALDE_HTTP_NOT_ACCEPTABLE = 406,
89 BALDE_HTTP_REQUEST_TIMEOUT = 408,
90 BALDE_HTTP_CONFLICT = 409,
91 BALDE_HTTP_GONE = 410,
92 BALDE_HTTP_LENGTH_REQUIRED = 411,
93 BALDE_HTTP_PRECONDITION_FAILED = 412,
94 BALDE_HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
95 BALDE_HTTP_REQUEST_URI_TOO_LONG = 414,
96 BALDE_HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
97 BALDE_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
98 BALDE_HTTP_EXPECTATION_FAILED = 417,
99 BALDE_HTTP_I_M_A_TEAPOT = 418,
100 BALDE_HTTP_UNPROCESSABLE_ENTITY = 422,
101 BALDE_HTTP_PRECONDITION_REQUIRED = 428,
102 BALDE_HTTP_TOO_MANY_REQUESTS = 429,
103 BALDE_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
104 BALDE_HTTP_INTERNAL_SERVER_ERROR = 500,
105 BALDE_HTTP_NOT_IMPLEMENTED = 501,
106 BALDE_HTTP_BAD_GATEWAY = 502,
107 BALDE_HTTP_SERVICE_UNAVAILABLE = 503,
131 struct _balde_app_private_t *
priv;
252 struct _balde_request_private_t *
priv;
277 struct _balde_response_private_t *
priv;
328 const gchar *env_name, gboolean silent);
368 GDestroyNotify destroy_func);
420 const gchar *endpoint, gboolean external, ...);
463 const gchar *content);
471 const gchar *content,
const gssize len);
546 const gchar *value,
const gint max_age,
const gint64 expires,
547 const gchar *path,
const gchar *domain,
const gboolean secure,
548 const gboolean http_only);
559 const gchar *path,
const gchar *domain);
741 const gchar *endpoint, gboolean external, ...);
void balde_session_delete(balde_request_t *request, const gchar *key)
Deletes a value from an HTTP session context.
const gchar * balde_request_get_arg(balde_request_t *request, const gchar *name)
Gets a query string argument.
balde_http_exception_code_t status_code
HTTP response status code.
Definition: balde.h:271
void balde_abort_set_error(balde_app_t *app, const balde_http_exception_code_t code)
Sets application error with an HTTP status code.
void balde_response_etag_matching(balde_request_t *request, balde_response_t *response)
Check if response matches a sent etag header and change reponse to be blank and change response code ...
const gchar * balde_request_get_header(balde_request_t *request, const gchar *name)
Gets a request header.
GString * content
File content.
Definition: balde.h:196
void balde_session_open(balde_app_t *app, balde_request_t *request)
Initializes an HTTP session context.
void balde_app_set_user_data_destroy_func(balde_app_t *app, GDestroyNotify destroy_func)
Sets user data destroy function.
const gchar * username
User name.
Definition: balde.h:157
void balde_app_set_config(balde_app_t *app, const gchar *name, const gchar *value)
Sets a configuration parameter.
struct _balde_app_private_t * priv
Private structure.
Definition: balde.h:131
const gchar * balde_response_get_tmpl_var(balde_response_t *response, const gchar *name)
Gets a template variable.
gchar * balde_file_save_to_disk(const balde_file_t *file, const gchar *destdir, const gchar *name)
Saves a file to disk.
balde_response_t * balde_make_response(const gchar *content)
Initialize a response context.
void balde_app_free(balde_app_t *app)
Free application context memory.
const gchar * balde_request_get_cookie(balde_request_t *request, const gchar *name)
Gets a cookie.
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.
const gchar * balde_app_get_config(balde_app_t *app, const gchar *name)
Gets a configuration parameter.
void balde_response_delete_cookie(balde_response_t *response, const gchar *name, const gchar *path, const gchar *domain)
Deletes a cookie from client.
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.
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.
void balde_resources_load(balde_app_t *app, GResource *resources)
Load static resources.
const gchar * server_name
Request server name.
Definition: balde.h:221
balde_app_t * balde_app_init(void)
Initializes the application context.
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.
void(* balde_before_request_func_t)(balde_app_t *, balde_request_t *)
"Before request" hook type definition
Definition: balde.h:297
struct _balde_request_private_t * priv
Private structure.
Definition: balde.h:252
GError * error
Application error context.
Definition: balde.h:125
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.
void balde_response_set_tmpl_var(balde_response_t *response, const gchar *name, const gchar *value)
Sets a template variable.
const gchar * type
File type.
Definition: balde.h:190
const GString * balde_request_get_body(balde_request_t *request)
Gets the request body.
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_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_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.
balde HTTP authorization context.
Definition: balde.h:151
const gchar * balde_request_get_form(balde_request_t *request, const gchar *name)
Gets a form input value.
void balde_app_run(balde_app_t *app, gint argc, gchar **argv)
Application main loop.
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.
balde_response_t *(* balde_view_func_t)(balde_app_t *, balde_request_t *)
View type definition.
Definition: balde.h:289
const gchar * name
File name.
Definition: balde.h:184
balde_http_exception_code_t
Supported HTTP status codes.
Definition: balde.h:74
void balde_response_set_etag_header(balde_response_t *response, gboolean weak)
Sets a response ETag header for the current content of the response.
balde HTTP request context
Definition: balde.h:209
balde HTTP response context
Definition: balde.h:265
void balde_app_free_user_data(balde_app_t *app)
Free memory allocated for user data.
void balde_response_append_body(balde_response_t *response, const gchar *content)
Appends a nul-terminated string to the response body.
void balde_session_set(balde_request_t *request, const gchar *key, const gchar *value)
Sets a value into an HTTP session context.
const gchar * script_name
Request script name.
Definition: balde.h:227
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.
balde file representation.
Definition: balde.h:178
gboolean https
Request using encrypted connection.
Definition: balde.h:246
balde_response_t * balde_make_response_len(const gchar *content, const gssize len)
Initialize a response context with specific length.
void balde_response_truncate_body(balde_response_t *response)
Truncate response's body.
void balde_response_set_header(balde_response_t *response, const gchar *name, const gchar *value)
Sets a response header.
balde_authorization_t * authorization
A structure that stores the authorization data received from the client.
Definition: balde.h:215
void balde_app_set_user_data(balde_app_t *app, gpointer user_data)
Sets user data.
const gchar * path
Request path.
Definition: balde.h:233
const gchar * balde_request_get_view_arg(balde_request_t *request, const gchar *name)
Gets a view argument.
balde_http_method_t method
Request HTTP method.
Definition: balde.h:240
struct _balde_response_private_t * priv
Private structure.
Definition: balde.h:277
const balde_file_t * balde_request_get_file(balde_request_t *request, const gchar *name)
Gets a file uploaded.
gpointer balde_app_get_user_data(balde_app_t *app)
Gets user data.
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.
gboolean copy
Private field.
Definition: balde.h:137
void balde_session_save(balde_request_t *request, balde_response_t *response)
Saves an HTTP session context and attaches it to a response context.
const gchar * balde_session_get(balde_request_t *request, const gchar *key)
Gets a value from an HTTP session context.
balde_http_method_t
Supported HTTP methods.
Definition: balde.h:53
const gchar * password
User password.
Definition: balde.h:163
balde application context
Definition: balde.h:119