libgpac
Documentation of the core library of GPAC
rmt_ws.c File Reference
#include <gpac/tools.h>
#include <gpac/thread.h>
#include <gpac/list.h>
#include <gpac/bitstream.h>
#include <gpac/network.h>
#include <gpac/download.h>
#include <gpac/base_coding.h>
+ Include dependency graph for rmt_ws.c:

Data Structures

struct  RMT_WS
 Handle to the main instance. More...
 
struct  RMT_ServerCtx
 structure representing the http server More...
 
struct  RMT_ClientCtx
 structure representing a websocket client More...
 

Enumerations

enum  {
  RMT_WEBSOCKET_CONTINUATION = 0 , RMT_WEBSOCKET_TEXT = 1 , RMT_WEBSOCKET_BINARY = 2 , RMT_WEBSOCKET_CLOSE = 8 ,
  RMT_WEBSOCKET_PING = 9 , RMT_WEBSOCKET_PONG = 10
}
 

Functions

GF_DownloadSession * gf_dm_sess_new_server (GF_DownloadManager *dm, GF_Socket *server, void *ssl_ctx, gf_dm_user_io user_io, void *usr_cbk, Bool async, GF_Err *e)
 
void gf_dm_sess_set_header (GF_DownloadSession *sess, const char *name, const char *value)
 
GF_Err gf_dm_sess_send_reply (GF_DownloadSession *sess, u32 reply_code, const char *response_body, u32 body_len, Bool no_body)
 
void gf_dm_sess_clear_headers (GF_DownloadSession *sess)
 
GF_Err dm_sess_write (GF_DownloadSession *session, const u8 *buffer, u32 size)
 
GF_Err gf_dm_read_data (GF_DownloadSession *sess, char *data, u32 data_size, u32 *out_read)
 
void httpout_format_date (u64 time, char szDate[200], Bool for_listing)
 
GF_EXPORT const char * gf_rmt_get_peer_address (RMT_ClientCtx *client)
 
GF_EXPORT void * gf_rmt_client_get_on_data_task (RMT_ClientCtx *client)
 gets the userdata associated with the client on data callback if defined More...
 
GF_EXPORT void gf_rmt_set_on_new_client_cbk (void *task, rmt_on_new_client_cbk cbk)
 
GF_EXPORT void * gf_rmt_get_on_new_client_task ()
 gets the userdata associated with the new client callback if defined More...
 
GF_EXPORT void gf_rmt_client_set_on_del_cbk (RMT_ClientCtx *client, void *task, rmt_client_on_del_cbk cbk)
 
GF_EXPORT void * gf_rmt_client_get_on_del_task (RMT_ClientCtx *client)
 gets the userdata associated with the client on deleted callback if defined More...
 
void rmt_clientctx_del (RMT_ClientCtx *client)
 
void rmt_serverctx_reset (RMT_ServerCtx *ctx)
 
void rmt_close_client (RMT_ClientCtx *client)
 
GF_Err rmt_send_reply (GF_DownloadSession *http_sess, int responseCode, char *response_body, char *content_type)
 
static void rmt_on_http_session_data (void *usr_cbk, GF_NETIO_Parameter *parameter)
 
GF_Err rmt_create_server (RMT_ServerCtx *ctx)
 
GF_EXPORT void gf_rmt_client_set_on_data_cbk (RMT_ClientCtx *client, void *task, rmt_client_on_data_cbk cbk)
 
GF_Err rmt_server_handle_new_client (RMT_ServerCtx *ctx)
 
GF_Err rmt_client_send_payload (RMT_ClientCtx *client, const u8 *payload, u64 size, Bool is_binary)
 
GF_Err rmt_client_handle_ws_payload (RMT_ClientCtx *client, u8 *payload, u64 size, Bool is_binary)
 
GF_Err rmt_client_handle_ws_frame (RMT_ClientCtx *client, GF_BitStream *bs)
 
GF_Err rmt_client_handle_event (RMT_ClientCtx *client)
 
GF_Err rmt_client_send_ping (RMT_ClientCtx *client)
 
GF_EXPORT GF_Err gf_rmt_client_send_to_ws (RMT_ClientCtx *client, const char *msg, u64 size, Bool is_binary)
 
Bool rmt_client_should_close (RMT_ClientCtx *client)
 
GF_Err rmt_server_wait_for_event (RMT_ServerCtx *ctx)
 
static u32 rmt_ws_thread_main (void *par)
 
RMT_Settingsgf_rmt_get_settings ()
 gets the current rmtws settings (creates the structure if necessary) More...
 
void rmt_ws_del (RMT_WS *rmt)
 deletes the main instance More...
 
RMT_WSrmt_ws_new ()
 creates the main instance More...
 

Variables

static RMT_Settings g_Settings
 
static Bool g_SettingsInitialized = GF_FALSE
 
static const char websocket_guid [] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
 
static char RMT_WEBSOCKET_PING_MSG [2] = { 0x89, 0x00 }
 

Data Structure Documentation

◆ RMT_WS

struct RMT_WS

Handle to the main instance.

Data Fields
GF_Thread * thread
Bool should_stop

◆ __rmt_serverctx

struct __rmt_serverctx

structure representing the http server

Data Fields
GF_Socket * server_sock
GF_SockGroup * sg
void * ssl_ctx
GF_DownloadManager * dm_sess
GF_List * active_clients

◆ __rmt_clientctx

struct __rmt_clientctx

structure representing a websocket client

Data Fields
GF_Socket * client_sock
RMT_ServerCtx * ctx
GF_DownloadSession * http_sess
char peer_address[GF_MAX_IP_NAME_LEN+16]
char buffer[1024]
Bool is_ws
u64 last_active_time
u64 last_ping_time
Bool should_close
rmt_client_on_data_cbk on_data_cbk
void * on_data_cbk_task
rmt_client_on_del_cbk on_del_cbk
void * on_del_cbk_task

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RMT_WEBSOCKET_CONTINUATION 
RMT_WEBSOCKET_TEXT 
RMT_WEBSOCKET_BINARY 
RMT_WEBSOCKET_CLOSE 
RMT_WEBSOCKET_PING 
RMT_WEBSOCKET_PONG 

Function Documentation

◆ gf_dm_sess_new_server()

GF_DownloadSession* gf_dm_sess_new_server ( GF_DownloadManager *  dm,
GF_Socket *  server,
void *  ssl_ctx,
gf_dm_user_io  user_io,
void *  usr_cbk,
Bool  async,
GF_Err e 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_dm_sess_set_header()

void gf_dm_sess_set_header ( GF_DownloadSession *  sess,
const char *  name,
const char *  value 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_dm_sess_send_reply()

GF_Err gf_dm_sess_send_reply ( GF_DownloadSession *  sess,
u32  reply_code,
const char *  response_body,
u32  body_len,
Bool  no_body 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_dm_sess_clear_headers()

void gf_dm_sess_clear_headers ( GF_DownloadSession *  sess)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dm_sess_write()

GF_Err dm_sess_write ( GF_DownloadSession *  session,
const u8 buffer,
u32  size 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_dm_read_data()

GF_Err gf_dm_read_data ( GF_DownloadSession *  sess,
char *  data,
u32  data_size,
u32 out_read 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ httpout_format_date()

void httpout_format_date ( u64  time,
char  szDate[200],
Bool  for_listing 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_rmt_get_peer_address()

GF_EXPORT const char* gf_rmt_get_peer_address ( RMT_ClientCtx *  client)

gets a string representing the client in the format ip:port

Returns
a "ip:port" string of the given client

◆ gf_rmt_client_get_on_data_task()

GF_EXPORT void* gf_rmt_client_get_on_data_task ( RMT_ClientCtx *  client)

gets the userdata associated with the client on data callback if defined

◆ gf_rmt_set_on_new_client_cbk()

GF_EXPORT void gf_rmt_set_on_new_client_cbk ( void *  task,
rmt_on_new_client_cbk  cbk 
)

sets the callback called when new clients connect to the sever

Parameters
taskuser data stored and passed back to the callback
cbkthe callback of type rmt_on_new_client_cbk
+ Here is the call graph for this function:

◆ gf_rmt_get_on_new_client_task()

GF_EXPORT void* gf_rmt_get_on_new_client_task ( )

gets the userdata associated with the new client callback if defined

◆ gf_rmt_client_set_on_del_cbk()

GF_EXPORT void gf_rmt_client_set_on_del_cbk ( RMT_ClientCtx *  client,
void *  task,
rmt_client_on_del_cbk  cbk 
)

sets the callback called when a client is deleted

Parameters
clientthe client for which we are setting the callback
taskuser data stored and passed back to the callback
cbkthe callback of type rmt_client_on_del_cbk

◆ gf_rmt_client_get_on_del_task()

GF_EXPORT void* gf_rmt_client_get_on_del_task ( RMT_ClientCtx *  client)

gets the userdata associated with the client on deleted callback if defined

◆ rmt_clientctx_del()

void rmt_clientctx_del ( RMT_ClientCtx *  client)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_serverctx_reset()

void rmt_serverctx_reset ( RMT_ServerCtx *  ctx)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_close_client()

void rmt_close_client ( RMT_ClientCtx *  client)
+ Here is the call graph for this function:

◆ rmt_send_reply()

GF_Err rmt_send_reply ( GF_DownloadSession *  http_sess,
int  responseCode,
char *  response_body,
char *  content_type 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_on_http_session_data()

static void rmt_on_http_session_data ( void *  usr_cbk,
GF_NETIO_Parameter *  parameter 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_create_server()

GF_Err rmt_create_server ( RMT_ServerCtx *  ctx)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_rmt_client_set_on_data_cbk()

GF_EXPORT void gf_rmt_client_set_on_data_cbk ( RMT_ClientCtx *  client,
void *  task,
rmt_client_on_data_cbk  cbk 
)

sets the callback called when a client receives data

Parameters
clientthe client for which we are setting the callback
taskuser data stored and passed back to the callback
cbkthe callback of type rmt_client_on_data_cbk

◆ rmt_server_handle_new_client()

GF_Err rmt_server_handle_new_client ( RMT_ServerCtx *  ctx)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_client_send_payload()

GF_Err rmt_client_send_payload ( RMT_ClientCtx *  client,
const u8 payload,
u64  size,
Bool  is_binary 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_client_handle_ws_payload()

GF_Err rmt_client_handle_ws_payload ( RMT_ClientCtx *  client,
u8 payload,
u64  size,
Bool  is_binary 
)
+ Here is the caller graph for this function:

◆ rmt_client_handle_ws_frame()

GF_Err rmt_client_handle_ws_frame ( RMT_ClientCtx *  client,
GF_BitStream *  bs 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_client_handle_event()

GF_Err rmt_client_handle_event ( RMT_ClientCtx *  client)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_client_send_ping()

GF_Err rmt_client_send_ping ( RMT_ClientCtx *  client)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_rmt_client_send_to_ws()

GF_EXPORT GF_Err gf_rmt_client_send_to_ws ( RMT_ClientCtx *  client,
const char *  msg,
u64  size,
Bool  is_binary 
)

sends data to a client on the websocket

Parameters
clientthe client object
msga buffer containing the data to send
sizethe size of the data to send
is_binaryfalse if we're sending a utf8 string, true otherwise
+ Here is the call graph for this function:

◆ rmt_client_should_close()

Bool rmt_client_should_close ( RMT_ClientCtx *  client)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_server_wait_for_event()

GF_Err rmt_server_wait_for_event ( RMT_ServerCtx *  ctx)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_ws_thread_main()

static u32 rmt_ws_thread_main ( void *  par)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_rmt_get_settings()

RMT_Settings* gf_rmt_get_settings ( )

gets the current rmtws settings (creates the structure if necessary)

+ Here is the caller graph for this function:

◆ rmt_ws_del()

void rmt_ws_del ( RMT_WS rmt)

deletes the main instance

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmt_ws_new()

RMT_WS* rmt_ws_new ( )

creates the main instance

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ g_Settings

RMT_Settings g_Settings
static

◆ g_SettingsInitialized

Bool g_SettingsInitialized = GF_FALSE
static

◆ websocket_guid

const char websocket_guid[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
static

◆ RMT_WEBSOCKET_PING_MSG

char RMT_WEBSOCKET_PING_MSG[2] = { 0x89, 0x00 }
static