Asterisk - The Open Source Telephony Project
21.4.1
|
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. 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. | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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 = "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 = "da6642af068ee5e6490c5b1d2cc1d238" , .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 = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
Mutex that protects vector_history . | |
static struct operator | left_paren |
Operator token for a left parenthesis. More... | |
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.
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 |
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 ast_strdupa, AST_VECTOR, AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_REMOVE, AST_VECTOR_SIZE, expression_token_alloc(), expression_token_free(), 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_VECTOR_RESET, clear_history_entry_cb(), history_lock, and packet_number.
|
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_VECTOR, AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_REMOVE, AST_VECTOR_SIZE, operator::evaluate, operator::evaluate_unary, expression_token_alloc(), expression_token_free(), expression_token::field, get_allowed_field(), allowed_field::get_field, expression_token::next, expression_token::op, operator::operands, OPT_INT_T, expression_token::result, allowed_field::return_type, operator::symbol, expression_token::token_type, TOKEN_TYPE_FIELD, and TOKEN_TYPE_RESULT.
Referenced by filter_history().
|
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_calloc, expression_token::field, expression_token::op, expression_token::result, expression_token::token_type, TOKEN_TYPE_FIELD, TOKEN_TYPE_OPERATOR, and TOKEN_TYPE_RESULT.
Referenced by build_expression_queue(), and evaluate_history_entry().
|
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 ao2_bump, ast_malloc, 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(), and history_lock.
|
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_ref, ast_atomic_fetchadd_int(), ast_tvnow(), cachingpool, pjsip_history_entry::msg, 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 |
Definition at line 1365 of file res_pjsip_history.c.
|
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.