Skip to content

Commit

Permalink
uid for each connected client
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquetft authored and Theldus committed Sep 5, 2024
1 parent 0d09382 commit a999870
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 96 deletions.
6 changes: 3 additions & 3 deletions examples/echo/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* in order to send messages and retrieve informations about the
* client.
*/
void onopen(ws_cli_conn_t *client)
void onopen(ws_cli_conn_t client)
{
char *cli, *port;
cli = ws_getaddress(client);
Expand All @@ -57,7 +57,7 @@ void onopen(ws_cli_conn_t *client)
* in order to send messages and retrieve informations about the
* client.
*/
void onclose(ws_cli_conn_t *client)
void onclose(ws_cli_conn_t client)
{
char *cli;
cli = ws_getaddress(client);
Expand All @@ -80,7 +80,7 @@ void onclose(ws_cli_conn_t *client)
*
* @param type Message type.
*/
void onmessage(ws_cli_conn_t *client,
void onmessage(ws_cli_conn_t client,
const unsigned char *msg, uint64_t size, int type)
{
char *cli;
Expand Down
8 changes: 4 additions & 4 deletions examples/ping/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @param client Client connection.
*/
void onopen(ws_cli_conn_t *client)
void onopen(ws_cli_conn_t client)
{
((void)client);
printf("Connected!\n");
Expand All @@ -45,7 +45,7 @@ void onopen(ws_cli_conn_t *client)
*
* @param client Client connection.
*/
void onclose(ws_cli_conn_t *client)
void onclose(ws_cli_conn_t client)
{
((void)client);
printf("Disconnected!\n");
Expand All @@ -60,7 +60,7 @@ void onclose(ws_cli_conn_t *client)
* @param size Message size (in bytes).
* @param type Message type.
*/
void onmessage(ws_cli_conn_t *client,
void onmessage(ws_cli_conn_t client,
const unsigned char *msg, uint64_t size, int type)
{
((void)client);
Expand Down Expand Up @@ -98,7 +98,7 @@ int main(void)
* calls. In this example, 10 seconds.
*/
printf("Sending ping...\n");
ws_ping(NULL, 2);
ws_ping(0, 2);

/* Sleep 10 seconds. */
sleep(10);
Expand Down
6 changes: 3 additions & 3 deletions examples/vtouchpad/vtouchpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct mouse_event parse_event(const char *ev, int *error)
*
* @param client Client connection.
*/
void onopen(ws_cli_conn_t *client) {
void onopen(ws_cli_conn_t client) {
(void)client;
printf("Connected!\n");
}
Expand All @@ -131,7 +131,7 @@ void onopen(ws_cli_conn_t *client) {
*
* @param client Client connection.
*/
void onclose(ws_cli_conn_t *client) {
void onclose(ws_cli_conn_t client) {
(void)client;
printf("Disconnected!\n");
}
Expand All @@ -148,7 +148,7 @@ void onclose(ws_cli_conn_t *client) {
*
* @param type Message type. (ignored)
*/
void onmessage(ws_cli_conn_t *client,
void onmessage(ws_cli_conn_t client,
const unsigned char *msg, uint64_t size, int type)
{
((void)client);
Expand Down
30 changes: 15 additions & 15 deletions include/ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ extern "C" {
#endif

/* Opaque client connection type. */
typedef struct ws_connection ws_cli_conn_t;
typedef uint64_t ws_cli_conn_t;

/* Opaque server instance type. */
typedef struct ws_server ws_server_t;
Expand All @@ -234,17 +234,17 @@ extern "C" {
* @brief Get server context.
* Set when initializing `.context` in `struct ws_server`.
*/
void *ws_get_server_context(ws_cli_conn_t *cli);
void *ws_get_server_context(ws_cli_conn_t client);

/**
* @brief Set connection context.
*/
void ws_set_connection_context(ws_cli_conn_t *cli, void *ptr);
void ws_set_connection_context(ws_cli_conn_t client, void *ptr);

/**
* @brief Get connection context.
*/
void *ws_get_connection_context(ws_cli_conn_t *cli);
void *ws_get_connection_context(ws_cli_conn_t client);

/**
* @brief events Web Socket events types.
Expand All @@ -254,16 +254,16 @@ extern "C" {
/**
* @brief On open event, called when a new client connects.
*/
void (*onopen)(ws_cli_conn_t *client);
void (*onopen)(ws_cli_conn_t client);
/**
* @brief On close event, called when a client disconnects.
*/
void (*onclose)(ws_cli_conn_t *client);
void (*onclose)(ws_cli_conn_t client);
/**
* @brief On message event, called when a client sends a text
* or binary message.
*/
void (*onmessage)(ws_cli_conn_t *client,
void (*onmessage)(ws_cli_conn_t client,
const unsigned char *msg, uint64_t msg_size, int type);
};

Expand Down Expand Up @@ -307,24 +307,24 @@ extern "C" {
extern int get_handshake_response(char *hsrequest, char **hsresponse);

/* External usage. */
extern char *ws_getaddress(ws_cli_conn_t *client);
extern char *ws_getport(ws_cli_conn_t *client);
extern char *ws_getaddress(ws_cli_conn_t client);
extern char *ws_getport(ws_cli_conn_t client);
extern int ws_sendframe(
ws_cli_conn_t *cli, const char *msg, uint64_t size, int type);
ws_cli_conn_t client, const char *msg, uint64_t size, int type);
extern int ws_sendframe_bcast(
uint16_t port, const char *msg, uint64_t size, int type);
extern int ws_sendframe_txt(ws_cli_conn_t *cli, const char *msg);
extern int ws_sendframe_txt(ws_cli_conn_t client, const char *msg);
extern int ws_sendframe_txt_bcast(uint16_t port, const char *msg);
extern int ws_sendframe_bin(ws_cli_conn_t *cli, const char *msg,
extern int ws_sendframe_bin(ws_cli_conn_t client, const char *msg,
uint64_t size);
extern int ws_sendframe_bin_bcast(uint16_t port, const char *msg,
uint64_t size);
extern int ws_get_state(ws_cli_conn_t *cli);
extern int ws_close_client(ws_cli_conn_t *cli);
extern int ws_get_state(ws_cli_conn_t client);
extern int ws_close_client(ws_cli_conn_t client);
extern int ws_socket(struct ws_server *ws_srv);

/* Ping routines. */
extern void ws_ping(ws_cli_conn_t *cli, int threshold);
extern void ws_ping(ws_cli_conn_t cid, int threshold);

#ifdef AFL_FUZZ
extern int ws_file(struct ws_events *evs, const char *file);
Expand Down
Loading

0 comments on commit a999870

Please sign in to comment.