Asterisk - The Open Source Telephony Project  18.5.0
Functions
res_pjproject.h File Reference
#include <pj/types.h>
#include <pj/pool.h>
Include dependency graph for res_pjproject.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ast_pjproject_caching_pool_destroy (pj_caching_pool *cp)
 Destroy caching pool factory and all cached pools. More...
 
void ast_pjproject_caching_pool_init (pj_caching_pool *cp, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
 Initialize the caching pool factory. More...
 
int ast_pjproject_get_buildopt (char *option, char *format_string,...)
 Retrieve a pjproject build option. More...
 
void ast_pjproject_log_intercept_begin (int fd)
 Begin PJPROJECT log interception for CLI output. More...
 
void ast_pjproject_log_intercept_end (void)
 End PJPROJECT log interception for CLI output. More...
 
int ast_sockaddr_from_pj_sockaddr (struct ast_sockaddr *addr, const pj_sockaddr *pjaddr)
 Fill an ast_sockaddr from a pj_sockaddr. More...
 
int ast_sockaddr_to_pj_sockaddr (const struct ast_sockaddr *addr, pj_sockaddr *pjaddr)
 Fill a pj_sockaddr from an ast_sockaddr. More...
 

Function Documentation

◆ ast_pjproject_caching_pool_destroy()

void ast_pjproject_caching_pool_destroy ( pj_caching_pool *  cp)

Destroy caching pool factory and all cached pools.

Since
13.21.0
Parameters
cpCaching pool factory to destroy
Returns
Nothing

Definition at line 472 of file res_pjproject.c.

Referenced by rtp_terminate_pjproject(), unload_module(), and unload_pjsip().

473 {
474  pj_caching_pool_destroy(cp);
475 }

◆ ast_pjproject_caching_pool_init()

void ast_pjproject_caching_pool_init ( pj_caching_pool *  cp,
const pj_pool_factory_policy *  policy,
pj_size_t  max_capacity 
)

Initialize the caching pool factory.

Since
13.21.0
Parameters
cpCaching pool factory to initialize
policyPool factory policy
max_capacityTotal capacity to be retained in the cache. Zero disables caching.
Returns
Nothing

Definition at line 465 of file res_pjproject.c.

References ast_option_pjproject_cache_pools.

Referenced by load_module(), and load_pjsip().

467 {
468  /* Passing a max_capacity of zero disables caching pools */
469  pj_caching_pool_init(cp, policy, ast_option_pjproject_cache_pools ? max_capacity : 0);
470 }
int ast_option_pjproject_cache_pools
Definition: options.c:75

◆ ast_pjproject_get_buildopt()

int ast_pjproject_get_buildopt ( char *  option,
char *  format_string,
  ... 
)

Retrieve a pjproject build option.

Parameters
optionThe build option requested
format_stringA scanf-style format string to parse the option value into
...Pointers to variables to receive the values parsed
Return values
Thenumber of values parsed
Since
13.8.0
Note
The option requested must be from those returned by pj_dump_config() which can be displayed with the 'pjsip show buildopts' CLI command.

Sample Usage:

int max_hostname;
ast_sip_get_pjproject_buildopt("PJ_MAX_HOSTNAME", "%d", &max_hostname);

Definition at line 246 of file res_pjproject.c.

References ast_alloca, AST_VECTOR_GET, and AST_VECTOR_SIZE.

Referenced by ast_sip_initialize_sorcery_location(), and load_module().

247 {
248  int res = 0;
249  char *format_temp;
250  int i;
251 
252  format_temp = ast_alloca(strlen(option) + strlen(" : ") + strlen(format_string) + 1);
253  sprintf(format_temp, "%s : %s", option, format_string);
254 
255  for (i = 0; i < AST_VECTOR_SIZE(&buildopts); i++) {
256  va_list arg_ptr;
257  va_start(arg_ptr, format_string);
258  res = vsscanf(AST_VECTOR_GET(&buildopts, i), format_temp, arg_ptr);
259  va_end(arg_ptr);
260  if (res) {
261  break;
262  }
263  }
264 
265  return res;
266 }
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_pjproject_log_intercept_begin()

void ast_pjproject_log_intercept_begin ( int  fd)

Begin PJPROJECT log interception for CLI output.

Since
13.8.0
Parameters
fdCLI file descriptior to send intercepted output.
Note
ast_pjproject_log_intercept_begin() and ast_pjproject_log_intercept_end() must always be called in pairs.
Returns
Nothing

Definition at line 269 of file res_pjproject.c.

References ast_mutex_lock, pjproject_log_intercept_data::fd, and pjproject_log_intercept_data::thread.

Referenced by do_cli_dump_endpt().

270 {
271  /* Protect from other CLI instances trying to do this at the same time. */
272  ast_mutex_lock(&pjproject_log_intercept_lock);
273 
274  pjproject_log_intercept.thread = pthread_self();
276 }
static struct pjproject_log_intercept_data pjproject_log_intercept
#define ast_mutex_lock(a)
Definition: lock.h:187

◆ ast_pjproject_log_intercept_end()

void ast_pjproject_log_intercept_end ( void  )

End PJPROJECT log interception for CLI output.

Since
13.8.0
Note
ast_pjproject_log_intercept_begin() and ast_pjproject_log_intercept_end() must always be called in pairs.
Returns
Nothing

Definition at line 278 of file res_pjproject.c.

References ast_mutex_unlock, AST_PTHREADT_NULL, pjproject_log_intercept_data::fd, and pjproject_log_intercept_data::thread.

Referenced by do_cli_dump_endpt().

279 {
282 
283  ast_mutex_unlock(&pjproject_log_intercept_lock);
284 }
static struct pjproject_log_intercept_data pjproject_log_intercept
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ ast_sockaddr_from_pj_sockaddr()

int ast_sockaddr_from_pj_sockaddr ( struct ast_sockaddr addr,
const pj_sockaddr *  pjaddr 
)

Fill an ast_sockaddr from a pj_sockaddr.

Since
13.24.0
Parameters
addrThe target address to receive the copied address
pjaddrThe source address to copy
Return values
0Success
-1Failure

Definition at line 502 of file res_pjproject.c.

References HAVE_PJPROJECT_BUNDLED, ast_sockaddr::len, and ast_sockaddr::ss.

Referenced by AST_TEST_DEFINE().

503 {
504  if (pjaddr->addr.sa_family == pj_AF_INET()) {
505  struct sockaddr_in *sin = (struct sockaddr_in *) &addr->ss;
506  sin->sin_family = AF_INET;
508  sin->sin_addr = pjaddr->ipv4.sin_addr;
509 #else
510  sin->sin_addr.s_addr = pjaddr->ipv4.sin_addr.s_addr;
511 #endif
512  sin->sin_port = pjaddr->ipv4.sin_port;
513  addr->len = sizeof(struct sockaddr_in);
514  } else if (pjaddr->addr.sa_family == pj_AF_INET6()) {
515  struct sockaddr_in6 *sin = (struct sockaddr_in6 *) &addr->ss;
516  sin->sin6_family = AF_INET6;
517  sin->sin6_port = pjaddr->ipv6.sin6_port;
518  sin->sin6_flowinfo = pjaddr->ipv6.sin6_flowinfo;
519  sin->sin6_scope_id = pjaddr->ipv6.sin6_scope_id;
520  memcpy(&sin->sin6_addr, &pjaddr->ipv6.sin6_addr, sizeof(sin->sin6_addr));
521  addr->len = sizeof(struct sockaddr_in6);
522  } else {
523  memset(addr, 0, sizeof(*addr));
524  return -1;
525  }
526  return 0;
527 }
struct sockaddr_storage ss
Definition: netsock2.h:98
socklen_t len
Definition: netsock2.h:99
#define HAVE_PJPROJECT_BUNDLED
Definition: autoconfig.h:632

◆ ast_sockaddr_to_pj_sockaddr()

int ast_sockaddr_to_pj_sockaddr ( const struct ast_sockaddr addr,
pj_sockaddr *  pjaddr 
)

Fill a pj_sockaddr from an ast_sockaddr.

Since
13.24.0
Parameters
addrThe source address to copy
pjaddrThe target address to receive the copied address
Return values
0Success
-1Failure

Definition at line 477 of file res_pjproject.c.

References ast_sockaddr::ss.

Referenced by AST_TEST_DEFINE(), and rtp_add_candidates_to_ice().

478 {
479  if (addr->ss.ss_family == AF_INET) {
480  struct sockaddr_in *sin = (struct sockaddr_in *) &addr->ss;
481  pjaddr->ipv4.sin_family = pj_AF_INET();
482 #ifdef HAVE_PJPROJECT_BUNDLED
483  pjaddr->ipv4.sin_addr = sin->sin_addr;
484 #else
485  pjaddr->ipv4.sin_addr.s_addr = sin->sin_addr.s_addr;
486 #endif
487  pjaddr->ipv4.sin_port = sin->sin_port;
488  } else if (addr->ss.ss_family == AF_INET6) {
489  struct sockaddr_in6 *sin = (struct sockaddr_in6 *) &addr->ss;
490  pjaddr->ipv6.sin6_family = pj_AF_INET6();
491  pjaddr->ipv6.sin6_port = sin->sin6_port;
492  pjaddr->ipv6.sin6_flowinfo = sin->sin6_flowinfo;
493  pjaddr->ipv6.sin6_scope_id = sin->sin6_scope_id;
494  memcpy(&pjaddr->ipv6.sin6_addr, &sin->sin6_addr, sizeof(pjaddr->ipv6.sin6_addr));
495  } else {
496  memset(pjaddr, 0, sizeof(*pjaddr));
497  return -1;
498  }
499  return 0;
500 }
struct sockaddr_storage ss
Definition: netsock2.h:98