35 #include "ulfius-cfg.h"
39 #ifndef U_DISABLE_GNUTLS
43 #include <gnutls/gnutls.h>
44 #include <gnutls/x509.h>
47 #ifndef U_DISABLE_JANSSON
51 #ifndef U_DISABLE_WEBSOCKET
56 #define POLLRDHUP 0x2000
60 #include <microhttpd.h>
62 #if defined(_WIN32) && !defined(U_DISABLE_WEBSOCKET)
63 #define U_DISABLE_WEBSOCKET
66 #if (MHD_VERSION < 0x00095300) && !defined(U_DISABLE_WEBSOCKET)
67 #define U_DISABLE_WEBSOCKET
74 #ifndef U_DISABLE_YDER
78 #define Y_LOG_MODE_NONE 0
79 #define Y_LOG_MODE_CONSOLE 0
80 #define Y_LOG_MODE_SYSLOG 0
81 #define Y_LOG_MODE_FILE 0
82 #define Y_LOG_MODE_JOURNALD 0
83 #define Y_LOG_MODE_CALLBACK 0
84 #define Y_LOG_MODE_CURRENT 0
86 #define Y_LOG_LEVEL_NONE 0
87 #define Y_LOG_LEVEL_DEBUG 0
88 #define Y_LOG_LEVEL_INFO 0
89 #define Y_LOG_LEVEL_WARNING 0
90 #define Y_LOG_LEVEL_ERROR 0
91 #define Y_LOG_LEVEL_CURRENT 0
93 int y_init_logs(
const char * app,
const unsigned long init_mode,
const unsigned long init_level,
const char * init_log_file,
const char * message);
94 int y_set_logs_callback(
void (* y_callback_log_message) (
void * cls,
const char * app_name,
const time_t date,
const unsigned long level,
const char * message),
void * cls,
const char * message);
95 void y_log_message(
const unsigned long type,
const char * message, ...);
104 #define ULFIUS_STREAM_BLOCK_SIZE_DEFAULT 1024
105 #define U_STREAM_END MHD_CONTENT_READER_END_OF_STREAM
106 #define U_STREAM_ERROR MHD_CONTENT_READER_END_WITH_ERROR
107 #define U_STREAM_SIZE_UNKNOWN MHD_SIZE_UNKNOWN
108 #define U_STREAM_SIZE_UNKOWN U_STREAM_SIZE_UNKNOWN
112 #define U_ERROR_MEMORY 2
113 #define U_ERROR_PARAMS 3
114 #define U_ERROR_LIBMHD 4
115 #define U_ERROR_LIBCURL 5
116 #define U_ERROR_NOT_FOUND 6
117 #define U_ERROR_DISCONNECTED 7
119 #define U_CALLBACK_CONTINUE 0
120 #define U_CALLBACK_IGNORE 1
121 #define U_CALLBACK_COMPLETE 2
122 #define U_CALLBACK_UNAUTHORIZED 3
123 #define U_CALLBACK_ERROR 4
125 #define U_COOKIE_SAME_SITE_EMPTY 0
126 #define U_COOKIE_SAME_SITE_STRICT 1
127 #define U_COOKIE_SAME_SITE_LAX 2
128 #define U_COOKIE_SAME_SITE_NONE 3
130 #define U_USE_IPV4 0x0001
131 #define U_USE_IPV6 0x0010
132 #define U_USE_ALL (U_USE_IPV4|U_USE_IPV6)
134 #define U_SSL_VERIFY_PEER 0x0001
135 #define U_SSL_VERIFY_HOSTNAME 0x0010
137 #define U_POST_PROCESS_NONE 0x0000
138 #define U_POST_PROCESS_URL_ENCODED 0x0001
139 #define U_POST_PROCESS_MULTIPART_FORMDATA 0x0010
150 #if MHD_VERSION >= 0x00095208
151 U_OPT_NETWORK_TYPE = 4,
173 #ifndef U_DISABLE_JANSSON
176 #ifndef U_DISABLE_GNUTLS
239 #if MHD_VERSION >= 0x00095208
240 unsigned short network_type;
259 #ifndef U_DISABLE_GNUTLS
320 #if MHD_VERSION >= 0x00095208
321 unsigned short network_type;
336 const char * filename,
337 const char * content_type,
338 const char * transfer_encoding,
346 #ifndef U_DISABLE_GNUTLS
422 #if MHD_VERSION >= 0x00095208
434 int ulfius_init_instance_ipv6(
struct _u_instance * u_instance,
unsigned int port,
struct sockaddr_in6 * bind_address,
unsigned short network_type,
const char * default_auth_realm);
465 #ifndef U_DISABLE_GNUTLS
503 void mhd_request_completed (
void *cls,
struct MHD_Connection *connection,
void **con_cls,
enum MHD_RequestTerminationCode toe);
536 int (* file_upload_callback) (
const struct _u_request * request,
538 const char * filename,
539 const char * content_type,
540 const char * transfer_encoding,
588 const char * http_method,
589 const char * url_prefix,
590 const char * url_format,
591 unsigned int priority,
592 int (* callback_function)(
const struct _u_request * request,
629 int (* callback_function)(
const struct _u_request * request,
struct _u_response * response,
void * user_data),
703 #ifndef U_DISABLE_CURL
750 const int verify_certificate,
752 const char * password,
757 const char * subject,
758 const char * mail_body);
782 const int verify_certificate,
784 const char * password,
789 const char * content_type,
790 const char * subject,
791 const char * mail_body);
819 const char * domain,
const char * path,
const int secure,
const int http_only);
840 const char * domain,
const char * path,
const int secure,
const int http_only,
const int same_site);
942 const unsigned int status,
943 ssize_t (* stream_callback) (
void * stream_user_data, uint64_t offset,
char * out_buf,
size_t max),
944 void (* stream_callback_free) (
void * stream_user_data),
945 uint64_t stream_size,
946 size_t stream_block_size,
947 void * stream_user_data);
1165 #ifndef U_DISABLE_JANSSON
1327 int u_map_put(
struct _u_map * u_map,
const char * key,
const char * value);
1340 int u_map_put_binary(
struct _u_map * u_map,
const char * key,
const char * value, uint64_t offset,
size_t length);
1367 const char *
u_map_get(
const struct _u_map * u_map,
const char * key);
1473 #ifndef U_DISABLE_WEBSOCKET
1479 #define U_WEBSOCKET_USER_AGENT "Ulfius Websocket Client Framework"
1481 #define U_WEBSOCKET_MAGIC_STRING "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
1482 #define U_WEBSOCKET_UPGRADE_VALUE "websocket"
1483 #define U_WEBSOCKET_BAD_REQUEST_BODY "Error in websocket handshake, wrong parameters"
1484 #define U_WEBSOCKET_USEC_WAIT 50
1485 #define WEBSOCKET_MAX_CLOSE_TRY 10
1487 #define U_WEBSOCKET_BIT_FIN 0x80
1488 #define U_WEBSOCKET_MASK 0x80
1489 #define U_WEBSOCKET_LEN_MASK 0x7F
1490 #define U_WEBSOCKET_OPCODE_CONTINUE 0x00
1491 #define U_WEBSOCKET_OPCODE_TEXT 0x01
1492 #define U_WEBSOCKET_OPCODE_BINARY 0x02
1493 #define U_WEBSOCKET_OPCODE_CLOSE 0x08
1494 #define U_WEBSOCKET_OPCODE_PING 0x09
1495 #define U_WEBSOCKET_OPCODE_PONG 0x0A
1496 #define U_WEBSOCKET_OPCODE_CLOSED 0xFD
1497 #define U_WEBSOCKET_OPCODE_ERROR 0xFE
1498 #define U_WEBSOCKET_OPCODE_NONE 0xFF
1500 #define U_WEBSOCKET_NONE 0
1501 #define U_WEBSOCKET_SERVER 1
1502 #define U_WEBSOCKET_CLIENT 2
1504 #define U_WEBSOCKET_STATUS_OPEN 0
1505 #define U_WEBSOCKET_STATUS_CLOSE 1
1506 #define U_WEBSOCKET_STATUS_ERROR 2
1508 #define U_WEBSOCKET_RSV1 0x40
1509 #define U_WEBSOCKET_RSV2 0x20
1510 #define U_WEBSOCKET_RSV3 0x10
1512 #define WEBSOCKET_RESPONSE_HTTP 0x0001
1513 #define WEBSOCKET_RESPONSE_UPGRADE 0x0002
1514 #define WEBSOCKET_RESPONSE_CONNECTION 0x0004
1515 #define WEBSOCKET_RESPONSE_ACCEPT 0x0008
1516 #define WEBSOCKET_RESPONSE_PROTCOL 0x0010
1517 #define WEBSOCKET_RESPONSE_EXTENSION 0x0020
1519 #define WEBSOCKET_DEFLATE_CHUNK_SIZE 32768
1520 #define WEBSOCKET_DEFLATE_WINDOWS_BITS 15
1522 #define U_WEBSOCKET_KEEP_NONE 0x00
1523 #define U_WEBSOCKET_KEEP_INCOMING 0x01
1524 #define U_WEBSOCKET_KEEP_OUTCOMING 0x10
1529 struct _websocket_deflate_context {
1534 unsigned int server_no_context_takeover;
1535 unsigned int client_no_context_takeover;
1536 unsigned int server_max_window_bits;
1537 unsigned int client_max_window_bits;
1544 struct _websocket_extension {
1545 char * extension_server;
1546 char * extension_client;
1548 int (* websocket_extension_message_out_perform)(
const uint8_t opcode,
1549 const uint64_t data_len_in,
1550 const char * data_in,
1551 uint64_t * data_len_out,
1553 const uint64_t fragment_len,
1556 void * websocket_extension_message_out_perform_user_data;
1557 int (* websocket_extension_message_in_perform)(
const uint8_t opcode,
1558 const uint64_t data_len_in,
1559 const char * data_in,
1560 uint64_t * data_len_out,
1562 const uint64_t fragment_len,
1565 void * websocket_extension_message_in_perform_user_data;
1566 int (* websocket_extension_server_match)(
const char * extension_client,
1567 const char ** extension_client_list,
1568 char ** extension_server,
1571 void * websocket_extension_server_match_user_data;
1572 int (* websocket_extension_client_match)(
const char * extension_server,
1575 void * websocket_extension_client_match_user_data;
1576 void (* websocket_extension_free_context)(
void * user_data,
1578 void * websocket_extension_free_context_user_data;
1589 struct _websocket_manager {
1590 #ifndef U_DISABLE_WS_MESSAGE_LIST
1591 struct _websocket_message_list * message_list_incoming;
1592 struct _websocket_message_list * message_list_outcoming;
1598 MHD_socket mhd_sock;
1601 gnutls_session_t gnutls_session;
1602 gnutls_certificate_credentials_t xcred;
1605 pthread_mutex_t read_lock;
1606 pthread_mutex_t write_lock;
1607 pthread_mutex_t status_lock;
1608 pthread_cond_t status_cond;
1609 struct pollfd fds_in;
1610 struct pollfd fds_out;
1613 struct _pointer_list * websocket_extension_list;
1621 struct _websocket_message {
1629 size_t fragment_len;
1633 #ifndef U_DISABLE_WS_MESSAGE_LIST
1637 struct _websocket_message_list {
1638 struct _websocket_message ** list;
1650 void (* websocket_manager_callback) (
const struct _u_request * request,
1651 struct _websocket_manager * websocket_manager,
1652 void * websocket_manager_user_data);
1653 void * websocket_manager_user_data;
1654 void (* websocket_incoming_message_callback) (
const struct _u_request * request,
1655 struct _websocket_manager * websocket_manager,
1656 const struct _websocket_message * message,
1657 void * websocket_incoming_user_data);
1658 void * websocket_incoming_user_data;
1659 void (* websocket_onclose_callback) (
const struct _u_request * request,
1660 struct _websocket_manager * websocket_manager,
1661 void * websocket_onclose_user_data);
1662 void * websocket_onclose_user_data;
1663 struct _websocket_manager * websocket_manager;
1664 struct MHD_UpgradeResponseHandle * urh;
1670 struct _websocket_client_handler {
1671 struct _websocket * websocket;
1689 const uint8_t opcode,
1690 const uint64_t data_len,
1705 const uint8_t opcode,
1706 const uint64_t data_len,
1708 const uint64_t fragment_len);
1710 #ifndef U_DISABLE_JANSSON
1718 json_t * j_message);
1729 #ifndef U_DISABLE_WS_MESSAGE_LIST
1767 const char * websocket_protocol,
1768 const char * websocket_extensions,
1769 void (* websocket_manager_callback) (
const struct _u_request * request,
1770 struct _websocket_manager * websocket_manager,
1771 void * websocket_manager_user_data),
1772 void * websocket_manager_user_data,
1773 void (* websocket_incoming_message_callback) (
const struct _u_request * request,
1774 struct _websocket_manager * websocket_manager,
1775 const struct _websocket_message * message,
1776 void * websocket_incoming_user_data),
1777 void * websocket_incoming_user_data,
1778 void (* websocket_onclose_callback) (
const struct _u_request * request,
1779 struct _websocket_manager * websocket_manager,
1780 void * websocket_onclose_user_data),
1781 void * websocket_onclose_user_data);
1800 const char * extension_server,
1802 int (* websocket_extension_message_out_perform)(
const uint8_t opcode,
1803 const uint64_t data_len_in,
1804 const char * data_in,
1805 uint64_t * data_len_out,
1807 const uint64_t fragment_len,
1810 void * websocket_extension_message_out_perform_user_data,
1811 int (* websocket_extension_message_in_perform)(
const uint8_t opcode,
1812 const uint64_t data_len_in,
1813 const char * data_in,
1814 uint64_t * data_len_out,
1816 const uint64_t fragment_len,
1819 void * websocket_extension_message_in_perform_user_data,
1820 int (* websocket_extension_server_match)(
const char * extension_client,
1821 const char ** extension_client_list,
1822 char ** extension_server,
1825 void * websocket_extension_server_match_user_data,
1826 void (* websocket_extension_free_context)(
void * user_data,
1828 void * websocket_extension_free_context_user_data);
1845 const uint64_t data_len_in,
1846 const char * data_in,
1847 uint64_t * data_len_out,
1849 const uint64_t fragment_len,
1867 const uint64_t data_len_in,
1868 const char * data_in,
1869 uint64_t * data_len_out,
1871 const uint64_t fragment_len,
1952 void (* websocket_manager_callback) (
const struct _u_request * request,
1953 struct _websocket_manager * websocket_manager,
1954 void * websocket_manager_user_data),
1955 void * websocket_manager_user_data,
1956 void (* websocket_incoming_message_callback) (
const struct _u_request * request,
1957 struct _websocket_manager * websocket_manager,
1958 const struct _websocket_message * message,
1959 void * websocket_incoming_user_data),
1960 void * websocket_incoming_user_data,
1961 void (* websocket_onclose_callback) (
const struct _u_request * request,
1962 struct _websocket_manager * websocket_manager,
1963 void * websocket_onclose_user_data),
1964 void * websocket_onclose_user_data,
1965 struct _websocket_client_handler * websocket_client_handler,
1984 const char * extension,
1986 int (* websocket_extension_message_out_perform)(
const uint8_t opcode,
1987 const uint64_t data_len_in,
1988 const char * data_in,
1989 uint64_t * data_len_out,
1991 const uint64_t fragment_len,
1994 void * websocket_extension_message_out_perform_user_data,
1995 int (* websocket_extension_message_in_perform)(
const uint8_t opcode,
1996 const uint64_t data_len_in,
1997 const char * data_in,
1998 uint64_t * data_len_out,
2000 const uint64_t fragment_len,
2003 void * websocket_extension_message_in_perform_user_data,
2004 int (* websocket_extension_client_match)(
const char * extension_server,
2007 void * websocket_extension_client_match_user_data,
2008 void (* websocket_extension_free_context)(
void * user_data,
2010 void * websocket_extension_free_context_user_data);
2073 const char * websocket_protocol,
2074 const char * websocket_extensions);
2079 #define ULFIUS_URL_SEPARATOR "/"
2080 #define ULFIUS_HTTP_ENCODING_JSON "application/json"
2081 #define ULFIUS_HTTP_HEADER_CONTENT "Content-Type"
2082 #define ULFIUS_HTTP_NOT_FOUND_BODY "Resource not found"
2083 #define ULFIUS_HTTP_ERROR_BODY "Server Error"
2085 #define ULFIUS_COOKIE_ATTRIBUTE_EXPIRES "Expires"
2086 #define ULFIUS_COOKIE_ATTRIBUTE_MAX_AGE "Max-Age"
2087 #define ULFIUS_COOKIE_ATTRIBUTE_DOMAIN "Domain"
2088 #define ULFIUS_COOKIE_ATTRIBUTE_PATH "Path"
2089 #define ULFIUS_COOKIE_ATTRIBUTE_SECURE "Secure"
2090 #define ULFIUS_COOKIE_ATTRIBUTE_HTTPONLY "HttpOnly"
2092 #define ULFIUS_POSTBUFFERSIZE 65536
2094 #define U_STATUS_STOP 0
2095 #define U_STATUS_RUNNING 1
2096 #define U_STATUS_ERROR 2
2098 #ifndef U_DISABLE_WEBSOCKET
2103 struct _websocket_handle {
2104 char * websocket_protocol;
2105 char * websocket_extensions;
2106 void (* websocket_manager_callback) (
const struct _u_request * request,
2107 struct _websocket_manager * websocket_manager,
2108 void * websocket_manager_user_data);
2109 void * websocket_manager_user_data;
2110 void (* websocket_incoming_message_callback) (
const struct _u_request * request,
2111 struct _websocket_manager * websocket_manager,
2112 const struct _websocket_message * message,
2113 void * websocket_incoming_user_data);
2114 void * websocket_incoming_user_data;
2115 void (* websocket_onclose_callback) (
const struct _u_request * request,
2116 struct _websocket_manager * websocket_manager,
2117 void * websocket_onclose_user_data);
2118 void * websocket_onclose_user_data;
2120 struct _pointer_list * websocket_extension_list;
2126 struct _websocket_handler {
2127 pthread_mutex_t websocket_active_lock;
2128 size_t nb_websocket_active;
2129 struct _websocket ** websocket_active;
2130 pthread_mutex_t websocket_close_lock;
2131 pthread_cond_t websocket_close_cond;
2147 #ifndef U_DISABLE_GNUTLS
char * ulfius_export_client_certificate_pem(const struct _u_request *request)
Definition: u_request.c:1008
int ulfius_import_client_certificate_pem(struct _u_request *request, const char *str_cert)
Definition: u_request.c:1032
u_option
Definition: ulfius.h:145
@ U_OPT_POST_BODY_PARAMETER_REMOVE
Remove from map containing the post body variables (if available), expected option value type: const ...
Definition: ulfius.h:170
@ U_OPT_CHECK_PROXY_CERTIFICATE
check proxy certificate and hostname, default true, used by ulfius_send_http_request,...
Definition: ulfius.h:155
@ U_OPT_CLIENT_KEY_PASSWORD
password to unlock client key file, available only if GnuTLS support is enabled, expected option valu...
Definition: ulfius.h:179
@ U_OPT_STATUS
HTTP response status code (200, 404, 500, etc), expected option value type: long.
Definition: ulfius.h:181
@ U_OPT_FOLLOW_REDIRECT
follow url redirections, used by ulfius_send_http_request, expected option value type: int
Definition: ulfius.h:157
@ U_OPT_COOKIE_PARAMETER
Add to the map containing the cookie variables, expected option value type: const char *,...
Definition: ulfius.h:165
@ U_OPT_TIMEOUT
connection timeout used by ulfius_send_http_request, default is 0 or Timeout in seconds to close the ...
Definition: ulfius.h:159
@ U_OPT_AUTH_BASIC_USER
basic authentication username, expected option value type: const char *
Definition: ulfius.h:160
@ U_OPT_CA_PATH
specify a path to CA certificates instead of system path, used by ulfius_send_http_request,...
Definition: ulfius.h:158
@ U_OPT_AUTH_REALM
realm to send to the client response on authenticationb failed, expected option value type: const cha...
Definition: ulfius.h:182
@ U_OPT_HTTP_URL
full url used to call this callback function or full url to call when used in a ulfius_send_http_requ...
Definition: ulfius.h:148
@ U_OPT_HEADER_PARAMETER_REMOVE
Remove from map containing the header variables, expected option value type: const char *.
Definition: ulfius.h:168
@ U_OPT_CLIENT_CERT_FILE
path to client certificate file for sending http requests with certificate authentication,...
Definition: ulfius.h:177
@ U_OPT_CLIENT_KEY_FILE
path to client key file for sending http requests with certificate authentication,...
Definition: ulfius.h:178
@ U_OPT_JSON_BODY
Set a stringified json_t * body to the request or the reponse, expected option value type: json_t *.
Definition: ulfius.h:174
@ U_OPT_HTTP_PROXY
proxy address to use for outgoing connections, used by ulfius_send_http_request, expected option valu...
Definition: ulfius.h:149
@ U_OPT_COOKIE_PARAMETER_REMOVE
Remove from map containing the cookie variables, expected option value type: const char *.
Definition: ulfius.h:169
@ U_OPT_HTTP_VERB
http method (GET, POST, PUT, DELETE, etc.), expected option value type: const char *
Definition: ulfius.h:147
@ U_OPT_NONE
Empty option to complete a ulfius_set_request_properties or ulfius_set_request_properties.
Definition: ulfius.h:146
@ U_OPT_BINARY_BODY
Set a raw body to the request or the reponse, expected option value type: const char *,...
Definition: ulfius.h:171
@ U_OPT_AUTH_BASIC_PASSWORD
basic authentication password, expected option value type: const char *
Definition: ulfius.h:161
@ U_OPT_SHARED_DATA
any data shared between callback functions, must be allocated and freed by the callback functions,...
Definition: ulfius.h:183
@ U_OPT_URL_PARAMETER_REMOVE
Remove from the map containing the url variables, both from the route and the ?key=value variables,...
Definition: ulfius.h:167
@ U_OPT_CHECK_SERVER_CERTIFICATE
check server certificate and hostname, default true, used by ulfius_send_http_request,...
Definition: ulfius.h:153
@ U_OPT_POST_BODY_PARAMETER
Add to the map containing the post body variables (if available), expected option value type: const c...
Definition: ulfius.h:166
@ U_OPT_CHECK_PROXY_CERTIFICATE_FLAG
check certificate peer and or proxy hostname if check_proxy_certificate is enabled,...
Definition: ulfius.h:156
@ U_OPT_STRING_BODY
Set a char * body to the request or the reponse, expected option value type: const char *.
Definition: ulfius.h:172
@ U_OPT_URL_PARAMETER
Add to the map containing the url variables, both from the route and the ?key=value variables,...
Definition: ulfius.h:163
@ U_OPT_HEADER_PARAMETER
Add to the map containing the header variables, expected option value type: const char *,...
Definition: ulfius.h:164
@ U_OPT_AUTH_BASIC
basic authentication user, then password, expected option value type: const char *,...
Definition: ulfius.h:162
@ U_OPT_HTTP_URL_APPEND
append char * value to the current url, expected option value type: const char *
Definition: ulfius.h:184
@ U_OPT_CHECK_SERVER_CERTIFICATE_FLAG
check certificate peer and or server hostname if check_server_certificate is enabled,...
Definition: ulfius.h:154
int ulfius_add_cookie_to_response(struct _u_response *response, const char *key, const char *value, const char *expires, const unsigned int max_age, const char *domain, const char *path, const int secure, const int http_only)
Definition: u_response.c:206
int ulfius_add_same_site_cookie_to_response(struct _u_response *response, const char *key, const char *value, const char *expires, const unsigned int max_age, const char *domain, const char *path, const int secure, const int http_only, const int same_site)
Definition: u_response.c:211
void ulfius_clean_endpoint_list(struct _u_endpoint *endpoint_list)
Definition: ulfius.c:1394
int ulfius_add_endpoint_list(struct _u_instance *u_instance, const struct _u_endpoint **u_endpoint_list)
Definition: ulfius.c:1445
int ulfius_add_endpoint(struct _u_instance *u_instance, const struct _u_endpoint *u_endpoint)
Definition: ulfius.c:1405
int ulfius_remove_endpoint(struct _u_instance *u_instance, const struct _u_endpoint *u_endpoint)
Definition: ulfius.c:1462
int ulfius_copy_endpoint(struct _u_endpoint *dest, const struct _u_endpoint *source)
Definition: ulfius.c:1336
int ulfius_remove_endpoint_by_val(struct _u_instance *u_instance, const char *http_method, const char *url_prefix, const char *url_format)
Definition: ulfius.c:1568
int ulfius_add_endpoint_by_val(struct _u_instance *u_instance, const char *http_method, const char *url_prefix, const char *url_format, unsigned int priority, int(*callback_function)(const struct _u_request *request, struct _u_response *response, void *user_data), void *user_data)
Definition: ulfius.c:1545
const struct _u_endpoint * ulfius_empty_endpoint(void)
Definition: ulfius.c:1516
int ulfius_equals_endpoints(const struct _u_endpoint *endpoint1, const struct _u_endpoint *endpoint2)
Definition: ulfius.c:1527
int ulfius_set_default_endpoint(struct _u_instance *u_instance, int(*callback_function)(const struct _u_request *request, struct _u_response *response, void *user_data), void *user_data)
Definition: ulfius.c:1581
struct _u_endpoint * ulfius_duplicate_endpoint_list(const struct _u_endpoint *endpoint_list)
Definition: ulfius.c:1358
void ulfius_clean_endpoint(struct _u_endpoint *endpoint)
Definition: ulfius.c:1379
int ulfius_send_smtp_email(const char *host, const int port, const int use_tls, const int verify_certificate, const char *user, const char *password, const char *from, const char *to, const char *cc, const char *bcc, const char *subject, const char *mail_body)
Definition: u_send_request.c:913
int ulfius_send_http_streaming_request(const struct _u_request *request, struct _u_response *response, size_t(*write_body_function)(void *contents, size_t size, size_t nmemb, void *user_data), void *write_body_data)
Definition: u_send_request.c:194
int ulfius_send_smtp_rich_email(const char *host, const int port, const int use_tls, const int verify_certificate, const char *user, const char *password, const char *from, const char *to, const char *cc, const char *bcc, const char *content_type, const char *subject, const char *mail_body)
Definition: u_send_request.c:709
int ulfius_send_http_request(const struct _u_request *request, struct _u_response *response)
Definition: u_send_request.c:162
void mhd_request_completed(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
Definition: ulfius.c:307
int ulfius_init_instance(struct _u_instance *u_instance, unsigned int port, struct sockaddr_in *bind_address, const char *default_auth_realm)
Definition: ulfius.c:1732
void * ulfius_uri_logger(void *cls, const char *uri)
Definition: ulfius.c:207
void ulfius_clean_instance(struct _u_instance *u_instance)
Definition: ulfius.c:1624
int ulfius_start_framework_with_mhd_options(struct _u_instance *u_instance, unsigned int mhd_flags, struct MHD_OptionItem *mhd_ops)
Definition: ulfius.c:1274
int ulfius_stop_framework(struct _u_instance *u_instance)
Definition: ulfius.c:1301
int ulfius_start_secure_ca_trust_framework(struct _u_instance *u_instance, const char *key_pem, const char *cert_pem, const char *root_ca_pem)
Definition: ulfius.c:1232
int ulfius_start_framework(struct _u_instance *u_instance)
Definition: ulfius.c:1166
int ulfius_start_secure_framework(struct _u_instance *u_instance, const char *key_pem, const char *cert_pem)
Definition: ulfius.c:1183
int ulfius_set_upload_file_callback_function(struct _u_instance *u_instance, int(*file_upload_callback)(const struct _u_request *request, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size, void *cls), void *cls)
Definition: ulfius.c:1604
void ulfius_global_close(void)
Definition: ulfius.c:1930
int ulfius_global_init(void)
Definition: ulfius.c:1906
void u_free(void *data)
Definition: ulfius.c:1746
int ulfius_add_header_to_response(struct _u_response *response, const char *key, const char *value)
Definition: u_response.c:717
int ulfius_set_empty_body_request(struct _u_request *request)
Definition: u_request.c:751
int ulfius_set_string_body_response(struct _u_response *response, const unsigned int status, const char *body)
Definition: u_response.c:516
int ulfius_set_string_body_request(struct _u_request *request, const char *string_body)
Definition: u_request.c:704
int ulfius_set_binary_body_response(struct _u_response *response, const unsigned int status, const char *body, const size_t length)
Definition: u_response.c:534
int ulfius_set_binary_body_request(struct _u_request *request, const char *binary_body, const size_t length)
Definition: u_request.c:726
int ulfius_set_empty_body_response(struct _u_response *response, const unsigned int status)
Definition: u_response.c:555
int ulfius_copy_cookie(struct _u_cookie *dest, const struct _u_cookie *source)
Definition: u_response.c:307
int ulfius_init_request(struct _u_request *request)
Definition: u_request.c:267
int ulfius_init_response(struct _u_response *response)
Definition: u_response.c:373
json_t * ulfius_get_json_body_response(struct _u_response *response, json_error_t *json_error)
Definition: u_response.c:709
json_t * ulfius_get_json_body_request(const struct _u_request *request, json_error_t *json_error)
Definition: u_request.c:979
int ulfius_copy_response(struct _u_response *dest, const struct _u_response *source)
Definition: u_response.c:426
int ulfius_clean_request_full(struct _u_request *request)
Definition: u_request.c:366
int ulfius_clean_response(struct _u_response *response)
Definition: u_response.c:332
int ulfius_set_response_properties(struct _u_response *response,...)
Definition: u_response.c:594
int ulfius_clean_request(struct _u_request *request)
Definition: u_request.c:323
char * ulfius_export_request_http(const struct _u_request *request)
Definition: u_request.c:792
struct _u_request * ulfius_duplicate_request(const struct _u_request *request)
Definition: u_request.c:767
int ulfius_copy_request(struct _u_request *dest, const struct _u_request *source)
Definition: u_request.c:380
char * ulfius_export_response_http(const struct _u_response *response)
Definition: u_response.c:725
int ulfius_set_json_body_response(struct _u_response *response, const unsigned int status, const json_t *j_body)
Definition: u_response.c:682
int ulfius_set_request_properties(struct _u_request *request,...)
Definition: u_request.c:494
struct _u_response * ulfius_duplicate_response(const struct _u_response *response)
Definition: u_response.c:493
int ulfius_clean_cookie(struct _u_cookie *cookie)
Definition: u_response.c:289
int ulfius_set_json_body_request(struct _u_request *request, json_t *j_body)
Definition: u_request.c:953
int ulfius_clean_response_full(struct _u_response *response)
Definition: u_response.c:364
int ulfius_set_response_shared_data(struct _u_response *response, void *shared_data, void(*free_shared_data)(void *shared_data))
Definition: u_response.c:663
int ulfius_set_stream_response(struct _u_response *response, const unsigned int status, ssize_t(*stream_callback)(void *stream_user_data, uint64_t offset, char *out_buf, size_t max), void(*stream_callback_free)(void *stream_user_data), uint64_t stream_size, size_t stream_block_size, void *stream_user_data)
Definition: u_response.c:569
int u_map_init(struct _u_map *u_map)
Definition: u_map.c:32
int u_map_remove_from_value_binary(struct _u_map *u_map, const char *key, size_t length)
Definition: u_map.c:296
int u_map_remove_from_key(struct _u_map *u_map, const char *key)
Definition: u_map.c:246
int u_map_clean(struct _u_map *u_map)
Definition: u_map.c:70
int u_map_remove_at(struct _u_map *u_map, const int index)
Definition: u_map.c:342
int u_map_remove_from_value_case(struct _u_map *u_map, const char *value)
Definition: u_map.c:319
struct _u_map * u_map_copy(const struct _u_map *source)
Definition: u_map.c:461
ssize_t u_map_get_case_length(const struct _u_map *u_map, const char *key)
Definition: u_map.c:447
const char * u_map_get(const struct _u_map *u_map, const char *key)
Definition: u_map.c:377
int u_map_remove_from_key_case(struct _u_map *u_map, const char *key)
Definition: u_map.c:269
int u_map_has_value(const struct _u_map *u_map, const char *value)
Definition: u_map.c:132
int u_map_has_value_case(const struct _u_map *u_map, const char *value)
Definition: u_map.c:407
int u_map_clean_enum(char **array)
Definition: u_map.c:98
int u_map_clean_full(struct _u_map *u_map)
Definition: u_map.c:89
const char ** u_map_enum_keys(const struct _u_map *u_map)
Definition: u_map.c:112
int u_map_has_key_case(const struct _u_map *u_map, const char *key)
Definition: u_map.c:395
ssize_t u_map_get_length(const struct _u_map *u_map, const char *key)
Definition: u_map.c:433
int u_map_empty(struct _u_map *u_map)
Definition: u_map.c:516
int u_map_copy_into(struct _u_map *dest, const struct _u_map *source)
Definition: u_map.c:489
int u_map_put(struct _u_map *u_map, const char *key, const char *value)
Definition: u_map.c:148
int u_map_has_value_binary(const struct _u_map *u_map, const char *value, size_t length)
Definition: u_map.c:136
const char ** u_map_enum_values(const struct _u_map *u_map)
Definition: u_map.c:116
int u_map_has_key(const struct _u_map *u_map, const char *key)
Definition: u_map.c:120
int u_map_remove_from_value(struct _u_map *u_map, const char *value)
Definition: u_map.c:292
int u_map_put_binary(struct _u_map *u_map, const char *key, const char *value, uint64_t offset, size_t length)
Definition: u_map.c:156
int u_map_count(const struct _u_map *source)
Definition: u_map.c:507
const char * u_map_get_case(const struct _u_map *u_map, const char *key)
Definition: u_map.c:419
char * ulfius_url_encode(const char *str)
Definition: ulfius.c:1843
char * ulfius_url_decode(const char *str)
Definition: ulfius.c:1877
char * key
Definition: ulfius.h:216
char * path
Definition: ulfius.h:221
char * expires
Definition: ulfius.h:218
char * domain
Definition: ulfius.h:220
int http_only
Definition: ulfius.h:223
int secure
Definition: ulfius.h:222
int same_site
Definition: ulfius.h:224
char * value
Definition: ulfius.h:217
unsigned int max_age
Definition: ulfius.h:219
Contains all informations needed for an endpoint.
Definition: ulfius.h:299
int(* callback_function)(const struct _u_request *request, struct _u_response *response, void *user_data)
Definition: ulfius.h:304
void * user_data
Definition: ulfius.h:307
unsigned int priority
Definition: ulfius.h:303
char * http_method
Definition: ulfius.h:300
char * url_format
Definition: ulfius.h:302
char * url_prefix
Definition: ulfius.h:301
Contains the needed data for an ulfius instance to work.
Definition: ulfius.h:316
int status
Definition: ulfius.h:318
size_t max_post_param_size
Definition: ulfius.h:331
struct MHD_Daemon * mhd_daemon
Definition: ulfius.h:317
int allowed_post_processor
Definition: ulfius.h:349
unsigned int port
Definition: ulfius.h:319
unsigned int timeout
Definition: ulfius.h:325
size_t max_post_body_size
Definition: ulfius.h:332
struct sockaddr_in * bind_address
Definition: ulfius.h:323
void * file_upload_cls
Definition: ulfius.h:343
struct _u_map * default_headers
Definition: ulfius.h:330
int check_utf8
Definition: ulfius.h:345
struct sockaddr_in6 * bind_address6
Definition: ulfius.h:324
struct _u_endpoint * endpoint_list
Definition: ulfius.h:328
int nb_endpoints
Definition: ulfius.h:326
struct _u_endpoint * default_endpoint
Definition: ulfius.h:329
void * websocket_handler
Definition: ulfius.h:333
int(* file_upload_callback)(const struct _u_request *request, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size, void *cls)
Definition: ulfius.h:334
char * default_auth_realm
Definition: ulfius.h:327
int mhd_response_copy_data
Definition: ulfius.h:344
int use_client_cert_auth
Definition: ulfius.h:347
int nb_values
Definition: ulfius.h:205
size_t * lengths
Definition: ulfius.h:208
char ** keys
Definition: ulfius.h:206
char ** values
Definition: ulfius.h:207
definition of the parameters available in a struct _u_request
Definition: ulfius.h:233
unsigned long timeout
Definition: ulfius.h:248
int check_server_certificate_flag
Definition: ulfius.h:243
int follow_redirect
Definition: ulfius.h:246
char * auth_basic_password
Definition: ulfius.h:251
char * http_protocol
Definition: ulfius.h:234
int check_proxy_certificate_flag
Definition: ulfius.h:245
char * client_key_password
Definition: ulfius.h:263
void * binary_body
Definition: ulfius.h:256
gnutls_x509_crt_t client_cert
Definition: ulfius.h:260
struct _u_map * map_cookie
Definition: ulfius.h:254
size_t binary_body_length
Definition: ulfius.h:257
struct _u_map * map_header
Definition: ulfius.h:253
int check_server_certificate
Definition: ulfius.h:242
struct sockaddr * client_address
Definition: ulfius.h:249
char * ca_path
Definition: ulfius.h:247
struct _u_map * map_post_body
Definition: ulfius.h:255
int check_proxy_certificate
Definition: ulfius.h:244
char * client_key_file
Definition: ulfius.h:262
char * url_path
Definition: ulfius.h:237
char * auth_basic_user
Definition: ulfius.h:250
char * http_verb
Definition: ulfius.h:235
unsigned int callback_position
Definition: ulfius.h:258
char * proxy
Definition: ulfius.h:238
char * http_url
Definition: ulfius.h:236
struct _u_map * map_url
Definition: ulfius.h:252
char * client_cert_file
Definition: ulfius.h:261
definition of the parameters available in a struct _u_response
Definition: ulfius.h:273
char * protocol
Definition: ulfius.h:275
size_t stream_block_size
Definition: ulfius.h:285
void * stream_user_data
Definition: ulfius.h:286
ssize_t(* stream_callback)(void *stream_user_data, uint64_t offset, char *out_buf, size_t max)
Definition: ulfius.h:282
void * websocket_handle
Definition: ulfius.h:287
uint64_t stream_size
Definition: ulfius.h:284
size_t binary_body_length
Definition: ulfius.h:281
struct _u_map * map_header
Definition: ulfius.h:276
long status
Definition: ulfius.h:274
unsigned int nb_cookies
Definition: ulfius.h:277
unsigned int timeout
Definition: ulfius.h:290
struct _u_cookie * map_cookie
Definition: ulfius.h:278
char * auth_realm
Definition: ulfius.h:279
void(* stream_callback_free)(void *stream_user_data)
Definition: ulfius.h:283
void(* free_shared_data)(void *shared_data)
Definition: ulfius.h:289
void * binary_body
Definition: ulfius.h:280
void * shared_data
Definition: ulfius.h:288
struct _u_request * request
Definition: ulfius.h:364
struct _u_map map_url_initial
Definition: ulfius.h:366
struct _u_instance * u_instance
Definition: ulfius.h:360
size_t max_post_param_size
Definition: ulfius.h:365
struct MHD_PostProcessor * post_processor
Definition: ulfius.h:361
int callback_first_iteration
Definition: ulfius.h:363
int has_post_processor
Definition: ulfius.h:362
int websocket_extension_message_in_inflate(const uint8_t opcode, const uint64_t data_len_in, const char *data_in, uint64_t *data_len_out, char **data_out, const uint64_t fragment_len, void *user_data, void *context)
Definition: u_websocket.c:2040
int ulfius_add_websocket_extension_message_perform(struct _u_response *response, const char *extension_server, uint8_t rsv, int(*websocket_extension_message_out_perform)(const uint8_t opcode, const uint64_t data_len_in, const char *data_in, uint64_t *data_len_out, char **data_out, const uint64_t fragment_len, void *user_data, void *context), void *websocket_extension_message_out_perform_user_data, int(*websocket_extension_message_in_perform)(const uint8_t opcode, const uint64_t data_len_in, const char *data_in, uint64_t *data_len_out, char **data_out, const uint64_t fragment_len, void *user_data, void *context), void *websocket_extension_message_in_perform_user_data, int(*websocket_extension_server_match)(const char *extension_client, const char **extension_client_list, char **extension_server, void *user_data, void **context), void *websocket_extension_server_match_user_data, void(*websocket_extension_free_context)(void *user_data, void *context), void *websocket_extension_free_context_user_data)
Definition: u_websocket.c:1881
int ulfius_websocket_client_connection_send_close_signal(struct _websocket_client_handler *websocket_client_handler)
Definition: u_websocket.c:2761
int ulfius_websocket_send_close_signal(struct _websocket_manager *websocket_manager)
Definition: u_websocket.c:2278
int websocket_extension_server_match_deflate(const char *extension_client, const char **extension_client_list, char **extension_server, void *user_data, void **context)
Definition: u_websocket.c:2118
int ulfius_add_websocket_client_deflate_extension(struct _websocket_client_handler *websocket_client_handler)
Definition: u_websocket.c:2752
int ulfius_websocket_client_connection_wait_close(struct _websocket_client_handler *websocket_client_handler, unsigned int timeout)
Definition: u_websocket.c:2815
int ulfius_add_websocket_client_extension_message_perform(struct _websocket_client_handler *websocket_client_handler, const char *extension, uint8_t rsv, int(*websocket_extension_message_out_perform)(const uint8_t opcode, const uint64_t data_len_in, const char *data_in, uint64_t *data_len_out, char **data_out, const uint64_t fragment_len, void *user_data, void *context), void *websocket_extension_message_out_perform_user_data, int(*websocket_extension_message_in_perform)(const uint8_t opcode, const uint64_t data_len_in, const char *data_in, uint64_t *data_len_out, char **data_out, const uint64_t fragment_len, void *user_data, void *context), void *websocket_extension_message_in_perform_user_data, int(*websocket_extension_client_match)(const char *extension_server, void *user_data, void **context), void *websocket_extension_client_match_user_data, void(*websocket_extension_free_context)(void *user_data, void *context), void *websocket_extension_free_context_user_data)
Definition: u_websocket.c:2438
int ulfius_websocket_client_connection_status(struct _websocket_client_handler *websocket_client_handler)
Definition: u_websocket.c:2801
int ulfius_websocket_wait_close(struct _websocket_manager *websocket_manager, unsigned int timeout)
Definition: u_websocket.c:2307
int ulfius_websocket_status(struct _websocket_manager *websocket_manager)
Definition: u_websocket.c:2293
int ulfius_websocket_send_json_message(struct _websocket_manager *websocket_manager, json_t *j_message)
Definition: u_websocket.c:1594
int ulfius_open_websocket_client_connection(struct _u_request *request, void(*websocket_manager_callback)(const struct _u_request *request, struct _websocket_manager *websocket_manager, void *websocket_manager_user_data), void *websocket_manager_user_data, void(*websocket_incoming_message_callback)(const struct _u_request *request, struct _websocket_manager *websocket_manager, const struct _websocket_message *message, void *websocket_incoming_user_data), void *websocket_incoming_user_data, void(*websocket_onclose_callback)(const struct _u_request *request, struct _websocket_manager *websocket_manager, void *websocket_onclose_user_data), void *websocket_onclose_user_data, struct _websocket_client_handler *websocket_client_handler, struct _u_response *response)
Definition: u_websocket.c:2524
int websocket_extension_message_out_deflate(const uint8_t opcode, const uint64_t data_len_in, const char *data_in, uint64_t *data_len_out, char **data_out, const uint64_t fragment_len, void *user_data, void *context)
Definition: u_websocket.c:1950
int ulfius_set_websocket_response(struct _u_response *response, const char *websocket_protocol, const char *websocket_extensions, void(*websocket_manager_callback)(const struct _u_request *request, struct _websocket_manager *websocket_manager, void *websocket_manager_user_data), void *websocket_manager_user_data, void(*websocket_incoming_message_callback)(const struct _u_request *request, struct _websocket_manager *websocket_manager, const struct _websocket_message *message, void *websocket_incoming_user_data), void *websocket_incoming_user_data, void(*websocket_onclose_callback)(const struct _u_request *request, struct _websocket_manager *websocket_manager, void *websocket_onclose_user_data), void *websocket_onclose_user_data)
Definition: u_websocket.c:1834
int ulfius_add_websocket_deflate_extension(struct _u_response *response)
Definition: u_websocket.c:2266
void websocket_extension_deflate_free_context(void *user_data, void *context)
Definition: u_websocket.c:2259
int ulfius_websocket_client_connection_close(struct _websocket_client_handler *websocket_client_handler)
Definition: u_websocket.c:2774
int ulfius_set_websocket_request(struct _u_request *request, const char *url, const char *websocket_protocol, const char *websocket_extensions)
Definition: u_websocket.c:2396
int ulfius_websocket_send_message(struct _websocket_manager *websocket_manager, const uint8_t opcode, const uint64_t data_len, const char *data)
Definition: u_websocket.c:1582
int ulfius_websocket_send_fragmented_message(struct _websocket_manager *websocket_manager, const uint8_t opcode, const uint64_t data_len, const char *data, const uint64_t fragment_len)
Definition: u_websocket.c:1482
struct _websocket_message * ulfius_websocket_pop_first_message(struct _websocket_message_list *message_list)
Definition: u_websocket.c:1629
json_t * ulfius_websocket_parse_json_message(const struct _websocket_message *message, json_error_t *json_error)
Definition: u_websocket.c:1614
int websocket_extension_client_match_deflate(const char *extension_server, void *user_data, void **context)
Definition: u_websocket.c:2641
void ulfius_clear_websocket_message(struct _websocket_message *message)
Definition: u_websocket.c:1652