162 return ao2_bump(default_log_mappings);
168 #define __LOG_SUPPRESS -1 181 l =
'0' + fmin(pj_level, 9);
205 const char * log_source =
"pjproject";
207 const char *log_func =
"<?>";
209 if (pjproject_log_intercept.
fd != -1
210 && pjproject_log_intercept.
thread == pthread_self()) {
215 ast_cli(pjproject_log_intercept.
fd,
"%s\n", data);
228 ast_log(ast_level, log_source, log_line, log_func,
"\t%s\n", data);
235 if (strstr(data,
"Teluu") || strstr(data,
"Dumping")) {
245 #pragma GCC diagnostic ignored "-Wformat-nonliteral" 252 format_temp =
ast_alloca(strlen(option) + strlen(
" : ") + strlen(format_string) + 1);
253 sprintf(format_temp,
"%s : %s", option, format_string);
257 va_start(arg_ptr, format_string);
258 res = vsscanf(
AST_VECTOR_GET(&buildopts, i), format_temp, arg_ptr);
267 #pragma GCC diagnostic warning "-Wformat-nonliteral" 274 pjproject_log_intercept.
thread = pthread_self();
275 pjproject_log_intercept.
fd =
fd;
280 pjproject_log_intercept.
fd = -1;
292 e->
command =
"pjproject show buildopts";
294 "Usage: pjproject show buildopts\n" 295 " Show the compile time config of the pjproject that Asterisk is\n" 296 " running against.\n";
302 ast_cli(a->
fd,
"PJPROJECT compile time config currently running against:\n");
337 e->
command =
"pjproject show log mappings";
339 "Usage: pjproject show log mappings\n" 340 " Show pjproject to Asterisk log mappings\n";
346 ast_cli(a->
fd,
"PJPROJECT to Asterisk log mappings:\n");
347 ast_cli(a->
fd,
"Asterisk Level : PJPROJECT log levels\n");
361 for (i = objset; i; i = i->
next) {
385 e->
command =
"pjproject set log level {default|0|1|2|3|4|5|6}";
387 "Usage: pjproject set log level {default|<level>}\n" 389 " Set the maximum active pjproject logging level.\n" 390 " See pjproject.conf.sample for additional information\n" 391 " about the various levels pjproject uses.\n";
401 if (!strcasecmp(a->
argv[4],
"default")) {
404 if (sscanf(a->
argv[4],
"%30d", &level_new) != 1
414 "Asterisk built or linked with pjproject PJ_LOG_MAX_LEVEL=%d.\n" 415 "Lowering request to the max supported level.\n",
419 if (level_old == level_new) {
420 ast_cli(a->
fd,
"pjproject log level is still %d.\n", level_old);
422 ast_cli(a->
fd,
"pjproject log level was %d and is now %d.\n",
423 level_old, level_new);
425 pj_log_set_level(level_new);
435 e->
command =
"pjproject show log level";
437 "Usage: pjproject show log level\n" 439 " Show the current maximum active pjproject logging level.\n" 440 " See pjproject.conf.sample for additional information\n" 441 " about the various levels pjproject uses.\n";
451 ast_cli(a->
fd,
"pjproject log level is %d.%s\n",
466 const pj_pool_factory_policy *policy, pj_size_t max_capacity)
474 pj_caching_pool_destroy(cp);
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;
485 pjaddr->ipv4.sin_addr.s_addr = sin->sin_addr.s_addr;
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));
496 memset(pjaddr, 0,
sizeof(*pjaddr));
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;
510 sin->sin_addr.s_addr = pjaddr->ipv4.sin_addr.s_addr;
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);
523 memset(addr, 0,
sizeof(*addr));
529 #ifdef TEST_FRAMEWORK 532 unsigned char *w = x;
535 memcpy(w, &r, len >
sizeof(r) ?
sizeof(r) : len);
543 char *candidates[] = {
550 }, **candidate = candidates;
554 info->name =
"ast_sockaddr_to_pj_sockaddr_test";
555 info->category =
"/res/res_pjproject/";
556 info->summary =
"Validate conversions from an ast_sockaddr to a pj_sockaddr";
557 info->description =
"This test converts an ast_sockaddr to a pj_sockaddr and validates\n" 558 "that the two evaluate to the same string when formatted.";
581 pj_sockaddr_print(&pjaddr, buffer,
sizeof(buffer), 1 | 2);
583 if (strcmp(*candidate, buffer)) {
598 char *candidates[] = {
605 }, **candidate = candidates;
609 info->name =
"ast_sockaddr_from_pj_sockaddr_test";
610 info->category =
"/res/res_pjproject/";
611 info->summary =
"Validate conversions from a pj_sockaddr to an ast_sockaddr";
612 info->description =
"This test converts a pj_sockaddr to an ast_sockaddr and validates\n" 613 "that the two evaluate to the same string when formatted.";
627 pj_strset(&t, *candidate, strlen(*candidate));
629 if (pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &t, &pjaddr) != PJ_SUCCESS) {
641 if (strcmp(*candidate, buffer)) {
657 ast_debug(3,
"Starting PJPROJECT logging to Asterisk logger\n");
666 ast_log(
LOG_WARNING,
"Failed to register pjproject log_mappings object with sorcery\n");
668 pjproject_sorcery =
NULL;
679 default_log_mappings =
ast_sorcery_alloc(pjproject_sorcery,
"log_mappings",
"log_mappings");
680 if (!default_log_mappings) {
681 ast_log(
LOG_ERROR,
"Unable to allocate memory for pjproject log_mappings\n");
707 pj_log_set_decor(PJ_LOG_HAS_SENDER | PJ_LOG_HAS_INDENT);
711 "Asterisk built or linked with pjproject PJ_LOG_MAX_LEVEL=%d which is too low for startup level: %d.\n",
718 "Asterisk built or linked with pjproject PJ_LOG_MAX_LEVEL=%d which is too low to get buildopts.\n",
730 #define NOT_EQUALS(a, b) (a != b) 741 ast_debug(3,
"Stopped PJPROJECT logging to Asterisk logger\n");
746 default_log_mappings =
NULL;
758 if (pjproject_sorcery) {
771 .requires =
"res_sorcery_config",
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
struct ast_variable * next
struct sockaddr_storage ss
static int load_module(void)
#define AST_CLI_DEFINE(fn, txt,...)
#define AST_VECTOR_ADD_SORTED(vec, elem, cmp)
Add an element into a sorted vector.
Asterisk main include file. File version handling, generic pbx functions.
static struct log_mappings * default_log_mappings
static void mapping_destroy(void *object)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
static struct pjproject_log_intercept_data pjproject_log_intercept
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
static void * mapping_alloc(const char *name)
#define DEFAULT_PJ_LOG_MAX_LEVEL
static pj_log_func * log_cb_orig
descriptor for a cli entry.
static char * handle_pjproject_show_buildopts(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_pjproject_max_log_level
const ast_string_field asterisk_notice
Structure for variables, used for configurations and for channel variables.
#define AST_TEST_REGISTER(cb)
Full structure for sorcery.
Type for a default handler that should do nothing.
const ast_string_field asterisk_verbose
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ast_mutex_lock(a)
#define ast_strdup(str)
A wrapper for strdup()
static struct ast_cli_entry pjproject_cli[]
static int reload_module(void)
void ast_cli(int fd, const char *fmt,...)
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.
Socket address structure.
static void fill_with_garbage(void *x, ssize_t len)
static char * handle_pjproject_show_log_mappings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
#define ast_debug(level,...)
Log a DEBUG message.
static unsigned decor_orig
void ast_pjproject_log_intercept_end(void)
End PJPROJECT log interception for CLI output.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define ast_test_status_update(a, b, c...)
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define AST_PTHREADT_NULL
static AST_VECTOR(buildopts, char *)
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
long int ast_random(void)
int ast_option_pjproject_log_level
void ast_pjproject_log_intercept_begin(int fd)
Begin PJPROJECT log interception for CLI output.
AST_TEST_DEFINE(ast_sockaddr_to_pj_sockaddr_test)
int ast_pjproject_get_buildopt(char *option, char *format_string,...)
Retrieve a pjproject build option.
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
static void capture_buildopts_cb(int level, const char *data, int len)
static char * handle_pjproject_set_log_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_option_pjproject_cache_pools
static struct ast_sorcery * pjproject_sorcery
#define SORCERY_OBJECT(details)
Macro which must be used at the beginning of each sorcery capable object.
static int unload_module(void)
#define HAVE_PJPROJECT_BUNDLED
#define AST_TEST_UNREGISTER(cb)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_sorcery_apply_default(sorcery, type, name, data)
#define AST_PJPROJECT_INIT_LOG_LEVEL()
Get maximum log level pjproject was compiled with.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
static struct log_mappings * get_log_mappings(void)
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
void ast_pjproject_caching_pool_destroy(pj_caching_pool *cp)
Destroy caching pool factory and all cached pools.
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
const ast_string_field asterisk_debug
static void log_forwarder(int level, const char *data, int len)
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
Module has failed to load, may be in an inconsistent state.
Vector container support.
Support for logging to various files, console and syslog Configuration in file logger.conf.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
void ast_sorcery_load(const struct ast_sorcery *sorcery)
Inform any wizards to load persistent objects.
void ast_sorcery_reload(const struct ast_sorcery *sorcery)
Inform any wizards to reload persistent objects.
#define MAX_PJ_LOG_MAX_LEVEL
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
int ast_sockaddr_from_pj_sockaddr(struct ast_sockaddr *addr, const pj_sockaddr *pjaddr)
Fill an ast_sockaddr from a pj_sockaddr.
static struct mappings mappings
Standard Command Line Interface.
static int get_log_level(int pj_level)
#define ast_sorcery_open()
Type for default option handler for stringfields.
Options provided by main asterisk program.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
const ast_string_field asterisk_warning
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_MUTEX_DEFINE_STATIC(mutex)
static char * handle_pjproject_show_log_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
const ast_string_field asterisk_error
int ast_sockaddr_to_pj_sockaddr(const struct ast_sockaddr *addr, pj_sockaddr *pjaddr)
Fill a pj_sockaddr from an ast_sockaddr.
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Sorcery Data Access Layer API.
#define ast_mutex_unlock(a)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.