Asterisk - The Open Source Telephony Project GIT-master-b023714
|
PJSIP History. More...
#include "asterisk.h"
#include <pjsip.h>
#include <regex.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/cli.h"
#include "asterisk/netsock2.h"
#include "asterisk/vector.h"
#include "asterisk/lock.h"
#include "asterisk/res_pjproject.h"
Go to the source code of this file.
Data Structures | |
struct | allowed_field |
A field that we understand and can perform operations on. More... | |
struct | expression_token |
A token in the expression or an evaluated part of the expression. More... | |
struct | operator |
An operator that we understand in an expression. More... | |
struct | pjsip_history_entry |
An item in the history. More... | |
struct | vector_history_t |
The one and only history that we've captured. More... | |
Macros | |
#define | APPEND_TO_OUTPUT(output, token) |
#define | HISTORY_INITIAL_SIZE 256 |
Enumerations | |
enum | expression_token_type { TOKEN_TYPE_FIELD , TOKEN_TYPE_OPERATOR , TOKEN_TYPE_RESULT } |
The type of token that has been parsed out of an expression. More... | |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static struct expression_token * | build_expression_queue (struct ast_cli_args *a) |
Build a reverse polish notation expression queue. | |
static int | clear_history_entries (void *obj) |
Remove all entries from vector_history . | |
static void | clear_history_entry_cb (struct pjsip_history_entry *entry) |
Vector callback that releases the reference for the entry in a history vector. | |
static void | display_entry_list (struct ast_cli_args *a, struct vector_history_t *vec) |
Print a list of the entries to the CLI. | |
static void | display_single_entry (struct ast_cli_args *a, struct pjsip_history_entry *entry) |
Print a detailed view of a single entry in the history to the CLI. | |
static void * | entry_get_addr (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's destination address. | |
static void * | entry_get_number (struct pjsip_history_entry *entry) |
Callback to retrieve the entry index number. | |
static void * | entry_get_sip_msg_call_id (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's SIP Call-ID header. | |
static void * | entry_get_sip_msg_request_method (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's SIP request method type. | |
static void * | entry_get_timestamp (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's timestamp. | |
static int | evaluate_and (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining logical AND. | |
static int | evaluate_equal (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining equality. | |
static int | evaluate_greater_than (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining if one operand is greater than another. | |
static int | evaluate_greater_than_or_equal (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining if one operand is greater than or equal to another. | |
static int | evaluate_history_entry (struct pjsip_history_entry *entry, struct expression_token *queue) |
Evaluate a single entry in this history using a RPN expression. | |
static int | evaluate_less_than (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining if one operand is less than another. | |
static int | evaluate_less_than_or_equal (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining if one operand is less than or equal to another. | |
static int | evaluate_like (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for regex 'like'. | |
static int | evaluate_not (struct operator*op, enum aco_option_type type, void *operand) |
Operator callback for determining logical NOT. | |
static int | evaluate_not_equal (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining inequality. | |
static int | evaluate_or (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
Operator callback for determining logical OR. | |
static struct expression_token * | expression_token_alloc (enum expression_token_type token_type, void *value) |
Allocate an expression token. | |
static struct expression_token * | expression_token_free (struct expression_token *token) |
Free an expression token and all others it references. | |
static struct vector_history_t * | filter_history (struct ast_cli_args *a) |
Create a filtered history based on a user provided expression. | |
static struct allowed_field * | get_allowed_field (struct expression_token *token) |
Determine if the expression token matches a field in allowed_fields . | |
static pj_bool_t | history_on_rx_msg (pjsip_rx_data *rdata) |
PJSIP callback when a SIP message is received. | |
static pj_status_t | history_on_tx_msg (pjsip_tx_data *tdata) |
PJSIP callback when a SIP message is transmitted. | |
static int | load_module (void) |
static struct pjsip_history_entry * | pjsip_history_entry_alloc (pjsip_msg *msg) |
Create a pjsip_history_entry AO2 object. | |
static void | pjsip_history_entry_dtor (void *obj) |
AO2 destructor for pjsip_history_entry . | |
static char * | pjsip_set_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | pjsip_show_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | safe_vector_cleanup (void *obj) |
Cleanup routine for a history vector, serviced on a registered PJSIP thread. | |
static void | sprint_list_entry (struct pjsip_history_entry *entry, char *line, int len) |
Format single line history entry. | |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP History" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_pjsip", } |
static struct allowed_field | allowed_fields [] |
The fields we allow. | |
static struct operator | allowed_operators [] |
Our allowed operations. | |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static pj_caching_pool | cachingpool |
Pool factory used by pjlib to allocate memory. | |
static struct ast_cli_entry | cli_pjsip [] |
static int | enabled |
Whether or not we are storing history. | |
static ast_mutex_t | history_lock = AST_MUTEX_INIT_VALUE |
Mutex that protects vector_history . | |
static struct operator | left_paren |
Operator token for a left parenthesis. | |
static int | log_level = -1 |
Log level for history output. | |
static pjsip_module | logging_module |
static int | packet_number |
Packet count. | |
static struct vector_history_t | vector_history |
PJSIP History.
Definition in file res_pjsip_history.c.
#define APPEND_TO_OUTPUT | ( | output, | |
token | |||
) |
#define HISTORY_INITIAL_SIZE 256 |
Definition at line 47 of file res_pjsip_history.c.
The type of token that has been parsed out of an expression.
Enumerator | |
---|---|
TOKEN_TYPE_FIELD | The |
TOKEN_TYPE_OPERATOR | The |
TOKEN_TYPE_RESULT | The |
Definition at line 135 of file res_pjsip_history.c.
|
static |
Definition at line 1410 of file res_pjsip_history.c.
|
static |
Definition at line 1410 of file res_pjsip_history.c.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1410 of file res_pjsip_history.c.
|
static |
Build a reverse polish notation expression queue.
This function is an implementation of the Shunting-Yard Algorithm. It takes a user provided infix-notation expression and converts it into a reverse polish notation expression, which is a queue of tokens that can be easily parsed.
a | The CLI arguments provided by the User, containing the infix expression |
NULL | error |
expression_token | A 'queue' of expression tokens in RPN |
Definition at line 804 of file res_pjsip_history.c.
References a, allowed_operators, APPEND_TO_OUTPUT, ARRAY_LEN, ast_log, ast_strdupa, AST_VECTOR, AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_REMOVE, AST_VECTOR_SIZE, error(), expression_token_alloc(), expression_token_free(), left_paren, LOG_WARNING, NULL, operator::precedence, operator::right_to_left, TOKEN_TYPE_FIELD, and TOKEN_TYPE_OPERATOR.
Referenced by filter_history().
|
static |
Remove all entries from vector_history
.
This must be called from a registered PJSIP thread
Definition at line 781 of file res_pjsip_history.c.
References ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_RESET, clear_history_entry_cb(), history_lock, packet_number, and vector_history.
Referenced by pjsip_set_history(), and unload_module().
|
static |
Vector callback that releases the reference for the entry in a history vector.
Definition at line 771 of file res_pjsip_history.c.
References ao2_ref.
Referenced by clear_history_entries(), filter_history(), and safe_vector_cleanup().
|
static |
Print a list of the entries to the CLI.
Definition at line 1186 of file res_pjsip_history.c.
References a, ast_cli(), AST_VECTOR_GET, AST_VECTOR_SIZE, and sprint_list_entry().
Referenced by pjsip_show_history().
|
static |
Print a detailed view of a single entry in the history to the CLI.
Definition at line 1152 of file res_pjsip_history.c.
References a, ast_calloc, ast_cli(), ast_free, ast_log, AST_TIME_T_LEN, ast_time_t_to_string(), buf, pjsip_history_entry::dst, LOG_WARNING, pjsip_history_entry::msg, pjsip_history_entry::number, pjsip_history_entry::src, pjsip_history_entry::timestamp, and pjsip_history_entry::transmitted.
Referenced by pjsip_show_history().
|
static |
Callback to retrieve the entry's destination address.
Definition at line 483 of file res_pjsip_history.c.
References pjsip_history_entry::dst, pjsip_history_entry::src, and pjsip_history_entry::transmitted.
|
static |
Callback to retrieve the entry index number.
Definition at line 471 of file res_pjsip_history.c.
References pjsip_history_entry::number.
|
static |
Callback to retrieve the entry's SIP Call-ID header.
Definition at line 503 of file res_pjsip_history.c.
References pjsip_history_entry::msg.
|
static |
Callback to retrieve the entry's SIP request method type.
Definition at line 493 of file res_pjsip_history.c.
References pjsip_history_entry::msg, and NULL.
|
static |
Callback to retrieve the entry's timestamp.
Definition at line 477 of file res_pjsip_history.c.
References pjsip_history_entry::timestamp.
|
static |
Operator callback for determining logical AND.
Definition at line 374 of file res_pjsip_history.c.
References ast_log, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_INT_T, OPT_UINT_T, expression_token::result, and type.
|
static |
Operator callback for determining equality.
Definition at line 167 of file res_pjsip_history.c.
References ast_log, ast_string_to_time_t(), ast_tvcmp(), expression_token::field, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_CHAR_ARRAY_T, OPT_DOUBLE_T, OPT_INT_T, OPT_NOOP_T, OPT_SOCKADDR_T, OPT_STRINGFIELD_T, OPT_UINT_T, and type.
Referenced by evaluate_not_equal().
|
static |
Operator callback for determining if one operand is greater than another.
Definition at line 291 of file res_pjsip_history.c.
References ast_log, ast_string_to_time_t(), ast_tvcmp(), expression_token::field, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_DOUBLE_T, OPT_INT_T, OPT_NOOP_T, OPT_UINT_T, and type.
Referenced by evaluate_less_than_or_equal().
|
static |
Operator callback for determining if one operand is greater than or equal to another.
Definition at line 348 of file res_pjsip_history.c.
References evaluate_less_than(), and type.
|
static |
Evaluate a single entry in this history using a RPN expression.
entry | The entry in the history to evaluate |
queue | The RPN expression |
0 | The expression evaluated FALSE on entry |
1 | The expression evaluated TRUE on entry |
-1 | The expression errored |
Definition at line 951 of file res_pjsip_history.c.
References ast_assert, ast_free, ast_log, AST_VECTOR, AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_REMOVE, AST_VECTOR_SIZE, error(), operator::evaluate, operator::evaluate_unary, expression_token_alloc(), expression_token_free(), expression_token::field, get_allowed_field(), allowed_field::get_field, LOG_WARNING, expression_token::next, NULL, expression_token::op, operator::operands, OPT_INT_T, result, expression_token::result, allowed_field::return_type, operator::symbol, expression_token::token_type, TOKEN_TYPE_FIELD, TOKEN_TYPE_RESULT, type, and value.
Referenced by filter_history().
|
static |
Operator callback for determining if one operand is less than another.
Definition at line 242 of file res_pjsip_history.c.
References ast_log, ast_string_to_time_t(), ast_tvcmp(), expression_token::field, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_DOUBLE_T, OPT_INT_T, OPT_NOOP_T, OPT_UINT_T, and type.
Referenced by evaluate_greater_than_or_equal().
|
static |
Operator callback for determining if one operand is less than or equal to another.
Definition at line 340 of file res_pjsip_history.c.
References evaluate_greater_than(), and type.
|
static |
Operator callback for regex 'like'.
Definition at line 410 of file res_pjsip_history.c.
References ast_copy_pj_str(), ast_log, buf, expression_token::field, LOG_WARNING, NULL, OPT_CHAR_ARRAY_T, OPT_STRINGFIELD_T, result, and type.
|
static |
Operator callback for determining logical NOT.
Definition at line 356 of file res_pjsip_history.c.
References ast_log, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_INT_T, OPT_UINT_T, and type.
|
static |
Operator callback for determining inequality.
Definition at line 234 of file res_pjsip_history.c.
References evaluate_equal(), and type.
|
static |
Operator callback for determining logical OR.
Definition at line 392 of file res_pjsip_history.c.
References ast_log, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_INT_T, OPT_UINT_T, expression_token::result, and type.
|
static |
Allocate an expression token.
token_type | The type of token in the expression |
value | The value/operator/result to pack into the token |
NULL | on failure |
expression_token | on success |
Definition at line 547 of file res_pjsip_history.c.
References ast_assert, ast_calloc, expression_token::field, NULL, expression_token::op, expression_token::result, expression_token::token_type, TOKEN_TYPE_FIELD, TOKEN_TYPE_OPERATOR, TOKEN_TYPE_RESULT, and value.
Referenced by build_expression_queue(), and evaluate_history_entry().
|
static |
Free an expression token and all others it references.
Definition at line 523 of file res_pjsip_history.c.
References ast_free, expression_token::next, and NULL.
Referenced by build_expression_queue(), evaluate_history_entry(), and filter_history().
|
static |
Create a filtered history based on a user provided expression.
a | The CLI arguments containing the expression |
NULL | on error |
A | vector containing the filtered history on success |
Definition at line 1099 of file res_pjsip_history.c.
References a, ao2_bump, ao2_cleanup, ast_free, ast_malloc, ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_PTR_FREE, AST_VECTOR_RESET, AST_VECTOR_SIZE, build_expression_queue(), clear_history_entry_cb(), evaluate_history_entry(), expression_token_free(), HISTORY_INITIAL_SIZE, history_lock, NULL, and vector_history.
Referenced by pjsip_show_history().
|
static |
Determine if the expression token matches a field in allowed_fields
.
Definition at line 587 of file res_pjsip_history.c.
References allowed_fields, ARRAY_LEN, ast_assert, expression_token::field, NULL, allowed_field::symbol, expression_token::token_type, and TOKEN_TYPE_FIELD.
Referenced by evaluate_history_entry().
|
static |
PJSIP callback when a SIP message is received.
Definition at line 728 of file res_pjsip_history.c.
References ao2_ref, ast_log_dynamic_level, ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_APPEND, pjsip_history_entry::dst, enabled, history_lock, log_level, NULL, pjsip_history_entry_alloc(), sprint_list_entry(), pjsip_history_entry::src, and vector_history.
|
static |
PJSIP callback when a SIP message is transmitted.
Definition at line 694 of file res_pjsip_history.c.
References ao2_ref, ast_log_dynamic_level, ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_APPEND, pjsip_history_entry::dst, enabled, history_lock, log_level, NULL, pjsip_history_entry_alloc(), sprint_list_entry(), pjsip_history_entry::src, pjsip_history_entry::transmitted, and vector_history.
|
static |
Definition at line 1370 of file res_pjsip_history.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_logger_register_level(), AST_MODULE_LOAD_SUCCESS, ast_pjproject_caching_pool_init(), ast_sip_register_service(), AST_VECTOR_INIT, cachingpool, cli_pjsip, HISTORY_INITIAL_SIZE, log_level, LOG_WARNING, logging_module, and vector_history.
|
static |
Create a pjsip_history_entry
AO2 object.
msg | The PJSIP message that this history entry wraps |
An | AO2 pjsip_history_entry object on success |
NULL | on failure |
Definition at line 628 of file res_pjsip_history.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_atomic_fetchadd_int(), ast_tvnow(), cachingpool, pjsip_history_entry::msg, NULL, pjsip_history_entry::number, packet_number, pjsip_history_entry_dtor(), pjsip_history_entry::pool, and pjsip_history_entry::timestamp.
Referenced by history_on_rx_msg(), and history_on_tx_msg().
|
static |
AO2 destructor for pjsip_history_entry
.
Definition at line 605 of file res_pjsip_history.c.
References NULL, and pjsip_history_entry::pool.
Referenced by pjsip_history_entry_alloc().
|
static |
Definition at line 1314 of file res_pjsip_history.c.
References a, ast_cli_entry::args, ast_cli(), ast_sip_push_task(), clear_history_entries(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, enabled, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 1220 of file res_pjsip_history.c.
References a, ao2_bump, ao2_cleanup, ast_cli(), ast_mutex_lock, ast_mutex_unlock, ast_sip_push_task(), AST_VECTOR_GET, AST_VECTOR_SIZE, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, display_entry_list(), display_single_entry(), filter_history(), history_lock, NULL, safe_vector_cleanup(), ast_cli_entry::usage, and vector_history.
|
static |
Cleanup routine for a history vector, serviced on a registered PJSIP thread.
Definition at line 1209 of file res_pjsip_history.c.
References ast_free, AST_VECTOR_FREE, AST_VECTOR_RESET, and clear_history_entry_cb().
Referenced by pjsip_show_history().
|
static |
Format single line history entry.
Definition at line 657 of file res_pjsip_history.c.
References AST_TIME_T_LEN, ast_time_t_to_string(), pjsip_history_entry::dst, len(), pjsip_history_entry::msg, pjsip_history_entry::number, pjsip_history_entry::src, pjsip_history_entry::timestamp, and pjsip_history_entry::transmitted.
Referenced by display_entry_list(), history_on_rx_msg(), and history_on_tx_msg().
|
static |
Definition at line 1387 of file res_pjsip_history.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_logger_unregister_level(), ast_pjproject_caching_pool_destroy(), ast_sip_push_task_wait_servant(), ast_sip_unregister_service(), AST_VECTOR_FREE, cachingpool, clear_history_entries(), cli_pjsip, log_level, logging_module, NULL, and vector_history.
|
static |
Definition at line 1410 of file res_pjsip_history.c.
|
static |
The fields we allow.
Definition at line 513 of file res_pjsip_history.c.
Referenced by get_allowed_field().
|
static |
Our allowed operations.
Definition at line 453 of file res_pjsip_history.c.
Referenced by build_expression_queue().
|
static |
Definition at line 1410 of file res_pjsip_history.c.
|
static |
Pool factory used by pjlib to allocate memory.
Definition at line 50 of file res_pjsip_history.c.
Referenced by load_module(), load_module(), pjsip_history_entry_alloc(), and unload_module().
|
static |
Definition at line 1365 of file res_pjsip_history.c.
Referenced by load_module(), and unload_module().
|
static |
Whether or not we are storing history.
Definition at line 53 of file res_pjsip_history.c.
Referenced by history_on_rx_msg(), history_on_tx_msg(), and pjsip_set_history().
|
static |
Mutex that protects vector_history
.
Definition at line 77 of file res_pjsip_history.c.
Referenced by clear_history_entries(), filter_history(), history_on_rx_msg(), history_on_tx_msg(), and pjsip_show_history().
|
static |
Operator token for a left parenthesis.
While this is used by the shunting-yard algorithm implementation, it should never appear in the resulting RPN queue of expression tokens
Definition at line 445 of file res_pjsip_history.c.
Referenced by build_expression_queue().
|
static |
Log level for history output.
Definition at line 159 of file res_pjsip_history.c.
Referenced by history_on_rx_msg(), history_on_tx_msg(), load_module(), unload_module(), and verify_log_result().
|
static |
Definition at line 1356 of file res_pjsip_history.c.
Referenced by load_module(), and unload_module().
|
static |
Packet count.
Definition at line 56 of file res_pjsip_history.c.
Referenced by clear_history_entries(), and pjsip_history_entry_alloc().
|
static |