mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
res_pjsip: Config option to enable PJSIP logger at load time.
Added a "debug" configuration option for res_pjsip that when set to "yes" enables SIP messages to be logged. It is specified under the "system" type. Also added an alembic script to add the option to realtime. (closes issue ASTERISK-23038) Reported by: Rusty Newton Review: https://reviewboard.asterisk.org/r/3148/ ........ Merged revisions 407036 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407037 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
5
CHANGES
5
CHANGES
@@ -98,6 +98,11 @@ chan_pjsip
|
|||||||
* Path support has been added with the 'support_path' option in registration
|
* Path support has been added with the 'support_path' option in registration
|
||||||
and aor sections.
|
and aor sections.
|
||||||
|
|
||||||
|
res_pjsip
|
||||||
|
------------------
|
||||||
|
* A 'debug' option has been added to the globals section that will allow
|
||||||
|
sip messages to be logged.
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
--- Functionality changes from Asterisk 11 to Asterisk 12 --------------------
|
--- Functionality changes from Asterisk 11 to Asterisk 12 --------------------
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
@@ -69,6 +69,8 @@ Realtime Configuration:
|
|||||||
potentially cause a migration problem. If so, it may be necessary to
|
potentially cause a migration problem. If so, it may be necessary to
|
||||||
manually alter the affected table/column to bring it back in line with the
|
manually alter the affected table/column to bring it back in line with the
|
||||||
migration scripts.
|
migration scripts.
|
||||||
|
* A new column was added to the 'ps_globals' realtime table for the 'debug'
|
||||||
|
option.
|
||||||
|
|
||||||
|
|
||||||
===========================================================
|
===========================================================
|
||||||
|
@@ -645,7 +645,6 @@
|
|||||||
; A value of 0 indicates no maximum (default: "0")
|
; A value of 0 indicates no maximum (default: "0")
|
||||||
;type= ; Must be of type system (default: "")
|
;type= ; Must be of type system (default: "")
|
||||||
|
|
||||||
|
|
||||||
;==========================GLOBAL SECTION OPTIONS=========================
|
;==========================GLOBAL SECTION OPTIONS=========================
|
||||||
;[global]
|
;[global]
|
||||||
; SYNOPSIS: Options that apply globally to all SIP communications
|
; SYNOPSIS: Options that apply globally to all SIP communications
|
||||||
@@ -664,8 +663,8 @@
|
|||||||
; endpoint (default: "d
|
; endpoint (default: "d
|
||||||
; efault_outbound_endpo
|
; efault_outbound_endpo
|
||||||
; int")
|
; int")
|
||||||
|
;debug=no ; Enable/Disable SIP debug logging. Valid options include yes|no
|
||||||
|
; or a host address (default: "no")
|
||||||
|
|
||||||
|
|
||||||
; MODULE PROVIDING BELOW SECTION(S): res_pjsip_acl
|
; MODULE PROVIDING BELOW SECTION(S): res_pjsip_acl
|
||||||
|
@@ -0,0 +1,21 @@
|
|||||||
|
"""add pjsip debug option
|
||||||
|
|
||||||
|
Revision ID: 21e526ad3040
|
||||||
|
Revises: 2fc7930b41b3
|
||||||
|
Create Date: 2014-01-30 10:44:02.297455
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '21e526ad3040'
|
||||||
|
down_revision = '2fc7930b41b3'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('ps_globals', sa.Column('debug', sa.String(40)))
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column('ps_globals', 'debug')
|
@@ -1886,4 +1886,13 @@ int ast_sip_register_supplement(struct ast_sip_supplement *supplement);
|
|||||||
*/
|
*/
|
||||||
void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
|
void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Retrieve the system debug setting (yes|no|host).
|
||||||
|
*
|
||||||
|
* \note returned string needs to be de-allocated by caller.
|
||||||
|
*
|
||||||
|
* \retval the system debug setting.
|
||||||
|
*/
|
||||||
|
char *ast_sip_get_debug(void);
|
||||||
|
|
||||||
#endif /* _RES_PJSIP_H */
|
#endif /* _RES_PJSIP_H */
|
||||||
|
@@ -1081,7 +1081,10 @@
|
|||||||
<configOption name="default_outbound_endpoint" default="default_outbound_endpoint">
|
<configOption name="default_outbound_endpoint" default="default_outbound_endpoint">
|
||||||
<synopsis>Endpoint to use when sending an outbound request to a URI without a specified endpoint.</synopsis>
|
<synopsis>Endpoint to use when sending an outbound request to a URI without a specified endpoint.</synopsis>
|
||||||
</configOption>
|
</configOption>
|
||||||
|
<configOption name="debug" default="no">
|
||||||
|
<synopsis>Enable/Disable SIP debug logging. Valid options include yes|no or
|
||||||
|
a host address</synopsis>
|
||||||
|
</configOption>
|
||||||
</configObject>
|
</configObject>
|
||||||
</configFile>
|
</configFile>
|
||||||
</configInfo>
|
</configInfo>
|
||||||
|
@@ -37,6 +37,8 @@ struct global_config {
|
|||||||
AST_DECLARE_STRING_FIELDS(
|
AST_DECLARE_STRING_FIELDS(
|
||||||
AST_STRING_FIELD(useragent);
|
AST_STRING_FIELD(useragent);
|
||||||
AST_STRING_FIELD(default_outbound_endpoint);
|
AST_STRING_FIELD(default_outbound_endpoint);
|
||||||
|
/*! Debug logging yes|no|host */
|
||||||
|
AST_STRING_FIELD(debug);
|
||||||
);
|
);
|
||||||
/* Value to put in Max-Forwards header */
|
/* Value to put in Max-Forwards header */
|
||||||
unsigned int max_forwards;
|
unsigned int max_forwards;
|
||||||
@@ -53,7 +55,7 @@ static void *global_alloc(const char *name)
|
|||||||
{
|
{
|
||||||
struct global_config *cfg = ast_sorcery_generic_alloc(sizeof(*cfg), global_destructor);
|
struct global_config *cfg = ast_sorcery_generic_alloc(sizeof(*cfg), global_destructor);
|
||||||
|
|
||||||
if (!cfg || ast_string_field_init(cfg, 64)) {
|
if (!cfg || ast_string_field_init(cfg, 80)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +99,21 @@ char *ast_sip_global_default_outbound_endpoint(void)
|
|||||||
return ast_strdup(cfg->default_outbound_endpoint);
|
return ast_strdup(cfg->default_outbound_endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *ast_sip_get_debug(void)
|
||||||
|
{
|
||||||
|
char *res;
|
||||||
|
struct global_config *cfg = get_global_cfg();
|
||||||
|
|
||||||
|
if (!cfg) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = ast_strdup(cfg->debug);
|
||||||
|
ao2_ref(cfg, -1);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery)
|
int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery)
|
||||||
{
|
{
|
||||||
snprintf(default_useragent, sizeof(default_useragent), "%s %s", DEFAULT_USERAGENT_PREFIX, ast_get_version());
|
snprintf(default_useragent, sizeof(default_useragent), "%s %s", DEFAULT_USERAGENT_PREFIX, ast_get_version());
|
||||||
@@ -114,6 +131,8 @@ int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery)
|
|||||||
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, useragent));
|
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, useragent));
|
||||||
ast_sorcery_object_field_register(sorcery, "global", "default_outbound_endpoint", DEFAULT_OUTBOUND_ENDPOINT,
|
ast_sorcery_object_field_register(sorcery, "global", "default_outbound_endpoint", DEFAULT_OUTBOUND_ENDPOINT,
|
||||||
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_outbound_endpoint));
|
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_outbound_endpoint));
|
||||||
|
ast_sorcery_object_field_register(sorcery, "global", "debug", "no",
|
||||||
|
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, debug));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -195,10 +195,50 @@ static struct ast_cli_entry cli_pjsip[] = {
|
|||||||
AST_CLI_DEFINE(pjsip_set_logger, "Enable/Disable PJSIP Logger Output")
|
AST_CLI_DEFINE(pjsip_set_logger, "Enable/Disable PJSIP Logger Output")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void check_debug(void)
|
||||||
|
{
|
||||||
|
RAII_VAR(char *, debug, ast_sip_get_debug(), ast_free);
|
||||||
|
|
||||||
|
if (ast_false(debug)) {
|
||||||
|
logging_mode = LOGGING_MODE_DISABLED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logging_mode = LOGGING_MODE_ENABLED;
|
||||||
|
|
||||||
|
if (ast_true(debug)) {
|
||||||
|
ast_sockaddr_setnull(&log_addr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* assume host */
|
||||||
|
if (ast_sockaddr_resolve_first_af(&log_addr, debug, 0, AST_AF_UNSPEC)) {
|
||||||
|
ast_log(LOG_WARNING, "Could not resolve host %s for debug "
|
||||||
|
"logging\n", debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void global_reloaded(const char *object_type)
|
||||||
|
{
|
||||||
|
check_debug();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct ast_sorcery_observer global_observer = {
|
||||||
|
.loaded = global_reloaded
|
||||||
|
};
|
||||||
|
|
||||||
static int load_module(void)
|
static int load_module(void)
|
||||||
{
|
{
|
||||||
|
if (ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &global_observer)) {
|
||||||
|
ast_log(LOG_WARNING, "Unable to add global observer\n");
|
||||||
|
return AST_MODULE_LOAD_DECLINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
check_debug();
|
||||||
|
|
||||||
ast_sip_register_service(&logging_module);
|
ast_sip_register_service(&logging_module);
|
||||||
ast_cli_register_multiple(cli_pjsip, ARRAY_LEN(cli_pjsip));
|
ast_cli_register_multiple(cli_pjsip, ARRAY_LEN(cli_pjsip));
|
||||||
|
|
||||||
return AST_MODULE_LOAD_SUCCESS;
|
return AST_MODULE_LOAD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +246,10 @@ static int unload_module(void)
|
|||||||
{
|
{
|
||||||
ast_cli_unregister_multiple(cli_pjsip, ARRAY_LEN(cli_pjsip));
|
ast_cli_unregister_multiple(cli_pjsip, ARRAY_LEN(cli_pjsip));
|
||||||
ast_sip_unregister_service(&logging_module);
|
ast_sip_unregister_service(&logging_module);
|
||||||
|
|
||||||
|
ast_sorcery_observer_remove(
|
||||||
|
ast_sip_get_sorcery(), "global", &global_observer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user