Asterisk - The Open Source Telephony Project GIT-master-8924258
Data Structures | Macros | Functions | Variables
res_pjsip_outbound_publish.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_simple.h>
#include "asterisk/res_pjproject.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_outbound_publish.h"
#include "asterisk/module.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/threadpool.h"
#include "asterisk/datastore.h"
#include "res_pjsip/include/res_pjsip_private.h"
Include dependency graph for res_pjsip_outbound_publish.c:

Go to the source code of this file.

Data Structures

struct  ast_sip_outbound_publish
 Outbound publish information. More...
 
struct  ast_sip_outbound_publish_client
 Outbound publish client state information (persists for lifetime of a publish) More...
 
struct  ast_sip_outbound_publish_state
 Outbound publish state information (persists for lifetime of a publish) More...
 
struct  publisher_handlers
 
struct  sip_outbound_publish_message
 Queued outbound publish message. More...
 
struct  sip_outbound_publisher
 

Macros

#define ADD_TO_NEW_STATES(__obj)
 
#define DATASTORE_BUCKETS   53
 
#define DEFAULT_PUBLISHER_BUCKETS   119
 
#define DEFAULT_STATE_BUCKETS   31
 Default number of client state container buckets. More...
 
#define DESTROY_CLIENT()
 
#define MAX_UNLOAD_TIMEOUT_TIME   35 /* Seconds */
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static AO2_GLOBAL_OBJ_STATIC (current_states)
 
 AO2_STRING_FIELD_CMP_FN (sip_outbound_publisher, user)
 
 AO2_STRING_FIELD_HASH_FN (sip_outbound_publisher, user)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
int ast_sip_publish_client_add_datastore (struct ast_sip_outbound_publish_client *client, struct ast_datastore *datastore)
 Add a datastore to a SIP event publisher. More...
 
struct ast_datastoreast_sip_publish_client_alloc_datastore (const struct ast_datastore_info *info, const char *uid)
 Alternative for ast_datastore_alloc() More...
 
struct ast_sip_outbound_publish_clientast_sip_publish_client_get (const char *name)
 Find a publish client using its name. More...
 
struct ast_datastoreast_sip_publish_client_get_datastore (struct ast_sip_outbound_publish_client *client, const char *name)
 Retrieve an event publisher datastore. More...
 
const char * ast_sip_publish_client_get_from_uri (struct ast_sip_outbound_publish_client *client)
 Get the From URI the client will use. More...
 
const char * ast_sip_publish_client_get_to_uri (struct ast_sip_outbound_publish_client *client)
 Get the To URI the client will use. More...
 
const char * ast_sip_publish_client_get_user_from_uri (struct ast_sip_outbound_publish_client *client, const char *user, char *uri, size_t size)
 Get the From URI the client will use for a specific user. More...
 
const char * ast_sip_publish_client_get_user_to_uri (struct ast_sip_outbound_publish_client *client, const char *user, char *uri, size_t size)
 Get the To URI the client will use for a specific user. More...
 
void ast_sip_publish_client_remove (struct ast_sip_outbound_publish_client *client, const char *user)
 Remove the user from the client (stopping it from publishing) More...
 
void ast_sip_publish_client_remove_datastore (struct ast_sip_outbound_publish_client *client, const char *name)
 Remove a publication datastore from an event publisher. More...
 
int ast_sip_publish_client_send (struct ast_sip_outbound_publish_client *client, const struct ast_sip_body *body)
 Send an outgoing PUBLISH message using a client. More...
 
int ast_sip_publish_client_user_send (struct ast_sip_outbound_publish_client *client, const char *user, const struct ast_sip_body *body)
 Send an outgoing PUBLISH message based on the user. More...
 
int ast_sip_register_event_publisher_handler (struct ast_sip_event_publisher_handler *handler)
 Register an event publisher handler. More...
 
void ast_sip_unregister_event_publisher_handler (struct ast_sip_event_publisher_handler *handler)
 Unregister a publish handler. More...
 
static int can_reuse_publish (struct ast_sip_outbound_publish *existing, struct ast_sip_outbound_publish *applied)
 
static int cancel_and_unpublish (void *obj, void *arg, int flags)
 Helper function which cancels and un-publishes a no longer used client. More...
 
static void cancel_publish_refresh (struct sip_outbound_publisher *publisher)
 Helper function which cancels the refresh timer on a publisher. More...
 
static int cancel_refresh_timer_task (void *data)
 Task for cancelling a refresh timer. More...
 
static int current_state_reusable (struct ast_sip_outbound_publish *publish, struct ast_sip_outbound_publish_state *current_state)
 
static int datastore_cmp (void *obj, void *arg, int flags)
 
static int datastore_hash (const void *obj, int flags)
 
static int explicit_publish_destroy (void *data)
 
static struct ast_sip_event_publisher_handlerfind_publisher_handler_for_event_name (const char *event_name)
 
static struct ao2_containerget_publishes_and_update_state (void)
 
static int load_module (void)
 
static int outbound_auth_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int outbound_publish_state_cmp (void *obj, void *arg, int flags)
 comparator function for client objects More...
 
static int outbound_publish_state_hash (const void *obj, const int flags)
 hashing function for state objects More...
 
static int publisher_client_send (void *obj, void *arg, void *data, int flags)
 
static int reload_module (void)
 
static void schedule_publish_refresh (struct sip_outbound_publisher *publisher, int expiration)
 Helper function which sets up the timer to send publication. More...
 
static int send_unpublish_task (void *data)
 Task for sending an unpublish. More...
 
static void set_transport (struct sip_outbound_publisher *publisher, pjsip_tx_data *tdata)
 
static void * sip_outbound_publish_alloc (const char *name)
 Allocator function for publish information. More...
 
static int sip_outbound_publish_apply (const struct ast_sorcery *sorcery, void *obj)
 Apply function which finds or allocates a state structure. More...
 
static void sip_outbound_publish_callback (struct pjsip_publishc_cbparam *param)
 Callback function for publish client responses. More...
 
static struct sip_outbound_publishersip_outbound_publish_client_add_publisher (struct ast_sip_outbound_publish_client *client, const char *user)
 
static void sip_outbound_publish_client_destroy (void *obj)
 Destructor function for publish client. More...
 
static struct sip_outbound_publishersip_outbound_publish_client_get_publisher (struct ast_sip_outbound_publish_client *client, const char *user)
 
static void sip_outbound_publish_datastore_destroy (void *obj)
 
static void sip_outbound_publish_destroy (void *obj)
 Destructor function for publish information. More...
 
static struct ast_sip_outbound_publish_statesip_outbound_publish_state_alloc (struct ast_sip_outbound_publish *publish)
 Allocator function for publish client. More...
 
static void sip_outbound_publish_state_destroy (void *obj)
 Destructor function for publish state. More...
 
static void sip_outbound_publish_synchronize (struct ast_sip_event_publisher_handler *removed)
 Helper function which starts or stops publish clients when applicable. More...
 
static void sip_outbound_publish_timer_cb (pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
 Publish client timer callback function. More...
 
static struct sip_outbound_publishersip_outbound_publisher_alloc (struct ast_sip_outbound_publish_client *client, const char *user)
 
static void sip_outbound_publisher_destroy (void *obj)
 Destructor function for publish client. More...
 
static int sip_outbound_publisher_init (void *data)
 Helper function that allocates a pjsip publish client and configures it. More...
 
static int sip_outbound_publisher_reinit (void *obj, void *arg, int flags)
 
static int sip_outbound_publisher_reinit_all (void *data)
 
static int sip_outbound_publisher_set_uri (pj_pool_t *pool, const char *uri, const char *user, pj_str_t *res_uri)
 
static int sip_outbound_publisher_set_uris (pj_pool_t *pool, struct sip_outbound_publisher *publisher, pj_str_t *server_uri, pj_str_t *to_uri, pj_str_t *from_uri)
 
static struct ast_sip_outbound_publish_statesip_publish_state_get (const char *id)
 
static int sip_publisher_service_queue (void *data)
 
static void stop_publishing (struct ast_sip_outbound_publish_client *client, struct ast_sip_event_publisher_handler *handler)
 
static void sub_add_handler (struct ast_sip_event_publisher_handler *handler)
 
static int unload_module (void)
 
static int validate_publish_config (struct ast_sip_outbound_publish *publish)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Outbound Publish Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .reload = reload_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "res_pjproject,res_pjsip", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static ast_rwlock_t load_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} }
 Used for locking while loading/reloading. More...
 
static struct ao2_containernew_states
 Used on [re]loads to hold new state data. More...
 
static int pjsip_max_url_size = PJSIP_MAX_URL_SIZE
 
struct publisher_handlers publisher_handlers = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static struct ast_serializer_shutdown_groupshutdown_group
 

Macro Definition Documentation

◆ ADD_TO_NEW_STATES

#define ADD_TO_NEW_STATES (   __obj)
Value:
do { if (__obj) { \
ao2_link(new_states, __obj); \
ao2_ref(__obj, -1); } } while (0)
static struct ao2_container * new_states
Used on [re]loads to hold new state data.

◆ DATASTORE_BUCKETS

#define DATASTORE_BUCKETS   53

Definition at line 1399 of file res_pjsip_outbound_publish.c.

◆ DEFAULT_PUBLISHER_BUCKETS

#define DEFAULT_PUBLISHER_BUCKETS   119

Definition at line 293 of file res_pjsip_outbound_publish.c.

◆ DEFAULT_STATE_BUCKETS

#define DEFAULT_STATE_BUCKETS   31

Default number of client state container buckets.

Definition at line 304 of file res_pjsip_outbound_publish.c.

◆ DESTROY_CLIENT

#define DESTROY_CLIENT ( )
Value:
do { \
pjsip_publishc_destroy(publisher->client); \
publisher->client = NULL; \
ao2_ref(publisher, -1); } while (0)
#define NULL
Definition: resample.c:96

◆ MAX_UNLOAD_TIMEOUT_TIME

#define MAX_UNLOAD_TIMEOUT_TIME   35 /* Seconds */

Time needs to be long enough for a transaction to timeout if nothing replies.

Definition at line 298 of file res_pjsip_outbound_publish.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 1743 of file res_pjsip_outbound_publish.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 1743 of file res_pjsip_outbound_publish.c.

◆ AO2_GLOBAL_OBJ_STATIC()

static AO2_GLOBAL_OBJ_STATIC ( current_states  )
static

◆ AO2_STRING_FIELD_CMP_FN()

AO2_STRING_FIELD_CMP_FN ( sip_outbound_publisher  ,
user   
)

◆ AO2_STRING_FIELD_HASH_FN()

AO2_STRING_FIELD_HASH_FN ( sip_outbound_publisher  ,
user   
)

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 1743 of file res_pjsip_outbound_publish.c.

◆ ast_sip_publish_client_add_datastore()

int ast_sip_publish_client_add_datastore ( struct ast_sip_outbound_publish_client client,
struct ast_datastore datastore 
)

Add a datastore to a SIP event publisher.

Note that SIP uses reference counted datastores. The datastore passed into this function must have been allocated using ao2_alloc() or there will be serious problems.

Parameters
clientThe publication client to add the datastore to
datastoreThe datastore to be added to the subscription
Return values
0Success
-1Failure

Definition at line 760 of file res_pjsip_outbound_publish.c.

762{
763 ast_assert(datastore != NULL);
764 ast_assert(datastore->info != NULL);
765 ast_assert(!ast_strlen_zero(datastore->uid));
766
767 if (!ao2_link(client->datastores, datastore)) {
768 return -1;
769 }
770 return 0;
771}
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const struct ast_datastore_info * info
Definition: datastore.h:67
const char * uid
Definition: datastore.h:65
struct ao2_container * datastores
Publisher datastores set up by handlers.
#define ast_assert(a)
Definition: utils.h:739

References ao2_link, ast_assert, ast_strlen_zero(), ast_sip_outbound_publish_client::datastores, ast_datastore::info, NULL, and ast_datastore::uid.

Referenced by asterisk_start_devicestate_publishing(), and asterisk_start_mwi_publishing().

◆ ast_sip_publish_client_alloc_datastore()

struct ast_datastore * ast_sip_publish_client_alloc_datastore ( const struct ast_datastore_info info,
const char *  uid 
)

Alternative for ast_datastore_alloc()

There are two major differences between this and ast_datastore_alloc() 1) This allocates a refcounted object 2) This will fill in a uid if one is not provided

DO NOT call ast_datastore_free() on a datastore allocated in this way since that function will attempt to free the datastore rather than play nicely with its refcount.

Parameters
infoCallbacks for datastore
uidIdentifier for datastore
Return values
NULLFailed to allocate datastore
non-NULLNewly allocated datastore

Definition at line 730 of file res_pjsip_outbound_publish.c.

731{
732 RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
733 const char *uid_ptr = uid;
734 char uuid_buf[AST_UUID_STR_LEN];
735
736 if (!info) {
737 return NULL;
738 }
739
740 datastore = ao2_alloc(sizeof(*datastore), sip_outbound_publish_datastore_destroy);
741 if (!datastore) {
742 return NULL;
743 }
744
745 datastore->info = info;
746 if (ast_strlen_zero(uid)) {
747 /* They didn't provide an ID so we'll provide one ourself */
748 uid_ptr = ast_uuid_generate_str(uuid_buf, sizeof(uuid_buf));
749 }
750
751 datastore->uid = ast_strdup(uid_ptr);
752 if (!datastore->uid) {
753 return NULL;
754 }
755
756 ao2_ref(datastore, +1);
757 return datastore;
758}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
def info(msg)
static void sip_outbound_publish_datastore_destroy(void *obj)
Structure for a data store object.
Definition: datastore.h:64
#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:941
#define AST_UUID_STR_LEN
Definition: uuid.h:27
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
Definition: uuid.c:141

References ao2_alloc, ao2_cleanup, ao2_ref, ast_strdup, ast_strlen_zero(), ast_uuid_generate_str(), AST_UUID_STR_LEN, sip_to_pjsip::info(), NULL, RAII_VAR, sip_outbound_publish_datastore_destroy(), and ast_datastore::uid.

Referenced by asterisk_start_devicestate_publishing(), and asterisk_start_mwi_publishing().

◆ ast_sip_publish_client_get()

struct ast_sip_outbound_publish_client * ast_sip_publish_client_get ( const char *  name)

Find a publish client using its name.

Parameters
nameThe name of the publish client
Return values
NULLfailure
non-NULLsuccess
Note
The publish client is returned with its reference count increased and must be released using ao2_cleanup.

Definition at line 564 of file res_pjsip_outbound_publish.c.

565{
567
568 if (!state) {
569 return NULL;
570 }
571
572 ao2_ref(state->client, +1);
573 ao2_ref(state, -1);
574 return state->client;
575}
static const char name[]
Definition: format_mp3.c:68
static struct ast_sip_outbound_publish_state * sip_publish_state_get(const char *id)
Outbound publish state information (persists for lifetime of a publish)

References ao2_ref, name, NULL, and sip_publish_state_get().

Referenced by asterisk_publication_devicestate_refresh(), asterisk_publication_mwi_refresh(), and send_refresh_cb().

◆ ast_sip_publish_client_get_datastore()

struct ast_datastore * ast_sip_publish_client_get_datastore ( struct ast_sip_outbound_publish_client client,
const char *  name 
)

Retrieve an event publisher datastore.

The datastore retrieved will have its reference count incremented. When the caller is done with the datastore, the reference counted needs to be decremented using ao2_ref().

Parameters
clientThe publication client from which to retrieve the datastore
nameThe name of the datastore to retrieve
Return values
NULLFailed to find the specified datastore
non-NULLThe specified datastore

Definition at line 773 of file res_pjsip_outbound_publish.c.

775{
776 return ao2_find(client->datastores, name, OBJ_SEARCH_KEY);
777}
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101

References ao2_find, ast_sip_outbound_publish_client::datastores, name, and OBJ_SEARCH_KEY.

Referenced by asterisk_publication_devicestate_refresh(), asterisk_publication_mwi_refresh(), asterisk_stop_devicestate_publishing(), and asterisk_stop_mwi_publishing().

◆ ast_sip_publish_client_get_from_uri()

const char * ast_sip_publish_client_get_from_uri ( struct ast_sip_outbound_publish_client client)

Get the From URI the client will use.

Since
14.0.0
Parameters
clientThe publication client to get the From URI
Return values
From-urion success
Empty-stringon failure

Definition at line 577 of file res_pjsip_outbound_publish.c.

578{
579 struct ast_sip_outbound_publish *publish = client->publish;
580
581 return S_OR(publish->from_uri, S_OR(publish->server_uri, ""));
582}
unsigned char publish
Definition: res_corosync.c:241
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
struct ast_sip_outbound_publish * publish
Outbound publish information.
Outbound publish information.

References publish, ast_sip_outbound_publish_client::publish, and S_OR.

◆ ast_sip_publish_client_get_to_uri()

const char * ast_sip_publish_client_get_to_uri ( struct ast_sip_outbound_publish_client client)

Get the To URI the client will use.

Since
14.0.0
Parameters
clientThe publication client to get the To URI
Return values
From-urion success
Empty-stringon failure

Definition at line 627 of file res_pjsip_outbound_publish.c.

628{
629 struct ast_sip_outbound_publish *publish = client->publish;
630
631 return S_OR(publish->to_uri, S_OR(publish->server_uri, ""));
632}

References publish, ast_sip_outbound_publish_client::publish, and S_OR.

◆ ast_sip_publish_client_get_user_from_uri()

const char * ast_sip_publish_client_get_user_from_uri ( struct ast_sip_outbound_publish_client client,
const char *  user,
char *  uri,
size_t  size 
)

Get the From URI the client will use for a specific user.

Since
14.0.0
Parameters
clientThe publication client to get the From URI of a user
userThe user to retrieve the From URI for
uriA buffer to place the URI into
sizeThe size of the buffer
Return values
From-urion success
Empty-stringon failure

Definition at line 611 of file res_pjsip_outbound_publish.c.

613{
614 struct sip_outbound_publisher *publisher;
615
617 if (!publisher) {
618 return NULL;
619 }
620
621 ast_copy_string(uri, publisher->from_uri, size);
622 ao2_ref(publisher, -1);
623
624 return uri;
625}
static struct sip_outbound_publisher * sip_outbound_publish_client_get_publisher(struct ast_sip_outbound_publish_client *client, const char *user)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
char * from_uri
The From URI for this specific publisher.
pjsip_publishc * client
Underlying publish client.
structure to hold users read from users.conf

References ao2_ref, ast_copy_string(), sip_outbound_publisher::client, sip_outbound_publisher::from_uri, NULL, and sip_outbound_publish_client_get_publisher().

Referenced by exten_state_publisher_cb().

◆ ast_sip_publish_client_get_user_to_uri()

const char * ast_sip_publish_client_get_user_to_uri ( struct ast_sip_outbound_publish_client client,
const char *  user,
char *  uri,
size_t  size 
)

Get the To URI the client will use for a specific user.

Since
14.0.0
Parameters
clientThe publication client to get the To URI of a user
userThe user to retrieve the To URI for
uriA buffer to place the URI into
sizeThe size of the buffer
Return values
To-urion success
Empty-stringon failure

Definition at line 634 of file res_pjsip_outbound_publish.c.

636{
637 struct sip_outbound_publisher *publisher;
638
640 if (!publisher) {
641 return NULL;
642 }
643
644 ast_copy_string(uri, publisher->to_uri, size);
645 ao2_ref(publisher, -1);
646
647 return uri;
648}
char * to_uri
The To URI for this specific publisher.

References ao2_ref, ast_copy_string(), sip_outbound_publisher::client, NULL, sip_outbound_publish_client_get_publisher(), and sip_outbound_publisher::to_uri.

Referenced by exten_state_publisher_cb().

◆ ast_sip_publish_client_remove()

void ast_sip_publish_client_remove ( struct ast_sip_outbound_publish_client client,
const char *  user 
)

Remove the user from the client (stopping it from publishing)

Parameters
clientThe publication client
userThe user to remove

Definition at line 1161 of file res_pjsip_outbound_publish.c.

1163{
1166}
ast_mutex_t lock
Definition: app_sla.c:337
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_UNLINK
Definition: astobj2.h:1039
#define SCOPED_WRLOCK(varname, lock)
scoped lock specialization for write locks
Definition: lock.h:603
static ast_rwlock_t load_lock
Used for locking while loading/reloading.
struct ao2_container * publishers
Container of all the client publishing objects.

References ao2_find, sip_outbound_publisher::client, load_lock, lock, OBJ_NODATA, OBJ_SEARCH_KEY, OBJ_UNLINK, and SCOPED_WRLOCK.

◆ ast_sip_publish_client_remove_datastore()

void ast_sip_publish_client_remove_datastore ( struct ast_sip_outbound_publish_client client,
const char *  name 
)

Remove a publication datastore from an event publisher.

This operation may cause the datastore's free() callback to be called if the reference count reaches zero.

Parameters
clientThe publication client to remove the datastore from
nameThe name of the datastore to remove

Definition at line 779 of file res_pjsip_outbound_publish.c.

References ao2_find, ast_sip_outbound_publish_client::datastores, name, OBJ_NODATA, OBJ_SEARCH_KEY, and OBJ_UNLINK.

Referenced by asterisk_start_devicestate_publishing(), asterisk_start_mwi_publishing(), asterisk_stop_devicestate_publishing(), and asterisk_stop_mwi_publishing().

◆ ast_sip_publish_client_send()

int ast_sip_publish_client_send ( struct ast_sip_outbound_publish_client client,
const struct ast_sip_body body 
)

Send an outgoing PUBLISH message using a client.

Parameters
clientThe publication client to send from
bodyAn optional body to add to the PUBLISH
Return values
-1failure
0success

Definition at line 878 of file res_pjsip_outbound_publish.c.

880{
881 SCOPED_AO2LOCK(lock, client);
882 int res = 0;
883
885 publisher_client_send, (void *)body, &res);
886 return res;
887}
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1723
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
Definition: lock.h:608
static int publisher_client_send(void *obj, void *arg, void *data, int flags)

References ao2_callback_data, sip_outbound_publish_message::body, lock, OBJ_NODATA, publisher_client_send(), ast_sip_outbound_publish_client::publishers, and SCOPED_AO2LOCK.

Referenced by asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), and send_refresh_cb().

◆ ast_sip_publish_client_user_send()

int ast_sip_publish_client_user_send ( struct ast_sip_outbound_publish_client client,
const char *  user,
const struct ast_sip_body body 
)

Send an outgoing PUBLISH message based on the user.

Parameters
clientThe publication client to send from
userThe user to send to
bodyAn optional body to add to the PUBLISH
Return values
-1failure
0success

Definition at line 1145 of file res_pjsip_outbound_publish.c.

1147{
1148 struct sip_outbound_publisher *publisher;
1149 int res;
1150
1152 if (!publisher) {
1153 return -1;
1154 }
1155
1156 publisher_client_send(publisher, (void *)body, &res, 0);
1157 ao2_ref(publisher, -1);
1158 return res;
1159}

References ao2_ref, sip_outbound_publisher::client, publisher_client_send(), and sip_outbound_publish_client_get_publisher().

Referenced by exten_state_publisher_cb().

◆ ast_sip_register_event_publisher_handler()

int ast_sip_register_event_publisher_handler ( struct ast_sip_event_publisher_handler handler)

Register an event publisher handler.

Return values
0Handler was registered successfully
non-zeroHandler was not registered successfully

Definition at line 650 of file res_pjsip_outbound_publish.c.

651{
652 struct ast_sip_event_publisher_handler *existing;
654
655 if (!handler->start_publishing || !handler->stop_publishing) {
656 ast_log(LOG_ERROR, "Handler does not implement required callbacks. Cannot register\n");
657 return -1;
658 } else if (ast_strlen_zero(handler->event_name)) {
659 ast_log(LOG_ERROR, "No event package specified for event publisher handler. Cannot register\n");
660 return -1;
661 }
662
663 existing = find_publisher_handler_for_event_name(handler->event_name);
664 if (existing) {
665 ast_log(LOG_ERROR, "Unable to register event publisher handler for event %s. "
666 "A handler is already registered\n", handler->event_name);
667 return -1;
668 }
669
671
673
674 return 0;
675}
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:587
static struct ast_sip_event_publisher_handler * find_publisher_handler_for_event_name(const char *event_name)
static void sub_add_handler(struct ast_sip_event_publisher_handler *handler)
static void sip_outbound_publish_synchronize(struct ast_sip_event_publisher_handler *removed)
Helper function which starts or stops publish clients when applicable.
Callbacks that event publisher handlers will define.
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition: test_ari.c:59

References ast_log, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), find_publisher_handler_for_event_name(), handler(), lock, LOG_ERROR, NULL, SCOPED_LOCK, sip_outbound_publish_synchronize(), and sub_add_handler().

Referenced by load_module().

◆ ast_sip_unregister_event_publisher_handler()

void ast_sip_unregister_event_publisher_handler ( struct ast_sip_event_publisher_handler handler)

◆ can_reuse_publish()

static int can_reuse_publish ( struct ast_sip_outbound_publish existing,
struct ast_sip_outbound_publish applied 
)
static

Definition at line 1275 of file res_pjsip_outbound_publish.c.

1276{
1277 int i;
1278
1279 if (strcmp(existing->server_uri, applied->server_uri) || strcmp(existing->from_uri, applied->from_uri) ||
1280 strcmp(existing->to_uri, applied->to_uri) || strcmp(existing->outbound_proxy, applied->outbound_proxy) ||
1281 strcmp(existing->event, applied->event) ||
1283 return 0;
1284 }
1285
1286 for (i = 0; i < AST_VECTOR_SIZE(&existing->outbound_auths); ++i) {
1287 if (strcmp(AST_VECTOR_GET(&existing->outbound_auths, i), AST_VECTOR_GET(&applied->outbound_auths, i))) {
1288 return 0;
1289 }
1290 }
1291
1292 return 1;
1293}
struct ast_sip_auth_vector outbound_auths
Configured authentication credentials.
const ast_string_field outbound_proxy
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

References AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_outbound_publish::event, ast_sip_outbound_publish::from_uri, ast_sip_outbound_publish::outbound_auths, ast_sip_outbound_publish::outbound_proxy, ast_sip_outbound_publish::server_uri, and ast_sip_outbound_publish::to_uri.

Referenced by current_state_reusable().

◆ cancel_and_unpublish()

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

Helper function which cancels and un-publishes a no longer used client.

Definition at line 1188 of file res_pjsip_outbound_publish.c.

1189{
1190 struct sip_outbound_publisher *publisher = obj;
1191 struct ast_sip_outbound_publish_client *client = publisher->owner;
1192
1193 SCOPED_AO2LOCK(lock, publisher);
1194
1195 if (!client->started) {
1196 /* If the publisher was never started, there's nothing to unpublish, so just
1197 * destroy the publication and remove its reference to the publisher.
1198 */
1199 if (ast_sip_push_task(publisher->serializer, explicit_publish_destroy, ao2_bump(publisher))) {
1200 ao2_ref(publisher, -1);
1201 }
1202 return 0;
1203 }
1204
1205 if (ast_sip_push_task(publisher->serializer, cancel_refresh_timer_task, ao2_bump(publisher))) {
1206 ast_log(LOG_WARNING, "Could not stop refresh timer on outbound publish '%s'\n",
1208 ao2_ref(publisher, -1);
1209 }
1210
1211 /* If nothing is being sent right now send the unpublish - the destroy will happen in the subsequent callback */
1212 if (!publisher->sending) {
1213 if (ast_sip_push_task(publisher->serializer, send_unpublish_task, ao2_bump(publisher))) {
1214 ast_log(LOG_WARNING, "Could not send unpublish message on outbound publish '%s'\n",
1216 ao2_ref(publisher, -1);
1217 }
1218 }
1219 publisher->destroy = 1;
1220 return 0;
1221}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
int ast_sip_push_task(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Pushes a task to SIP servants.
Definition: res_pjsip.c:2099
#define LOG_WARNING
static int cancel_refresh_timer_task(void *data)
Task for cancelling a refresh timer.
static int explicit_publish_destroy(void *data)
static int send_unpublish_task(void *data)
Task for sending an unpublish.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
Outbound publish client state information (persists for lifetime of a publish)
unsigned int started
Publishing has been fully started and event type informed.
struct ast_sip_outbound_publish_client * owner
The client object that 'owns' this client.
struct sip_outbound_publish_message * sending
The message currently being sent.
unsigned int destroy
Publish client should be destroyed.
struct ast_taskprocessor * serializer
Serializer for stuff and things.

References ao2_bump, ao2_ref, ast_log, ast_sip_push_task(), ast_sorcery_object_get_id(), cancel_refresh_timer_task(), sip_outbound_publisher::destroy, explicit_publish_destroy(), lock, LOG_WARNING, sip_outbound_publisher::owner, ast_sip_outbound_publish_client::publish, SCOPED_AO2LOCK, send_unpublish_task(), sip_outbound_publisher::sending, sip_outbound_publisher::serializer, and ast_sip_outbound_publish_client::started.

Referenced by sip_outbound_publish_state_destroy(), and sip_outbound_publish_synchronize().

◆ cancel_publish_refresh()

static void cancel_publish_refresh ( struct sip_outbound_publisher publisher)
static

Helper function which cancels the refresh timer on a publisher.

Definition at line 399 of file res_pjsip_outbound_publish.c.

400{
401 if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),
402 &publisher->timer, 0)) {
403 /* The timer was successfully cancelled, drop the refcount of the publisher */
404 ao2_ref(publisher, -1);
405 }
406}
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
pj_timer_entry timer
Timer entry for refreshing publish.

References ao2_ref, ast_sip_get_pjsip_endpoint(), and sip_outbound_publisher::timer.

Referenced by cancel_refresh_timer_task(), and schedule_publish_refresh().

◆ cancel_refresh_timer_task()

static int cancel_refresh_timer_task ( void *  data)
static

Task for cancelling a refresh timer.

Definition at line 453 of file res_pjsip_outbound_publish.c.

454{
455 struct sip_outbound_publisher *publisher = data;
456
457 cancel_publish_refresh(publisher);
458 ao2_ref(publisher, -1);
459
460 return 0;
461}
static void cancel_publish_refresh(struct sip_outbound_publisher *publisher)
Helper function which cancels the refresh timer on a publisher.

References ao2_ref, and cancel_publish_refresh().

Referenced by cancel_and_unpublish(), and sip_outbound_publish_client_add_publisher().

◆ current_state_reusable()

static int current_state_reusable ( struct ast_sip_outbound_publish publish,
struct ast_sip_outbound_publish_state current_state 
)
static

Definition at line 1528 of file res_pjsip_outbound_publish.c.

1530{
1531 struct ast_sip_outbound_publish *old_publish;
1532
1533 /*
1534 * Don't maintain the old state/client objects if the multi_user option changed.
1535 */
1536 if ((!publish->multi_user && current_state->client->publish->multi_user) ||
1537 (publish->multi_user && !current_state->client->publish->multi_user)) {
1538 return 0;
1539 }
1540
1541
1542 if (!can_reuse_publish(current_state->client->publish, publish)) {
1543 /*
1544 * Something significant has changed in the configuration, so we are
1545 * unable to use the old state object. The current state needs to go
1546 * away and a new one needs to be created.
1547 */
1548 return 0;
1549 }
1550
1551 /*
1552 * We can reuse the current state object so keep it, but swap out the
1553 * underlying publish object with the new one.
1554 */
1555 old_publish = current_state->client->publish;
1556 current_state->client->publish = publish;
1558 current_state->client->publishers)) {
1559 /*
1560 * If the state object fails to re-initialize then swap
1561 * the old publish info back in.
1562 */
1563 current_state->client->publish = publish;
1564 ast_log(LOG_ERROR, "Unable to reinitialize client(s) for outbound publish '%s'\n",
1565 ast_sorcery_object_get_id(current_state->client->publish));
1566 return -1;
1567 }
1568
1569 /*
1570 * Since we swapped out the publish object the new one needs a ref
1571 * while the old one needs to go away.
1572 */
1573 ao2_ref(current_state->client->publish, +1);
1574 ao2_cleanup(old_publish);
1575
1576 /* Tell the caller that the current state object should be used */
1577 return 1;
1578}
int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to SIP servants and wait for it to complete.
Definition: res_pjsip.c:2165
static int can_reuse_publish(struct ast_sip_outbound_publish *existing, struct ast_sip_outbound_publish *applied)
static int sip_outbound_publisher_reinit_all(void *data)
struct ast_sip_outbound_publish_client * client
Outbound publish client.
unsigned int multi_user
The publishing client is used for multiple users when true.

References ao2_cleanup, ao2_ref, ast_log, ast_sip_push_task_wait_servant(), ast_sorcery_object_get_id(), can_reuse_publish(), ast_sip_outbound_publish_state::client, LOG_ERROR, ast_sip_outbound_publish::multi_user, NULL, publish, ast_sip_outbound_publish_client::publish, ast_sip_outbound_publish_client::publishers, and sip_outbound_publisher_reinit_all().

Referenced by sip_outbound_publish_apply().

◆ datastore_cmp()

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

Definition at line 1423 of file res_pjsip_outbound_publish.c.

1424{
1425 const struct ast_datastore *object_left = obj;
1426 const struct ast_datastore *object_right = arg;
1427 const char *right_key = arg;
1428 int cmp;
1429
1430 switch (flags & OBJ_SEARCH_MASK) {
1431 case OBJ_SEARCH_OBJECT:
1432 right_key = object_right->uid;
1433 /* Fall through */
1434 case OBJ_SEARCH_KEY:
1435 cmp = strcmp(object_left->uid, right_key);
1436 break;
1438 cmp = strncmp(object_left->uid, right_key, strlen(right_key));
1439 break;
1440 default:
1441 /*
1442 * What arg points to is specific to this traversal callback
1443 * and has no special meaning to astobj2.
1444 */
1445 cmp = 0;
1446 break;
1447 }
1448 if (cmp) {
1449 return 0;
1450 }
1451 /*
1452 * At this point the traversal callback is identical to a sorted
1453 * container.
1454 */
1455 return CMP_MATCH;
1456}
@ CMP_MATCH
Definition: astobj2.h:1027
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1116
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition: astobj2.h:1087
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1072

References CMP_MATCH, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, and ast_datastore::uid.

Referenced by sip_outbound_publish_state_alloc().

◆ datastore_hash()

static int datastore_hash ( const void *  obj,
int  flags 
)
static

Definition at line 1401 of file res_pjsip_outbound_publish.c.

1402{
1403 const struct ast_datastore *datastore;
1404 const char *uid;
1405
1406 switch (flags & OBJ_SEARCH_MASK) {
1407 case OBJ_SEARCH_KEY:
1408 uid = obj;
1409 break;
1410 case OBJ_SEARCH_OBJECT:
1411 datastore = obj;
1412 uid = datastore->uid;
1413 break;
1414 default:
1415 /* Hash can only work on something with a full key. */
1416 ast_assert(0);
1417 return 0;
1418 }
1419
1420 return ast_str_hash(uid);
1421}
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1259

References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and ast_datastore::uid.

Referenced by sip_outbound_publish_state_alloc().

◆ explicit_publish_destroy()

static int explicit_publish_destroy ( void *  data)
static

Definition at line 1168 of file res_pjsip_outbound_publish.c.

1169{
1170 struct sip_outbound_publisher *publisher = data;
1171
1172 /*
1173 * If there is no pjsip publishing client then we obviously don't need
1174 * to destroy it. Also, the ref for the Asterisk publishing client that
1175 * pjsip had would not exist or should already be gone as well.
1176 */
1177 if (publisher->client) {
1178 pjsip_publishc_destroy(publisher->client);
1179 ao2_ref(publisher, -1);
1180 }
1181
1182 ao2_ref(publisher, -1);
1183
1184 return 0;
1185}

References ao2_ref, and sip_outbound_publisher::client.

Referenced by cancel_and_unpublish().

◆ find_publisher_handler_for_event_name()

static struct ast_sip_event_publisher_handler * find_publisher_handler_for_event_name ( const char *  event_name)
static

Definition at line 386 of file res_pjsip_outbound_publish.c.

387{
389
391 if (!strcmp(iter->event_name, event_name)) {
392 break;
393 }
394 }
395 return iter;
396}
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
const char * event_name
The name of the event this handler deals with.

References AST_RWLIST_TRAVERSE, ast_sip_event_publisher_handler::event_name, and ast_sip_event_publisher_handler::next.

Referenced by ast_sip_register_event_publisher_handler(), sip_outbound_publish_synchronize(), and stop_publishing().

◆ get_publishes_and_update_state()

static struct ao2_container * get_publishes_and_update_state ( void  )
static

Definition at line 359 of file res_pjsip_outbound_publish.c.

360{
361 struct ao2_container *container;
363
365 ast_sip_get_sorcery(), "outbound-publish",
367
368 if (!new_states) {
369 return container;
370 }
371
375
376 return container;
377}
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
Definition: astobj2.h:901
struct ao2_container * container
Definition: res_fax.c:531
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition: sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition: sorcery.h:123
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
Generic container type.

References ao2_cleanup, ao2_global_obj_replace_unref, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_fields(), container, load_lock, lock, new_states, NULL, and SCOPED_WRLOCK.

Referenced by sip_outbound_publish_synchronize().

◆ load_module()

static int load_module ( void  )
static

Definition at line 1683 of file res_pjsip_outbound_publish.c.

1684{
1685 /* As of pjproject 2.4.5, PJSIP_MAX_URL_SIZE isn't exposed yet but we try anyway. */
1686 ast_pjproject_get_buildopt("PJSIP_MAX_URL_SIZE", "%d", &pjsip_max_url_size);
1687
1689 if (!shutdown_group) {
1691 }
1692
1693 ast_sorcery_apply_config(ast_sip_get_sorcery(), "res_pjsip_outbound_publish");
1694 ast_sorcery_apply_default(ast_sip_get_sorcery(), "outbound-publish", "config", "pjsip.conf,criteria=type=outbound-publish");
1695
1698 ast_log(LOG_ERROR, "Unable to register 'outbound-publish' type with sorcery\n");
1699 unload_module();
1701 }
1702
1703 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "type", "", OPT_NOOP_T, 0, 0);
1705 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "from_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, from_uri));
1707 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "to_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, to_uri));
1708 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, outbound_proxy));
1709 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "expiration", "3600", OPT_UINT_T, 0, FLDSET(struct ast_sip_outbound_publish, expiration));
1710 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "max_auth_attempts", "5", OPT_UINT_T, 0, FLDSET(struct ast_sip_outbound_publish, max_auth_attempts));
1711 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "transport", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, transport));
1712 ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "outbound-publish", "outbound_auth", "", outbound_auth_handler, NULL, NULL, 0, 0);
1713 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "multi_user", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_outbound_publish, multi_user));
1714
1715 ast_sorcery_reload_object(ast_sip_get_sorcery(), "outbound-publish");
1716
1720
1721 pjsip_publishc_init_module(ast_sip_get_pjsip_endpoint());
1722
1724}
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
int ast_pjproject_get_buildopt(char *option, char *format_string,...)
Retrieve a pjproject build option.
static struct ast_serializer_shutdown_group * shutdown_group
static int outbound_auth_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static int pjsip_max_url_size
static int sip_outbound_publish_apply(const struct ast_sorcery *sorcery, void *obj)
Apply function which finds or allocates a state structure.
static void * sip_outbound_publish_alloc(const char *name)
Allocator function for publish information.
static int unload_module(void)
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
#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 ast_sorcery_apply_config(sorcery, name)
Definition: sorcery.h:455
#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_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
Definition: sorcery.c:1442
Definition: astman.c:222
static char server_uri[512]
struct ast_serializer_shutdown_group * ast_serializer_shutdown_group_alloc(void)
Create a serializer group shutdown control object.
Definition: threadpool.c:1229

References ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_pjproject_get_buildopt(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_serializer_shutdown_group_alloc(), ast_sip_get_pjsip_endpoint(), ast_sip_get_sorcery(), ast_sorcery_apply_config, ast_sorcery_apply_default, ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_register, ast_sorcery_reload_object(), ast_sip_outbound_publish::expiration, FLDSET, ast_sip_outbound_publish::from_uri, LOG_ERROR, ast_sip_outbound_publish::max_auth_attempts, ast_sip_outbound_publish::multi_user, NULL, OPT_BOOL_T, OPT_NOOP_T, OPT_STRINGFIELD_T, OPT_UINT_T, outbound_auth_handler(), ast_sip_outbound_publish::outbound_proxy, pjsip_max_url_size, server_uri, shutdown_group, sip_outbound_publish_alloc(), sip_outbound_publish_apply(), sip_outbound_publish_synchronize(), STRFLDSET, ast_sip_outbound_publish::to_uri, ast_sip_outbound_publish::transport, and unload_module().

◆ outbound_auth_handler()

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

Definition at line 1650 of file res_pjsip_outbound_publish.c.

1651{
1652 struct ast_sip_outbound_publish *publish = obj;
1653
1654 return ast_sip_auth_vector_init(&publish->outbound_auths, var->value);
1655}
#define var
Definition: ast_expr2f.c:605
int ast_sip_auth_vector_init(struct ast_sip_auth_vector *vector, const char *auth_names)
Initialize an auth vector with the configured values.

References ast_sip_auth_vector_init(), publish, and var.

Referenced by load_module().

◆ outbound_publish_state_cmp()

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

comparator function for client objects

Definition at line 331 of file res_pjsip_outbound_publish.c.

332{
333 const struct ast_sip_outbound_publish_state *object_left = obj;
334 const struct ast_sip_outbound_publish_state *object_right = arg;
335 const char *right_key = arg;
336 int cmp;
337
338 switch (flags & OBJ_SEARCH_MASK) {
340 right_key = object_right->id;
341 /* Fall through */
342 case OBJ_SEARCH_KEY:
343 cmp = strcmp(object_left->id, right_key);
344 break;
346 /* Not supported by container. */
347 ast_assert(0);
348 return 0;
349 default:
350 cmp = 0;
351 break;
352 }
353 if (cmp) {
354 return 0;
355 }
356 return CMP_MATCH;
357}

References ast_assert, CMP_MATCH, ast_sip_outbound_publish_state::id, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by sip_outbound_publish_apply().

◆ outbound_publish_state_hash()

static int outbound_publish_state_hash ( const void *  obj,
const int  flags 
)
static

hashing function for state objects

Definition at line 310 of file res_pjsip_outbound_publish.c.

311{
312 const struct ast_sip_outbound_publish_state *object;
313 const char *key;
314
315 switch (flags & OBJ_SEARCH_MASK) {
316 case OBJ_SEARCH_KEY:
317 key = obj;
318 break;
320 object = obj;
321 key = object->id;
322 break;
323 default:
324 ast_assert(0);
325 return 0;
326 }
327 return ast_str_hash(key);
328}

References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.

Referenced by sip_outbound_publish_apply().

◆ publisher_client_send()

static int publisher_client_send ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Definition at line 832 of file res_pjsip_outbound_publish.c.

833{
834 struct sip_outbound_publisher *publisher = obj;
835 const struct ast_sip_body *body = arg;
837 size_t type_len = 0, subtype_len = 0, body_text_len = 0;
838 int *res = data;
839 SCOPED_AO2LOCK(lock, publisher);
840
841 *res = -1;
842 if (!publisher->client) {
843 return -1;
844 }
845
846 /* If a body is present we need more space for the contents of it */
847 if (body) {
848 type_len = strlen(body->type) + 1;
849 subtype_len = strlen(body->subtype) + 1;
850 body_text_len = strlen(body->body_text) + 1;
851 }
852
853 message = ast_calloc(1, sizeof(*message) + type_len + subtype_len + body_text_len);
854 if (!message) {
855 return -1;
856 }
857
858 if (body) {
859 char *dst = message->body_contents;
860
861 message->body.type = strcpy(dst, body->type);
862 dst += type_len;
863 message->body.subtype = strcpy(dst, body->subtype);
864 dst += subtype_len;
865 message->body.body_text = strcpy(dst, body->body_text);
866 }
867
869
871 if (*res) {
872 ao2_ref(publisher, -1);
873 }
874
875 return *res;
876}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
static int sip_publisher_service_queue(void *data)
SIP body description.
Definition: res_pjsip.h:2444
const char * type
Definition: res_pjsip.h:2446
const char * body_text
Definition: res_pjsip.h:2450
const char * subtype
Definition: res_pjsip.h:2448
Queued outbound publish message.
struct ast_sip_body body
Optional body.
struct sip_outbound_publish_message::@463 entry
Linked list information.
struct sip_outbound_publisher::@464 queue
Queue of outgoing publish messages to send.

References ao2_bump, ao2_ref, ast_calloc, AST_LIST_INSERT_TAIL, ast_sip_push_task(), sip_outbound_publish_message::body, ast_sip_body::body_text, sip_outbound_publisher::client, sip_outbound_publish_message::entry, lock, sip_outbound_publisher::queue, SCOPED_AO2LOCK, sip_outbound_publisher::serializer, sip_publisher_service_queue(), ast_sip_body::subtype, and ast_sip_body::type.

Referenced by ast_sip_publish_client_send(), ast_sip_publish_client_user_send(), and sip_outbound_publish_timer_cb().

◆ reload_module()

static int reload_module ( void  )
static

◆ schedule_publish_refresh()

static void schedule_publish_refresh ( struct sip_outbound_publisher publisher,
int  expiration 
)
static

Helper function which sets up the timer to send publication.

Definition at line 409 of file res_pjsip_outbound_publish.c.

410{
412 pj_time_val delay = { .sec = 0, };
413
414 cancel_publish_refresh(publisher);
415
416 if (expiration > 0) {
417 delay.sec = expiration - PJSIP_PUBLISHC_DELAY_BEFORE_REFRESH;
418 }
419 if (publish->expiration && ((delay.sec > publish->expiration) || !delay.sec)) {
420 delay.sec = publish->expiration;
421 }
422 if (delay.sec < PJSIP_PUBLISHC_DELAY_BEFORE_REFRESH) {
423 delay.sec = PJSIP_PUBLISHC_DELAY_BEFORE_REFRESH;
424 }
425
426 ao2_ref(publisher, +1);
427 if (pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(), &publisher->timer, &delay) != PJ_SUCCESS) {
428 ast_log(LOG_WARNING, "Failed to pass timed publish refresh to scheduler\n");
429 ao2_ref(publisher, -1);
430 }
431 ao2_ref(publish, -1);
432}
unsigned int expiration
Requested expiration time.

References ao2_bump, ao2_ref, ast_log, ast_sip_get_pjsip_endpoint(), cancel_publish_refresh(), ast_sip_outbound_publish::expiration, LOG_WARNING, sip_outbound_publisher::owner, publish, ast_sip_outbound_publish_client::publish, and sip_outbound_publisher::timer.

Referenced by sip_outbound_publish_callback().

◆ send_unpublish_task()

static int send_unpublish_task ( void *  data)
static

Task for sending an unpublish.

Definition at line 476 of file res_pjsip_outbound_publish.c.

477{
478 struct sip_outbound_publisher *publisher = data;
479 pjsip_tx_data *tdata;
480
481 if (pjsip_publishc_unpublish(publisher->client, &tdata) == PJ_SUCCESS) {
482 set_transport(publisher, tdata);
483 pjsip_publishc_send(publisher->client, tdata);
484 }
485
486 ao2_ref(publisher, -1);
487
488 return 0;
489}
static void set_transport(struct sip_outbound_publisher *publisher, pjsip_tx_data *tdata)

References ao2_ref, sip_outbound_publisher::client, and set_transport().

Referenced by cancel_and_unpublish(), and sip_outbound_publish_callback().

◆ set_transport()

static void set_transport ( struct sip_outbound_publisher publisher,
pjsip_tx_data *  tdata 
)
static

Definition at line 463 of file res_pjsip_outbound_publish.c.

464{
465 if (!ast_strlen_zero(publisher->owner->publish->transport)) {
466 pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
467
469 publisher->owner->publish->transport, &selector);
470 pjsip_tx_data_set_transport(tdata, &selector);
471 ast_sip_tpselector_unref(&selector);
472 }
473}
void ast_sip_tpselector_unref(pjsip_tpselector *selector)
Unreference a pjsip_tpselector.
Definition: res_pjsip.c:923
int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip_tpselector *selector)
Sets pjsip_tpselector from ast_sip_transport.
Definition: res_pjsip.c:893

References ast_sip_set_tpselector_from_transport_name(), ast_sip_tpselector_unref(), ast_strlen_zero(), sip_outbound_publisher::owner, ast_sip_outbound_publish_client::publish, and ast_sip_outbound_publish::transport.

Referenced by send_unpublish_task(), sip_outbound_publish_callback(), and sip_publisher_service_queue().

◆ sip_outbound_publish_alloc()

static void * sip_outbound_publish_alloc ( const char *  name)
static

Allocator function for publish information.

Definition at line 703 of file res_pjsip_outbound_publish.c.

704{
707
708 if (!publish || ast_string_field_init(publish, 256)) {
710 return NULL;
711 }
712
713 return publish;
714}
static void sip_outbound_publish_destroy(void *obj)
Destructor function for publish information.
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_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359

References ao2_cleanup, ast_sorcery_generic_alloc(), ast_string_field_init, NULL, publish, and sip_outbound_publish_destroy().

Referenced by load_module().

◆ sip_outbound_publish_apply()

static int sip_outbound_publish_apply ( const struct ast_sorcery sorcery,
void *  obj 
)
static

Apply function which finds or allocates a state structure.

Definition at line 1581 of file res_pjsip_outbound_publish.c.

1582{
1583#define ADD_TO_NEW_STATES(__obj) \
1584 do { if (__obj) { \
1585 ao2_link(new_states, __obj); \
1586 ao2_ref(__obj, -1); } } while (0)
1587
1588 struct ast_sip_outbound_publish *applied = obj;
1589 struct ast_sip_outbound_publish_state *current_state, *new_state;
1590 struct sip_outbound_publisher *publisher = NULL;
1591 int res;
1592
1593 /*
1594 * New states are being loaded or reloaded. We'll need to add the new
1595 * object if created/updated, or keep the old object if an error occurs.
1596 */
1597 if (!new_states) {
1601
1602 if (!new_states) {
1603 ast_log(LOG_ERROR, "Unable to allocate new states container\n");
1604 return -1;
1605 }
1606 }
1607
1608 /* If there is current state we'll want to maintain it if any errors occur */
1609 current_state = sip_publish_state_get(ast_sorcery_object_get_id(applied));
1610
1611 if ((res = validate_publish_config(applied))) {
1612 ADD_TO_NEW_STATES(current_state);
1613 return res;
1614 }
1615
1616 if (current_state && (res = current_state_reusable(applied, current_state))) {
1617 /*
1618 * The current state object was able to be reused, or an error
1619 * occurred. Either way we keep the current state and be done.
1620 */
1621 ADD_TO_NEW_STATES(current_state);
1622 return res == 1 ? 0 : -1;
1623 }
1624
1625 /*
1626 * No current state was found or it was unable to be reused. Either way
1627 * we'll need to create a new state object.
1628 */
1629 new_state = sip_outbound_publish_state_alloc(applied);
1630 if (!new_state) {
1631 ast_log(LOG_ERROR, "Unable to create state for outbound publish '%s'\n",
1632 ast_sorcery_object_get_id(applied));
1633 ADD_TO_NEW_STATES(current_state);
1634 return -1;
1635 };
1636
1637 if (!applied->multi_user &&
1638 !(publisher = sip_outbound_publish_client_add_publisher(new_state->client, NULL))) {
1639 ADD_TO_NEW_STATES(current_state);
1640 ao2_ref(new_state, -1);
1641 return -1;
1642 }
1643 ao2_cleanup(publisher);
1644
1645 ADD_TO_NEW_STATES(new_state);
1646 ao2_cleanup(current_state);
1647 return res;
1648}
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
static int current_state_reusable(struct ast_sip_outbound_publish *publish, struct ast_sip_outbound_publish_state *current_state)
static int outbound_publish_state_hash(const void *obj, const int flags)
hashing function for state objects
#define DEFAULT_STATE_BUCKETS
Default number of client state container buckets.
static int outbound_publish_state_cmp(void *obj, void *arg, int flags)
comparator function for client objects
static int validate_publish_config(struct ast_sip_outbound_publish *publish)
static struct ast_sip_outbound_publish_state * sip_outbound_publish_state_alloc(struct ast_sip_outbound_publish *publish)
Allocator function for publish client.
static struct sip_outbound_publisher * sip_outbound_publish_client_add_publisher(struct ast_sip_outbound_publish_client *client, const char *user)
#define ADD_TO_NEW_STATES(__obj)

References ADD_TO_NEW_STATES, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_cleanup, ao2_container_alloc_hash, ao2_ref, ast_log, ast_sorcery_object_get_id(), ast_sip_outbound_publish_state::client, current_state_reusable(), DEFAULT_STATE_BUCKETS, LOG_ERROR, ast_sip_outbound_publish::multi_user, new_states, NULL, outbound_publish_state_cmp(), outbound_publish_state_hash(), sip_outbound_publish_client_add_publisher(), sip_outbound_publish_state_alloc(), sip_publish_state_get(), and validate_publish_config().

Referenced by load_module().

◆ sip_outbound_publish_callback()

static void sip_outbound_publish_callback ( struct pjsip_publishc_cbparam *  param)
static

Callback function for publish client responses.

Definition at line 1296 of file res_pjsip_outbound_publish.c.

1297{
1298#define DESTROY_CLIENT() do { \
1299 pjsip_publishc_destroy(publisher->client); \
1300 publisher->client = NULL; \
1301 ao2_ref(publisher, -1); } while (0)
1302
1303 RAII_VAR(struct sip_outbound_publisher *, publisher, ao2_bump(param->token), ao2_cleanup);
1304 RAII_VAR(struct ast_sip_outbound_publish *, publish, ao2_bump(publisher->owner->publish), ao2_cleanup);
1305 SCOPED_AO2LOCK(lock, publisher);
1306 pjsip_tx_data *tdata;
1307
1308 if (publisher->destroy) {
1309 if (publisher->sending) {
1310 publisher->sending = NULL;
1311
1312 if (!ast_sip_push_task(publisher->serializer, send_unpublish_task, ao2_bump(publisher))) {
1313 return;
1314 }
1315 ast_log(LOG_WARNING, "Could not send unpublish message on outbound publish '%s'\n",
1317 ao2_ref(publisher, -1);
1318 }
1319 /* Once the destroy is called this callback will not get called any longer, so drop the publisher ref */
1321 return;
1322 }
1323
1324 if (param->code == 401 || param->code == 407) {
1325 pjsip_transaction *tsx = pjsip_rdata_get_tsx(param->rdata);
1326
1327 if (!ast_sip_create_request_with_auth(&publish->outbound_auths,
1328 param->rdata, tsx->last_tx, &tdata)) {
1329 set_transport(publisher, tdata);
1330 pjsip_publishc_send(publisher->client, tdata);
1331 }
1332 publisher->auth_attempts++;
1333
1334 if (publisher->auth_attempts == publish->max_auth_attempts) {
1336 ast_log(LOG_ERROR, "Reached maximum number of PUBLISH authentication attempts on outbound publish '%s'\n",
1338
1339 goto end;
1340 }
1341 return;
1342 }
1343
1344 publisher->auth_attempts = 0;
1345
1346 if (param->code == 412) {
1348 if (sip_outbound_publisher_init(publisher)) {
1349 ast_log(LOG_ERROR, "Failed to create a new outbound publish client for '%s' on 412 response\n",
1351 goto end;
1352 }
1353
1354 /* Setting this to NULL will cause a new PUBLISH to get created and sent for the same underlying body */
1355 publisher->sending = NULL;
1356 } else if (param->code == 423) {
1357 /* Update the expiration with the new expiration time if available */
1358 pjsip_expires_hdr *expires;
1359
1360 expires = pjsip_msg_find_hdr(param->rdata->msg_info.msg, PJSIP_H_MIN_EXPIRES, NULL);
1361 if (!expires || !expires->ivalue) {
1363 ast_log(LOG_ERROR, "Received 423 response on outbound publish '%s' without a Min-Expires header\n",
1365 goto end;
1366 }
1367
1368 pjsip_publishc_update_expires(publisher->client, expires->ivalue);
1369 publisher->sending = NULL;
1370 } else if (publisher->sending) {
1371 /* Remove the message currently being sent so that when the queue is serviced another will get sent */
1372 AST_LIST_REMOVE_HEAD(&publisher->queue, entry);
1373 ast_free(publisher->sending);
1374 publisher->sending = NULL;
1375 if (!param->rdata) {
1376 ast_log(LOG_NOTICE, "No response received for outbound publish '%s'\n",
1378 }
1379 }
1380
1381 if (AST_LIST_EMPTY(&publisher->queue)) {
1382 schedule_publish_refresh(publisher, param->expiration);
1383 }
1384
1385end:
1386 if (!publisher->client) {
1388
1389 while ((message = AST_LIST_REMOVE_HEAD(&publisher->queue, entry))) {
1391 }
1392 } else {
1393 if (ast_sip_push_task(publisher->serializer, sip_publisher_service_queue, ao2_bump(publisher))) {
1394 ao2_ref(publisher, -1);
1395 }
1396 }
1397}
#define ast_free(a)
Definition: astmm.h:180
char * end
Definition: eagi_proxy.c:73
#define LOG_NOTICE
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge, pjsip_tx_data *tdata, pjsip_tx_data **new_request)
Create a response to an authentication challenge.
Definition: res_pjsip.c:214
static void schedule_publish_refresh(struct sip_outbound_publisher *publisher, int expiration)
Helper function which sets up the timer to send publication.
#define DESTROY_CLIENT()
static int sip_outbound_publisher_init(void *data)
Helper function that allocates a pjsip publish client and configures it.

References ao2_bump, ao2_cleanup, ao2_ref, ast_free, AST_LIST_EMPTY, AST_LIST_REMOVE_HEAD, ast_log, ast_sip_create_request_with_auth(), ast_sip_push_task(), ast_sorcery_object_get_id(), DESTROY_CLIENT, end, sip_outbound_publish_message::entry, lock, LOG_ERROR, LOG_NOTICE, LOG_WARNING, NULL, publish, RAII_VAR, schedule_publish_refresh(), SCOPED_AO2LOCK, send_unpublish_task(), set_transport(), sip_outbound_publisher_init(), and sip_publisher_service_queue().

Referenced by sip_outbound_publisher_init().

◆ sip_outbound_publish_client_add_publisher()

static struct sip_outbound_publisher * sip_outbound_publish_client_add_publisher ( struct ast_sip_outbound_publish_client client,
const char *  user 
)
static

Definition at line 1121 of file res_pjsip_outbound_publish.c.

1123{
1124 struct sip_outbound_publisher *publisher =
1126
1127 if (!publisher) {
1128 return NULL;
1129 }
1130
1131 if (!ao2_link(client->publishers, publisher)) {
1132 /*
1133 * No need to bump the reference here. The task will take care of
1134 * removing the reference.
1135 */
1136 if (ast_sip_push_task(publisher->serializer, cancel_refresh_timer_task, publisher)) {
1137 ao2_ref(publisher, -1);
1138 }
1139 return NULL;
1140 }
1141
1142 return publisher;
1143}
static struct sip_outbound_publisher * sip_outbound_publisher_alloc(struct ast_sip_outbound_publish_client *client, const char *user)

References ao2_link, ao2_ref, ast_sip_push_task(), cancel_refresh_timer_task(), sip_outbound_publisher::client, NULL, sip_outbound_publisher::serializer, and sip_outbound_publisher_alloc().

Referenced by sip_outbound_publish_apply(), and sip_outbound_publish_client_get_publisher().

◆ sip_outbound_publish_client_destroy()

static void sip_outbound_publish_client_destroy ( void *  obj)
static

Destructor function for publish client.

Definition at line 1224 of file res_pjsip_outbound_publish.c.

1225{
1226 struct ast_sip_outbound_publish_client *client = obj;
1227
1228 ao2_cleanup(client->datastores);
1229
1230 /*
1231 * The client's publishers have already been unpublished and destroyed
1232 * by this point, so it is safe to finally remove the reference to the
1233 * publish object. The client needed to hold a reference to it until
1234 * the publishers were done with it.
1235 */
1236 ao2_cleanup(client->publish);
1237}

References ao2_cleanup, ast_sip_outbound_publish_client::datastores, and ast_sip_outbound_publish_client::publish.

Referenced by sip_outbound_publish_state_alloc().

◆ sip_outbound_publish_client_get_publisher()

static struct sip_outbound_publisher * sip_outbound_publish_client_get_publisher ( struct ast_sip_outbound_publish_client client,
const char *  user 
)
static

Definition at line 587 of file res_pjsip_outbound_publish.c.

589{
590 struct sip_outbound_publisher *publisher;
591
592 /*
593 * Lock before searching since there could be a race between searching and adding.
594 * Just use the load_lock since we might need to lock it anyway (if adding) and
595 * also it simplifies the code (otherwise we'd have to lock the publishers, no-
596 * lock the search and pass a flag to 'add publisher to no-lock the potential link).
597 */
599 publisher = ao2_find(client->publishers, user, OBJ_SEARCH_KEY);
600 if (!publisher) {
603 return NULL;
604 }
605 }
607
608 return publisher;
609}
#define ast_rwlock_wrlock(a)
Definition: lock.h:240
#define ast_rwlock_unlock(a)
Definition: lock.h:238

References ao2_find, ast_rwlock_unlock, ast_rwlock_wrlock, sip_outbound_publisher::client, load_lock, NULL, OBJ_SEARCH_KEY, and sip_outbound_publish_client_add_publisher().

Referenced by ast_sip_publish_client_get_user_from_uri(), ast_sip_publish_client_get_user_to_uri(), and ast_sip_publish_client_user_send().

◆ sip_outbound_publish_datastore_destroy()

static void sip_outbound_publish_datastore_destroy ( void *  obj)
static

Definition at line 716 of file res_pjsip_outbound_publish.c.

717{
718 struct ast_datastore *datastore = obj;
719
720 /* Using the destroy function (if present) destroy the data */
721 if (datastore->info->destroy != NULL && datastore->data != NULL) {
722 datastore->info->destroy(datastore->data);
723 datastore->data = NULL;
724 }
725
726 ast_free((void *) datastore->uid);
727 datastore->uid = NULL;
728}
void(* destroy)(void *data)
Definition: datastore.h:34
void * data
Definition: datastore.h:66

References ast_free, ast_datastore::data, ast_datastore_info::destroy, ast_datastore::info, NULL, and ast_datastore::uid.

Referenced by ast_sip_publish_client_alloc_datastore().

◆ sip_outbound_publish_destroy()

static void sip_outbound_publish_destroy ( void *  obj)
static

Destructor function for publish information.

Definition at line 693 of file res_pjsip_outbound_publish.c.

694{
695 struct ast_sip_outbound_publish *publish = obj;
696
697 ast_sip_auth_vector_destroy(&publish->outbound_auths);
698
700}
void ast_sip_auth_vector_destroy(struct ast_sip_auth_vector *vector)
Free contents of an auth vector.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374

References ast_sip_auth_vector_destroy(), ast_string_field_free_memory, and publish.

Referenced by sip_outbound_publish_alloc().

◆ sip_outbound_publish_state_alloc()

static struct ast_sip_outbound_publish_state * sip_outbound_publish_state_alloc ( struct ast_sip_outbound_publish publish)
static

Allocator function for publish client.

Definition at line 1459 of file res_pjsip_outbound_publish.c.

1461{
1462 const char *id = ast_sorcery_object_get_id(publish);
1464 ao2_alloc(sizeof(*state) + strlen(id) + 1, sip_outbound_publish_state_destroy);
1465
1466 if (!state) {
1467 return NULL;
1468 }
1469
1470 state->client = ao2_alloc(sizeof(*state->client), sip_outbound_publish_client_destroy);
1471 if (!state->client) {
1472 ao2_ref(state, -1);
1473 return NULL;
1474 }
1475
1478 if (!state->client->datastores) {
1479 ao2_ref(state, -1);
1480 return NULL;
1481 }
1482
1485 sip_outbound_publisher_hash_fn, NULL, sip_outbound_publisher_cmp_fn);
1486 if (!state->client->publishers) {
1487 ao2_ref(state, -1);
1488 return NULL;
1489 }
1490
1491 state->client->publish = ao2_bump(publish);
1492
1493 strcpy(state->id, id);
1494 return state;
1495}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
enum cc_state state
Definition: ccss.c:399
#define DATASTORE_BUCKETS
static void sip_outbound_publish_client_destroy(void *obj)
Destructor function for publish client.
static void sip_outbound_publish_state_destroy(void *obj)
Destructor function for publish state.
static int datastore_cmp(void *obj, void *arg, int flags)
static int datastore_hash(const void *obj, int flags)

References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_bump, ao2_container_alloc_hash, ao2_ref, ast_sorcery_object_get_id(), DATASTORE_BUCKETS, datastore_cmp(), datastore_hash(), NULL, publish, sip_outbound_publish_client_destroy(), sip_outbound_publish_state_destroy(), and state.

Referenced by sip_outbound_publish_apply().

◆ sip_outbound_publish_state_destroy()

static void sip_outbound_publish_state_destroy ( void *  obj)
static

Destructor function for publish state.

Definition at line 1240 of file res_pjsip_outbound_publish.c.

1241{
1243
1244 stop_publishing(state->client, NULL);
1245 /*
1246 * Since the state is being destroyed the associated client needs to also
1247 * be destroyed. However simply removing the reference to the client will
1248 * not initiate client destruction since the client's publisher(s) hold a
1249 * reference to the client object as well. So we need to unpublish the
1250 * the client's publishers here, which will remove the publisher's client
1251 * reference during that process.
1252 *
1253 * That being said we don't want to remove the client's reference to the
1254 * publish object just yet. We'll hold off on that until client destruction
1255 * itself. This is because the publishers need access to the client's
1256 * publish object while they are unpublishing.
1257 */
1259 ao2_cleanup(state->client->publishers);
1260
1261 state->client->started = 0;
1262 ao2_cleanup(state->client);
1263}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
static void stop_publishing(struct ast_sip_outbound_publish_client *client, struct ast_sip_event_publisher_handler *handler)
static int cancel_and_unpublish(void *obj, void *arg, int flags)
Helper function which cancels and un-publishes a no longer used client.

References ao2_callback, ao2_cleanup, cancel_and_unpublish(), NULL, OBJ_NODATA, OBJ_UNLINK, and stop_publishing().

Referenced by sip_outbound_publish_state_alloc().

◆ sip_outbound_publish_synchronize()

static void sip_outbound_publish_synchronize ( struct ast_sip_event_publisher_handler removed)
static

Helper function which starts or stops publish clients when applicable.

Definition at line 506 of file res_pjsip_outbound_publish.c.

507{
509 struct ao2_container *states;
510 struct ao2_iterator i;
512
513 if (!publishes) {
514 return;
515 }
516
517 states = ao2_global_obj_ref(current_states);
518 if (!states) {
519 return;
520 }
521
522 i = ao2_iterator_init(states, 0);
523 while ((state = ao2_iterator_next(&i))) {
524 struct ast_sip_outbound_publish *publish = ao2_bump(state->client->publish);
526
527 if (!state->client->started) {
528 /* If the publisher client has not yet been started try to start it */
529 if (!handler) {
530 ast_debug(2, "Could not find handler for event '%s' for outbound publish client '%s'\n",
532 } else if (handler->start_publishing(publish, state->client)) {
533 ast_log(LOG_ERROR, "Failed to start outbound publish with event '%s' for client '%s'\n",
535 } else {
536 state->client->started = 1;
537 }
538 } else if (state->client->started && !handler && removed && !strcmp(publish->event, removed->event_name)) {
539 stop_publishing(state->client, removed);
540 ao2_callback(state->client->publishers, OBJ_NODATA, cancel_and_unpublish, NULL);
541 state->client->started = 0;
542 }
543 ao2_ref(publish, -1);
544 ao2_ref(state, -1);
545 }
547 ao2_ref(states, -1);
548}
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ast_debug(level,...)
Log a DEBUG message.
static struct ao2_container * get_publishes_and_update_state(void)
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821

References ao2_bump, ao2_callback, ao2_cleanup, ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_debug, ast_log, ast_sorcery_object_get_id(), cancel_and_unpublish(), ast_sip_event_publisher_handler::event_name, find_publisher_handler_for_event_name(), get_publishes_and_update_state(), handler(), LOG_ERROR, NULL, OBJ_NODATA, publish, RAII_VAR, state, and stop_publishing().

Referenced by ast_sip_register_event_publisher_handler(), ast_sip_unregister_event_publisher_handler(), load_module(), and reload_module().

◆ sip_outbound_publish_timer_cb()

static void sip_outbound_publish_timer_cb ( pj_timer_heap_t *  timer_heap,
struct pj_timer_entry *  entry 
)
static

Publish client timer callback function.

Definition at line 437 of file res_pjsip_outbound_publish.c.

438{
439 struct sip_outbound_publisher *publisher = entry->user_data;
440
441 ao2_lock(publisher);
442 if (AST_LIST_EMPTY(&publisher->queue)) {
443 int res;
444 /* If there are no outstanding messages send an empty PUBLISH message so our publication doesn't expire */
445 publisher_client_send(publisher, NULL, &res, 0);
446 }
447 ao2_unlock(publisher);
448
449 ao2_ref(publisher, -1);
450}
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717

References ao2_lock, ao2_ref, ao2_unlock, AST_LIST_EMPTY, NULL, publisher_client_send(), and sip_outbound_publisher::queue.

Referenced by sip_outbound_publisher_alloc().

◆ sip_outbound_publisher_alloc()

static struct sip_outbound_publisher * sip_outbound_publisher_alloc ( struct ast_sip_outbound_publish_client client,
const char *  user 
)
static

Definition at line 1069 of file res_pjsip_outbound_publish.c.

1071{
1072 struct sip_outbound_publisher *publisher;
1073 char tps_name[AST_TASKPROCESSOR_MAX_NAME + 1];
1074
1075 publisher = ao2_alloc(sizeof(*publisher) + (user ? strlen(user) : 0) + 1,
1077 if (!publisher) {
1078 return NULL;
1079 }
1080
1081 /*
1082 * Bump the ref to the client. This essentially creates a circular reference,
1083 * but it is needed in order to make sure the client object doesn't get pulled
1084 * out from under us when the publisher stops publishing.
1085 *
1086 * The circular reference is alleviated by calling cancel_and_unpublish for
1087 * each client, from the state's destructor. By calling it there all references
1088 * to the publishers should go to zero, thus calling the publisher's destructor.
1089 * This in turn removes the client reference we added here. The state then removes
1090 * its reference to the client, which should take it to zero.
1091 */
1092 publisher->owner = ao2_bump(client);
1093 publisher->timer.user_data = publisher;
1094 publisher->timer.cb = sip_outbound_publish_timer_cb;
1095 if (user) {
1096 strcpy(publisher->user, user);
1097 } else {
1098 *publisher->user = '\0';
1099 }
1100
1101 ast_taskprocessor_build_name(tps_name, sizeof(tps_name), "pjsip/outpub/%s",
1103
1104 publisher->serializer = ast_sip_create_serializer_group(tps_name,
1106 if (!publisher->serializer) {
1107 ao2_ref(publisher, -1);
1108 return NULL;
1109 }
1110
1112 ast_log(LOG_ERROR, "Unable to create publisher for outbound publish '%s'\n",
1114 ao2_ref(publisher, -1);
1115 return NULL;
1116 }
1117
1118 return publisher;
1119}
struct ast_taskprocessor * ast_sip_create_serializer_group(const char *name, struct ast_serializer_shutdown_group *shutdown_group)
Create a new serializer for SIP tasks.
Definition: res_pjsip.c:2089
static void sip_outbound_publisher_destroy(void *obj)
Destructor function for publish client.
static void sip_outbound_publish_timer_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
Publish client timer callback function.
char user[0]
User, if any, associated with the publisher.
void ast_taskprocessor_build_name(char *buf, unsigned int size, const char *format,...)
Build a taskprocessor name with a sequence number on the end.
#define AST_TASKPROCESSOR_MAX_NAME
Suggested maximum taskprocessor name length (less null terminator).
Definition: taskprocessor.h:61

References ao2_alloc, ao2_bump, ao2_ref, ast_log, ast_sip_create_serializer_group(), ast_sip_push_task_wait_servant(), ast_sorcery_object_get_id(), ast_taskprocessor_build_name(), AST_TASKPROCESSOR_MAX_NAME, sip_outbound_publisher::client, LOG_ERROR, NULL, sip_outbound_publisher::owner, sip_outbound_publisher::serializer, shutdown_group, sip_outbound_publish_timer_cb(), sip_outbound_publisher_destroy(), sip_outbound_publisher_init(), sip_outbound_publisher::timer, and sip_outbound_publisher::user.

Referenced by sip_outbound_publish_client_add_publisher().

◆ sip_outbound_publisher_destroy()

static void sip_outbound_publisher_destroy ( void *  obj)
static

Destructor function for publish client.

Definition at line 1051 of file res_pjsip_outbound_publish.c.

1052{
1053 struct sip_outbound_publisher *publisher = obj;
1055
1056 /* You might be tempted to think "the publish client isn't being destroyed" but it actually is - just elsewhere */
1057
1058 while ((message = AST_LIST_REMOVE_HEAD(&publisher->queue, entry))) {
1060 }
1061
1062 ao2_cleanup(publisher->owner);
1063 ast_free(publisher->from_uri);
1064 ast_free(publisher->to_uri);
1065
1067}
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.

References ao2_cleanup, ast_free, AST_LIST_REMOVE_HEAD, ast_taskprocessor_unreference(), sip_outbound_publish_message::entry, sip_outbound_publisher::from_uri, sip_outbound_publisher::owner, sip_outbound_publisher::queue, sip_outbound_publisher::serializer, and sip_outbound_publisher::to_uri.

Referenced by sip_outbound_publisher_alloc().

◆ sip_outbound_publisher_init()

static int sip_outbound_publisher_init ( void *  data)
static

Helper function that allocates a pjsip publish client and configures it.

Definition at line 971 of file res_pjsip_outbound_publish.c.

972{
973 struct sip_outbound_publisher *publisher = data;
975 pjsip_publishc_opt opt = {
976 .queue_request = PJ_FALSE,
977 };
978 pj_pool_t *pool;
979 pj_str_t event, server_uri, to_uri, from_uri;
980
981 if (publisher->client) {
982 return 0;
983 }
984
985 if (pjsip_publishc_create(ast_sip_get_pjsip_endpoint(), &opt,
987 &publisher->client) != PJ_SUCCESS) {
988 ao2_ref(publisher, -1);
989 return -1;
990 }
991
992 publish = ao2_bump(publisher->owner->publish);
993
994 if (!ast_strlen_zero(publish->outbound_proxy)) {
995 pjsip_route_hdr route_set, *route;
996 static const pj_str_t ROUTE_HNAME = { "Route", 5 };
997
998 pj_list_init(&route_set);
999
1000 if (!(route = pjsip_parse_hdr(pjsip_publishc_get_pool(publisher->client), &ROUTE_HNAME,
1001 (char*)publish->outbound_proxy, strlen(publish->outbound_proxy), NULL))) {
1002 pjsip_publishc_destroy(publisher->client);
1003 return -1;
1004 }
1005 pj_list_insert_nodes_before(&route_set, route);
1006
1007 pjsip_publishc_set_route_set(publisher->client, &route_set);
1008 }
1009
1010 pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "URI Validation",
1012 if (!pool) {
1013 ast_log(LOG_ERROR, "Could not create pool for URI validation on outbound publish '%s'\n",
1015 pjsip_publishc_destroy(publisher->client);
1016 return -1;
1017 }
1018
1019 if (sip_outbound_publisher_set_uris(pool, publisher, &server_uri, &from_uri, &to_uri)) {
1020 pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
1021 pjsip_publishc_destroy(publisher->client);
1022 return -1;
1023 }
1024
1025 pj_cstr(&event, publish->event);
1026 if (pjsip_publishc_init(publisher->client, &event, &server_uri, &from_uri, &to_uri,
1027 publish->expiration) != PJ_SUCCESS) {
1028 ast_log(LOG_ERROR, "Failed to initialize publishing client on outbound publish '%s'\n",
1030 pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
1031 pjsip_publishc_destroy(publisher->client);
1032 return -1;
1033 }
1034
1035 pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
1036 return 0;
1037}
static int sip_outbound_publisher_set_uris(pj_pool_t *pool, struct sip_outbound_publisher *publisher, pj_str_t *server_uri, pj_str_t *to_uri, pj_str_t *from_uri)
static void sip_outbound_publish_callback(struct pjsip_publishc_cbparam *param)
Callback function for publish client responses.

References ao2_bump, ao2_cleanup, ao2_ref, ast_log, ast_sip_get_pjsip_endpoint(), ast_sorcery_object_get_id(), ast_strlen_zero(), sip_outbound_publisher::client, sip_outbound_publisher::from_uri, LOG_ERROR, NULL, sip_outbound_publisher::owner, pjsip_max_url_size, publish, ast_sip_outbound_publish_client::publish, RAII_VAR, server_uri, sip_outbound_publish_callback(), sip_outbound_publisher_set_uris(), and sip_outbound_publisher::to_uri.

Referenced by sip_outbound_publish_callback(), sip_outbound_publisher_alloc(), and sip_outbound_publisher_reinit().

◆ sip_outbound_publisher_reinit()

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

Definition at line 1039 of file res_pjsip_outbound_publish.c.

1040{
1041 return sip_outbound_publisher_init(obj);
1042}

References sip_outbound_publisher_init().

Referenced by sip_outbound_publisher_reinit_all().

◆ sip_outbound_publisher_reinit_all()

static int sip_outbound_publisher_reinit_all ( void *  data)
static

Definition at line 1044 of file res_pjsip_outbound_publish.c.

1045{
1047 return 0;
1048}
static int sip_outbound_publisher_reinit(void *obj, void *arg, int flags)

References ao2_callback, NULL, OBJ_NODATA, and sip_outbound_publisher_reinit().

Referenced by current_state_reusable().

◆ sip_outbound_publisher_set_uri()

static int sip_outbound_publisher_set_uri ( pj_pool_t *  pool,
const char *  uri,
const char *  user,
pj_str_t *  res_uri 
)
static

Definition at line 889 of file res_pjsip_outbound_publish.c.

891{
892 pj_str_t tmp;
893 pjsip_uri *parsed;
894 pjsip_sip_uri *parsed_uri;
895 int size;
896
897 pj_strdup2_with_null(pool, &tmp, uri);
898 if (!(parsed = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0))) {
899 return -1;
900 }
901
902 if (!(parsed_uri = pjsip_uri_get_uri(parsed))) {
903 return -1;
904 }
905
906 if (!ast_strlen_zero(user)) {
907 pj_strdup2(pool, &parsed_uri->user, user);
908 }
909
910 res_uri->ptr = (char*) pj_pool_alloc(pool, pjsip_max_url_size);
911 if (!res_uri->ptr) {
912 return -1;
913 }
914
915 if ((size = pjsip_uri_print(PJSIP_URI_IN_OTHER, parsed_uri, res_uri->ptr,
916 pjsip_max_url_size - 1)) <= 0) {
917 return -1;
918 }
919 res_uri->ptr[size] = '\0';
920 res_uri->slen = size;
921
922 return 0;
923}

References ast_strlen_zero(), and pjsip_max_url_size.

Referenced by sip_outbound_publisher_set_uris().

◆ sip_outbound_publisher_set_uris()

static int sip_outbound_publisher_set_uris ( pj_pool_t *  pool,
struct sip_outbound_publisher publisher,
pj_str_t *  server_uri,
pj_str_t *  to_uri,
pj_str_t *  from_uri 
)
static

Definition at line 925 of file res_pjsip_outbound_publish.c.

928{
929 struct ast_sip_outbound_publish *publish = publisher->owner->publish;
930
931 if (sip_outbound_publisher_set_uri(pool, publish->server_uri, publisher->user, server_uri)) {
932 ast_log(LOG_ERROR, "Invalid server URI '%s' specified on outbound publish '%s'\n",
934 return -1;
935 }
936
937 if (ast_strlen_zero(publish->to_uri)) {
938 to_uri->ptr = server_uri->ptr;
939 to_uri->slen = server_uri->slen;
940 } else if (sip_outbound_publisher_set_uri(pool, publish->to_uri, publisher->user, to_uri)) {
941 ast_log(LOG_ERROR, "Invalid to URI '%s' specified on outbound publish '%s'\n",
943 return -1;
944 }
945
946 publisher->to_uri = ast_strdup(to_uri->ptr);
947 if (!publisher->to_uri) {
948 return -1;
949 }
950
951 if (ast_strlen_zero(publish->from_uri)) {
952 from_uri->ptr = server_uri->ptr;
953 from_uri->slen = server_uri->slen;
954 } else if (sip_outbound_publisher_set_uri(pool, publish->from_uri, publisher->user, from_uri)) {
955 ast_log(LOG_ERROR, "Invalid from URI '%s' specified on outbound publish '%s'\n",
957 return -1;
958 }
959
960 publisher->from_uri = ast_strdup(from_uri->ptr);
961 if (!publisher->from_uri) {
962 return -1;
963 }
964
965 return 0;
966}
static int sip_outbound_publisher_set_uri(pj_pool_t *pool, const char *uri, const char *user, pj_str_t *res_uri)

References ast_log, ast_sorcery_object_get_id(), ast_strdup, ast_strlen_zero(), ast_sip_outbound_publish::from_uri, sip_outbound_publisher::from_uri, LOG_ERROR, sip_outbound_publisher::owner, publish, ast_sip_outbound_publish_client::publish, server_uri, sip_outbound_publisher_set_uri(), ast_sip_outbound_publish::to_uri, sip_outbound_publisher::to_uri, and sip_outbound_publisher::user.

Referenced by sip_outbound_publisher_init().

◆ sip_publish_state_get()

static struct ast_sip_outbound_publish_state * sip_publish_state_get ( const char *  id)
static

Definition at line 550 of file res_pjsip_outbound_publish.c.

551{
552 struct ao2_container *states = ao2_global_obj_ref(current_states);
554
555 if (!states) {
556 return NULL;
557 }
558
559 res = ao2_find(states, id, OBJ_SEARCH_KEY);
560 ao2_ref(states, -1);
561 return res;
562}

References ao2_find, ao2_global_obj_ref, ao2_ref, NULL, and OBJ_SEARCH_KEY.

Referenced by ast_sip_publish_client_get(), and sip_outbound_publish_apply().

◆ sip_publisher_service_queue()

static int sip_publisher_service_queue ( void *  data)
static

Definition at line 785 of file res_pjsip_outbound_publish.c.

786{
787 RAII_VAR(struct sip_outbound_publisher *, publisher, data, ao2_cleanup);
788 SCOPED_AO2LOCK(lock, publisher);
790 pjsip_tx_data *tdata;
791 pj_status_t status;
792
793 if (publisher->destroy || publisher->sending || !(message = AST_LIST_FIRST(&publisher->queue))) {
794 return 0;
795 }
796
797 if (pjsip_publishc_publish(publisher->client, PJ_FALSE, &tdata) != PJ_SUCCESS) {
798 goto fatal;
799 }
800
801 if (!ast_strlen_zero(message->body.type) && !ast_strlen_zero(message->body.subtype) &&
802 ast_sip_add_body(tdata, &message->body)) {
803 pjsip_tx_data_dec_ref(tdata);
804 goto fatal;
805 }
806
807 set_transport(publisher, tdata);
808
809 status = pjsip_publishc_send(publisher->client, tdata);
810 if (status == PJ_EBUSY) {
811 /* We attempted to send the message but something else got there first */
812 goto service;
813 } else if (status != PJ_SUCCESS) {
814 goto fatal;
815 }
816
817 publisher->sending = message;
818
819 return 0;
820
821fatal:
822 AST_LIST_REMOVE_HEAD(&publisher->queue, entry);
824
825service:
826 if (ast_sip_push_task(publisher->serializer, sip_publisher_service_queue, ao2_bump(publisher))) {
827 ao2_ref(publisher, -1);
828 }
829 return -1;
830}
jack_status_t status
Definition: app_jack.c:149
enum ast_cc_service_type service
Definition: ccss.c:389
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421
int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body)
Add a body to an outbound SIP message.
Definition: res_pjsip.c:2052

References ao2_bump, ao2_cleanup, ao2_ref, ast_free, AST_LIST_FIRST, AST_LIST_REMOVE_HEAD, ast_sip_add_body(), ast_sip_push_task(), ast_strlen_zero(), ast_datastore::data, sip_outbound_publish_message::entry, lock, RAII_VAR, SCOPED_AO2LOCK, service, set_transport(), sip_publisher_service_queue(), and status.

Referenced by publisher_client_send(), sip_outbound_publish_callback(), and sip_publisher_service_queue().

◆ stop_publishing()

static void stop_publishing ( struct ast_sip_outbound_publish_client client,
struct ast_sip_event_publisher_handler handler 
)
static

Definition at line 491 of file res_pjsip_outbound_publish.c.

493{
494 if (!handler) {
496 }
497
498 if (handler) {
499 handler->stop_publishing(client);
500 }
501}

References sip_outbound_publisher::client, find_publisher_handler_for_event_name(), and handler().

Referenced by sip_outbound_publish_state_destroy(), and sip_outbound_publish_synchronize().

◆ sub_add_handler()

static void sub_add_handler ( struct ast_sip_event_publisher_handler handler)
static

Definition at line 381 of file res_pjsip_outbound_publish.c.

382{
384}
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741

References AST_RWLIST_INSERT_TAIL, and handler().

Referenced by ast_sip_register_event_publisher_handler().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 1658 of file res_pjsip_outbound_publish.c.

1659{
1660 int remaining;
1661
1663
1664 ao2_global_obj_release(current_states);
1665
1666 /* Wait for publication serializers to get destroyed. */
1667 ast_debug(2, "Waiting for publication to complete for unload.\n");
1669 if (remaining) {
1670 ast_log(LOG_WARNING, "Unload incomplete. Could not stop %d outbound publications. Try again later.\n",
1671 remaining);
1672 return -1;
1673 }
1674
1675 ast_debug(2, "Successful shutdown.\n");
1676
1679
1680 return 0;
1681}
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition: astobj2.h:859
#define MAX_UNLOAD_TIMEOUT_TIME
int ast_sorcery_object_unregister(struct ast_sorcery *sorcery, const char *type)
Unregister an object type.
Definition: sorcery.c:1061
int ast_serializer_shutdown_group_join(struct ast_serializer_shutdown_group *shutdown_group, int timeout)
Wait for the serializers in the group to shutdown with timeout.
Definition: threadpool.c:1241

References ao2_cleanup, ao2_global_obj_release, ast_debug, ast_log, ast_serializer_shutdown_group_join(), ast_sip_get_sorcery(), ast_sorcery_object_unregister(), LOG_WARNING, MAX_UNLOAD_TIMEOUT_TIME, NULL, and shutdown_group.

Referenced by load_module().

◆ validate_publish_config()

static int validate_publish_config ( struct ast_sip_outbound_publish publish)
static

Definition at line 1497 of file res_pjsip_outbound_publish.c.

1498{
1499 if (ast_strlen_zero(publish->server_uri)) {
1500 ast_log(LOG_ERROR, "No server URI specified on outbound publish '%s'\n",
1502 return -1;
1503 } else if (ast_sip_validate_uri_length(publish->server_uri)) {
1504 ast_log(LOG_ERROR, "Server URI or hostname length exceeds pjproject limit or is not a sip(s) uri: '%s' on outbound publish '%s'\n",
1505 publish->server_uri,
1507 return -1;
1508 } else if (ast_strlen_zero(publish->event)) {
1509 ast_log(LOG_ERROR, "No event type specified for outbound publish '%s'\n",
1511 return -1;
1512 } else if (!ast_strlen_zero(publish->from_uri)
1513 && ast_sip_validate_uri_length(publish->from_uri)) {
1514 ast_log(LOG_ERROR, "From URI or hostname length exceeds pjproject limit or is not a sip(s) uri: '%s' on outbound publish '%s'\n",
1515 publish->from_uri,
1517 return -1;
1518 } else if (!ast_strlen_zero(publish->to_uri)
1520 ast_log(LOG_ERROR, "To URI or hostname length exceeds pjproject limit or is not a sip(s) uri: '%s' on outbound publish '%s'\n",
1521 publish->to_uri,
1523 return -1;
1524 }
1525 return 0;
1526}
int ast_sip_validate_uri_length(const char *uri)
Definition: location.c:529

References ast_log, ast_sip_validate_uri_length(), ast_sorcery_object_get_id(), ast_strlen_zero(), LOG_ERROR, and publish.

Referenced by sip_outbound_publish_apply().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Outbound Publish Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .reload = reload_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "res_pjproject,res_pjsip", }
static

Definition at line 1743 of file res_pjsip_outbound_publish.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 1743 of file res_pjsip_outbound_publish.c.

◆ load_lock

ast_rwlock_t load_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} }
static

Used for locking while loading/reloading.

Mutli-user configurations make it so publishers can be dynamically added and removed. Publishers should not be added or removed during a [re]load since it could cause the current_clients container to be out of sync. Thus the reason for this lock.

Definition at line 291 of file res_pjsip_outbound_publish.c.

Referenced by ast_sip_publish_client_remove(), get_publishes_and_update_state(), and sip_outbound_publish_client_get_publisher().

◆ new_states

struct ao2_container* new_states
static

Used on [re]loads to hold new state data.

Definition at line 307 of file res_pjsip_outbound_publish.c.

Referenced by get_publishes_and_update_state(), load_module(), and sip_outbound_publish_apply().

◆ pjsip_max_url_size

int pjsip_max_url_size = PJSIP_MAX_URL_SIZE
static

◆ publisher_handlers

struct publisher_handlers publisher_handlers = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }

◆ shutdown_group

struct ast_serializer_shutdown_group* shutdown_group
static

Shutdown group to monitor sip_outbound_registration_client_state serializers.

Definition at line 301 of file res_pjsip_outbound_publish.c.

Referenced by load_module(), sip_outbound_publisher_alloc(), and unload_module().