122 #define HOSTS_BUCKETS 53 181 struct pjsip_rx_data *rdata = arg;
183 pj_str_t pj_header_name;
195 (header = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &pj_header_name, header));
196 header = header->next) {
204 len = pjsip_hdr_print_on(header, buf,
sizeof(buf) - 1);
213 pos = strchr(buf,
':');
230 ast_debug(3,
"Identify '%s': SIP message has '%s' header but value '%s' does not match '%s'.\n",
236 if (!header_present) {
237 ast_debug(3,
"Identify '%s': SIP message does not have '%s' header.\n",
253 ast_debug(3,
"Source address %s matches identify '%s'\n",
258 ast_debug(3,
"Source address %s does not match identify '%s'\n",
275 ast_debug(3,
"No identify sections to match against\n");
279 match =
ao2_callback(candidates, 0, identify_match_cb, arg);
287 ast_debug(3,
"Identify '%s' SIP message matched to endpoint %s\n",
290 ast_log(
LOG_WARNING,
"Identify '%s' points to endpoint '%s' but endpoint could not be found\n",
325 int num_addrs = 0,
error = 0, i;
333 for (i = 0; i < num_addrs; ++i) {
362 unsigned short srvport;
364 snprintf(service,
sizeof(service),
"%s.%s", prefix, host);
366 while (!(srv_ret =
ast_srv_lookup(&context, service, &srvhost, &srvport))) {
391 char *current_string;
406 mask = strrchr(current_string,
'/');
413 if (!identify->
matches || error) {
414 ast_log(
LOG_ERROR,
"Failed to add address '%s' to ip endpoint identifier '%s'\n",
422 if (!identify->
hosts) {
424 if (!identify->
hosts) {
425 ast_log(
LOG_ERROR,
"Failed to create container to store hosts on ip endpoint identifier '%s'\n",
433 ast_log(
LOG_ERROR,
"Failed to store host '%s' for resolution on ip endpoint identifier '%s'\n",
446 char *current_string;
472 c_value = strchr(c_header,
':');
474 ast_log(
LOG_ERROR,
"Identify '%s' missing ':' separator in match_header '%s'.\n",
483 ast_log(
LOG_ERROR,
"Identify '%s' has no SIP header to match in match_header '%s'.\n",
488 if (!strcmp(c_value,
"//")) {
498 len = strlen(c_value);
499 if (2 < len && c_value[0] ==
'/' && c_value[len - 1] ==
'/') {
501 c_value[len - 1] =
'\0';
504 if (regcomp(&identify->
regex_buf, c_value, REG_EXTENDED | REG_NOSUB)) {
505 ast_log(
LOG_ERROR,
"Identify '%s' failed to compile match_header regex '%s'.\n",
513 if (!identify->
hosts) {
525 char *colon = strrchr(current_string,
':');
535 current_string, results);
539 current_string, results);
550 ast_log(
LOG_WARNING,
"Identify '%s' provided address '%s' did not resolve to any address\n",
552 }
else if (results == -1) {
553 ast_log(
LOG_ERROR,
"Identify '%s' failed when adding resolution results of '%s'\n",
603 for (; ha; ha = ha->
next) {
736 "%*s: <Identify/Endpoint%*.*s>\n",
745 "%*s: <criteria%*.*s>\n",
772 for (match = ident->
matches; match; match = match->
next) {
824 .
command =
"pjsip list identifies",
825 .
usage =
"Usage: pjsip list identifies [ like <pattern> ]\n" 826 " List the configured PJSIP Identifies\n" 827 " Optional regular expression pattern is used to filter the list.\n"),
829 .
command =
"pjsip show identifies",
830 .
usage =
"Usage: pjsip show identifies [ like <pattern> ]\n" 831 " Show the configured PJSIP Identifies\n" 832 " Optional regular expression pattern is used to filter the list.\n"),
834 .
command =
"pjsip show identify",
835 .
usage =
"Usage: pjsip show identify <id>\n" 836 " Show the configured PJSIP Identify\n"),
862 if (!cli_formatter) {
866 cli_formatter->
name =
"identify";
904 .requires =
"res_pjsip",
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
struct ast_str * output_buffer
struct ao2_container *(* get_container)(const char *regex)
#define AST_CLI_DEFINE(fn, txt,...)
static struct ast_cli_entry cli_identify[]
void astman_append(struct mansession *s, const char *fmt,...)
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static void match_to_var_list_append(struct ast_variable **head, struct ast_ha *ha)
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.
descriptor for a cli entry.
static struct ast_sip_endpoint * common_identify(ao2_callback_fn *identify_match_cb, void *arg)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define ao2_callback(c, flags, cb_fn, arg)
static int load_module(void)
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Structure for variables, used for configurations and for channel variables.
void ast_srv_cleanup(struct srv_context **context)
Cleanup resources associated with ast_srv_lookup.
static int header_identify_match_check(void *obj, void *arg, int flags)
Comparator function for matching an object by header.
Perform no matching, return all objects.
enum ast_cc_service_type service
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Full structure for sorcery.
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Type for a default handler that should do nothing.
enum ast_acl_sense ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr)
Apply a set of rules to a given IP address.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ast_sorcery_apply_config(sorcery, name)
Return all matching objects.
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
#define ast_strdup(str)
A wrapper for strdup()
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
struct ast_sip_endpoint *(* identify_endpoint)(pjsip_rx_data *rdata)
Callback used to identify the source of a message. See ast_sip_identify_endpoint for more details...
void ast_sorcery_load_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to load persistent objects.
static int ip_identify_match_srv_lookup(struct ip_identify_match *identify, const char *prefix, const char *host, int results)
Helper function which performs an SRV lookup and then resolves the hostname.
Socket address structure.
void ast_ha_join(const struct ast_ha *ha, struct ast_str **buf)
Convert HAs to a comma separated string value.
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * my_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
static struct ast_sip_endpoint_identifier ip_identifier
static int unload_module(void)
#define ast_strlen_zero(foo)
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
internal representation of ACL entries In principle user applications would have no need for this...
struct ao2_container * hosts
Hosts to be resolved when applying configuration.
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
static int ip_identify_match_host_lookup(struct ip_identify_match *identify, const char *host)
Helper function which performs a host lookup and adds result to identify match.
#define ast_debug(level,...)
Log a DEBUG message.
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
unsigned int srv_lookups
Perform SRV resolution of hostnames.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
static struct ast_sip_endpoint * header_identify(pjsip_rx_data *rdata)
struct ao2_container * ast_str_container_alloc_options(enum ao2_alloc_opts opts, int buckets)
Allocates a hash container for bare strings.
struct ast_sockaddr netmask
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define CLI_INDENT_TO_SPACES(x)
Access Control of various sorts.
static struct ast_sip_endpoint_identifier header_identifier
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
#define HOSTS_BUCKETS
The number of buckets for storing hosts for resolution.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
void *(* retrieve_by_id)(const char *id)
static struct ast_sip_cli_formatter_entry * cli_formatter
struct ao2_container * container
#define ast_variable_new(name, value, filename)
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
An entity with which Asterisk communicates.
static struct ast_sip_endpoint * ip_identify(pjsip_rx_data *rdata)
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
static int send_identify_ami_event(void *obj, void *arg, void *data, int flags)
#define CLI_HEADER_FILLER
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Type for default option handler for bools (ast_true/ast_false)
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 ao2_callback_data(container, flags, cb_fn, arg, data)
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
#define ao2_iterator_next(iter)
#define ao2_alloc(data_size, destructor_fn)
static int match_to_str(const void *obj, const intptr_t *args, char **buf)
static void * ip_identify_alloc(const char *name)
Allocator function for a matching object.
struct ast_sip_endpoint_formatter endpoint_identify_formatter
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
const ast_string_field match_header_name
#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.
An entity responsible for identifying the source of a SIP message.
const char *(* get_id)(const void *obj)
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
int ast_sockaddr_cidr_bits(const struct ast_sockaddr *sa)
Count the 1 bits in a netmask.
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",)
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
static int ip_identify_apply(const struct ast_sorcery *sorcery, void *obj)
Apply handler for identify type.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
static int cli_print_header(void *obj, void *arg, int flags)
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
int ast_srv_lookup(struct srv_context **context, const char *service, const char **host, unsigned short *port)
Retrieve set of SRV lookups, in order.
SORCERY_OBJECT(details)
Sorcery object details.
void ast_sorcery_object_set_has_dynamic_contents(const void *object)
Set the dynamic contents flag on a sorcery object.
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
static struct ao2_container * cli_get_container(const char *regex)
char * strsep(char **str, const char *delims)
struct ast_ha * ast_append_ha_with_port(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule with optional port to a list of HAs.
static struct ast_sorcery * sorcery
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
int ast_sip_register_endpoint_identifier_with_name(struct ast_sip_endpoint_identifier *identifier, const char *name)
Register a SIP endpoint identifier with a name.
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
static void * cli_retrieve_by_id(const char *id)
void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
Unregister a SIP endpoint identifier.
Type for default option handler for stringfields.
ao2_callback_fn * print_header
int error(const char *format,...)
static int match_to_var_list(const void *obj, struct ast_variable **fields)
static int ip_identify_match_check(void *obj, void *arg, int flags)
Comparator function for matching an object by IP address.
static int cli_print_body(void *obj, void *arg, int flags)
static char context[AST_MAX_CONTEXT]
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
static int ip_identify_match_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for match field.
static int reload_module(void)
ao2_callback_fn * print_body
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object's ast_variable list.
const ast_string_field endpoint_name
Structure for an IP identification matching object.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
const ast_string_field match_header
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
#define ast_variable_list_append(head, new_var)
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
static void ip_identify_destroy(void *obj)
Destructor function for a matching object.
struct ast_ha * matches
Networks or addresses that should match this.
static int sip_identify_to_ami(const struct ip_identify_match *identify, struct ast_str **buf)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
static char prefix[MAX_PREFIX]
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
unsigned show_details_only_level_0
const ast_string_field match_header_value