Ulfius: include/u_private.h File Reference

Ulfius HTTP Framework for REST Applications in C

Loading...
Searching...
No Matches
Macros | Functions
u_private.h File Reference
`#include <ulfius.h>`

Go to the source code of this file.

## Macros
#define | UNUSED(x) (void)(x)
#define | _U_W_BUFF_LEN 256
#define | _U_W_EXT_DEFLATE "permessage-deflate"
#define | _U_W_EXT_DEFLATE_S_CTX "server_no_context_takeover"
#define | _U_W_EXT_DEFLATE_C_CTX "client_no_context_takeover"

## Functions
struct _u_endpoint ** | ulfius_endpoint_match (const char *method, const char *url, struct _u_endpoint *endpoint_list)
int | ulfius_parse_url (const char *url, const struct _u_endpoint *endpoint, struct _u_map *map, int check_utf8)
int | ulfius_set_response_header (struct MHD_Response *response, const struct _u_map *response_map_header)
int | ulfius_set_response_cookie (struct MHD_Response *mhd_response, const struct _u_response *response)
const unsigned char * | utf8_check (const char *s_orig, size_t len)
void | ulfius_free_websocket_extension_pointer_list (void *extension)
void | ulfius_free_websocket_extension (struct _websocket_extension *websocket_extension)
int | ulfius_init_websocket_extension (struct _websocket_extension *websocket_extension)
void | ulfius_start_websocket_cb (void *cls, struct MHD_Connection *connection, void *con_cls, const char *extra_in, size_t extra_in_size, MHD_socket sock, struct MHD_UpgradeResponseHandle *urh)
int | ulfius_generate_handshake_answer (const char *key, char *out_digest)
int | ulfius_check_list_match (const char *source, const char *match, const char *separator, char **result)
int | ulfius_check_first_match (const char *source, const char *match, const char *separator, char **result)
int | ulfius_init_websocket_message_list (struct _websocket_message_list *message_list)
void | ulfius_clear_websocket_message_list (struct _websocket_message_list *message_list)
int | ulfius_push_websocket_message (struct _websocket_message_list *message_list, struct _websocket_message *message)
int | ulfius_clear_websocket (struct _websocket *websocket)
void | ulfius_clear_websocket_manager (struct _websocket_manager *websocket_manager)
int | ulfius_close_websocket (struct _websocket *websocket)
int | ulfius_instance_add_websocket_active (struct _u_instance *instance, struct _websocket *websocket)
int | ulfius_instance_remove_websocket_active (struct _u_instance *instance, struct _websocket *websocket)
int | ulfius_init_websocket (struct _websocket *websocket)
int | ulfius_init_websocket_manager (struct _websocket_manager *websocket_manager)
int | ulfius_check_handshake_response (const char *key, const char *response)

## Macro Definition Documentation

## ◆ _U_W_BUFF_LEN

#define _U_W_BUFF_LEN 256

## ◆ _U_W_EXT_DEFLATE

#define _U_W_EXT_DEFLATE "permessage-deflate"

## ◆ _U_W_EXT_DEFLATE_C_CTX

#define _U_W_EXT_DEFLATE_C_CTX "client_no_context_takeover"

## ◆ _U_W_EXT_DEFLATE_S_CTX

#define _U_W_EXT_DEFLATE_S_CTX "server_no_context_takeover"

## ◆ UNUSED

#define UNUSED | ( |  | x | ) | (void)(x)

Ulfius Framework

REST framework library

u_private.h: private structures and functions declarations

Copyright 2015-2022 Nicolas Mora mail@.nosp@m.babe.nosp@m.loues.nosp@m.t.or.nosp@m.g

This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License.

This library 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.

You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses/. Macro to avoid compiler warning when some parameters are unused and that's ok

## Function Documentation

## ◆ ulfius_check_first_match()

int ulfius_check_first_match | ( | const char * | source,
|  | const char * | match,
|  | const char * | separator,
|  | char ** | result
| ) |  |

Return the first match between two list of items If match is NULL, then return the first element of source result must be u_free'd after use

Return the first match between two list of items If match is NULL, then return the first element of source Returned value must be u_free'd after use

## ◆ ulfius_check_handshake_response()

int ulfius_check_handshake_response | ( | const char * | key,
|  | const char * | response
| ) |  |

Check if the response corresponds to the transformation of the key with the magic string

## ◆ ulfius_check_list_match()

int ulfius_check_list_match | ( | const char * | source,
|  | const char * | match,
|  | const char * | separator,
|  | char ** | result
| ) |  |

Return a match list between two list of items If match is NULL, then return source duplicate result must be u_free'd after use

Return a match list between two list of items If match is NULL, then result will be NULL and returned value will be U_OK *result value must be u_free'd after use

## ◆ ulfius_clear_websocket()

int ulfius_clear_websocket | ( | struct _websocket * | websocket | ) |

Clear data of a websocket

Init/clear websocket functions Clear all data related to the websocket

## ◆ ulfius_clear_websocket_manager()

void ulfius_clear_websocket_manager | ( | struct _websocket_manager * | websocket_manager | ) |

Clear data of a websocket_manager

## ◆ ulfius_clear_websocket_message_list()

void ulfius_clear_websocket_message_list | ( | struct _websocket_message_list * | message_list | ) |

Clear data of a websocket message list

## ◆ ulfius_close_websocket()

int ulfius_close_websocket | ( | struct _websocket * | websocket | ) |

Close the websocket

## ◆ ulfius_endpoint_match()

struct _u_endpoint ** ulfius_endpoint_match | ( | const char * | method,
|  | const char * | url,
|  | struct _u_endpoint * | endpoint_list
| ) |  |

For using Ulfius in embedded systems Thanks to Dirk Uhlemann ulfius_endpoint_match return the endpoint array matching the url called with the proper http method the returned array always has its last value to NULL return NULL on memory error

ulfius_endpoint_match return the endpoint array matching the url called with the proper http method the returned array always has its last value to NULL return NULL on memory error returned value must be free'd after use

## ◆ ulfius_free_websocket_extension()

void ulfius_free_websocket_extension | ( | struct _websocket_extension * | websocket_extension | ) |

## ◆ ulfius_free_websocket_extension_pointer_list()

void ulfius_free_websocket_extension_pointer_list | ( | void * | extension | ) |

Internal websocket functions

## ◆ ulfius_generate_handshake_answer()

int ulfius_generate_handshake_answer | ( | const char * | key,
|  | char * | out_digest
| ) |  |

Generates a handhshake answer from the key given in parameter

## ◆ ulfius_init_websocket()

int ulfius_init_websocket | ( | struct _websocket * | websocket | ) |

Initialize a struct _websocket return U_OK on success

## ◆ ulfius_init_websocket_extension()

int ulfius_init_websocket_extension | ( | struct _websocket_extension * | websocket_extension | ) |

## ◆ ulfius_init_websocket_manager()

int ulfius_init_websocket_manager | ( | struct _websocket_manager * | websocket_manager | ) |

Initialize a struct _websocket_manager return U_OK on success

## ◆ ulfius_init_websocket_message_list()

int ulfius_init_websocket_message_list | ( | struct _websocket_message_list * | message_list | ) |

Initialize a websocket message list Return U_OK on success

## ◆ ulfius_instance_add_websocket_active()

int ulfius_instance_add_websocket_active | ( | struct _u_instance * | instance,
|  | struct _websocket * | websocket
| ) |  |

Add a websocket in the list of active websockets of the instance

## ◆ ulfius_instance_remove_websocket_active()

int ulfius_instance_remove_websocket_active | ( | struct _u_instance * | instance,
|  | struct _websocket * | websocket
| ) |  |

Remove a websocket from the list of active websockets of the instance

## ◆ ulfius_parse_url()

int ulfius_parse_url | ( | const char * | url,
|  | const struct _u_endpoint * | endpoint,
|  | struct _u_map * | map,
|  | int | check_utf8
| ) |  |

ulfius_parse_url fills map with the keys/values defined in the url that are described in the endpoint format url return U_OK on success

## ◆ ulfius_push_websocket_message()

int ulfius_push_websocket_message | ( | struct _websocket_message_list * | message_list,
|  | struct _websocket_message * | message
| ) |  |

Append a message in a message list Return U_OK on success

## ◆ ulfius_set_response_cookie()

int ulfius_set_response_cookie | ( | struct MHD_Response * | mhd_response,
|  | const struct _u_response * | response
| ) |  |

ulfius_set_response_cookie adds cookies defined in the response_map_cookie return the number of added headers, -1 on error

## ◆ ulfius_set_response_header()

int ulfius_set_response_header | ( | struct MHD_Response * | response,
|  | const struct _u_map * | response_map_header
| ) |  |

ulfius_set_response_header adds headers defined in the response_map_header to the response return the number of added headers, -1 on error

## ◆ ulfius_start_websocket_cb()

void ulfius_start_websocket_cb | ( | void * | cls,
|  | struct MHD_Connection * | connection,
|  | void * | con_cls,
|  | const char * | extra_in,
|  | size_t | extra_in_size,
|  | MHD_socket | sock,
|  | struct MHD_UpgradeResponseHandle * | urh
| ) |  |

Websocket callback function for MHD Starts the websocket manager if set, then sets a listening message loop Complete the callback when the websocket is closed The websocket can be closed by the client, the manager, the program, or on network disconnect

Websocket callback function for MHD Starts the websocket manager if set,

## ◆ utf8_check()

const unsigned char * utf8_check | ( | const char * | s_orig,
|  | size_t | len
| ) |  |

The utf8_check() function scans the string starting at s. It returns a pointer to the first byte of the first malformed or overlong UTF-8 sequence found, or NULL if the string contains only correct UTF-8. It also spots UTF-8 sequences that could cause trouble if converted to UTF-16, namely surrogate characters (U+D800..U+DFFF) and non-Unicode positions (U+FFFE..U+FFFF). This routine is very likely to find a malformed sequence if the input uses any other encoding than UTF-8. It therefore can be used as a very effective heuristic for distinguishing between UTF-8 and other encodings.

I wrote this code mainly as a specification of functionality; there are no doubt performance optimizations possible for certain CPUs.

Markus Kuhn http://www.cl.cam.ac.uk/~mgk25/ – 2005-03-30 Nicolas Mora mail@.nosp@m.babe.nosp@m.loues.nosp@m.t.or.nosp@m.g License: http://www.cl.cam.ac.uk/~mgk25/short-license.html