Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uid for each connected client #96

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ sorts of events:

```c
/* New client. */
void onopen(ws_cli_conn_t *client);
void onopen(ws_cli_conn_t client);

/* Client disconnected. */
void onclose(ws_cli_conn_t *client);
void onclose(ws_cli_conn_t client);

/* Client sent a text message. */
void onmessage(ws_cli_conn_t *client, const unsigned char *msg,
void onmessage(ws_cli_conn_t client, const unsigned char *msg,
uint64_t size, int type);
```

Expand All @@ -93,7 +93,7 @@ folder, ;-).
* @brief This function is called whenever a new connection is opened.
* @param client Client connection.
*/
void onopen(ws_cli_conn_t *client)
void onopen(ws_cli_conn_t client)
{
char *cli;
cli = ws_getaddress(client);
Expand All @@ -104,7 +104,7 @@ void onopen(ws_cli_conn_t *client)
* @brief This function is called whenever a connection is closed.
* @param client Client connection.
*/
void onclose(ws_cli_conn_t *client)
void onclose(ws_cli_conn_t client)
{
char *cli;
cli = ws_getaddress(client);
Expand All @@ -118,7 +118,7 @@ void onclose(ws_cli_conn_t *client)
* @param size Message size.
* @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
2 changes: 1 addition & 1 deletion doc/man/man3/ws_close_client.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_close_connection \- Close the client connection.
.nf
.B #include <ws.h>
.sp
.BI "int ws_close_client(ws_cli_conn_t " *client ");
.BI "int ws_close_client(ws_cli_conn_t " client ");
.fi
.SH DESCRIPTION
.BR ws_close_client ()
Expand Down
2 changes: 1 addition & 1 deletion doc/man/man3/ws_get_state.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_get_state \- Get a client current state
.nf
.B #include <ws.h>
.sp
.BI "int ws_get_state(ws_cli_conn_t " *client ");
.BI "int ws_get_state(ws_cli_conn_t " client ");
.fi
.SH DESCRIPTION
.BR ws_get_state ()
Expand Down
2 changes: 1 addition & 1 deletion doc/man/man3/ws_getaddress.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_getaddress \- Gets the client IP address
.nf
.B #include <ws.h>
.sp
.BI "char* ws_getaddress(ws_cli_conn_t " "*client" );
.BI "char* ws_getaddress(ws_cli_conn_t " "client" );
.fi
.SH DESCRIPTION
.BR ws_getaddress ()
Expand Down
2 changes: 1 addition & 1 deletion doc/man/man3/ws_getport.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_getaddress \- Gets the client connected port
.nf
.B #include <ws.h>
.sp
.BI "char* ws_getport(ws_cli_conn_t " "*client" );
.BI "char* ws_getport(ws_cli_conn_t " "client" );
.fi
.SH DESCRIPTION
.BR ws_getport ()
Expand Down
2 changes: 1 addition & 1 deletion doc/man/man3/ws_ping.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_ping \- Sends a ping to a single client or broadcast
.nf
.B #include <ws.h>
.sp
.BI "void ws_ping(ws_cli_conn_t " *client ", int " broadcast ");"
.BI "void ws_ping(ws_cli_conn_t " client ", int " broadcast ");"
.fi
.SH DESCRIPTION
.BR ws_ping ()
Expand Down
2 changes: 1 addition & 1 deletion doc/man/man3/ws_sendframe.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_sendframe \- Creates and send a masked WebSocket frame with some payload data
.nf
.B #include <ws.h>
.sp
.BI "int ws_sendframe(ws_cli_conn_t " *client ", const char " *msg ", ssize_t " size ", int " type ");
.BI "int ws_sendframe(ws_cli_conn_t " client ", const char " *msg ", ssize_t " size ", int " type ");
.fi
.SH DESCRIPTION
.BR ws_sendframe ()
Expand Down
2 changes: 1 addition & 1 deletion doc/man/man3/ws_sendframe_bin.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_sendframe_bin \- Sends a WebSocket binary frame.
.nf
.B #include <ws.h>
.sp
.BI "int ws_sendframe_bin(ws_cli_conn_t " *client ", const char " *msg ", size " size ");
.BI "int ws_sendframe_bin(ws_cli_conn_t " client ", const char " *msg ", size " size ");
.fi
.SH DESCRIPTION
.BR ws_sendframe_bin ()
Expand Down
2 changes: 1 addition & 1 deletion doc/man/man3/ws_sendframe_txt.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ws_sendframe_txt \- Sends a WebSocket text frame.
.nf
.B #include <ws.h>
.sp
.BI "int ws_sendframe_txt(ws_cli_conn_t " *client ", const char " *msg ");
.BI "int ws_sendframe_txt(ws_cli_conn_t " client ", const char " *msg ");
.fi
.SH DESCRIPTION
.BR ws_sendframe_txt ()
Expand Down
12 changes: 6 additions & 6 deletions doc/man/man3/ws_socket.3
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ is defined as follows:
.nf
struct ws_events
{
void (*onopen)(ws_cli_conn_t *client);
void (*onclose)(ws_cli_conn_t *client);
void (*onmessage)(ws_cli_conn_t *client,
void (*onopen)(ws_cli_conn_t client);
void (*onclose)(ws_cli_conn_t client);
void (*onmessage)(ws_cli_conn_t client,
const unsigned char * msg,
uint64_t size, int type);
};
Expand Down Expand Up @@ -107,9 +107,9 @@ creating a new thread.
.nf
#include <ws.h>

void onopen(ws_cli_conn_t *client) {}
void onclose(ws_cli_conn_t *client) {}
void onmessage(ws_cli_conn_t *client) {}
void onopen(ws_cli_conn_t client) {}
void onclose(ws_cli_conn_t client) {}
void onmessage(ws_cli_conn_t client) {}

int main(void) {
ws_socket(&(struct ws_server){
Expand Down
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