Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
location.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/logger.h"
#include "asterisk/astobj2.h"
#include "asterisk/paths.h"
#include "asterisk/sorcery.h"
#include "asterisk/taskprocessor.h"
#include "include/res_pjsip_private.h"
#include "asterisk/res_pjsip_cli.h"
#include "asterisk/statsd.h"
#include "asterisk/named_locks.h"
#include "asterisk/res_pjproject.h"
Include dependency graph for location.c:

Go to the source code of this file.

Functions

static int ami_show_aors (struct mansession *s, const struct message *m)
 
static void * aor_alloc (const char *name)
 Allocator for AOR. More...
 
static int aor_apply_handler (const struct ast_sorcery *sorcery, void *object)
 
static int aor_apply_outbound_proxy (void *obj, void *arg, int flags)
 
static void aor_deleted_observer (const void *object)
 
static void aor_destroy (void *obj)
 Destructor for AOR. More...
 
int ast_sip_contact_to_str (void *object, void *arg, int flags)
 Handler used to convert a contact to a string. More...
 
int ast_sip_destroy_sorcery_location (void)
 
int ast_sip_for_each_aor (const char *aors, ao2_callback_fn on_aor, void *arg)
 For every aor in the comma separated aors string call the given 'on_aor' handler. More...
 
int ast_sip_for_each_contact (const struct ast_sip_aor *aor, ao2_callback_fn on_contact, void *arg)
 For every contact on an AOR call the given 'on_contact' handler. More...
 
int ast_sip_initialize_sorcery_location (void)
 Initialize sorcery with location support. More...
 
int ast_sip_location_add_contact (struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, struct ast_sip_endpoint *endpoint)
 Add a new contact to an AOR. More...
 
int ast_sip_location_add_contact_nolock (struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, struct ast_sip_endpoint *endpoint)
 Add a new contact to an AOR without locking the AOR. More...
 
struct ast_sip_contactast_sip_location_create_contact (struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, int prune_on_boot, struct ast_sip_endpoint *endpoint)
 Create a new contact for an AOR without locking the AOR. More...
 
int ast_sip_location_delete_contact (struct ast_sip_contact *contact)
 Delete a contact. More...
 
void ast_sip_location_prune_boot_contacts (void)
 Prune the prune_on_boot contacts. More...
 
struct ast_sip_aorast_sip_location_retrieve_aor (const char *aor_name)
 Retrieve a named AOR. More...
 
struct ao2_containerast_sip_location_retrieve_aor_contacts (const struct ast_sip_aor *aor)
 Retrieve all contacts currently available for an AOR. More...
 
struct ao2_containerast_sip_location_retrieve_aor_contacts_filtered (const struct ast_sip_aor *aor, unsigned int flags)
 Retrieve all contacts currently available for an AOR and filter based on flags. More...
 
struct ao2_containerast_sip_location_retrieve_aor_contacts_nolock (const struct ast_sip_aor *aor)
 Retrieve all contacts currently available for an AOR without locking the AOR. More...
 
struct ao2_containerast_sip_location_retrieve_aor_contacts_nolock_filtered (const struct ast_sip_aor *aor, unsigned int flags)
 Retrieve all contacts currently available for an AOR without locking the AOR and filter based on flags. More...
 
struct ast_sip_contactast_sip_location_retrieve_contact (const char *contact_name)
 Retrieve a named contact. More...
 
void ast_sip_location_retrieve_contact_and_aor_from_list (const char *aor_list, struct ast_sip_aor **aor, struct ast_sip_contact **contact)
 Retrieve the first bound contact AND the AOR chosen from a list of AORs. More...
 
void ast_sip_location_retrieve_contact_and_aor_from_list_filtered (const char *aor_list, unsigned int flags, struct ast_sip_aor **aor, struct ast_sip_contact **contact)
 Retrieve the first bound contact AND the AOR chosen from a list of AORs and filter based on flags. More...
 
struct ast_sip_contactast_sip_location_retrieve_contact_from_aor_list (const char *aor_list)
 Retrieve the first bound contact from a list of AORs. More...
 
struct ao2_containerast_sip_location_retrieve_contacts_from_aor_list (const char *aor_list)
 Retrieve all contacts from a list of AORs. More...
 
struct ast_sip_contactast_sip_location_retrieve_first_aor_contact (const struct ast_sip_aor *aor)
 Retrieve the first bound contact for an AOR. More...
 
struct ast_sip_contactast_sip_location_retrieve_first_aor_contact_filtered (const struct ast_sip_aor *aor, unsigned int flags)
 Retrieve the first bound contact for an AOR and filter based on flags. More...
 
int ast_sip_location_update_contact (struct ast_sip_contact *contact)
 Update a contact. More...
 
int ast_sip_validate_uri_length (const char *contact_uri)
 
static int cli_aor_gather_contacts (void *obj, void *arg, int flags)
 
static struct ao2_containercli_aor_get_container (const char *regex)
 
static const char * cli_aor_get_id (const void *obj)
 
static int cli_aor_iterate (void *container, ao2_callback_fn callback, void *args)
 
static int cli_aor_print_body (void *obj, void *arg, int flags)
 
static int cli_aor_print_header (void *obj, void *arg, int flags)
 
static void * cli_aor_retrieve_by_id (const char *id)
 
static int cli_contact_compare (void *obj, void *arg, int flags)
 
static struct ao2_containercli_contact_get_container (const char *regex)
 
static const char * cli_contact_get_id (const void *obj)
 
static int cli_contact_iterate (void *container, ao2_callback_fn callback, void *args)
 
static int cli_contact_populate_container (void *obj, void *arg, int flags)
 
static int cli_contact_print_body (void *obj, void *arg, int flags)
 
static int cli_contact_print_header (void *obj, void *arg, int flags)
 
static void * cli_contact_retrieve_by_id (const char *id)
 
static int cli_contact_sort (const void *obj, const void *arg, int flags)
 
static int cli_filter_contacts (void *obj, void *arg, int flags)
 
static int cli_gather_contact (void *obj, void *arg, int flags)
 
static struct ao2_containercli_get_aors (void)
 
static void * contact_alloc (const char *name)
 Allocator for contact. More...
 
static int contact_apply_handler (const struct ast_sorcery *sorcery, void *object)
 Always create a contact_status for each contact. More...
 
static void contact_destroy (void *obj)
 Destructor for contact. More...
 
static int contact_expire (void *obj, void *arg, int flags)
 Internal callback function which deletes and unlinks any expired contacts. More...
 
static int contact_link_static (void *obj, void *arg, int flags)
 Internal callback function which links static contacts into another container. More...
 
static int contact_remove_unreachable (void *obj, void *arg, int flags)
 Internal callback function which removes any contact which is unreachable. More...
 
static int contact_to_var_list (void *object, void *arg, int flags)
 
static void contact_wrapper_destroy (void *obj)
 
static int contacts_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int contacts_to_var_list (const void *obj, struct ast_variable **fields)
 
static int destroy_contact (void *obj, void *arg, int flags)
 Internal callback function which destroys the specified contact. More...
 
static int expiration_str2struct (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for translating from a string timeval to actual structure. More...
 
static int expiration_struct2str (const void *obj, const intptr_t *args, char **buf)
 Custom handler for translating from an actual structure timeval to string. More...
 
static int format_ami_aor_handler (void *obj, void *arg, int flags)
 
static int format_ami_aorlist_handler (void *obj, void *arg, int flags)
 
static int format_ami_endpoint_aor (const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
 
static int gather_contacts_for_aor (void *obj, void *arg, int flags)
 
static int permanent_uri_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Custom handler for permanent URIs. More...
 
static int permanent_uri_sort_fn (const void *obj_left, const void *obj_right, int flags)
 
static int prune_boot_contacts_cb (void *obj, void *arg, int flags)
 
static int sip_aor_to_ami (const struct ast_sip_aor *aor, struct ast_str **buf)
 
static int voicemail_extension_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int voicemail_extension_to_str (const void *obj, const intptr_t *args, char **buf)
 

Variables

struct ast_sip_cli_formatter_entryaor_formatter
 
static const struct ast_sorcery_observer aor_observer
 Observer for contacts so state can be updated on respective endpoints. More...
 
static struct ast_cli_entry cli_commands []
 
struct ast_sip_cli_formatter_entrycontact_formatter
 
struct ast_sip_endpoint_formatter endpoint_aor_formatter
 
static int pj_max_hostname = PJ_MAX_HOSTNAME
 
static int pjsip_max_url_size = PJSIP_MAX_URL_SIZE
 

Function Documentation

◆ ami_show_aors()

static int ami_show_aors ( struct mansession s,
const struct message m 
)
static

Definition at line 1260 of file location.c.

References ao2_callback, ao2_container_count(), ao2_ref, astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), cli_get_aors(), ast_sip_ami::count, format_ami_aorlist_handler(), ast_sip_ami::m, OBJ_NODATA, and ast_sip_ami::s.

Referenced by ast_sip_initialize_sorcery_location().

1261 {
1262  struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
1263  struct ao2_container *aors;
1264 
1265  aors = cli_get_aors();
1266  if (!aors) {
1267  astman_send_error(s, m, "Could not get AORs\n");
1268  return 0;
1269  }
1270 
1271  if (!ao2_container_count(aors)) {
1272  astman_send_error(s, m, "No AORs found\n");
1273  ao2_ref(aors, -1);
1274  return 0;
1275  }
1276 
1277  astman_send_listack(s, m, "A listing of AORs follows, presented as AorList events",
1278  "start");
1279 
1281 
1282  astman_send_list_complete_start(s, m, "AorListComplete", ami.count);
1284 
1285  ao2_ref(aors, -1);
1286 
1287  return 0;
1288 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static struct ao2_container * cli_get_aors(void)
Definition: location.c:1229
const struct message * m
Definition: res_pjsip.h:2741
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition: manager.c:3237
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
AMI variable container.
Definition: res_pjsip.h:2737
static int format_ami_aorlist_handler(void *obj, void *arg, int flags)
Definition: location.c:1239
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:3245
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct mansession * s
Definition: res_pjsip.h:2739
Generic container type.
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:3201

◆ aor_alloc()

static void* aor_alloc ( const char *  name)
static

Allocator for AOR.

Definition at line 50 of file location.c.

References ao2_ref, aor_destroy(), ast_named_lock_get, AST_NAMED_LOCK_TYPE_MUTEX, ast_sorcery_lockable_alloc(), ast_string_field_init, lock, and NULL.

Referenced by ast_sip_initialize_sorcery_location().

51 {
52  void *lock;
53  struct ast_sip_aor *aor;
54 
56  if (!lock) {
57  return NULL;
58  }
59 
60  aor = ast_sorcery_lockable_alloc(sizeof(struct ast_sip_aor), aor_destroy, lock);
61  ao2_ref(lock, -1);
62 
63  if (!aor) {
64  return NULL;
65  }
66  ast_string_field_init(aor, 128);
67 
68  return aor;
69 }
A SIP address of record.
Definition: res_pjsip.h:361
void * ast_sorcery_lockable_alloc(size_t size, ao2_destructor_fn destructor, void *lockobj)
Allocate a generic sorcery capable object with locking.
Definition: sorcery.c:1712
#define NULL
Definition: resample.c:96
static void aor_destroy(void *obj)
Destructor for AOR.
Definition: location.c:40
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
ast_mutex_t lock
Definition: app_meetme.c:1091
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static const char name[]
Definition: cdr_mysql.c:74
#define ast_named_lock_get(lock_type, keyspace, key)
Geta named lock handle.
Definition: named_locks.h:83

◆ aor_apply_handler()

static int aor_apply_handler ( const struct ast_sorcery sorcery,
void *  object 
)
static

Definition at line 1352 of file location.c.

References ao2_callback, aor_apply_outbound_proxy(), ast_strlen_zero, OBJ_MULTIPLE, OBJ_NODATA, ast_sip_aor::outbound_proxy, and ast_sip_aor::permanent_contacts.

Referenced by ast_sip_initialize_sorcery_location().

1353 {
1354  struct ast_sip_aor *aor = object;
1355 
1356  if (!aor->permanent_contacts || ast_strlen_zero(aor->outbound_proxy)) {
1357  return 0;
1358  }
1359 
1361 
1362  return 0;
1363 }
A SIP address of record.
Definition: res_pjsip.h:361
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
const ast_string_field outbound_proxy
Definition: res_pjsip.h:367
#define ast_strlen_zero(foo)
Definition: strings.h:52
static int aor_apply_outbound_proxy(void *obj, void *arg, int flags)
Definition: location.c:1342
struct ao2_container * permanent_contacts
Definition: res_pjsip.h:383

◆ aor_apply_outbound_proxy()

static int aor_apply_outbound_proxy ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1342 of file location.c.

References ast_string_field_set, and ast_sip_aor::outbound_proxy.

Referenced by aor_apply_handler().

1343 {
1344  struct ast_sip_contact *contact = obj;
1345  struct ast_sip_aor *aor = arg;
1346 
1348 
1349  return 0;
1350 }
A SIP address of record.
Definition: res_pjsip.h:361
const ast_string_field outbound_proxy
Definition: res_pjsip.h:367
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ aor_deleted_observer()

static void aor_deleted_observer ( const void *  object)
static

Definition at line 81 of file location.c.

References ao2_callback, ao2_ref, ast_sip_get_sorcery(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_prefix(), destroy_contact(), NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, ast_sip_aor::permanent_contacts, and prefix.

82 {
83  const struct ast_sip_aor *aor = object;
84  const char *aor_id = ast_sorcery_object_get_id(object);
85  /* Give enough space for ;@ at the end, since that is our object naming scheme */
86  size_t prefix_len = strlen(aor_id) + sizeof(";@") - 1;
87  char prefix[prefix_len + 1];
88  struct ao2_container *contacts;
89 
90  if (aor->permanent_contacts) {
92  }
93 
94  sprintf(prefix, "%s;@", aor_id); /* Safe */
95  if (!(contacts = ast_sorcery_retrieve_by_prefix(ast_sip_get_sorcery(), "contact", prefix, prefix_len))) {
96  return;
97  }
98  /* Destroy any contacts that may still exist that were made for this AoR */
100 
101  ao2_ref(contacts, -1);
102 }
A SIP address of record.
Definition: res_pjsip.h:361
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
struct ao2_container * ast_sorcery_retrieve_by_prefix(const struct ast_sorcery *sorcery, const char *type, const char *prefix, const size_t prefix_len)
Retrieve multiple objects whose id begins with the specified prefix.
Definition: sorcery.c:1984
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
static int destroy_contact(void *obj, void *arg, int flags)
Internal callback function which destroys the specified contact.
Definition: location.c:72
struct ao2_container * permanent_contacts
Definition: res_pjsip.h:383
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Generic container type.
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ aor_destroy()

static void aor_destroy ( void *  obj)
static

Destructor for AOR.

Definition at line 40 of file location.c.

References ao2_cleanup, ast_free, ast_string_field_free_memory, ast_sip_aor::permanent_contacts, and ast_sip_aor::voicemail_extension.

Referenced by aor_alloc().

41 {
42  struct ast_sip_aor *aor = obj;
43 
47 }
A SIP address of record.
Definition: res_pjsip.h:361
char * voicemail_extension
Definition: res_pjsip.h:389
#define ast_free(a)
Definition: astmm.h:182
struct ao2_container * permanent_contacts
Definition: res_pjsip.h:383
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ ast_sip_contact_to_str()

int ast_sip_contact_to_str ( void *  object,
void *  arg,
int  flags 
)

Handler used to convert a contact to a string.

Parameters
objectthe ast_sip_aor_contact_pair containing a list of contacts to iterate and the contact
arguser data passed to handler
flags
Return values
0Success, non-zero on failure

Definition at line 767 of file location.c.

References ast_str_append(), buf, and ast_sip_contact_wrapper::contact_id.

Referenced by contacts_to_str(), sip_contact_to_str(), and sip_endpoints_aors_ami().

768 {
769  struct ast_sip_contact_wrapper *wrapper = object;
770  struct ast_str **buf = arg;
771 
772  ast_str_append(buf, 0, "%s,", wrapper->contact_id);
773 
774  return 0;
775 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584

◆ ast_sip_destroy_sorcery_location()

int ast_sip_destroy_sorcery_location ( void  )

Definition at line 1467 of file location.c.

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_manager_unregister(), ast_sip_get_sorcery(), ast_sip_unregister_cli_formatter(), ast_sip_unregister_endpoint_formatter(), and ast_sorcery_observer_remove().

Referenced by ast_res_pjsip_destroy_configuration().

1468 {
1473  ast_manager_unregister("PJSIPShowAors");
1474 
1476 
1477  return 0;
1478 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_sip_cli_formatter_entry * aor_formatter
Definition: location.c:1323
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
Definition: res_pjsip.c:3685
struct ast_sip_endpoint_formatter endpoint_aor_formatter
Definition: location.c:875
static const struct ast_sorcery_observer aor_observer
Observer for contacts so state can be updated on respective endpoints.
Definition: location.c:105
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7258
static struct ast_cli_entry cli_commands[]
Definition: location.c:1290
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
Definition: sorcery.c:2418
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
struct ast_sip_cli_formatter_entry * contact_formatter
Definition: location.c:1322

◆ ast_sip_for_each_aor()

int ast_sip_for_each_aor ( const char *  aors,
ao2_callback_fn  on_aor,
void *  arg 
)

For every aor in the comma separated aors string call the given 'on_aor' handler.

Parameters
aorsa comma separated list of aors
on_aorcallback for each aor
arguser data passed to handler
Return values
0Success, non-zero on failure

Definition at line 684 of file location.c.

References ao2_ref, ast_sip_location_retrieve_aor(), ast_strdupa, ast_strip(), ast_strlen_zero, copy(), name, and strsep().

Referenced by ami_registrations_endpoint(), ast_sip_location_retrieve_contacts_from_aor_list(), cli_aor_iterate(), format_ami_contact_status(), format_ami_endpoint_aor(), format_ami_endpoints(), mwi_new_subscribe(), and mwi_subscribe_all().

685 {
686  char *copy;
687  char *name;
688  int res;
689 
690  if (!on_aor || ast_strlen_zero(aors)) {
691  return 0;
692  }
693 
694  copy = ast_strdupa(aors);
695  while ((name = ast_strip(strsep(&copy, ",")))) {
696  struct ast_sip_aor *aor;
697 
698  aor = ast_sip_location_retrieve_aor(name);
699  if (aor) {
700  res = on_aor(aor, arg, 0);
701  ao2_ref(aor, -1);
702  if (res) {
703  return -1;
704  }
705  }
706  }
707  return 0;
708 }
A SIP address of record.
Definition: res_pjsip.h:361
struct ast_sip_aor * ast_sip_location_retrieve_aor(const char *aor_name)
Retrieve a named AOR.
Definition: location.c:147
static int copy(char *infile, char *outfile)
Utility function to copy a file.
#define ast_strlen_zero(foo)
Definition: strings.h:52
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static const char name[]
Definition: cdr_mysql.c:74
char * strsep(char **str, const char *delims)

◆ ast_sip_for_each_contact()

int ast_sip_for_each_contact ( const struct ast_sip_aor aor,
ao2_callback_fn  on_contact,
void *  arg 
)

For every contact on an AOR call the given 'on_contact' handler.

Parameters
aorthe aor containing a list of contacts to iterate
on_contactcallback on each contact on an AOR. The object received by the callback will be a ast_sip_contact_wrapper structure.
arguser data passed to handler
Return values
0Success, non-zero on failure

Definition at line 719 of file location.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_malloc, ast_sip_location_retrieve_aor_contacts(), ast_sorcery_object_get_id(), ast_strdup, contact_wrapper_destroy(), NULL, and RAII_VAR.

Referenced by ami_registrations_aor(), cli_aor_gather_contacts(), cli_contact_iterate(), contacts_to_str(), contacts_to_var_list(), format_contact_status_for_aor(), and sip_endpoints_aors_ami().

721 {
722  struct ao2_container *contacts;
723  struct ao2_iterator i;
724  int res = 0;
725  void *object = NULL;
726 
727  if (!on_contact ||
728  !(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
729  return 0;
730  }
731 
732  i = ao2_iterator_init(contacts, 0);
733  while ((object = ao2_iterator_next(&i))) {
734  RAII_VAR(struct ast_sip_contact *, contact, object, ao2_cleanup);
735  RAII_VAR(struct ast_sip_contact_wrapper *, wrapper, NULL, ao2_cleanup);
736  const char *aor_id = ast_sorcery_object_get_id(aor);
737 
738  wrapper = ao2_alloc_options(sizeof(struct ast_sip_contact_wrapper),
740  if (!wrapper) {
741  res = -1;
742  break;
743  }
744  wrapper->contact_id = ast_malloc(strlen(aor_id) + strlen(contact->uri) + 2);
745  if (!wrapper->contact_id) {
746  res = -1;
747  break;
748  }
749  sprintf(wrapper->contact_id, "%s/%s", aor_id, contact->uri);
750  wrapper->aor_id = ast_strdup(aor_id);
751  if (!wrapper->aor_id) {
752  res = -1;
753  break;
754  }
755  wrapper->contact = contact;
756  ao2_bump(wrapper->contact);
757 
758  if ((res = on_contact(wrapper, arg, 0))) {
759  break;
760  }
761  }
763  ao2_ref(contacts, -1);
764  return res;
765 }
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
struct ao2_container * ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor)
Retrieve all contacts currently available for an AOR.
Definition: location.c:247
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
static void contact_wrapper_destroy(void *obj)
Definition: location.c:710
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ ast_sip_initialize_sorcery_location()

int ast_sip_initialize_sorcery_location ( void  )

Initialize sorcery with location support.

Definition at line 1366 of file location.c.

References ami_show_aors(), ao2_alloc, aor_alloc(), aor_apply_handler(), ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_manager_register_xml, ast_pjproject_get_buildopt(), ast_sip_get_contact_status_label(), ast_sip_get_sorcery(), ast_sip_register_cli_formatter(), ast_sip_register_endpoint_formatter(), ast_sorcery_apply_default, ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_register, ast_sorcery_object_set_congestion_levels(), ast_sorcery_observer_add(), AST_STATSD_GAUGE, ast_statsd_log_full_va(), AST_TASKPROCESSOR_HIGH_WATER_LEVEL, cli_aor_get_container(), cli_aor_get_id(), cli_aor_iterate(), cli_aor_print_body(), cli_aor_print_header(), cli_aor_retrieve_by_id(), cli_contact_get_container(), cli_contact_get_id(), cli_contact_iterate(), cli_contact_print_body(), cli_contact_print_header(), cli_contact_retrieve_by_id(), contact_alloc(), contact_apply_handler(), contacts_to_str(), contacts_to_var_list(), default_expiration, EVENT_FLAG_SYSTEM, expiration_str2struct(), expiration_struct2str(), FLDSET, ast_sip_cli_formatter_entry::get_container, ast_sip_cli_formatter_entry::get_id, ast_sip_cli_formatter_entry::iterate, LOG_ERROR, mailboxes, ast_sip_cli_formatter_entry::name, NULL, OPT_BOOL_T, OPT_DOUBLE_T, OPT_NOOP_T, OPT_STRINGFIELD_T, OPT_UINT_T, OPT_YESNO_T, PARSE_IN_RANGE, permanent_uri_handler(), pj_max_hostname, pjsip_max_url_size, ast_sip_cli_formatter_entry::print_body, ast_sip_cli_formatter_entry::print_header, REMOVED, ast_sip_cli_formatter_entry::retrieve_by_id, sorcery, STRFLDSET, voicemail_extension_handler(), and voicemail_extension_to_str().

Referenced by ast_res_pjsip_initialize_configuration().

1367 {
1369  int i;
1370 
1371  ast_pjproject_get_buildopt("PJ_MAX_HOSTNAME", "%d", &pj_max_hostname);
1372  /* As of pjproject 2.4.5, PJSIP_MAX_URL_SIZE isn't exposed yet but we try anyway. */
1373  ast_pjproject_get_buildopt("PJSIP_MAX_URL_SIZE", "%d", &pjsip_max_url_size);
1374 
1375  ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar");
1376  ast_sorcery_object_set_congestion_levels(sorcery, "contact", -1,
1378  ast_sorcery_apply_default(sorcery, "aor", "config", "pjsip.conf,criteria=type=aor");
1379 
1382  return -1;
1383  }
1384 
1385  ast_sorcery_observer_add(sorcery, "aor", &aor_observer);
1386 
1387  ast_sorcery_object_field_register(sorcery, "contact", "type", "", OPT_NOOP_T, 0, 0);
1388  ast_sorcery_object_field_register(sorcery, "contact", "uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, uri));
1389  ast_sorcery_object_field_register(sorcery, "contact", "path", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, path));
1390  ast_sorcery_object_field_register_custom(sorcery, "contact", "expiration_time", "", expiration_str2struct, expiration_struct2str, NULL, 0, 0);
1391  ast_sorcery_object_field_register(sorcery, "contact", "qualify_frequency", 0, OPT_UINT_T,
1392  PARSE_IN_RANGE, FLDSET(struct ast_sip_contact, qualify_frequency), 0, 86400);
1393  ast_sorcery_object_field_register(sorcery, "contact", "qualify_timeout", "3.0", OPT_DOUBLE_T, 0, FLDSET(struct ast_sip_contact, qualify_timeout));
1394  ast_sorcery_object_field_register(sorcery, "contact", "authenticate_qualify", "no", OPT_YESNO_T, 1, FLDSET(struct ast_sip_contact, authenticate_qualify));
1395  ast_sorcery_object_field_register(sorcery, "contact", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, outbound_proxy));
1396  ast_sorcery_object_field_register(sorcery, "contact", "user_agent", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, user_agent));
1397  ast_sorcery_object_field_register(sorcery, "contact", "endpoint", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, endpoint_name));
1398  ast_sorcery_object_field_register(sorcery, "contact", "reg_server", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, reg_server));
1399  ast_sorcery_object_field_register(sorcery, "contact", "via_addr", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, via_addr));
1400  ast_sorcery_object_field_register(sorcery, "contact", "via_port", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_contact, via_port));
1401  ast_sorcery_object_field_register(sorcery, "contact", "call_id", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, call_id));
1402  ast_sorcery_object_field_register(sorcery, "contact", "prune_on_boot", "no", OPT_YESNO_T, 1, FLDSET(struct ast_sip_contact, prune_on_boot));
1403 
1404  ast_sorcery_object_field_register(sorcery, "aor", "type", "", OPT_NOOP_T, 0, 0);
1405  ast_sorcery_object_field_register(sorcery, "aor", "minimum_expiration", "60", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, minimum_expiration));
1406  ast_sorcery_object_field_register(sorcery, "aor", "maximum_expiration", "7200", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, maximum_expiration));
1407  ast_sorcery_object_field_register(sorcery, "aor", "default_expiration", "3600", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, default_expiration));
1408  ast_sorcery_object_field_register(sorcery, "aor", "qualify_frequency", 0, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_aor, qualify_frequency), 0, 86400);
1409  ast_sorcery_object_field_register(sorcery, "aor", "qualify_timeout", "3.0", OPT_DOUBLE_T, 0, FLDSET(struct ast_sip_aor, qualify_timeout));
1410  ast_sorcery_object_field_register(sorcery, "aor", "authenticate_qualify", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, authenticate_qualify));
1411  ast_sorcery_object_field_register(sorcery, "aor", "max_contacts", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, max_contacts));
1412  ast_sorcery_object_field_register(sorcery, "aor", "remove_existing", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, remove_existing));
1414  ast_sorcery_object_field_register(sorcery, "aor", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, mailboxes));
1416  ast_sorcery_object_field_register(sorcery, "aor", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, outbound_proxy));
1417  ast_sorcery_object_field_register(sorcery, "aor", "support_path", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, support_path));
1418 
1420 
1422  if (!contact_formatter) {
1423  ast_log(LOG_ERROR, "Unable to allocate memory for contact_formatter\n");
1424  return -1;
1425  }
1426  contact_formatter->name = "contact";
1433 
1435  if (!aor_formatter) {
1436  ast_log(LOG_ERROR, "Unable to allocate memory for aor_formatter\n");
1437  return -1;
1438  }
1439  aor_formatter->name = "aor";
1446 
1450 
1451  if (ast_manager_register_xml("PJSIPShowAors", EVENT_FLAG_SYSTEM, ami_show_aors)) {
1452  return -1;
1453  }
1454 
1455  /*
1456  * Reset StatsD gauges in case we didn't shut down cleanly.
1457  * Note that this must done here, as contacts will create the contact_status
1458  * object before PJSIP options handling is initialized.
1459  */
1460  for (i = 0; i <= REMOVED; i++) {
1461  ast_statsd_log_full_va("PJSIP.contacts.states.%s", AST_STATSD_GAUGE, 0, 1.0, ast_sip_get_contact_status_label(i));
1462  }
1463 
1464  return 0;
1465 }
static int expiration_str2struct(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for translating from a string timeval to actual structure.
Definition: location.c:482
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
void ast_statsd_log_full_va(const char *metric_name, const char *metric_type, intmax_t value, double sample_rate,...)
Send a stat to the configured statsd server.
Definition: res_statsd.c:199
A SIP address of record.
Definition: res_pjsip.h:361
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Definition: res_pjsip_cli.h:52
struct ast_sip_cli_formatter_entry * aor_formatter
Definition: location.c:1323
static int ami_show_aors(struct mansession *s, const struct message *m)
Definition: location.c:1260
#define AST_TASKPROCESSOR_HIGH_WATER_LEVEL
Definition: taskprocessor.h:63
static void * aor_alloc(const char *name)
Allocator for AOR.
Definition: location.c:50
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
static int cli_contact_iterate(void *container, ao2_callback_fn callback, void *args)
Definition: location.c:976
static int cli_aor_print_body(void *obj, void *arg, int flags)
Definition: location.c:1183
Full structure for sorcery.
Definition: sorcery.c:230
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
Type for a default handler that should do nothing.
static void * contact_alloc(const char *name)
Allocator for contact.
Definition: location.c:120
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
int ast_pjproject_get_buildopt(char *option, char *format_string,...)
Retrieve a pjproject build option.
const char * ast_sip_get_contact_status_label(const enum ast_sip_contact_status_type status)
translate ast_sip_contact_status_type to character string.
static int contacts_to_var_list(const void *obj, struct ast_variable **fields)
Definition: location.c:657
#define NULL
Definition: resample.c:96
struct ast_sip_endpoint_formatter endpoint_aor_formatter
Definition: location.c:875
static void * cli_aor_retrieve_by_id(const char *id)
Definition: location.c:1146
int ast_sorcery_object_set_congestion_levels(struct ast_sorcery *sorcery, const char *type, long low_water, long high_water)
Set the high and low alert water marks of the sorcery object type.
Definition: sorcery.c:1114
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition: pjsip_cli.c:310
static int cli_aor_iterate(void *container, ao2_callback_fn callback, void *args)
Definition: location.c:1139
static int cli_contact_print_body(void *obj, void *arg, int flags)
Definition: location.c:1106
Type for default option handler for bools (ast_true/ast_false)
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:3679
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define ast_log
Definition: astobj2.c:42
#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.
Definition: sorcery.h:1005
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
Type for default option handler for unsigned integers.
static const struct ast_sorcery_observer aor_observer
Observer for contacts so state can be updated on respective endpoints.
Definition: location.c:105
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
static int cli_contact_print_header(void *obj, void *arg, int flags)
Definition: location.c:1091
static int default_expiration
Definition: pbx_dundi.c:199
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:838
static struct ao2_container * cli_contact_get_container(const char *regex)
Definition: location.c:1026
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
Definition: sorcery.c:2386
static const char * cli_aor_get_id(const void *obj)
Definition: location.c:1151
#define LOG_ERROR
Definition: logger.h:285
static int permanent_uri_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for permanent URIs.
Definition: location.c:589
static int voicemail_extension_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: location.c:666
Type for default option handler for bools (ast_true/ast_false)
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:477
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static int contacts_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: location.c:808
static int contact_apply_handler(const struct ast_sorcery *sorcery, void *object)
Always create a contact_status for each contact.
Definition: location.c:1326
static int aor_apply_handler(const struct ast_sorcery *sorcery, void *object)
Definition: location.c:1352
static int cli_aor_print_header(void *obj, void *arg, int flags)
Definition: location.c:1156
static int expiration_struct2str(const void *obj, const intptr_t *args, char **buf)
Custom handler for translating from an actual structure timeval to string.
Definition: location.c:489
Type for default option handler for doubles.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
static struct ast_cli_entry cli_commands[]
Definition: location.c:1290
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
static struct ao2_container * cli_aor_get_container(const char *regex)
Definition: location.c:879
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
#define AST_STATSD_GAUGE
Support for publishing to a statsd server.
Definition: statsd.h:32
static struct ast_sorcery * sorcery
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Type for default option handler for stringfields.
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
struct ast_sip_cli_formatter_entry * contact_formatter
Definition: location.c:1322
static int pjsip_max_url_size
Definition: location.c:37
static void * cli_contact_retrieve_by_id(const char *id)
Definition: location.c:1076
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:186
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
static const char * cli_contact_get_id(const void *obj)
Definition: location.c:916
const char * name
Definition: res_pjsip_cli.h:58
static int voicemail_extension_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: location.c:675
static int pj_max_hostname
Definition: location.c:36

◆ ast_sip_location_add_contact()

int ast_sip_location_add_contact ( struct ast_sip_aor aor,
const char *  uri,
struct timeval  expiration_time,
const char *  path_info,
const char *  user_agent,
const char *  via_addr,
int  via_port,
const char *  call_id,
struct ast_sip_endpoint endpoint 
)

Add a new contact to an AOR.

Parameters
aorPointer to the AOR
uriFull contact URI
expiration_timeOptional expiration time of the contact
path_infoPath information
user_agentUser-Agent header from REGISTER request
via_addr
via_port
call_id
endpointThe endpoint that resulted in the contact being added
Return values
-1failure
0success
Warning
This function holds a named write lock on the aor. If you already hold the lock you should call ast_sip_location_add_contact_nolock instead.

Definition at line 429 of file location.c.

References ao2_lock, ao2_unlock, and ast_sip_location_add_contact_nolock().

433 {
434  int res;
435 
436  ao2_lock(aor);
437  res = ast_sip_location_add_contact_nolock(aor, uri, expiration_time, path_info, user_agent,
438  via_addr, via_port, call_id,
439  endpoint);
440  ao2_unlock(aor);
441 
442  return res;
443 }
#define ao2_unlock(a)
Definition: astobj2.h:730
int ast_sip_location_add_contact_nolock(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, struct ast_sip_endpoint *endpoint)
Add a new contact to an AOR without locking the AOR.
Definition: location.c:416
#define ao2_lock(a)
Definition: astobj2.h:718

◆ ast_sip_location_add_contact_nolock()

int ast_sip_location_add_contact_nolock ( struct ast_sip_aor aor,
const char *  uri,
struct timeval  expiration_time,
const char *  path_info,
const char *  user_agent,
const char *  via_addr,
int  via_port,
const char *  call_id,
struct ast_sip_endpoint endpoint 
)

Add a new contact to an AOR without locking the AOR.

Since
13.9.0
Parameters
aorPointer to the AOR
uriFull contact URI
expiration_timeOptional expiration time of the contact
path_infoPath information
user_agentUser-Agent header from REGISTER request
via_addr
via_port
call_id
endpointThe endpoint that resulted in the contact being added
Return values
-1failure
0success
Warning
This function should only be called if you already hold a named write lock on the aor.

Definition at line 416 of file location.c.

References ao2_cleanup, and ast_sip_location_create_contact().

Referenced by ast_sip_location_add_contact().

420 {
421  struct ast_sip_contact *contact;
422 
423  contact = ast_sip_location_create_contact(aor, uri, expiration_time, path_info,
424  user_agent, via_addr, via_port, call_id, 0, endpoint);
425  ao2_cleanup(contact);
426  return contact ? 0 : -1;
427 }
const ast_string_field call_id
Definition: res_pjsip.h:303
const ast_string_field user_agent
Definition: res_pjsip.h:303
const ast_string_field via_addr
Definition: res_pjsip.h:303
struct ast_sip_contact * ast_sip_location_create_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, int prune_on_boot, struct ast_sip_endpoint *endpoint)
Create a new contact for an AOR without locking the AOR.
Definition: location.c:355
Contact associated with an address of record.
Definition: res_pjsip.h:281
struct timeval expiration_time
Definition: res_pjsip.h:305
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const ast_string_field uri
Definition: res_pjsip.h:303

◆ ast_sip_location_create_contact()

struct ast_sip_contact* ast_sip_location_create_contact ( struct ast_sip_aor aor,
const char *  uri,
struct timeval  expiration_time,
const char *  path_info,
const char *  user_agent,
const char *  via_addr,
int  via_port,
const char *  call_id,
int  prune_on_boot,
struct ast_sip_endpoint endpoint 
)

Create a new contact for an AOR without locking the AOR.

Since
13.18.0
Parameters
aorPointer to the AOR
uriFull contact URI
expiration_timeOptional expiration time of the contact
path_infoPath information
user_agentUser-Agent header from REGISTER request
via_addr
via_port
call_id
prune_on_bootNon-zero if the contact cannot survive a restart/boot.
endpointThe endpoint that resulted in the contact being added
Returns
The created contact or NULL on failure.
Warning
This function should only be called if you already hold a named write lock on the aor.

Definition at line 355 of file location.c.

References ao2_bump, ao2_ref, ast_config_AST_SYSTEM_NAME, ast_md5_hash(), ast_sip_get_sorcery(), ast_sorcery_alloc(), ast_sorcery_create(), ast_sorcery_object_get_id(), ast_string_field_set, ast_strlen_zero, ast_sip_contact::authenticate_qualify, ast_sip_aor::authenticate_qualify, ast_sip_contact::endpoint, ast_sip_contact::endpoint_name, ast_sip_contact::expiration_time, MAX_OBJECT_FIELD, name, NULL, ast_sip_contact::outbound_proxy, ast_sip_aor::outbound_proxy, ast_sip_contact::path, ast_sip_contact::prune_on_boot, ast_sip_contact::qualify_frequency, ast_sip_aor::qualify_frequency, ast_sip_contact::qualify_timeout, ast_sip_aor::qualify_timeout, ast_sip_contact::reg_server, ast_sip_aor::support_path, and ast_sip_contact::via_port.

Referenced by ast_sip_location_add_contact_nolock(), and register_aor_core().

359 {
360  struct ast_sip_contact *contact;
361  char name[MAX_OBJECT_FIELD * 2 + 3];
362  char hash[33];
363 
364  ast_md5_hash(hash, uri);
365  snprintf(name, sizeof(name), "%s;@%s", ast_sorcery_object_get_id(aor), hash);
366 
367  contact = ast_sorcery_alloc(ast_sip_get_sorcery(), "contact", name);
368  if (!contact) {
369  return NULL;
370  }
371 
372  ast_string_field_set(contact, uri, uri);
373  contact->expiration_time = expiration_time;
374  contact->qualify_frequency = aor->qualify_frequency;
375  contact->qualify_timeout = aor->qualify_timeout;
377  if (path_info && aor->support_path) {
378  ast_string_field_set(contact, path, path_info);
379  }
380 
381  if (!ast_strlen_zero(aor->outbound_proxy)) {
383  }
384 
385  if (!ast_strlen_zero(user_agent)) {
387  }
388 
391  }
392 
393  if (!ast_strlen_zero(via_addr)) {
395  }
396  contact->via_port = via_port;
397 
398  if (!ast_strlen_zero(call_id)) {
400  }
401 
402  contact->endpoint = ao2_bump(endpoint);
403  if (endpoint) {
405  }
406 
407  contact->prune_on_boot = prune_on_boot;
408 
409  if (ast_sorcery_create(ast_sip_get_sorcery(), contact)) {
410  ao2_ref(contact, -1);
411  return NULL;
412  }
413  return contact;
414 }
double qualify_timeout
Definition: res_pjsip.h:387
int authenticate_qualify
Definition: res_pjsip.h:309
const ast_string_field outbound_proxy
Definition: res_pjsip.h:303
const ast_string_field call_id
Definition: res_pjsip.h:303
const ast_string_field user_agent
Definition: res_pjsip.h:303
const ast_string_field path
Definition: res_pjsip.h:303
const ast_string_field via_addr
Definition: res_pjsip.h:303
unsigned int qualify_frequency
Definition: res_pjsip.h:307
const ast_string_field outbound_proxy
Definition: res_pjsip.h:367
const ast_string_field reg_server
Definition: res_pjsip.h:303
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
struct ast_sip_endpoint * endpoint
Definition: res_pjsip.h:313
#define ao2_bump(obj)
Definition: astobj2.h:491
unsigned int qualify_frequency
Definition: res_pjsip.h:375
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
Definition: sorcery.c:2057
const ast_string_field endpoint_name
Definition: res_pjsip.h:303
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
double qualify_timeout
Definition: res_pjsip.h:311
unsigned int support_path
Definition: res_pjsip.h:385
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
Definition: sorcery.h:110
Contact associated with an address of record.
Definition: res_pjsip.h:281
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition: sorcery.c:1744
struct timeval expiration_time
Definition: res_pjsip.h:305
static const char name[]
Definition: cdr_mysql.c:74
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
int authenticate_qualify
Definition: res_pjsip.h:377
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.
Definition: main/utils.c:248
const ast_string_field uri
Definition: res_pjsip.h:303
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ ast_sip_location_delete_contact()

int ast_sip_location_delete_contact ( struct ast_sip_contact contact)

Delete a contact.

Parameters
contactContact object to delete
Return values
-1failure
0success

Definition at line 450 of file location.c.

References ast_sip_get_sorcery(), and ast_sorcery_delete().

Referenced by contact_expire(), destroy_contact(), prune_boot_contacts_cb(), and registrar_contact_delete().

451 {
452  return ast_sorcery_delete(ast_sip_get_sorcery(), contact);
453 }
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
Definition: sorcery.c:2233
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.

◆ ast_sip_location_prune_boot_contacts()

void ast_sip_location_prune_boot_contacts ( void  )

Prune the prune_on_boot contacts.

Since
13.18.0

Definition at line 469 of file location.c.

References ao2_callback, ao2_ref, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_fields(), NULL, and prune_boot_contacts_cb().

Referenced by ast_res_pjsip_initialize_configuration().

470 {
471  struct ao2_container *contacts;
472 
473  contacts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact",
475  if (contacts) {
477  ao2_ref(contacts, -1);
478  }
479 }
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
static int prune_boot_contacts_cb(void *obj, void *arg, int flags)
Definition: location.c:455
Perform no matching, return all objects.
Definition: sorcery.h:123
Return all matching objects.
Definition: sorcery.h:120
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
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.
Definition: sorcery.c:1897
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Generic container type.

◆ ast_sip_location_retrieve_aor()

struct ast_sip_aor* ast_sip_location_retrieve_aor ( const char *  aor_name)

Retrieve a named AOR.

Parameters
aor_nameName of the AOR
Return values
NULLif not found
non-NULLif found

Definition at line 147 of file location.c.

References ast_sip_get_sorcery(), and ast_sorcery_retrieve_by_id().

Referenced by ast_sip_for_each_aor(), ast_sip_location_retrieve_contact_and_aor_from_list_filtered(), find_aor(), find_aor_for_resource(), find_registrar_aor(), handle_slash(), notify_endpoint(), pjsip_acf_dial_contacts_read(), register_contact_transport_remove_cb(), and send_unsolicited_mwi_notify().

148 {
149  return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "aor", aor_name);
150 }
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.

◆ ast_sip_location_retrieve_aor_contacts()

struct ao2_container* ast_sip_location_retrieve_aor_contacts ( const struct ast_sip_aor aor)

Retrieve all contacts currently available for an AOR.

Parameters
aorPointer to the AOR
Return values
NULLif no contacts available
non-NULLif contacts available
Warning
Since this function prunes expired contacts before returning, it holds a named write lock on the aor. If you already hold the lock, call ast_sip_location_retrieve_aor_contacts_nolock instead.

Definition at line 247 of file location.c.

References AST_SIP_CONTACT_FILTER_DEFAULT, and ast_sip_location_retrieve_aor_contacts_filtered().

Referenced by ast_sip_for_each_contact(), format_ami_aor_handler(), gather_contacts_for_aor(), notify_endpoint(), pjsip_aor_function_read(), and send_unsolicited_mwi_notify().

248 {
250 }
Default filter flags.
Definition: res_pjsip.h:1006
struct ao2_container * ast_sip_location_retrieve_aor_contacts_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve all contacts currently available for an AOR and filter based on flags.
Definition: location.c:252

◆ ast_sip_location_retrieve_aor_contacts_filtered()

struct ao2_container* ast_sip_location_retrieve_aor_contacts_filtered ( const struct ast_sip_aor aor,
unsigned int  flags 
)

Retrieve all contacts currently available for an AOR and filter based on flags.

Since
13.16.0
Parameters
aorPointer to the AOR
flagsFiltering flags
Return values
NULLif no contacts available
non-NULLif contacts available
Warning
Since this function prunes expired contacts before returning, it holds a named write lock on the aor. If you already hold the lock, call ast_sip_location_retrieve_aor_contacts_nolock instead.

Definition at line 252 of file location.c.

References ao2_lock, ao2_unlock, and ast_sip_location_retrieve_aor_contacts_nolock_filtered().

Referenced by ast_sip_location_retrieve_aor_contacts(), ast_sip_location_retrieve_first_aor_contact_filtered(), and pjsip_acf_dial_contacts_read().

254 {
255  struct ao2_container *contacts;
256 
257  /* ao2_lock / ao2_unlock do not actually write aor since it has an ao2 lockobj. */
258  ao2_lock((void*)aor);
260  ao2_unlock((void*)aor);
261 
262  return contacts;
263 }
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_lock(a)
Definition: astobj2.h:718
struct ao2_container * ast_sip_location_retrieve_aor_contacts_nolock_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve all contacts currently available for an AOR without locking the AOR and filter based on flag...
Definition: location.c:219
Generic container type.

◆ ast_sip_location_retrieve_aor_contacts_nolock()

struct ao2_container* ast_sip_location_retrieve_aor_contacts_nolock ( const struct ast_sip_aor aor)

Retrieve all contacts currently available for an AOR without locking the AOR.

Since
13.9.0
Parameters
aorPointer to the AOR
Return values
NULLif no contacts available
non-NULLif contacts available
Warning
This function should only be called if you already hold a named write lock on the aor.

Definition at line 214 of file location.c.

References AST_SIP_CONTACT_FILTER_DEFAULT, and ast_sip_location_retrieve_aor_contacts_nolock_filtered().

Referenced by register_aor().

215 {
217 }
Default filter flags.
Definition: res_pjsip.h:1006
struct ao2_container * ast_sip_location_retrieve_aor_contacts_nolock_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve all contacts currently available for an AOR without locking the AOR and filter based on flag...
Definition: location.c:219

◆ ast_sip_location_retrieve_aor_contacts_nolock_filtered()

struct ao2_container* ast_sip_location_retrieve_aor_contacts_nolock_filtered ( const struct ast_sip_aor aor,
unsigned int  flags 
)

Retrieve all contacts currently available for an AOR without locking the AOR and filter based on flags.

Since
13.16.0
Parameters
aorPointer to the AOR
flagsFiltering flags
Return values
NULLif no contacts available
non-NULLif contacts available
Warning
This function should only be called if you already hold a named write lock on the aor.

Definition at line 219 of file location.c.

References ao2_callback, AST_SIP_CONTACT_FILTER_REACHABLE, ast_sip_get_sorcery(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_prefix(), contact_expire(), contact_link_static(), contact_remove_unreachable(), NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, ast_sip_aor::permanent_contacts, and prefix.

Referenced by ast_sip_location_retrieve_aor_contacts_filtered(), and ast_sip_location_retrieve_aor_contacts_nolock().

221 {
222  /* Give enough space for ;@ at the end, since that is our object naming scheme */
223  size_t prefix_len = strlen(ast_sorcery_object_get_id(aor)) + sizeof(";@") - 1;
224  char prefix[prefix_len + 1];
225  struct ao2_container *contacts;
226 
227  sprintf(prefix, "%s;@", ast_sorcery_object_get_id(aor)); /* Safe */
228  if (!(contacts = ast_sorcery_retrieve_by_prefix(ast_sip_get_sorcery(), "contact", prefix, prefix_len))) {
229  return NULL;
230  }
231 
232  /* Prune any expired contacts and delete them, we do this first because static contacts can never expire */
234 
235  /* Add any permanent contacts from the AOR */
236  if (aor->permanent_contacts) {
238  }
239 
240  if (flags & AST_SIP_CONTACT_FILTER_REACHABLE) {
242  }
243 
244  return contacts;
245 }
static int contact_remove_unreachable(void *obj, void *arg, int flags)
Internal callback function which removes any contact which is unreachable.
Definition: location.c:177
static int contact_expire(void *obj, void *arg, int flags)
Internal callback function which deletes and unlinks any expired contacts.
Definition: location.c:153
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
static int contact_link_static(void *obj, void *arg, int flags)
Internal callback function which links static contacts into another container.
Definition: location.c:168
struct ao2_container * ast_sorcery_retrieve_by_prefix(const struct ast_sorcery *sorcery, const char *type, const char *prefix, const size_t prefix_len)
Retrieve multiple objects whose id begins with the specified prefix.
Definition: sorcery.c:1984
#define NULL
Definition: resample.c:96
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
struct ao2_container * permanent_contacts
Definition: res_pjsip.h:383
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Return only reachable or unknown contacts.
Definition: res_pjsip.h:1009
Generic container type.
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ ast_sip_location_retrieve_contact()

struct ast_sip_contact* ast_sip_location_retrieve_contact ( const char *  contact_name)

Retrieve a named contact.

Parameters
contact_nameName of the contact
Return values
NULLif not found
non-NULLif found

Definition at line 350 of file location.c.

References ast_sip_get_sorcery(), and ast_sorcery_retrieve_by_id().

Referenced by register_contact_transport_remove_cb().

351 {
352  return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "contact", contact_name);
353 }
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.

◆ ast_sip_location_retrieve_contact_and_aor_from_list()

void ast_sip_location_retrieve_contact_and_aor_from_list ( const char *  aor_list,
struct ast_sip_aor **  aor,
struct ast_sip_contact **  contact 
)

Retrieve the first bound contact AND the AOR chosen from a list of AORs.

Parameters
aor_listA comma-separated list of AOR names
aorThe chosen AOR
contactThe chosen contact

Definition at line 266 of file location.c.

References AST_SIP_CONTACT_FILTER_DEFAULT, and ast_sip_location_retrieve_contact_and_aor_from_list_filtered().

Referenced by ast_sip_location_retrieve_contact_from_aor_list().

268 {
270 }
Default filter flags.
Definition: res_pjsip.h:1006
void ast_sip_location_retrieve_contact_and_aor_from_list_filtered(const char *aor_list, unsigned int flags, struct ast_sip_aor **aor, struct ast_sip_contact **contact)
Retrieve the first bound contact AND the AOR chosen from a list of AORs and filter based on flags...
Definition: location.c:272

◆ ast_sip_location_retrieve_contact_and_aor_from_list_filtered()

void ast_sip_location_retrieve_contact_and_aor_from_list_filtered ( const char *  aor_list,
unsigned int  flags,
struct ast_sip_aor **  aor,
struct ast_sip_contact **  contact 
)

Retrieve the first bound contact AND the AOR chosen from a list of AORs and filter based on flags.

Since
13.16.0
Parameters
aor_listA comma-separated list of AOR names
flagsFiltering flags
aorThe chosen AOR
contactThe chosen contact

Definition at line 272 of file location.c.

References ao2_ref, ast_log, ast_sip_location_retrieve_aor(), ast_sip_location_retrieve_first_aor_contact_filtered(), ast_strdupa, ast_strip(), ast_strlen_zero, LOG_WARNING, NULL, and strsep().

Referenced by ast_sip_location_retrieve_contact_and_aor_from_list(), and ast_sip_session_create_outgoing().

274 {
275  char *aor_name;
276  char *rest;
277 
278  /* If the location is still empty we have nowhere to go */
279  if (ast_strlen_zero(aor_list) || !(rest = ast_strdupa(aor_list))) {
280  ast_log(LOG_WARNING, "Unable to determine contacts from empty aor list\n");
281  return;
282  }
283 
284  *aor = NULL;
285  *contact = NULL;
286 
287  while ((aor_name = ast_strip(strsep(&rest, ",")))) {
288  *aor = ast_sip_location_retrieve_aor(aor_name);
289 
290  if (!(*aor)) {
291  continue;
292  }
294  /* If a valid contact is available use its URI for dialing */
295  if (*contact) {
296  break;
297  }
298 
299  ao2_ref(*aor, -1);
300  *aor = NULL;
301  }
302 }
#define LOG_WARNING
Definition: logger.h:274
struct ast_sip_aor * ast_sip_location_retrieve_aor(const char *aor_name)
Retrieve a named AOR.
Definition: location.c:147
#define NULL
Definition: resample.c:96
struct ast_sip_contact * ast_sip_location_retrieve_first_aor_contact_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve the first bound contact for an AOR and filter based on flags.
Definition: location.c:199
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
char * strsep(char **str, const char *delims)

◆ ast_sip_location_retrieve_contact_from_aor_list()

struct ast_sip_contact* ast_sip_location_retrieve_contact_from_aor_list ( const char *  aor_list)

Retrieve the first bound contact from a list of AORs.

Parameters
aor_listA comma-separated list of AOR names
Return values
NULLif no contacts available
non-NULLif contacts available

Definition at line 304 of file location.c.

References ao2_cleanup, ast_sip_location_retrieve_contact_and_aor_from_list(), cli_contact_populate_container(), and permanent_uri_sort_fn().

Referenced by ast_sip_create_subscription(), create_out_of_dialog_request(), handle_atsign(), handle_single_token(), insert_user_in_contact_uri(), mwi_contact_deleted(), and transfer().

305 {
306  struct ast_sip_aor *aor;
307  struct ast_sip_contact *contact;
308 
309  ast_sip_location_retrieve_contact_and_aor_from_list(aor_list, &aor, &contact);
310 
311  ao2_cleanup(aor);
312 
313  return contact;
314 }
A SIP address of record.
Definition: res_pjsip.h:361
void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor, struct ast_sip_contact **contact)
Retrieve the first bound contact AND the AOR chosen from a list of AORs.
Definition: location.c:266
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_sip_location_retrieve_contacts_from_aor_list()

struct ao2_container* ast_sip_location_retrieve_contacts_from_aor_list ( const char *  aor_list)

Retrieve all contacts from a list of AORs.

Parameters
aor_listA comma-separated list of AOR names
Return values
NULLif no contacts available
non-NULLcontainer (which must be freed) if contacts available

Definition at line 335 of file location.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_list, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, ast_sip_for_each_aor(), gather_contacts_for_aor(), NULL, and permanent_uri_sort_fn().

336 {
337  struct ao2_container *contacts;
338 
341  if (!contacts) {
342  return NULL;
343  }
344 
345  ast_sip_for_each_aor(aor_list, gather_contacts_for_aor, contacts);
346 
347  return contacts;
348 }
int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg)
For every aor in the comma separated aors string call the given &#39;on_aor&#39; handler. ...
Definition: location.c:684
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
#define NULL
Definition: resample.c:96
static int gather_contacts_for_aor(void *obj, void *arg, int flags)
Definition: location.c:319
static int permanent_uri_sort_fn(const void *obj_left, const void *obj_right, int flags)
Definition: location.c:495
Reject objects with duplicate keys in container.
Definition: astobj2.h:1192
Generic container type.

◆ ast_sip_location_retrieve_first_aor_contact()

struct ast_sip_contact* ast_sip_location_retrieve_first_aor_contact ( const struct ast_sip_aor aor)

Retrieve the first bound contact for an AOR.

Parameters
aorPointer to the AOR
Return values
NULLif no contacts available
non-NULLif contacts available

Definition at line 194 of file location.c.

References AST_SIP_CONTACT_FILTER_DEFAULT, and ast_sip_location_retrieve_first_aor_contact_filtered().

Referenced by handle_slash().

195 {
197 }
Default filter flags.
Definition: res_pjsip.h:1006
struct ast_sip_contact * ast_sip_location_retrieve_first_aor_contact_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve the first bound contact for an AOR and filter based on flags.
Definition: location.c:199

◆ ast_sip_location_retrieve_first_aor_contact_filtered()

struct ast_sip_contact* ast_sip_location_retrieve_first_aor_contact_filtered ( const struct ast_sip_aor aor,
unsigned int  flags 
)

Retrieve the first bound contact for an AOR and filter based on flags.

Since
13.16.0
Parameters
aorPointer to the AOR
flagsFiltering flags
Return values
NULLif no contacts available
non-NULLif contacts available

Definition at line 199 of file location.c.

References ao2_callback, ao2_cleanup, ao2_container_count(), ast_sip_location_retrieve_aor_contacts_filtered(), and NULL.

Referenced by ast_sip_location_retrieve_contact_and_aor_from_list_filtered(), and ast_sip_location_retrieve_first_aor_contact().

201 {
202  struct ao2_container *contacts;
203  struct ast_sip_contact *contact = NULL;
204 
206  if (contacts && ao2_container_count(contacts)) {
207  /* Get the first AOR contact in the container. */
208  contact = ao2_callback(contacts, 0, NULL, NULL);
209  }
210  ao2_cleanup(contacts);
211  return contact;
212 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define NULL
Definition: resample.c:96
struct ao2_container * ast_sip_location_retrieve_aor_contacts_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve all contacts currently available for an AOR and filter based on flags.
Definition: location.c:252
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.

◆ ast_sip_location_update_contact()

int ast_sip_location_update_contact ( struct ast_sip_contact contact)

Update a contact.

Parameters
contactNew contact object with details
Return values
-1failure
0success

Definition at line 445 of file location.c.

References ast_sip_get_sorcery(), and ast_sorcery_update().

Referenced by register_aor_core().

446 {
447  return ast_sorcery_update(ast_sip_get_sorcery(), contact);
448 }
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
Definition: sorcery.c:2145

◆ ast_sip_validate_uri_length()

int ast_sip_validate_uri_length ( const char *  contact_uri)

Definition at line 525 of file location.c.

References ast_strdupa, ast_strip_quoted(), host, pj_max_hostname, pjsip_max_url_size, and strsep().

Referenced by permanent_uri_handler(), sip_outbound_registration_apply(), and validate_publish_config().

526 {
527  int max_length = pj_max_hostname - 1;
528  char *contact = ast_strdupa(contact_uri);
529  char *host;
530  char *at;
531  int theres_a_port = 0;
532 
533  if (strlen(contact_uri) > pjsip_max_url_size - 1) {
534  return -1;
535  }
536 
537  contact = ast_strip_quoted(contact, "<", ">");
538 
539  if (!strncasecmp(contact, "sip:", 4)) {
540  host = contact + 4;
541  } else if (!strncasecmp(contact, "sips:", 5)) {
542  host = contact + 5;
543  } else {
544  /* Not a SIP URI */
545  return -1;
546  }
547 
548  at = strchr(contact, '@');
549  if (at) {
550  /* sip[s]:user@host */
551  host = at + 1;
552  }
553 
554  if (host[0] == '[') {
555  /* Host is an IPv6 address. Just get up to the matching bracket */
556  char *close_bracket;
557 
558  close_bracket = strchr(host, ']');
559  if (!close_bracket) {
560  return -1;
561  }
562  close_bracket++;
563  if (*close_bracket == ':') {
564  theres_a_port = 1;
565  }
566  *close_bracket = '\0';
567  } else {
568  /* uri parameters could contain ';' so trim them off first */
569  host = strsep(&host, ";?");
570  /* Host is FQDN or IPv4 address. Need to find closing delimiter */
571  if (strchr(host, ':')) {
572  theres_a_port = 1;
573  host = strsep(&host, ":");
574  }
575  }
576 
577  if (!theres_a_port) {
578  max_length -= strlen("_sips.tcp.");
579  }
580 
581  if (strlen(host) > max_length) {
582  return -1;
583  }
584 
585  return 0;
586 }
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
Definition: main/utils.c:1639
static char host[256]
Definition: muted.c:77
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
char * strsep(char **str, const char *delims)
static int pjsip_max_url_size
Definition: location.c:37
static int pj_max_hostname
Definition: location.c:36

◆ cli_aor_gather_contacts()

static int cli_aor_gather_contacts ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 909 of file location.c.

References ast_sip_for_each_contact(), and cli_contact_populate_container().

Referenced by cli_contact_get_container().

910 {
911  struct ast_sip_aor *aor = obj;
912 
914 }
A SIP address of record.
Definition: res_pjsip.h:361
int ast_sip_for_each_contact(const struct ast_sip_aor *aor, ao2_callback_fn on_contact, void *arg)
For every contact on an AOR call the given &#39;on_contact&#39; handler.
Definition: location.c:719
static int cli_contact_populate_container(void *obj, void *arg, int flags)
Definition: location.c:902

◆ cli_aor_get_container()

static struct ao2_container* cli_aor_get_container ( const char *  regex)
static

Definition at line 879 of file location.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_list, ao2_container_dup(), ao2_ref, ast_sip_get_sorcery(), ast_sorcery_object_id_compare(), ast_sorcery_object_id_sort(), ast_sorcery_retrieve_by_regex(), container, and NULL.

Referenced by ast_sip_initialize_sorcery_location().

880 {
881  struct ao2_container *container;
882  struct ao2_container *s_container;
883 
885  if (!container) {
886  return NULL;
887  }
888 
889  /* Create a sorted container of aors. */
892  if (s_container
893  && ao2_container_dup(s_container, container, 0)) {
894  ao2_ref(s_container, -1);
895  s_container = NULL;
896  }
897  ao2_ref(container, -1);
898 
899  return s_container;
900 }
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition: sorcery.c:2459
#define NULL
Definition: resample.c:96
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.
Definition: sorcery.c:1949
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
Definition: sorcery.c:2435
struct ao2_container * container
Definition: res_fax.c:502
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.
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Generic container type.

◆ cli_aor_get_id()

static const char* cli_aor_get_id ( const void *  obj)
static

Definition at line 1151 of file location.c.

References ast_sorcery_object_get_id().

Referenced by ast_sip_initialize_sorcery_location().

1152 {
1153  return ast_sorcery_object_get_id(obj);
1154 }
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312

◆ cli_aor_iterate()

static int cli_aor_iterate ( void *  container,
ao2_callback_fn  callback,
void *  args 
)
static

Definition at line 1139 of file location.c.

References ast_sip_for_each_aor(), and container.

Referenced by ast_sip_initialize_sorcery_location().

1140 {
1141  const char *aor_list = container;
1142 
1143  return ast_sip_for_each_aor(aor_list, callback, args);
1144 }
int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg)
For every aor in the comma separated aors string call the given &#39;on_aor&#39; handler. ...
Definition: location.c:684
const char * args
struct ao2_container * container
Definition: res_fax.c:502

◆ cli_aor_print_body()

static int cli_aor_print_body ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1183 of file location.c.

References ao2_ref, ast_assert, ast_sip_cli_print_sorcery_objectset(), ast_sip_lookup_cli_formatter(), ast_sorcery_object_get_id(), ast_str_append(), CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, context, ast_sip_cli_context::indent_level, ast_sip_cli_formatter_entry::iterate, ast_sip_aor::max_contacts, NULL, ast_sip_cli_context::output_buffer, ast_sip_cli_formatter_entry::print_body, ast_sip_cli_context::recurse, ast_sip_cli_context::show_details, and ast_sip_cli_context::show_details_only_level_0.

Referenced by ast_sip_initialize_sorcery_location().

1184 {
1185  struct ast_sip_aor *aor = obj;
1186  struct ast_sip_cli_context *context = arg;
1187  int indent;
1188  int flexwidth;
1189 
1190  ast_assert(context->output_buffer != NULL);
1191 
1192 // context->current_aor = aor;
1193 
1194  indent = CLI_INDENT_TO_SPACES(context->indent_level);
1195  flexwidth = CLI_LAST_TABSTOP - indent - 12;
1196 
1197  ast_str_append(&context->output_buffer, 0, "%*s: %-*.*s %12u\n",
1198  indent,
1199  "Aor",
1200  flexwidth, flexwidth,
1202 
1203  if (context->recurse) {
1204  struct ast_sip_cli_formatter_entry *formatter_entry;
1205 
1206  context->indent_level++;
1207 
1208  formatter_entry = ast_sip_lookup_cli_formatter("contact");
1209  if (formatter_entry) {
1210  formatter_entry->iterate(aor, formatter_entry->print_body, context);
1211  ao2_ref(formatter_entry, -1);
1212  }
1213 
1214  context->indent_level--;
1215 
1216  if (context->indent_level == 0) {
1217  ast_str_append(&context->output_buffer, 0, "\n");
1218  }
1219  }
1220 
1221  if (context->show_details || (context->show_details_only_level_0 && context->indent_level == 0)) {
1222  ast_str_append(&context->output_buffer, 0, "\n");
1223  ast_sip_cli_print_sorcery_objectset(aor, context, 0);
1224  }
1225 
1226  return 0;
1227 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
A SIP address of record.
Definition: res_pjsip.h:361
Definition: res_pjsip_cli.h:52
#define CLI_LAST_TABSTOP
Definition: res_pjsip_cli.h:27
unsigned int max_contacts
Definition: res_pjsip.h:379
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
struct ast_sip_cli_formatter_entry * ast_sip_lookup_cli_formatter(const char *name)
Looks up a CLI formatter by type.
Definition: pjsip_cli.c:305
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object&#39;s ast_variable list.
Definition: pjsip_cli.c:36
unsigned show_details_only_level_0
Definition: res_pjsip_cli.h:46

◆ cli_aor_print_header()

static int cli_aor_print_header ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1156 of file location.c.

References ao2_ref, ast_assert, ast_sip_lookup_cli_formatter(), ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, context, ast_sip_cli_context::indent_level, NULL, ast_sip_cli_context::output_buffer, ast_sip_cli_formatter_entry::print_header, and ast_sip_cli_context::recurse.

Referenced by ast_sip_initialize_sorcery_location().

1157 {
1158  struct ast_sip_cli_context *context = arg;
1159  int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1160  int filler = CLI_LAST_TABSTOP - indent - 7;
1161 
1162  ast_assert(context->output_buffer != NULL);
1163 
1164  ast_str_append(&context->output_buffer, 0,
1165  "%*s: <Aor%*.*s> <MaxContact>\n",
1166  indent, "Aor", filler, filler, CLI_HEADER_FILLER);
1167 
1168  if (context->recurse) {
1169  struct ast_sip_cli_formatter_entry *formatter_entry;
1170 
1171  context->indent_level++;
1172  formatter_entry = ast_sip_lookup_cli_formatter("contact");
1173  if (formatter_entry) {
1174  formatter_entry->print_header(NULL, context, 0);
1175  ao2_ref(formatter_entry, -1);
1176  }
1177  context->indent_level--;
1178  }
1179 
1180  return 0;
1181 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
Definition: res_pjsip_cli.h:52
#define CLI_LAST_TABSTOP
Definition: res_pjsip_cli.h:27
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
struct ast_sip_cli_formatter_entry * ast_sip_lookup_cli_formatter(const char *name)
Looks up a CLI formatter by type.
Definition: pjsip_cli.c:305
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ cli_aor_retrieve_by_id()

static void* cli_aor_retrieve_by_id ( const char *  id)
static

Definition at line 1146 of file location.c.

References ast_sip_get_sorcery(), and ast_sorcery_retrieve_by_id().

Referenced by ast_sip_initialize_sorcery_location().

1147 {
1148  return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "aor", id);
1149 }
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.

◆ cli_contact_compare()

static int cli_contact_compare ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 947 of file location.c.

References CMP_MATCH, CMP_STOP, ast_sip_contact_wrapper::contact_id, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by cli_contact_get_container().

948 {
949  const struct ast_sip_contact_wrapper *left_wrapper = obj;
950  const struct ast_sip_contact_wrapper *right_wrapper = arg;
951  const char *right_key = arg;
952  int cmp = 0;
953 
954  switch (flags & OBJ_SEARCH_MASK) {
955  case OBJ_SEARCH_OBJECT:
956  right_key = right_wrapper->contact_id;
957  /* Fall through */
958  case OBJ_SEARCH_KEY:
959  if (strcmp(left_wrapper->contact_id, right_key) == 0) {;
960  cmp = CMP_MATCH | CMP_STOP;
961  }
962  break;
964  if (strncmp(left_wrapper->contact_id, right_key, strlen(right_key)) == 0) {
965  cmp = CMP_MATCH;
966  }
967  break;
968  default:
969  cmp = 0;
970  break;
971  }
972 
973  return cmp;
974 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076

◆ cli_contact_get_container()

static struct ao2_container* cli_contact_get_container ( const char *  regex)
static

Definition at line 1026 of file location.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_callback, ao2_cleanup, ao2_container_alloc_list, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, ao2_ref, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_fields(), ast_sorcery_retrieve_by_regex(), ast_strlen_zero, ast_variable_new, ast_variables_destroy(), cli_aor_gather_contacts(), cli_contact_compare(), cli_contact_sort(), cli_filter_contacts(), cli_gather_contact(), NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, and RAII_VAR.

Referenced by ast_sip_initialize_sorcery_location(), and cli_contact_retrieve_by_id().

1027 {
1028  RAII_VAR(struct ao2_container *, aors, NULL, ao2_cleanup);
1029  RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
1030  RAII_VAR(struct ast_variable *, var_aor, NULL, ast_variables_destroy);
1031  struct ao2_container *contacts_container;
1032  regex_t regexbuf;
1033 
1034  if (!(var_aor = ast_variable_new("contact !=", "", ""))) {
1035  return NULL;
1036  }
1037 
1038  /* Retrieving all the contacts may result in finding the same contact multiple
1039  * times. So that they don't get displayed multiple times we only allow a
1040  * single one to be placed into the container.
1041  */
1044  if (!contacts_container) {
1045  return NULL;
1046  }
1047 
1048  contacts = ast_sorcery_retrieve_by_regex(ast_sip_get_sorcery(), "contact", regex);
1049  if (!contacts) {
1050  ao2_ref(contacts_container, -1);
1051  return NULL;
1052  }
1053  ao2_callback(contacts, OBJ_NODATA, cli_gather_contact, contacts_container);
1054 
1056  "aor", AST_RETRIEVE_FLAG_MULTIPLE, var_aor);
1057  if (!aors) {
1058  ao2_ref(contacts_container, -1);
1059  return NULL;
1060  }
1061 
1062  ao2_callback(aors, OBJ_NODATA, cli_aor_gather_contacts, contacts_container);
1063 
1064  if (!ast_strlen_zero(regex)) {
1065  if (regcomp(&regexbuf, regex, REG_EXTENDED | REG_NOSUB)) {
1066  ao2_ref(contacts_container, -1);
1067  return NULL;
1068  }
1069  ao2_callback(contacts_container, OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA, cli_filter_contacts, &regexbuf);
1070  regfree(&regexbuf);
1071  }
1072 
1073  return contacts_container;
1074 }
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
static int cli_filter_contacts(void *obj, void *arg, int flags)
Definition: location.c:981
Structure for variables, used for configurations and for channel variables.
Return all matching objects.
Definition: sorcery.h:120
#define NULL
Definition: resample.c:96
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.
Definition: sorcery.c:1949
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_variable_new(name, value, filename)
static int cli_gather_contact(void *obj, void *arg, int flags)
Definition: location.c:993
static int cli_aor_gather_contacts(void *obj, void *arg, int flags)
Definition: location.c:909
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948
static int cli_contact_compare(void *obj, void *arg, int flags)
Definition: location.c:947
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.
Definition: sorcery.c:1897
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Reject objects with duplicate keys in container.
Definition: astobj2.h:1192
Generic container type.
static int cli_contact_sort(const void *obj, const void *arg, int flags)
Definition: location.c:922

◆ cli_contact_get_id()

static const char* cli_contact_get_id ( const void *  obj)
static

Definition at line 916 of file location.c.

References ast_sip_contact_wrapper::contact_id.

Referenced by ast_sip_initialize_sorcery_location().

917 {
918  const struct ast_sip_contact_wrapper *wrapper = obj;
919  return wrapper->contact_id;
920 }
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396

◆ cli_contact_iterate()

static int cli_contact_iterate ( void *  container,
ao2_callback_fn  callback,
void *  args 
)
static

Definition at line 976 of file location.c.

References ast_sip_for_each_contact().

Referenced by ast_sip_initialize_sorcery_location().

977 {
978  return ast_sip_for_each_contact(container, callback, args);
979 }
const char * args
int ast_sip_for_each_contact(const struct ast_sip_aor *aor, ao2_callback_fn on_contact, void *arg)
For every contact on an AOR call the given &#39;on_contact&#39; handler.
Definition: location.c:719
struct ao2_container * container
Definition: res_fax.c:502

◆ cli_contact_populate_container()

static int cli_contact_populate_container ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 902 of file location.c.

References ao2_link.

Referenced by ast_sip_location_retrieve_contact_from_aor_list(), cli_aor_gather_contacts(), and gather_contacts_for_aor().

903 {
904  ao2_link(arg, obj);
905 
906  return 0;
907 }
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ cli_contact_print_body()

static int cli_contact_print_body ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1106 of file location.c.

References ao2_cleanup, ast_sip_contact::aor, ast_assert, ast_sip_get_contact_short_status_label(), ast_sip_get_contact_status(), ast_sorcery_object_get_id(), ast_str_append(), AVAILABLE, CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, ast_sip_contact_wrapper::contact, context, ast_sip_cli_context::indent_level, NAN, NULL, ast_sip_cli_context::output_buffer, ast_sip_contact_status::rtt, status, ast_sip_contact_status::status, UNKNOWN, and ast_sip_contact::uri.

Referenced by ast_sip_initialize_sorcery_location().

1107 {
1108  struct ast_sip_contact_wrapper *wrapper = obj;
1109  struct ast_sip_contact *contact = wrapper->contact;
1110  struct ast_sip_cli_context *context = arg;
1111  int indent;
1112  int flexwidth;
1113  const char *contact_id = ast_sorcery_object_get_id(contact);
1114  const char *hash_start = contact_id + strlen(contact->aor) + 2;
1116 
1117  ast_assert(contact->uri != NULL);
1118  ast_assert(context->output_buffer != NULL);
1119 
1120  status = ast_sip_get_contact_status(contact);
1121 
1122  indent = CLI_INDENT_TO_SPACES(context->indent_level);
1123  flexwidth = CLI_LAST_TABSTOP - indent - 9 - strlen(contact->aor) + 1;
1124 
1125  ast_str_append(&context->output_buffer, 0, "%*s: %s/%-*.*s %-10.10s %-7.7s %11.3f\n",
1126  indent,
1127  "Contact",
1128  contact->aor,
1129  flexwidth, flexwidth,
1130  contact->uri,
1131  hash_start,
1133  (status && (status->status == AVAILABLE)) ? ((long long) status->rtt) / 1000.0 : NAN);
1134 
1135  ao2_cleanup(status);
1136  return 0;
1137 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
A contact&#39;s status.
Definition: res_pjsip.h:341
struct ast_sip_contact_status * ast_sip_get_contact_status(const struct ast_sip_contact *contact)
Retrieve the current status for a contact.
#define CLI_LAST_TABSTOP
Definition: res_pjsip_cli.h:27
#define NAN
const char * ast_sip_get_contact_short_status_label(const enum ast_sip_contact_status_type status)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
enum ast_sip_contact_status_type status
Definition: res_pjsip.h:351
struct ast_sip_contact * contact
Definition: res_pjsip.h:402
Contact associated with an address of record.
Definition: res_pjsip.h:281
const ast_string_field aor
Definition: res_pjsip.h:303
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
const ast_string_field uri
Definition: res_pjsip.h:303
jack_status_t status
Definition: app_jack.c:146

◆ cli_contact_print_header()

static int cli_contact_print_header ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1091 of file location.c.

References ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, context, ast_sip_cli_context::indent_level, NULL, and ast_sip_cli_context::output_buffer.

Referenced by ast_sip_initialize_sorcery_location().

1092 {
1093  struct ast_sip_cli_context *context = arg;
1094  int indent = CLI_INDENT_TO_SPACES(context->indent_level);
1095  int filler = CLI_LAST_TABSTOP - indent - 23;
1096 
1097  ast_assert(context->output_buffer != NULL);
1098 
1099  ast_str_append(&context->output_buffer, 0,
1100  "%*s: <Aor/ContactUri%*.*s> <Hash....> <Status> <RTT(ms)..>\n",
1101  indent, "Contact", filler, filler, CLI_HEADER_FILLER);
1102 
1103  return 0;
1104 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
#define CLI_LAST_TABSTOP
Definition: res_pjsip_cli.h:27
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ cli_contact_retrieve_by_id()

static void* cli_contact_retrieve_by_id ( const char *  id)
static

Definition at line 1076 of file location.c.

References ao2_find, ao2_ref, cli_contact_get_container(), container, NULL, and OBJ_SEARCH_KEY.

Referenced by ast_sip_initialize_sorcery_location().

1077 {
1078  struct ao2_container *container;
1079  void *obj;
1080 
1081  container = cli_contact_get_container("");
1082  if (!container) {
1083  return NULL;
1084  }
1085 
1086  obj = ao2_find(container, id, OBJ_SEARCH_KEY);
1087  ao2_ref(container, -1);
1088  return obj;
1089 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * container
Definition: res_fax.c:502
static struct ao2_container * cli_contact_get_container(const char *regex)
Definition: location.c:1026
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
Generic container type.

◆ cli_contact_sort()

static int cli_contact_sort ( const void *  obj,
const void *  arg,
int  flags 
)
static

Definition at line 922 of file location.c.

References ast_sip_contact_wrapper::contact_id, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by cli_contact_get_container().

923 {
924  const struct ast_sip_contact_wrapper *left_wrapper = obj;
925  const struct ast_sip_contact_wrapper *right_wrapper = arg;
926  const char *right_key = arg;
927  int cmp = 0;
928 
929  switch (flags & OBJ_SEARCH_MASK) {
930  case OBJ_SEARCH_OBJECT:
931  right_key = right_wrapper->contact_id;
932  /* Fall through */
933  case OBJ_SEARCH_KEY:
934  cmp = strcmp(left_wrapper->contact_id, right_key);
935  break;
937  cmp = strncmp(left_wrapper->contact_id, right_key, strlen(right_key));
938  break;
939  default:
940  cmp = 0;
941  break;
942  }
943 
944  return cmp;
945 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076

◆ cli_filter_contacts()

static int cli_filter_contacts ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 981 of file location.c.

References CMP_MATCH, ast_sip_contact_wrapper::contact_id, and NULL.

Referenced by cli_contact_get_container().

982 {
983  struct ast_sip_contact_wrapper *wrapper = obj;
984  regex_t *regexbuf = arg;
985 
986  if (!regexec(regexbuf, wrapper->contact_id, 0, NULL, 0)) {
987  return 0;
988  }
989 
990  return CMP_MATCH;
991 }
#define NULL
Definition: resample.c:96
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396

◆ cli_gather_contact()

static int cli_gather_contact ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 993 of file location.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ao2_cleanup, ao2_link, ast_sip_contact::aor, ast_config_AST_SYSTEM_NAME, ast_malloc, ast_strdup, contact_wrapper_destroy(), NULL, RAII_VAR, ast_sip_contact::reg_server, and ast_sip_contact::uri.

Referenced by cli_contact_get_container().

994 {
995  struct ast_sip_contact *contact = obj;
996  RAII_VAR(struct ast_sip_contact_wrapper *, wrapper, NULL, ao2_cleanup);
997 
998  if (strcmp(contact->reg_server, ast_config_AST_SYSTEM_NAME ?: "")) {
999  return 0;
1000  }
1001 
1002  wrapper = ao2_alloc_options(sizeof(struct ast_sip_contact_wrapper),
1004  if (!wrapper) {
1005  return -1;
1006  }
1007 
1008  wrapper->contact_id = ast_malloc(strlen(contact->aor) + strlen(contact->uri) + 2);
1009  if (!wrapper->contact_id) {
1010  return -1;
1011  }
1012  sprintf(wrapper->contact_id, "%s/%s", contact->aor, contact->uri);
1013 
1014  wrapper->aor_id = ast_strdup(contact->aor);
1015  if (!wrapper->aor_id) {
1016  return -1;
1017  }
1018 
1019  wrapper->contact = ao2_bump(contact);
1020 
1021  ao2_link(arg, wrapper);
1022 
1023  return 0;
1024 }
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const ast_string_field reg_server
Definition: res_pjsip.h:303
#define NULL
Definition: resample.c:96
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
#define ao2_bump(obj)
Definition: astobj2.h:491
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
static void contact_wrapper_destroy(void *obj)
Definition: location.c:710
Contact associated with an address of record.
Definition: res_pjsip.h:281
const ast_string_field aor
Definition: res_pjsip.h:303
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const ast_string_field uri
Definition: res_pjsip.h:303
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ cli_get_aors()

static struct ao2_container* cli_get_aors ( void  )
static

Definition at line 1229 of file location.c.

References AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_fields(), and NULL.

Referenced by ami_show_aors().

1230 {
1231  struct ao2_container *aors;
1232 
1235 
1236  return aors;
1237 }
Perform no matching, return all objects.
Definition: sorcery.h:123
Return all matching objects.
Definition: sorcery.h:120
#define NULL
Definition: resample.c:96
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.
Definition: sorcery.c:1897
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Generic container type.

◆ contact_alloc()

static void* contact_alloc ( const char *  name)
static

Allocator for contact.

Definition at line 120 of file location.c.

References ao2_cleanup, ast_sip_contact::aor, ast_assert, ast_sorcery_generic_alloc(), ast_strdupa, ast_string_field_init, ast_string_field_set, contact_destroy(), id, and NULL.

Referenced by ast_sip_initialize_sorcery_location().

121 {
123  char *id = ast_strdupa(name);
124  char *aor = id;
125  char *aor_separator = NULL;
126 
127  if (!contact) {
128  return NULL;
129  }
130 
131  if (ast_string_field_init(contact, 256)) {
132  ao2_cleanup(contact);
133  return NULL;
134  }
135 
136  /* Dynamic contacts are delimited with ";@" and static ones with "@@" */
137  if ((aor_separator = strstr(id, ";@")) || (aor_separator = strstr(id, "@@"))) {
138  *aor_separator = '\0';
139  }
140  ast_assert(aor_separator != NULL);
141 
142  ast_string_field_set(contact, aor, aor);
143 
144  return contact;
145 }
#define ast_assert(a)
Definition: utils.h:695
static void contact_destroy(void *obj)
Destructor for contact.
Definition: location.c:111
#define NULL
Definition: resample.c:96
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
Contact associated with an address of record.
Definition: res_pjsip.h:281
static const char name[]
Definition: cdr_mysql.c:74
const ast_string_field aor
Definition: res_pjsip.h:303
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
enum queue_result id
Definition: app_queue.c:1507
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ contact_apply_handler()

static int contact_apply_handler ( const struct ast_sorcery sorcery,
void *  object 
)
static

Always create a contact_status for each contact.

Definition at line 1326 of file location.c.

References ao2_cleanup, ast_log, ast_res_pjsip_find_or_create_contact_status(), ast_sorcery_object_get_id(), ast_strlen_zero, LOG_ERROR, status, and ast_sip_contact::uri.

Referenced by ast_sip_initialize_sorcery_location().

1327 {
1329  struct ast_sip_contact *contact = object;
1330 
1331  if (ast_strlen_zero(contact->uri)) {
1332  ast_log(LOG_ERROR, "A URI on dynamic contact '%s' is empty\n",
1333  ast_sorcery_object_get_id(contact));
1334  return -1;
1335  }
1337  ao2_cleanup(status);
1338 
1339  return status ? 0 : -1;
1340 }
A contact&#39;s status.
Definition: res_pjsip.h:341
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define LOG_ERROR
Definition: logger.h:285
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const ast_string_field uri
Definition: res_pjsip.h:303
jack_status_t status
Definition: app_jack.c:146
struct ast_sip_contact_status * ast_res_pjsip_find_or_create_contact_status(const struct ast_sip_contact *contact)

◆ contact_destroy()

static void contact_destroy ( void *  obj)
static

Destructor for contact.

Definition at line 111 of file location.c.

References ao2_cleanup, ast_string_field_free_memory, and ast_sip_contact::endpoint.

Referenced by contact_alloc().

112 {
113  struct ast_sip_contact *contact = obj;
114 
116  ao2_cleanup(contact->endpoint);
117 }
struct ast_sip_endpoint * endpoint
Definition: res_pjsip.h:313
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ contact_expire()

static int contact_expire ( void *  obj,
void *  arg,
int  flags 
)
static

Internal callback function which deletes and unlinks any expired contacts.

Definition at line 153 of file location.c.

References ast_sip_location_delete_contact(), ast_tvdiff_ms(), ast_tvnow(), CMP_MATCH, and ast_sip_contact::expiration_time.

Referenced by ast_sip_location_retrieve_aor_contacts_nolock_filtered().

154 {
155  struct ast_sip_contact *contact = obj;
156 
157  /* If the contact has not yet expired it is valid */
158  if (ast_tvdiff_ms(contact->expiration_time, ast_tvnow()) > 0) {
159  return 0;
160  }
161 
163 
164  return CMP_MATCH;
165 }
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
int ast_sip_location_delete_contact(struct ast_sip_contact *contact)
Delete a contact.
Definition: location.c:450
Contact associated with an address of record.
Definition: res_pjsip.h:281
struct timeval expiration_time
Definition: res_pjsip.h:305

◆ contact_link_static()

static int contact_link_static ( void *  obj,
void *  arg,
int  flags 
)
static

Internal callback function which links static contacts into another container.

Definition at line 168 of file location.c.

References ao2_link.

Referenced by ast_sip_location_retrieve_aor_contacts_nolock_filtered().

169 {
170  struct ao2_container *dest = arg;
171 
172  ao2_link(dest, obj);
173  return 0;
174 }
Generic container type.
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ contact_remove_unreachable()

static int contact_remove_unreachable ( void *  obj,
void *  arg,
int  flags 
)
static

Internal callback function which removes any contact which is unreachable.

Definition at line 177 of file location.c.

References ao2_ref, ast_sip_get_contact_status(), CMP_MATCH, status, ast_sip_contact_status::status, and UNAVAILABLE.

Referenced by ast_sip_location_retrieve_aor_contacts_nolock_filtered().

178 {
179  struct ast_sip_contact *contact = obj;
181  int unreachable;
182 
183  status = ast_sip_get_contact_status(contact);
184  if (!status) {
185  return 0;
186  }
187 
188  unreachable = (status->status == UNAVAILABLE);
189  ao2_ref(status, -1);
190 
191  return unreachable ? CMP_MATCH : 0;
192 }
A contact&#39;s status.
Definition: res_pjsip.h:341
struct ast_sip_contact_status * ast_sip_get_contact_status(const struct ast_sip_contact *contact)
Retrieve the current status for a contact.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
enum ast_sip_contact_status_type status
Definition: res_pjsip.h:351
Contact associated with an address of record.
Definition: res_pjsip.h:281
jack_status_t status
Definition: app_jack.c:146

◆ contact_to_var_list()

static int contact_to_var_list ( void *  object,
void *  arg,
int  flags 
)
static

Definition at line 647 of file location.c.

References ast_variable_list_append, ast_variable_new, ast_sip_contact_wrapper::contact, ast_sip_contact::uri, and var.

Referenced by contacts_to_var_list().

648 {
649  struct ast_sip_contact_wrapper *wrapper = object;
650  struct ast_variable **var = arg;
651 
652  ast_variable_list_append(&*var, ast_variable_new("contact", wrapper->contact->uri, ""));
653 
654  return 0;
655 }
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
#define ast_variable_new(name, value, filename)
struct ast_sip_contact * contact
Definition: res_pjsip.h:402
const ast_string_field uri
Definition: res_pjsip.h:303
#define ast_variable_list_append(head, new_var)

◆ contact_wrapper_destroy()

static void contact_wrapper_destroy ( void *  obj)
static

Definition at line 710 of file location.c.

References ao2_cleanup, ast_sip_contact_wrapper::aor_id, ast_free, ast_sip_contact_wrapper::contact, and ast_sip_contact_wrapper::contact_id.

Referenced by ast_sip_for_each_contact(), and cli_gather_contact().

711 {
712  struct ast_sip_contact_wrapper *wrapper = obj;
713 
714  ast_free(wrapper->aor_id);
715  ast_free(wrapper->contact_id);
716  ao2_cleanup(wrapper->contact);
717 }
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:396
struct ast_sip_contact * contact
Definition: res_pjsip.h:402
#define ast_free(a)
Definition: astmm.h:182
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ contacts_to_str()

static int contacts_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 808 of file location.c.

References ast_free, ast_sip_contact_to_str(), ast_sip_for_each_contact(), ast_str_buffer(), ast_str_create, ast_str_truncate(), ast_strdup, MAX_OBJECT_FIELD, NULL, and str.

Referenced by ast_sip_initialize_sorcery_location().

809 {
810  const struct ast_sip_aor *aor = obj;
811  struct ast_str *str;
812 
814  if (!str) {
815  *buf = NULL;
816  return -1;
817  }
818 
820  ast_str_truncate(str, -1);
821 
822  *buf = ast_strdup(ast_str_buffer(str));
823  ast_free(str);
824 
825  return *buf ? 0 : -1;
826 }
int ast_sip_contact_to_str(void *object, void *arg, int flags)
Handler used to convert a contact to a string.
Definition: location.c:767
A SIP address of record.
Definition: res_pjsip.h:361
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
Definition: strings.h:738
int ast_sip_for_each_contact(const struct ast_sip_aor *aor, ao2_callback_fn on_contact, void *arg)
For every contact on an AOR call the given &#39;on_contact&#39; handler.
Definition: location.c:719
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
Definition: sorcery.h:110
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ contacts_to_var_list()

static int contacts_to_var_list ( const void *  obj,
struct ast_variable **  fields 
)
static

Definition at line 657 of file location.c.

References ast_sip_for_each_contact(), and contact_to_var_list().

Referenced by ast_sip_initialize_sorcery_location().

658 {
659  const struct ast_sip_aor *aor = obj;
660 
662 
663  return 0;
664 }
A SIP address of record.
Definition: res_pjsip.h:361
static int contact_to_var_list(void *object, void *arg, int flags)
Definition: location.c:647
int ast_sip_for_each_contact(const struct ast_sip_aor *aor, ao2_callback_fn on_contact, void *arg)
For every contact on an AOR call the given &#39;on_contact&#39; handler.
Definition: location.c:719

◆ destroy_contact()

static int destroy_contact ( void *  obj,
void *  arg,
int  flags 
)
static

Internal callback function which destroys the specified contact.

Definition at line 72 of file location.c.

References ast_sip_location_delete_contact(), and CMP_MATCH.

Referenced by aor_deleted_observer().

73 {
74  struct ast_sip_contact *contact = obj;
75 
77 
78  return CMP_MATCH;
79 }
int ast_sip_location_delete_contact(struct ast_sip_contact *contact)
Delete a contact.
Definition: location.c:450
Contact associated with an address of record.
Definition: res_pjsip.h:281

◆ expiration_str2struct()

static int expiration_str2struct ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for translating from a string timeval to actual structure.

Definition at line 482 of file location.c.

References ast_get_timeval(), ast_tv(), ast_sip_contact::expiration_time, NULL, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_location().

483 {
484  struct ast_sip_contact *contact = obj;
485  return ast_get_timeval(var->value, &contact->expiration_time, ast_tv(0, 0), NULL);
486 }
#define NULL
Definition: resample.c:96
int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default, int *consumed)
get values from config variables.
Definition: main/utils.c:2171
Contact associated with an address of record.
Definition: res_pjsip.h:281
struct timeval expiration_time
Definition: res_pjsip.h:305
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition: time.h:226

◆ expiration_struct2str()

static int expiration_struct2str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Custom handler for translating from an actual structure timeval to string.

Definition at line 489 of file location.c.

References ast_asprintf, and ast_sip_contact::expiration_time.

Referenced by ast_sip_initialize_sorcery_location().

490 {
491  const struct ast_sip_contact *contact = obj;
492  return (ast_asprintf(buf, "%ld", contact->expiration_time.tv_sec) < 0) ? -1 : 0;
493 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:269
Contact associated with an address of record.
Definition: res_pjsip.h:281
struct timeval expiration_time
Definition: res_pjsip.h:305

◆ format_ami_aor_handler()

static int format_ami_aor_handler ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 828 of file location.c.

References ao2_container_count(), ao2_ref, ast_sip_ami::arg, ast_free, ast_sip_create_ami_event(), ast_sip_location_retrieve_aor_contacts(), ast_sorcery_object_get_id(), ast_str_append(), ast_str_buffer(), astman_append(), buf, ast_sip_ami::count, ast_sip_aor::permanent_contacts, ast_sip_ami::s, and sip_aor_to_ami().

Referenced by format_ami_endpoint_aor().

829 {
830  struct ast_sip_aor *aor = obj;
831  struct ast_sip_ami *ami = arg;
832  const struct ast_sip_endpoint *endpoint = ami->arg;
833  struct ast_str *buf;
834  struct ao2_container *contacts;
835  int total_contacts;
836  int num_permanent;
837 
838  buf = ast_sip_create_ami_event("AorDetail", ami);
839  if (!buf) {
840  return -1;
841  }
843  if (!contacts) {
844  ast_free(buf);
845  return -1;
846  }
847 
848  sip_aor_to_ami(aor, &buf);
849  total_contacts = ao2_container_count(contacts);
850  num_permanent = aor->permanent_contacts ?
852 
853  ast_str_append(&buf, 0, "TotalContacts: %d\r\n", total_contacts);
854  ast_str_append(&buf, 0, "ContactsRegistered: %d\r\n",
855  total_contacts - num_permanent);
856  ast_str_append(&buf, 0, "EndpointName: %s\r\n",
857  ast_sorcery_object_get_id(endpoint));
858 
859  astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
860  ami->count++;
861 
862  ast_free(buf);
863  ao2_ref(contacts, -1);
864  return 0;
865 }
static int sip_aor_to_ami(const struct ast_sip_aor *aor, struct ast_str **buf)
Definition: location.c:777
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
A SIP address of record.
Definition: res_pjsip.h:361
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void * arg
Definition: res_pjsip.h:2745
AMI variable container.
Definition: res_pjsip.h:2737
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
struct ao2_container * ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor)
Retrieve all contacts currently available for an AOR.
Definition: location.c:247
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
struct mansession * s
Definition: res_pjsip.h:2739
An entity with which Asterisk communicates.
Definition: res_pjsip.h:812
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
struct ao2_container * permanent_contacts
Definition: res_pjsip.h:383
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.
Generic container type.

◆ format_ami_aorlist_handler()

static int format_ami_aorlist_handler ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1239 of file location.c.

References ast_sip_ami::arg, ast_free, ast_sip_create_ami_event(), ast_str_buffer(), astman_append(), buf, ast_sip_ami::count, ast_sip_ami::s, and sip_aor_to_ami().

Referenced by ami_show_aors().

1240 {
1241  struct ast_sip_aor *aor = obj;
1242  struct ast_sip_ami *ami = arg;
1243  struct ast_str *buf;
1244 
1245  buf = ast_sip_create_ami_event("AorList", ami);
1246  if (!buf) {
1247  return -1;
1248  }
1249 
1250  sip_aor_to_ami(aor, &buf);
1251 
1252  astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
1253  ami->count++;
1254 
1255  ast_free(buf);
1256 
1257  return 0;
1258 }
static int sip_aor_to_ami(const struct ast_sip_aor *aor, struct ast_str **buf)
Definition: location.c:777
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:3080
A SIP address of record.
Definition: res_pjsip.h:361
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void * arg
Definition: res_pjsip.h:2745
AMI variable container.
Definition: res_pjsip.h:2737
struct mansession * s
Definition: res_pjsip.h:2739
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
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.

◆ format_ami_endpoint_aor()

static int format_ami_endpoint_aor ( const struct ast_sip_endpoint endpoint,
struct ast_sip_ami ami 
)
static

Definition at line 867 of file location.c.

References ast_sip_endpoint::aors, ast_sip_ami::arg, ast_sip_for_each_aor(), and format_ami_aor_handler().

869 {
870  ami->arg = (void *)endpoint;
871  return ast_sip_for_each_aor(endpoint->aors,
873 }
int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg)
For every aor in the comma separated aors string call the given &#39;on_aor&#39; handler. ...
Definition: location.c:684
void * arg
Definition: res_pjsip.h:2745
static int format_ami_aor_handler(void *obj, void *arg, int flags)
Definition: location.c:828
const ast_string_field aors
Definition: res_pjsip.h:821

◆ gather_contacts_for_aor()

static int gather_contacts_for_aor ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 319 of file location.c.

References ao2_callback, ao2_ref, ast_sip_location_retrieve_aor_contacts(), cli_contact_populate_container(), CMP_MATCH, container, OBJ_MULTIPLE, and OBJ_NODATA.

Referenced by ast_sip_location_retrieve_contacts_from_aor_list().

320 {
321  struct ao2_container *aor_contacts;
322  struct ast_sip_aor *aor = obj;
323  struct ao2_container *container = arg;
324 
325  aor_contacts = ast_sip_location_retrieve_aor_contacts(aor);
326  if (!aor_contacts) {
327  return 0;
328  }
330  container);
331  ao2_ref(aor_contacts, -1);
332  return CMP_MATCH;
333 }
A SIP address of record.
Definition: res_pjsip.h:361
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
struct ao2_container * ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor)
Retrieve all contacts currently available for an AOR.
Definition: location.c:247
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * container
Definition: res_fax.c:502
static int cli_contact_populate_container(void *obj, void *arg, int flags)
Definition: location.c:902
Generic container type.

◆ permanent_uri_handler()

static int permanent_uri_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Custom handler for permanent URIs.

Definition at line 589 of file location.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_list, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, ao2_link, ao2_ref, ast_log, ast_md5_hash(), ast_res_pjsip_find_or_create_contact_status(), ast_sip_get_sorcery(), ast_sip_validate_uri_length(), ast_sorcery_alloc(), ast_sorcery_object_get_id(), ast_strdupa, ast_string_field_set, ast_strip(), ast_strlen_zero, LOG_ERROR, NULL, ast_sip_aor::permanent_contacts, permanent_uri_sort_fn(), status, strsep(), ast_sip_contact_status::uri, and ast_variable::value.

Referenced by ast_sip_initialize_sorcery_location().

590 {
591  struct ast_sip_aor *aor = obj;
592  const char *aor_id = ast_sorcery_object_get_id(aor);
593  char *contacts;
594  char *contact_uri;
595 
596  if (ast_strlen_zero(var->value)) {
597  return 0;
598  }
599 
600  contacts = ast_strdupa(var->value);
601  while ((contact_uri = ast_strip(strsep(&contacts, ",")))) {
602  struct ast_sip_contact *contact;
604  char hash[33];
605  char contact_id[strlen(aor_id) + sizeof(hash) + 2];
606 
607  if (ast_strlen_zero(contact_uri)) {
608  continue;
609  }
610 
611  if (ast_sip_validate_uri_length(contact_uri)) {
612  ast_log(LOG_ERROR, "Contact uri or hostname length exceeds pjproject limit or is not a sip(s) uri: %s\n", contact_uri);
613  return -1;
614  }
615 
616  if (!aor->permanent_contacts) {
619  if (!aor->permanent_contacts) {
620  return -1;
621  }
622  }
623 
624  ast_md5_hash(hash, contact_uri);
625  snprintf(contact_id, sizeof(contact_id), "%s@@%s", aor_id, hash);
626  contact = ast_sorcery_alloc(ast_sip_get_sorcery(), "contact", contact_id);
627  if (!contact) {
628  return -1;
629  }
630 
631  ast_string_field_set(contact, uri, contact_uri);
632 
634  if (!status) {
635  ao2_ref(contact, -1);
636  return -1;
637  }
638  ao2_ref(status, -1);
639 
640  ao2_link(aor->permanent_contacts, contact);
641  ao2_ref(contact, -1);
642  }
643 
644  return 0;
645 }
A contact&#39;s status.
Definition: res_pjsip.h:341
A SIP address of record.
Definition: res_pjsip.h:361
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1335
#define NULL
Definition: resample.c:96
const ast_string_field uri
Definition: res_pjsip.h:347
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
static int permanent_uri_sort_fn(const void *obj_left, const void *obj_right, int flags)
Definition: location.c:495
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
int ast_sip_validate_uri_length(const char *contact_uri)
Definition: location.c:525
#define LOG_ERROR
Definition: logger.h:285
Contact associated with an address of record.
Definition: res_pjsip.h:281
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition: sorcery.c:1744
struct ao2_container * permanent_contacts
Definition: res_pjsip.h:383
char * strsep(char **str, const char *delims)
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Reject objects with duplicate keys in container.
Definition: astobj2.h:1192
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.
Definition: main/utils.c:248
jack_status_t status
Definition: app_jack.c:146
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514
struct ast_sip_contact_status * ast_res_pjsip_find_or_create_contact_status(const struct ast_sip_contact *contact)
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ permanent_uri_sort_fn()

static int permanent_uri_sort_fn ( const void *  obj_left,
const void *  obj_right,
int  flags 
)
static

Definition at line 495 of file location.c.

References ast_assert, ast_sorcery_object_get_id(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_sip_location_retrieve_contact_from_aor_list(), ast_sip_location_retrieve_contacts_from_aor_list(), and permanent_uri_handler().

496 {
497  const struct ast_sip_contact *object_left = obj_left;
498  const struct ast_sip_contact *object_right = obj_right;
499  const char *right_key = obj_right;
500  int cmp;
501 
502  switch (flags & OBJ_SEARCH_MASK) {
503  case OBJ_SEARCH_OBJECT:
504  right_key = ast_sorcery_object_get_id(object_right);
505  /* Fall through */
506  case OBJ_SEARCH_KEY:
507  cmp = strcmp(ast_sorcery_object_get_id(object_left), right_key);
508  break;
510  /*
511  * We could also use a partial key struct containing a length
512  * so strlen() does not get called for every comparison instead.
513  */
514  cmp = strncmp(ast_sorcery_object_get_id(object_left), right_key, strlen(right_key));
515  break;
516  default:
517  /* Sort can only work on something with a full or partial key. */
518  ast_assert(0);
519  cmp = 0;
520  break;
521  }
522  return cmp;
523 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
Contact associated with an address of record.
Definition: res_pjsip.h:281
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076

◆ prune_boot_contacts_cb()

static int prune_boot_contacts_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 455 of file location.c.

References ast_sip_contact::aor, ast_config_AST_SYSTEM_NAME, ast_sip_location_delete_contact(), ast_verb, ast_sip_contact::prune_on_boot, ast_sip_contact::reg_server, and ast_sip_contact::uri.

Referenced by ast_sip_location_prune_boot_contacts().

456 {
457  struct ast_sip_contact *contact = obj;
458 
459  if (contact->prune_on_boot
460  && !strcmp(contact->reg_server, ast_config_AST_SYSTEM_NAME ?: "")) {
461  ast_verb(3, "Removed contact '%s' from AOR '%s' due to system boot\n",
462  contact->uri, contact->aor);
464  }
465 
466  return 0;
467 }
const ast_string_field reg_server
Definition: res_pjsip.h:303
#define ast_verb(level,...)
Definition: logger.h:463
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
int ast_sip_location_delete_contact(struct ast_sip_contact *contact)
Delete a contact.
Definition: location.c:450
Contact associated with an address of record.
Definition: res_pjsip.h:281
const ast_string_field aor
Definition: res_pjsip.h:303
const ast_string_field uri
Definition: res_pjsip.h:303

◆ sip_aor_to_ami()

static int sip_aor_to_ami ( const struct ast_sip_aor aor,
struct ast_str **  buf 
)
static

Definition at line 777 of file location.c.

References ast_free, AST_HANDLER_ONLY_STRING, ast_sip_get_sorcery(), ast_sorcery_object_get_id(), ast_sorcery_object_get_type(), ast_sorcery_objectset_create2(), ast_str_append(), ast_to_camel_case, ast_variables_destroy(), ast_variable::name, ast_variable::next, NULL, S_OR, and ast_variable::value.

Referenced by format_ami_aor_handler(), and format_ami_aorlist_handler().

778 {
779  struct ast_variable *objset;
780  struct ast_variable *i;
781 
784  if (!objset) {
785  return -1;
786  }
787 
788  ast_str_append(buf, 0, "ObjectType: %s\r\n",
790  ast_str_append(buf, 0, "ObjectName: %s\r\n",
792 
793  for (i = objset; i; i = i->next) {
794  char *camel = ast_to_camel_case(i->name);
795 
796  if (strcmp(camel, "Contact") == 0) {
797  ast_free(camel);
798  camel = NULL;
799  }
800  ast_str_append(buf, 0, "%s: %s\r\n", S_OR(camel, "Contacts"), i->value);
801  ast_free(camel);
802  }
803 
804  ast_variables_destroy(objset);
805  return 0;
806 }
struct ast_variable * next
struct ast_variable * ast_sorcery_objectset_create2(const struct ast_sorcery *sorcery, const void *object, enum ast_sorcery_field_handler_flags flags)
Create an object set (KVP list) for an object.
Definition: sorcery.c:1511
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
Structure for variables, used for configurations and for channel variables.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define NULL
Definition: resample.c:96
#define ast_to_camel_case(s)
Definition: strings.h:509
const char * ast_sorcery_object_get_type(const void *object)
Get the type of a sorcery object.
Definition: sorcery.c:2324
Use string handler only.
Definition: sorcery.h:137
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define ast_free(a)
Definition: astmm.h:182
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79

◆ voicemail_extension_handler()

static int voicemail_extension_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 666 of file location.c.

References ast_strdup, ast_variable::value, and ast_sip_aor::voicemail_extension.

Referenced by ast_sip_initialize_sorcery_location().

667 {
668  struct ast_sip_aor *aor = obj;
669 
670  aor->voicemail_extension = ast_strdup(var->value);
671 
672  return aor->voicemail_extension ? 0 : -1;
673 }
A SIP address of record.
Definition: res_pjsip.h:361
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
char * voicemail_extension
Definition: res_pjsip.h:389

◆ voicemail_extension_to_str()

static int voicemail_extension_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 675 of file location.c.

References ast_strdup, and ast_sip_aor::voicemail_extension.

Referenced by ast_sip_initialize_sorcery_location().

676 {
677  const struct ast_sip_aor *aor = obj;
678 
680 
681  return 0;
682 }
A SIP address of record.
Definition: res_pjsip.h:361
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
char * voicemail_extension
Definition: res_pjsip.h:389

Variable Documentation

◆ aor_formatter

struct ast_sip_cli_formatter_entry* aor_formatter

Definition at line 1323 of file location.c.

◆ aor_observer

const struct ast_sorcery_observer aor_observer
static
Initial value:
= {
}
static void aor_deleted_observer(const void *object)
Definition: location.c:81

Observer for contacts so state can be updated on respective endpoints.

Definition at line 105 of file location.c.

◆ cli_commands

struct ast_cli_entry cli_commands[]
static

Definition at line 1290 of file location.c.

◆ contact_formatter

struct ast_sip_cli_formatter_entry* contact_formatter

Definition at line 1322 of file location.c.

◆ endpoint_aor_formatter

struct ast_sip_endpoint_formatter endpoint_aor_formatter
Initial value:
= {
}
static int format_ami_endpoint_aor(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
Definition: location.c:867

Definition at line 875 of file location.c.

◆ pj_max_hostname

int pj_max_hostname = PJ_MAX_HOSTNAME
static

Definition at line 36 of file location.c.

Referenced by ast_sip_initialize_sorcery_location(), and ast_sip_validate_uri_length().

◆ pjsip_max_url_size

int pjsip_max_url_size = PJSIP_MAX_URL_SIZE
static

Definition at line 37 of file location.c.

Referenced by ast_sip_initialize_sorcery_location(), and ast_sip_validate_uri_length().