RTS API Documentation  1.10.11
Data Structures | Macros | Typedefs | Enumerations | Functions
switch_msrp.h File Reference
#include <switch.h>
+ Include dependency graph for switch_msrp.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  msrp_msg_s
 
struct  switch_msrp_session_s
 

Macros

#define switch_msrp_send(ms, msg)   switch_msrp_perform_send(ms, msg, __FILE__, __SWITCH_FUNC__, __LINE__)
 

Typedefs

typedef struct switch_msrp_session_s switch_msrp_session_t
 
typedef struct msrp_client_socket_s switch_msrp_client_socket_t
 
typedef struct msrp_socket_s switch_msrp_socket_t
 
typedef struct msrp_msg_s switch_msrp_msg_t
 

Enumerations

enum  {
  MSRP_ST_WAIT_HEADER, MSRP_ST_PARSE_HEADER, MSRP_ST_WAIT_BODY, MSRP_ST_DONE,
  MSRP_ST_ERROR, MSRP_METHOD_REPLY, MSRP_METHOD_SEND, MSRP_METHOD_AUTH,
  MSRP_METHOD_REPORT
}
 
enum  switch_msrp_header_type_t {
  MSRP_H_FROM_PATH, MSRP_H_TO_PATH, MSRP_H_MESSAGE_ID, MSRP_H_CONTENT_TYPE,
  MSRP_H_SUCCESS_REPORT, MSRP_H_FAILURE_REPORT, MSRP_H_STATUS, MSRP_H_KEEPALIVE,
  MSRP_H_TRASACTION_ID, MSRP_H_DELIMITER, MSRP_H_CODE_DESCRIPTION, MSRP_H_UNKNOWN
}
 

Functions

switch_status_t switch_msrp_init (void)
 
switch_status_t switch_msrp_destroy (void)
 
switch_msrp_session_tswitch_msrp_session_new (switch_memory_pool_t *pool, const char *call_id, switch_bool_t secure)
 
switch_status_t switch_msrp_session_destroy (switch_msrp_session_t **ms)
 
switch_msrp_msg_tswitch_msrp_session_pop_msg (switch_msrp_session_t *ms)
 
switch_status_t switch_msrp_perform_send (switch_msrp_session_t *ms, switch_msrp_msg_t *msg, const char *file, const char *func, int line)
 
switch_status_t switch_msrp_start_client (switch_msrp_session_t *msrp_session)
 
const char * switch_msrp_listen_ip (void)
 
switch_msrp_msg_tswitch_msrp_msg_create (void)
 
void switch_msrp_msg_destroy (switch_msrp_msg_t **msg)
 
void switch_msrp_load_apis_and_applications (switch_loadable_module_interface_t **moudle_interface)
 
const char * switch_msrp_msg_get_header (switch_msrp_msg_t *msrp_msg, switch_msrp_header_type_t htype)
 
switch_status_t switch_msrp_msg_add_header (switch_msrp_msg_t *msrp_msg, switch_msrp_header_type_t htype, char *fmt,...)
 
void switch_msrp_msg_set_payload (switch_msrp_msg_t *msrp_msg, const char *buf, switch_size_t payload_bytes)
 
char * switch_msrp_header_name (switch_msrp_header_type_t htype)
 
switch_msrp_msg_tswitch_msrp_msg_dup (switch_msrp_msg_t *msg)
 

Macro Definition Documentation

◆ switch_msrp_send

#define switch_msrp_send (   ms,
  msg 
)    switch_msrp_perform_send(ms, msg, __FILE__, __SWITCH_FUNC__, __LINE__)

Definition at line 141 of file switch_msrp.h.

Referenced by msrp_worker(), SWITCH_STANDARD_API(), and SWITCH_STANDARD_APP().

Typedef Documentation

◆ switch_msrp_client_socket_t

Definition at line 69 of file switch_msrp.h.

◆ switch_msrp_msg_t

typedef struct msrp_msg_s switch_msrp_msg_t

◆ switch_msrp_session_t

Definition at line 68 of file switch_msrp.h.

◆ switch_msrp_socket_t

Definition at line 70 of file switch_msrp.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MSRP_ST_WAIT_HEADER 
MSRP_ST_PARSE_HEADER 
MSRP_ST_WAIT_BODY 
MSRP_ST_DONE 
MSRP_ST_ERROR 
MSRP_METHOD_REPLY 
MSRP_METHOD_SEND 
MSRP_METHOD_AUTH 
MSRP_METHOD_REPORT 

Definition at line 37 of file switch_msrp.h.

◆ switch_msrp_header_type_t

Enumerator
MSRP_H_FROM_PATH 
MSRP_H_TO_PATH 
MSRP_H_MESSAGE_ID 
MSRP_H_CONTENT_TYPE 
MSRP_H_SUCCESS_REPORT 
MSRP_H_FAILURE_REPORT 
MSRP_H_STATUS 
MSRP_H_KEEPALIVE 
MSRP_H_TRASACTION_ID 
MSRP_H_DELIMITER 
MSRP_H_CODE_DESCRIPTION 
MSRP_H_UNKNOWN 

Definition at line 50 of file switch_msrp.h.

Function Documentation

◆ switch_msrp_destroy()

switch_status_t switch_msrp_destroy ( void  )

Definition at line 349 of file switch_msrp.c.

References close_socket(), globals, msrp_deinit_ssl(), msrp_socket_s::sock, SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, switch_log_printf(), switch_safe_free, SWITCH_STATUS_SUCCESS, and switch_thread_join().

Referenced by switch_core_destroy(), and SWITCH_STANDARD_API().

350 {
352  switch_socket_t *sock;
353 
354  globals.running = 0;
355 
356  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "destroying thread\n");
357 
358  sock = globals.msock.sock;
359  close_socket(&sock);
360 
361  sock = globals.msock_ssl.sock;
362  close_socket(&sock);
363 
364  if (globals.msock.thread) switch_thread_join(&st, globals.msock.thread);
365  if (globals.msock_ssl.thread) switch_thread_join(&st, globals.msock_ssl.thread);
366  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "destroy thread done\n");
367 
368  globals.msock.thread = NULL;
369  globals.msock_ssl.thread = NULL;
370 
371  msrp_deinit_ssl();
372 
374 
375  return st;
376 }
#define SWITCH_CHANNEL_LOG
static void close_socket(switch_socket_t **sock)
Definition: switch_msrp.c:239
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
static void msrp_deinit_ssl(void)
Definition: switch_msrp.c:102
switch_status_t
Common return values.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
struct fspr_socket_t switch_socket_t
Definition: switch_apr.h:1026
static struct @7 globals

◆ switch_msrp_header_name()

char* switch_msrp_header_name ( switch_msrp_header_type_t  htype)

◆ switch_msrp_init()

switch_status_t switch_msrp_init ( void  )

Definition at line 294 of file switch_msrp.c.

References DEBUG_MSRP, globals, load_config(), memset(), msock_init(), msrp_init_ssl(), msrp_listener(), pool, SWITCH_CHANNEL_LOG, switch_core_new_memory_pool, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_stacksize_set(), and msrp_socket_s::thread.

Referenced by switch_core_init_and_modload(), and SWITCH_STANDARD_API().

295 {
298  switch_threadattr_t *thd_attr = NULL;
299  switch_status_t status;
300 
303  return SWITCH_STATUS_FALSE;
304  }
305 
306  memset(&globals, 0, sizeof(globals));
307  set_global_ip("0.0.0.0");
308  globals.pool = pool;
309  globals.msock.port = (switch_port_t)0;
310  globals.msock_ssl.port = (switch_port_t)0;
311  globals.msock_ssl.secure = 1;
312  globals.message_buffer_size = 50;
313  globals.debug = DEBUG_MSRP;
314 
315  load_config();
316 
317  if (globals.msock.port) {
318  globals.running = 1;
319 
320  status = msock_init(globals.ip, globals.msock.port, &globals.msock.sock, pool);
321 
322  if (status == SWITCH_STATUS_SUCCESS) {
323  switch_threadattr_create(&thd_attr, pool);
324  // switch_threadattr_detach_set(thd_attr, 1);
326  switch_thread_create(&thread, thd_attr, msrp_listener, &globals.msock, pool);
327  globals.msock.thread = thread;
328  }
329  }
330 
331  if (globals.msock_ssl.port) {
332  globals.running = 1;
333 
334  msrp_init_ssl();
335  status = msock_init(globals.ip, globals.msock_ssl.port, &globals.msock_ssl.sock, pool);
336 
337  if (status == SWITCH_STATUS_SUCCESS) {
338  switch_threadattr_create(&thd_attr, pool);
339  // switch_threadattr_detach_set(thd_attr, 1);
341  switch_thread_create(&thread, thd_attr, msrp_listener, &globals.msock_ssl, pool);
342  globals.msock_ssl.thread = thread;
343  }
344  }
345 
346  return SWITCH_STATUS_SUCCESS;
347 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
#define SWITCH_CHANNEL_LOG
static switch_status_t load_config(void)
Definition: switch_msrp.c:190
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
static void *SWITCH_THREAD_FUNC msrp_listener(switch_thread_t *thread, void *obj)
Definition: switch_msrp.c:1425
#define DEBUG_MSRP
Definition: switch_msrp.c:38
static switch_thread_t * thread
Definition: switch_log.c:486
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
static switch_status_t msock_init(char *ip, switch_port_t port, switch_socket_t **sock, switch_memory_pool_t *pool)
Definition: switch_msrp.c:250
uint16_t switch_port_t
switch_memory_pool_t * pool
Definition: switch_msrp.c:58
switch_status_t
Common return values.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
struct fspr_pool_t switch_memory_pool_t
static void msrp_init_ssl(void)
Definition: switch_msrp.c:115
struct fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
memset(buf, 0, buflen)
static struct @7 globals

◆ switch_msrp_listen_ip()

const char* switch_msrp_listen_ip ( void  )

Definition at line 289 of file switch_msrp.c.

References globals.

Referenced by switch_core_media_negotiate_sdp().

290 {
291  return globals.ip;
292 }
static struct @7 globals

◆ switch_msrp_load_apis_and_applications()

void switch_msrp_load_apis_and_applications ( switch_loadable_module_interface_t **  moudle_interface)

Definition at line 1870 of file switch_msrp.c.

References MSRP_SYNTAX, SAF_SUPPORT_NOMEDIA, SAF_SUPPORT_TEXT_ONLY, SWITCH_ADD_API, SWITCH_ADD_APP, and switch_console_set_complete().

1871 {
1872  switch_application_interface_t *app_interface;
1873  switch_api_interface_t *api_interface;
1874 
1875  SWITCH_ADD_API(api_interface, "msrp", "MSRP Functions", msrp_api_function, MSRP_SYNTAX);
1876 
1877  SWITCH_ADD_API(api_interface, "uuid_msrp_send", "send msrp text", uuid_msrp_send_function, "<msg>");
1878  SWITCH_ADD_APP(app_interface, "msrp_recv_file", "Recv msrp message to file", "Recv msrp message", msrp_recv_file_function, "<filename>", SAF_SUPPORT_TEXT_ONLY | SAF_SUPPORT_NOMEDIA);
1879  SWITCH_ADD_APP(app_interface, "msrp_send_file", "Send file via msrp", "Send file via msrp", msrp_send_file_function, "<filename>", SAF_SUPPORT_TEXT_ONLY | SAF_SUPPORT_NOMEDIA);
1880 
1881  switch_console_set_complete("add msrp debug on");
1882  switch_console_set_complete("add msrp debug off");
1883  switch_console_set_complete("restart");
1884  switch_console_set_complete("add uuid_msrp_send ::console::list_uuid");
1885 }
switch_status_t switch_console_set_complete(const char *string)
A module interface to implement an application.
#define SWITCH_ADD_APP(app_int, int_name, short_descript, long_descript, funcptr, syntax_string, app_flags)
A module interface to implement an api function.
#define MSRP_SYNTAX
Definition: switch_msrp.c:1848
#define SWITCH_ADD_API(api_int, int_name, descript, funcptr, syntax_string)

◆ switch_msrp_msg_add_header()

switch_status_t switch_msrp_msg_add_header ( switch_msrp_msg_t msrp_msg,
switch_msrp_header_type_t  htype,
char *  fmt,
  ... 
)

Definition at line 651 of file switch_msrp.c.

References msrp_msg_s::code_description, msrp_msg_s::delimiter, msrp_msg_s::headers, MSRP_H_CODE_DESCRIPTION, MSRP_H_DELIMITER, MSRP_H_TRASACTION_ID, switch_event_add_header_string(), switch_msrp_msg_get_header(), switch_msrp_msg_header_name(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_MEMERR, switch_vasprintf(), and msrp_msg_s::transaction_id.

Referenced by msrp_parse_header(), msrp_parse_headers(), msrp_worker(), SWITCH_STANDARD_API(), and SWITCH_STANDARD_APP().

652 {
653  switch_status_t status;
654 
655  int ret = 0;
656  char *data;
657  va_list ap;
658 
659  va_start(ap, fmt);
660  ret = switch_vasprintf(&data, fmt, ap);
661  va_end(ap);
662 
663  if (ret == -1) {
664  return SWITCH_STATUS_MEMERR;
665  }
666 
668 
669  switch (htype) {
672  break;
673  case MSRP_H_DELIMITER:
675  break;
678  break;
679  default: break;
680  }
681 
682  return status;
683 }
const char * code_description
Definition: switch_msrp.h:79
const char * switch_msrp_msg_get_header(switch_msrp_msg_t *msrp_msg, switch_msrp_header_type_t htype)
Definition: switch_msrp.c:685
char * switch_msrp_msg_header_name(switch_msrp_header_type_t htype)
Definition: switch_msrp.c:645
const char * delimiter
Definition: switch_msrp.h:77
int cJSON_bool fmt
Definition: switch_cJSON.h:150
switch_event_t * headers
Definition: switch_msrp.h:75
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
const char * transaction_id
Definition: switch_msrp.h:76
int switch_vasprintf(_Out_opt_ char **buf, _In_z_ _Printf_format_string_ const char *format, _In_ va_list ap)
switch_status_t
Common return values.

◆ switch_msrp_msg_create()

switch_msrp_msg_t* switch_msrp_msg_create ( void  )

Definition at line 1625 of file switch_msrp.c.

References msrp_msg_s::headers, memset(), switch_assert, switch_event_create, and SWITCH_EVENT_GENERAL.

Referenced by msrp_parse_buffer(), msrp_worker(), SWITCH_STANDARD_API(), and SWITCH_STANDARD_APP().

1626 {
1627  switch_msrp_msg_t *msg = malloc(sizeof(switch_msrp_msg_t));
1628  switch_assert(msg);
1629 
1630  memset(msg, 0, sizeof(switch_msrp_msg_t));
1632  switch_assert(msg->headers);
1633 
1634  return msg;
1635 }
switch_event_t * headers
Definition: switch_msrp.h:75
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_msrp_msg_destroy()

void switch_msrp_msg_destroy ( switch_msrp_msg_t **  msg)

Definition at line 1663 of file switch_msrp.c.

References msrp_msg_s::headers, msrp_msg_s::payload, switch_event_destroy(), and switch_safe_free.

Referenced by msrp_worker(), switch_msrp_perform_send(), switch_msrp_session_destroy(), SWITCH_STANDARD_API(), and SWITCH_STANDARD_APP().

1664 {
1665  switch_msrp_msg_t *msrp_msg = *msg;
1666  if (msrp_msg->headers) {
1667  switch_event_destroy(&msrp_msg->headers);
1668  }
1669 
1670  switch_safe_free(msrp_msg->payload);
1671  *msg = NULL;
1672 }
switch_event_t * headers
Definition: switch_msrp.h:75
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
void switch_event_destroy(switch_event_t **event)
Destroy an event.
char * payload
Definition: switch_msrp.h:87

◆ switch_msrp_msg_dup()

switch_msrp_msg_t* switch_msrp_msg_dup ( switch_msrp_msg_t msg)

Definition at line 1637 of file switch_msrp.c.

References msrp_msg_s::code_description, msrp_msg_s::code_number, msrp_msg_s::delimiter, msrp_msg_s::headers, memset(), msrp_msg_s::method, MSRP_H_CODE_DESCRIPTION, MSRP_H_DELIMITER, MSRP_H_TRASACTION_ID, msrp_msg_s::payload, msrp_msg_s::payload_bytes, msrp_msg_s::state, switch_assert, switch_event_dup(), switch_msrp_msg_get_header(), and msrp_msg_s::transaction_id.

Referenced by msrp_worker(), and switch_msrp_perform_send().

1638 {
1639  switch_msrp_msg_t *new_msg = malloc(sizeof(switch_msrp_msg_t));
1640  switch_assert(new_msg);
1641  memset(new_msg, 0, sizeof(switch_msrp_msg_t));
1642  switch_event_dup(&new_msg->headers, msg->headers);
1643  switch_assert(new_msg->headers);
1644 
1648  new_msg->state = msg->state;
1649  new_msg->method = msg->method;
1650  new_msg->code_number = msg->code_number;
1651  new_msg->payload_bytes = msg->payload_bytes;
1652 
1653  if (msg->payload_bytes > 0 && msg->payload) {
1654  new_msg->payload = malloc(msg->payload_bytes + 1);
1655  switch_assert(new_msg->payload);
1656  memcpy(new_msg->payload, msg->payload, msg->payload_bytes);
1657  *(new_msg->payload + msg->payload_bytes) = '\0';
1658  }
1659 
1660  return new_msg;
1661 }
const char * code_description
Definition: switch_msrp.h:79
const char * switch_msrp_msg_get_header(switch_msrp_msg_t *msrp_msg, switch_msrp_header_type_t htype)
Definition: switch_msrp.c:685
const char * delimiter
Definition: switch_msrp.h:77
switch_status_t switch_event_dup(switch_event_t **event, switch_event_t *todup)
Duplicate an event.
switch_size_t payload_bytes
Definition: switch_msrp.h:83
switch_event_t * headers
Definition: switch_msrp.h:75
const char * transaction_id
Definition: switch_msrp.h:76
int code_number
Definition: switch_msrp.h:78
#define switch_assert(expr)
char * payload
Definition: switch_msrp.h:87
memset(buf, 0, buflen)

◆ switch_msrp_msg_get_header()

const char* switch_msrp_msg_get_header ( switch_msrp_msg_t msrp_msg,
switch_msrp_header_type_t  htype 
)

Definition at line 685 of file switch_msrp.c.

References msrp_msg_s::headers, switch_event_get_header, and switch_msrp_msg_header_name().

Referenced by msrp_check_success_report(), msrp_msg_serialize(), msrp_reply(), msrp_report(), msrp_worker(), switch_msrp_do_send(), switch_msrp_msg_add_header(), switch_msrp_msg_dup(), and SWITCH_STANDARD_APP().

685  {
686  char *v = switch_event_get_header(msrp_msg->headers, switch_msrp_msg_header_name(htype));
687  return v;
688 }
char * switch_msrp_msg_header_name(switch_msrp_header_type_t htype)
Definition: switch_msrp.c:645
switch_event_t * headers
Definition: switch_msrp.h:75
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172

◆ switch_msrp_msg_set_payload()

void switch_msrp_msg_set_payload ( switch_msrp_msg_t msrp_msg,
const char *  buf,
switch_size_t  payload_bytes 
)

Definition at line 82 of file switch_msrp.c.

References msrp_msg_s::payload, msrp_msg_s::payload_bytes, switch_assert, and switch_malloc.

Referenced by msrp_parse_buffer(), msrp_worker(), SWITCH_STANDARD_API(), and SWITCH_STANDARD_APP().

83 {
84  if (!msrp_msg->payload) {
85  switch_malloc(msrp_msg->payload, payload_bytes + 1);
86  } else if (msrp_msg->payload_bytes < payload_bytes + 1) {
87  msrp_msg->payload = realloc(msrp_msg->payload, payload_bytes + 1);
88  }
89 
90  switch_assert(msrp_msg->payload);
91  memcpy(msrp_msg->payload, buf, payload_bytes);
92  *(msrp_msg->payload + payload_bytes) = '\0';
93  msrp_msg->payload_bytes = payload_bytes;
94 }
#define switch_malloc(ptr, len)
switch_size_t payload_bytes
Definition: switch_msrp.h:83
switch_byte_t switch_byte_t * buf
#define switch_assert(expr)
char * payload
Definition: switch_msrp.h:87

◆ switch_msrp_perform_send()

switch_status_t switch_msrp_perform_send ( switch_msrp_session_t ms,
switch_msrp_msg_t msg,
const char *  file,
const char *  func,
int  line 
)

Definition at line 1583 of file switch_msrp.c.

References switch_msrp_session_s::call_id, globals, msrp_msg_s::payload, msrp_msg_s::payload_bytes, switch_msrp_session_s::pool, switch_msrp_session_s::running, switch_msrp_session_s::send_queue, SWITCH_CHANNEL_ID_LOG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_msrp_do_send(), switch_msrp_msg_destroy(), switch_msrp_msg_dup(), switch_queue_create(), switch_queue_term(), switch_queue_trypop(), switch_queue_trypush(), SWITCH_SIZE_T_FMT, and SWITCH_STATUS_SUCCESS.

1584 {
1585  switch_msrp_msg_t *msg = NULL;
1587 
1588  if (!ms->running) {
1589  if (!ms->send_queue) {
1590  switch_queue_create(&ms->send_queue, 100, ms->pool);
1591  }
1592 
1593  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, ms->call_id, SWITCH_LOG_WARNING, "MSRP not ready! Buffering one message %" SWITCH_SIZE_T_FMT " bytes\n", msrp_msg->payload_bytes);
1594 
1595  if (globals.debug && msrp_msg->payload) {
1596  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, ms->call_id, SWITCH_LOG_WARNING, "MSRP not ready! Buffered one message [%s]\n", msrp_msg->payload);
1597  }
1598 
1599  msg = switch_msrp_msg_dup(msrp_msg);
1600 
1601  status = switch_queue_trypush(ms->send_queue, msg);
1602 
1603  if (status != SWITCH_STATUS_SUCCESS) {
1604  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, ms->call_id, SWITCH_LOG_ERROR, "MSRP queue FULL! Discard one message %" SWITCH_SIZE_T_FMT " bytes\n", msg->payload_bytes);
1606  }
1607 
1608  return status;
1609  }
1610 
1611  if (ms->send_queue) {
1612  while (status == SWITCH_STATUS_SUCCESS && switch_queue_trypop(ms->send_queue, (void **)&msg) == SWITCH_STATUS_SUCCESS) {
1613  status = switch_msrp_do_send(ms, msg, file, func, line);
1614  }
1615 
1617  ms->send_queue = NULL;
1618  }
1619 
1620  status = switch_msrp_do_send(ms, msrp_msg, file, func, line);
1621 
1622  return status;
1623 }
void switch_msrp_msg_destroy(switch_msrp_msg_t **msg)
Definition: switch_msrp.c:1663
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
switch_size_t payload_bytes
Definition: switch_msrp.h:83
static switch_status_t switch_msrp_do_send(switch_msrp_session_t *ms, switch_msrp_msg_t *msrp_msg, const char *file, const char *func, int line)
Definition: switch_msrp.c:1519
switch_memory_pool_t * pool
Definition: switch_msrp.h:92
#define SWITCH_SIZE_T_FMT
switch_status_t
Common return values.
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
switch_status_t switch_queue_term(switch_queue_t *queue)
Definition: switch_apr.c:1274
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_queue_t * send_queue
Definition: switch_msrp.h:118
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233
static struct @7 globals
switch_msrp_msg_t * switch_msrp_msg_dup(switch_msrp_msg_t *msg)
Definition: switch_msrp.c:1637

◆ switch_msrp_session_destroy()

switch_status_t switch_msrp_session_destroy ( switch_msrp_session_t **  ms)

Definition at line 392 of file switch_msrp.c.

References close_socket(), SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, SWITCH_LOG_INFO, switch_log_printf(), switch_msrp_msg_destroy(), switch_mutex_destroy(), switch_mutex_lock(), switch_mutex_unlock(), switch_queue_trypop(), SWITCH_STATUS_SUCCESS, and switch_yield.

Referenced by switch_media_handle_destroy().

393 {
394  int sanity = 500;
395 
396  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying MSRP session %s\n", (*ms)->call_id);
397 
398  switch_mutex_lock((*ms)->mutex);
399 
400  if ((*ms)->csock && (*ms)->csock->sock) {
401  close_socket(&(*ms)->csock->sock);
402  }
403 
404  switch_mutex_unlock((*ms)->mutex);
405 
406  switch_yield(20000);
407 
408  while(sanity-- > 0 && (*ms)->running) {
409  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "waiting MSRP worker %s\n", (*ms)->call_id);
410  switch_yield(20000);
411  }
412 
413  if ((*ms)->send_queue) {
414  switch_msrp_msg_t *msg = NULL;
415 
416  while (switch_queue_trypop((*ms)->send_queue, (void **)&msg) == SWITCH_STATUS_SUCCESS) {
418  }
419  }
420 
421  switch_mutex_destroy((*ms)->mutex);
422  ms = NULL;
423  return SWITCH_STATUS_SUCCESS;
424 }
switch_status_t switch_mutex_destroy(switch_mutex_t *lock)
Definition: switch_apr.c:303
#define SWITCH_CHANNEL_LOG
void switch_msrp_msg_destroy(switch_msrp_msg_t **msg)
Definition: switch_msrp.c:1663
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
static void close_socket(switch_socket_t **sock)
Definition: switch_msrp.c:239
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.

◆ switch_msrp_session_new()

switch_msrp_session_t* switch_msrp_session_new ( switch_memory_pool_t pool,
const char *  call_id,
switch_bool_t  secure 
)

Definition at line 378 of file switch_msrp.c.

References switch_msrp_session_s::call_id, globals, switch_msrp_session_s::local_port, switch_msrp_session_s::msrp_msg_buffer_size, switch_msrp_session_s::mutex, pool, switch_msrp_session_s::pool, msrp_socket_s::secure, switch_msrp_session_s::secure, switch_assert, switch_core_alloc, switch_core_strdup, switch_mutex_init(), and SWITCH_MUTEX_NESTED.

Referenced by switch_core_media_gen_local_sdp(), and switch_core_media_negotiate_sdp().

379 {
382  switch_assert(ms);
383  ms->pool = pool;
384  ms->secure = secure;
385  ms->local_port = secure ? globals.msock_ssl.port : globals.msock.port;
386  ms->msrp_msg_buffer_size = globals.message_buffer_size;
387  ms->call_id = switch_core_strdup(pool, call_id);
389  return ms;
390 }
switch_size_t msrp_msg_buffer_size
Definition: switch_msrp.h:110
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_memory_pool_t * pool
Definition: switch_msrp.h:92
switch_memory_pool_t * pool
Definition: switch_msrp.c:58
switch_mutex_t * mutex
Definition: switch_msrp.h:109
#define switch_assert(expr)
static struct @7 globals

◆ switch_msrp_session_pop_msg()

switch_msrp_msg_t* switch_msrp_session_pop_msg ( switch_msrp_session_t ms)

Definition at line 445 of file switch_msrp.c.

References switch_msrp_session_s::last_msg, switch_msrp_session_s::msrp_msg, switch_msrp_session_s::msrp_msg_count, switch_msrp_session_s::mutex, msrp_msg_s::next, switch_mutex_lock(), switch_mutex_unlock(), and switch_yield.

Referenced by SWITCH_STANDARD_APP().

446 {
447  switch_msrp_msg_t *m = NULL;
448 
450 
451  m = ms->msrp_msg;
452 
453  if (m == NULL) {
455  switch_yield(20000);
457  }
458 
459  m = ms->msrp_msg;
460 
461  if (m == NULL) {
463  return NULL;
464  }
465 
466  ms->msrp_msg = ms->msrp_msg->next;
467  ms->msrp_msg_count--;
468 
469  if (ms->msrp_msg == NULL) ms->last_msg = NULL;
470 
472 
473  return m;
474 }
switch_msrp_msg_t * msrp_msg
Definition: switch_msrp.h:107
switch_msrp_msg_t * last_msg
Definition: switch_msrp.h:108
struct msrp_msg_s * next
Definition: switch_msrp.h:88
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * mutex
Definition: switch_msrp.h:109
switch_size_t msrp_msg_count
Definition: switch_msrp.h:111

◆ switch_msrp_start_client()

switch_status_t switch_msrp_start_client ( switch_msrp_session_t msrp_session)

Definition at line 1488 of file switch_msrp.c.

References switch_msrp_session_s::call_id, msrp_client_socket_s::client_mode, worker_helper::csock, worker_helper::debug, globals, worker_helper::msrp_session, msrp_worker(), worker_helper::pool, switch_msrp_session_s::pool, msrp_client_socket_s::secure, switch_msrp_session_s::secure, msrp_client_socket_s::sock, switch_assert, SWITCH_CHANNEL_LOG, switch_core_alloc, SWITCH_LOG_NOTICE, switch_log_printf(), SWITCH_STATUS_SUCCESS, switch_thread_create(), SWITCH_THREAD_STACKSIZE, switch_threadattr_create(), switch_threadattr_detach_set(), switch_threadattr_stacksize_set(), and msrp_socket_s::thread.

Referenced by switch_core_media_negotiate_sdp().

1489 {
1492  switch_threadattr_t *thd_attr = NULL;
1493 
1494  helper = switch_core_alloc(msrp_session->pool, sizeof(worker_helper_t));
1495 
1496  switch_assert(helper != NULL);
1497  helper->pool = msrp_session->pool;
1498  helper->debug = globals.debug;
1499  helper->csock.sock = NULL; // client mode
1500  helper->csock.secure = msrp_session->secure;
1501  helper->csock.client_mode = 1;
1502  helper->msrp_session = msrp_session;
1503 
1504  switch_threadattr_create(&thd_attr, helper->pool);
1505  switch_threadattr_detach_set(thd_attr, 1);
1507  switch_thread_create(&thread, thd_attr, msrp_worker, helper, helper->pool);
1508  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "MSRP new worker client started! %s\n", msrp_session->call_id);
1509 
1510  return SWITCH_STATUS_SUCCESS;
1511 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
switch_socket_t * sock
Definition: switch_msrp.c:48
static void *SWITCH_THREAD_FUNC msrp_worker(switch_thread_t *thread, void *obj)
Definition: switch_msrp.c:1051
static switch_thread_t * thread
Definition: switch_log.c:486
switch_msrp_session_t * msrp_session
Definition: switch_msrp.c:79
switch_status_t switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
Definition: switch_apr.c:678
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
#define SWITCH_THREAD_STACKSIZE
Definition: switch_types.h:584
switch_memory_pool_t * pool
Definition: switch_msrp.c:77
switch_memory_pool_t * pool
Definition: switch_msrp.h:92
switch_msrp_client_socket_t csock
Definition: switch_msrp.c:78
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
#define switch_assert(expr)
struct fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
static struct @7 globals