Asterisk - The Open Source Telephony Project
18.5.0
|
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 | pjsip_history_entry |
An item in the history. 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 | AST_VECTOR (vector_history_t, struct pjsip_history_entry *) |
The one and only history that we've captured. More... | |
static struct expression_token * | build_expression_queue (struct ast_cli_args *a) |
Build a reverse polish notation expression queue. More... | |
static int | clear_history_entries (void *obj) |
Remove all entries from vector_history. More... | |
static void | clear_history_entry_cb (struct pjsip_history_entry *entry) |
Vector callback that releases the reference for the entry in a history vector. More... | |
static void | display_entry_list (struct ast_cli_args *a, struct vector_history_t *vec) |
Print a list of the entries to the CLI. More... | |
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. More... | |
static void * | entry_get_addr (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's destination address. More... | |
static void * | entry_get_number (struct pjsip_history_entry *entry) |
Callback to retrieve the entry index number. More... | |
static void * | entry_get_sip_msg_call_id (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's SIP Call-ID header. More... | |
static void * | entry_get_sip_msg_request_method (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's SIP request method type. More... | |
static void * | entry_get_timestamp (struct pjsip_history_entry *entry) |
Callback to retrieve the entry's timestamp. More... | |
static int | evaluate_and (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
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. More... | |
static int | evaluate_greater_than (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
static int | evaluate_greater_than_or_equal (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
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. More... | |
static int | evaluate_less_than (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
static int | evaluate_less_than_or_equal (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
static int | evaluate_like (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
static int | evaluate_not (struct operator*op, enum aco_option_type type, void *operand) |
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. More... | |
static int | evaluate_or (struct operator*op, enum aco_option_type type, void *op_left, struct expression_token *op_right) |
static struct expression_token * | expression_token_alloc (enum expression_token_type token_type, void *value) |
Allocate an expression token. More... | |
static struct expression_token * | expression_token_free (struct expression_token *token) |
Free an expression token and all others it references. More... | |
static struct vector_history_t * | filter_history (struct ast_cli_args *a) |
Create a filtered history based on a user provided expression. More... | |
static struct allowed_field * | get_allowed_field (struct expression_token *token) |
Determine if the expression token matches a field in allowed_fields . More... | |
static pj_bool_t | history_on_rx_msg (pjsip_rx_data *rdata) |
PJSIP callback when a SIP message is received. More... | |
static pj_status_t | history_on_tx_msg (pjsip_tx_data *tdata) |
PJSIP callback when a SIP message is transmitted. More... | |
static int | load_module (void) |
static struct pjsip_history_entry * | pjsip_history_entry_alloc (pjsip_msg *msg) |
Create a pjsip_history_entry AO2 object. More... | |
static void | pjsip_history_entry_dtor (void *obj) |
AO2 destructor for pjsip_history_entry . More... | |
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. More... | |
static void | sprint_list_entry (struct pjsip_history_entry *entry, char *line, int len) |
Format single line history entry. More... | |
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 = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .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. More... | |
static struct operator | allowed_operators [] |
Our allowed operations. More... | |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static pj_caching_pool | cachingpool |
Pool factory used by pjlib to allocate memory. More... | |
static struct ast_cli_entry | cli_pjsip [] |
static int | enabled |
Whether or not we are storing history. More... | |
static ast_mutex_t | history_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
Mutex that protects vector_history. More... | |
static struct operator | left_paren |
Operator token for a left parenthesis. More... | |
static int | log_level = -1 |
Log level for history output. More... | |
static pjsip_module | logging_module |
static int | packet_number |
Packet count. More... | |
PJSIP History.
Definition in file res_pjsip_history.c.
#define APPEND_TO_OUTPUT | ( | output, | |
token | |||
) |
Referenced by build_expression_queue().
#define HISTORY_INITIAL_SIZE 256 |
Definition at line 47 of file res_pjsip_history.c.
Referenced by filter_history(), and load_module().
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 138 of file res_pjsip_history.c.
|
static |
Definition at line 1407 of file res_pjsip_history.c.
|
static |
Definition at line 1407 of file res_pjsip_history.c.
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1407 of file res_pjsip_history.c.
|
static |
The one and only history that we've captured.
An operator that we understand in an expression
Our operator's symbol
Precedence of the symbol
Non-zero if the operator is evaluated right-to-left
Number of operands the operator takes
Evaluation function for unary operators
op | The operator being evaluated |
type | The type of value contained in operand |
operand | A pointer to the value to evaluate |
-1 | error |
0 | evaluation is False |
1 | evaluation is True |
Evaluation function for binary operators
op | The operator being evaluated |
type | The type of value contained in op_left |
op_left | A pointer to the value to evaluate (a result or extracted from an entry) |
op_right | The expression token containing the other value (a result or user-provided) |
-1 | error |
0 | evaluation is False |
1 | evaluation is True |
Definition at line 80 of file res_pjsip_history.c.
Referenced by build_expression_queue(), and evaluate_history_entry().
|
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 802 of file res_pjsip_history.c.
References APPEND_TO_OUTPUT, ast_cli_args::argc, ast_cli_args::argv, 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(), LOG_WARNING, NULL, 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 779 of file res_pjsip_history.c.
References ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_RESET, clear_history_entry_cb(), history_lock, and packet_number.
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 769 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 1183 of file res_pjsip_history.c.
References ast_cli(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_cli_args::fd, 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 1150 of file res_pjsip_history.c.
References ast_calloc, ast_cli(), ast_free, ast_log, buf, pjsip_history_entry::dst, ast_cli_args::fd, 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 |
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, and expression_token::result.
|
static |
Operator callback for determining equality.
Definition at line 167 of file res_pjsip_history.c.
References ast_log, 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, and OPT_UINT_T.
Referenced by evaluate_not_equal().
|
static |
Definition at line 291 of file res_pjsip_history.c.
References ast_log, ast_tvcmp(), expression_token::field, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_DOUBLE_T, OPT_INT_T, OPT_NOOP_T, and OPT_UINT_T.
Referenced by evaluate_less_than_or_equal().
|
static |
Definition at line 348 of file res_pjsip_history.c.
References evaluate_less_than().
|
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 949 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(), 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, OPT_INT_T, result, expression_token::result, allowed_field::return_type, expression_token::token_type, TOKEN_TYPE_FIELD, TOKEN_TYPE_RESULT, type, and value.
Referenced by filter_history().
|
static |
Definition at line 242 of file res_pjsip_history.c.
References ast_log, ast_tvcmp(), expression_token::field, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_DOUBLE_T, OPT_INT_T, OPT_NOOP_T, and OPT_UINT_T.
Referenced by evaluate_greater_than_or_equal().
|
static |
Definition at line 340 of file res_pjsip_history.c.
References evaluate_greater_than().
|
static |
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, and result.
|
static |
Definition at line 356 of file res_pjsip_history.c.
References ast_log, LOG_WARNING, OPT_BOOL_T, OPT_BOOLFLAG_T, OPT_INT_T, and OPT_UINT_T.
|
static |
Operator callback for determining inequality.
Definition at line 234 of file res_pjsip_history.c.
References evaluate_equal().
|
static |
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, and expression_token::result.
|
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 |
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 1097 of file res_pjsip_history.c.
References 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, and NULL.
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 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 726 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(), and pjsip_history_entry::src.
|
static |
PJSIP callback when a SIP message is transmitted.
Definition at line 692 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 pjsip_history_entry::transmitted.
|
static |
Definition at line 1367 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, HISTORY_INITIAL_SIZE, log_level, LOG_WARNING, and logging_module.
Referenced by unload_module().
|
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 1311 of file res_pjsip_history.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_sip_push_task(), clear_history_entries(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, enabled, ast_cli_args::fd, NULL, and ast_cli_entry::usage.
|
static |
Definition at line 1217 of file res_pjsip_history.c.
References ao2_bump, ao2_cleanup, ast_cli_args::argc, ast_cli_args::argv, 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(), ast_cli_args::fd, filter_history(), history_lock, NULL, safe_vector_cleanup(), and ast_cli_entry::usage.
|
static |
Cleanup routine for a history vector, serviced on a registered PJSIP thread.
Definition at line 1206 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 pjsip_history_entry::dst, 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 1384 of file res_pjsip_history.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_logger_unregister_level(), AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_EXTENDED, ast_pjproject_caching_pool_destroy(), ast_sip_push_task_wait_servant(), ast_sip_unregister_service(), AST_VECTOR_FREE, ASTERISK_GPL_KEY, cachingpool, clear_history_entries(), load_module(), log_level, logging_module, and NULL.
|
static |
Definition at line 1407 of file res_pjsip_history.c.
|
static |
The fields we allow.
Definition at line 513 of file res_pjsip_history.c.
|
static |
Our allowed operations.
Definition at line 453 of file res_pjsip_history.c.
|
static |
Definition at line 1407 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(), pjsip_history_entry_alloc(), and unload_module().
|
static |
Definition at line 1362 of file res_pjsip_history.c.
|
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.
|
static |
Log level for history output.
Definition at line 162 of file res_pjsip_history.c.
Referenced by history_on_rx_msg(), history_on_tx_msg(), load_module(), and unload_module().
|
static |
Definition at line 1353 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().