Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions
res_pjsip_outbound_publish.h File Reference
#include "asterisk/linkedlists.h"
Include dependency graph for res_pjsip_outbound_publish.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_sip_event_publisher_handler
 Callbacks that event publisher handlers will define. More...
 

Functions

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...
 

Function Documentation

◆ 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 724 of file res_pjsip_outbound_publish.c.

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().

726 {
727  ast_assert(datastore != NULL);
728  ast_assert(datastore->info != NULL);
729  ast_assert(!ast_strlen_zero(datastore->uid));
730 
731  if (!ao2_link(client->datastores, datastore)) {
732  return -1;
733  }
734  return 0;
735 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
const char * uid
Definition: datastore.h:69
#define ast_strlen_zero(foo)
Definition: strings.h:52
const struct ast_datastore_info * info
Definition: datastore.h:71
struct ao2_container * datastores
Publisher datastores set up by handlers.
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ 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 694 of file res_pjsip_outbound_publish.c.

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().

695 {
696  RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
697  const char *uid_ptr = uid;
698  char uuid_buf[AST_UUID_STR_LEN];
699 
700  if (!info) {
701  return NULL;
702  }
703 
704  datastore = ao2_alloc(sizeof(*datastore), sip_outbound_publish_datastore_destroy);
705  if (!datastore) {
706  return NULL;
707  }
708 
709  datastore->info = info;
710  if (ast_strlen_zero(uid)) {
711  /* They didn't provide an ID so we'll provide one ourself */
712  uid_ptr = ast_uuid_generate_str(uuid_buf, sizeof(uuid_buf));
713  }
714 
715  datastore->uid = ast_strdup(uid_ptr);
716  if (!datastore->uid) {
717  return NULL;
718  }
719 
720  ao2_ref(datastore, +1);
721  return datastore;
722 }
#define AST_UUID_STR_LEN
Definition: uuid.h:27
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
static void sip_outbound_publish_datastore_destroy(void *obj)
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
def info(msg)
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
Definition: uuid.c:143
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ 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 528 of file res_pjsip_outbound_publish.c.

References ao2_ref, ast_sip_outbound_publish_state::client, NULL, and sip_publish_state_get().

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

529 {
531 
532  if (!state) {
533  return NULL;
534  }
535 
536  ao2_ref(state->client, +1);
537  ao2_ref(state, -1);
538  return state->client;
539 }
struct ast_sip_outbound_publish_client * client
Outbound publish client.
#define NULL
Definition: resample.c:96
Outbound publish state information (persists for lifetime of a publish)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static const char name[]
Definition: cdr_mysql.c:74
static struct ast_sip_outbound_publish_state * sip_publish_state_get(const char *id)

◆ 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 737 of file res_pjsip_outbound_publish.c.

References ao2_find, ast_sip_outbound_publish_client::datastores, and OBJ_SEARCH_KEY.

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

739 {
740  return ao2_find(client->datastores, name, OBJ_SEARCH_KEY);
741 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
struct ao2_container * datastores
Publisher datastores set up by handlers.
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ 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 541 of file res_pjsip_outbound_publish.c.

References sip_outbound_publisher::client, ast_sip_outbound_publish::from_uri, ast_sip_outbound_publish_client::publish, publish, S_OR, ast_sip_outbound_publish::server_uri, and sip_outbound_publish_client_add_publisher().

542 {
543  struct ast_sip_outbound_publish *publish = client->publish;
544 
545  return S_OR(publish->from_uri, S_OR(publish->server_uri, ""));
546 }
unsigned char publish
Definition: res_corosync.c:241
Outbound publish information.
const ast_string_field server_uri
URI for the entity and server.
struct ast_sip_outbound_publish * publish
Outbound publish information.
const ast_string_field from_uri
URI for the From header.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79

◆ 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 591 of file res_pjsip_outbound_publish.c.

References ast_sip_outbound_publish_client::publish, publish, S_OR, ast_sip_outbound_publish::server_uri, and ast_sip_outbound_publish::to_uri.

592 {
593  struct ast_sip_outbound_publish *publish = client->publish;
594 
595  return S_OR(publish->to_uri, S_OR(publish->server_uri, ""));
596 }
unsigned char publish
Definition: res_corosync.c:241
Outbound publish information.
const ast_string_field server_uri
URI for the entity and server.
struct ast_sip_outbound_publish * publish
Outbound publish information.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
const ast_string_field to_uri
URI for the To header.

◆ 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 575 of file res_pjsip_outbound_publish.c.

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

Referenced by exten_state_publisher_cb().

577 {
578  struct sip_outbound_publisher *publisher;
579 
580  publisher = sip_outbound_publish_client_get_publisher(client, user);
581  if (!publisher) {
582  return NULL;
583  }
584 
585  ast_copy_string(uri, publisher->from_uri, size);
586  ao2_ref(publisher, -1);
587 
588  return uri;
589 }
#define NULL
Definition: resample.c:96
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct sip_outbound_publisher * sip_outbound_publish_client_get_publisher(struct ast_sip_outbound_publish_client *client, const char *user)
char * from_uri
The From URI for this specific publisher.
structure to hold users read from users.conf
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ 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 598 of file res_pjsip_outbound_publish.c.

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

Referenced by exten_state_publisher_cb().

600 {
601  struct sip_outbound_publisher *publisher;
602 
603  publisher = sip_outbound_publish_client_get_publisher(client, user);
604  if (!publisher) {
605  return NULL;
606  }
607 
608  ast_copy_string(uri, publisher->to_uri, size);
609  ao2_ref(publisher, -1);
610 
611  return uri;
612 }
#define NULL
Definition: resample.c:96
char * to_uri
The To URI for this specific publisher.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct sip_outbound_publisher * sip_outbound_publish_client_get_publisher(struct ast_sip_outbound_publish_client *client, const char *user)
structure to hold users read from users.conf
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ 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 1125 of file res_pjsip_outbound_publish.c.

References ao2_find, load_lock, lock, OBJ_NODATA, OBJ_SEARCH_KEY, OBJ_UNLINK, ast_sip_outbound_publish_client::publishers, and SCOPED_WRLOCK.

1127 {
1130 }
static ast_rwlock_t load_lock
Used for locking while loading/reloading.
#define SCOPED_WRLOCK(varname, lock)
scoped lock specialization for write locks
Definition: lock.h:597
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
ast_mutex_t lock
Definition: app_meetme.c:1091
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
structure to hold users read from users.conf
struct ao2_container * publishers
Container of all the client publishing objects.

◆ 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 743 of file res_pjsip_outbound_publish.c.

References ao2_find, ast_sip_outbound_publish_client::datastores, 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().

745 {
747 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
struct ao2_container * datastores
Publisher datastores set up by handlers.
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ 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 842 of file res_pjsip_outbound_publish.c.

References ao2_callback_data, 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().

844 {
845  SCOPED_AO2LOCK(lock, client);
846  int res = 0;
847 
849  publisher_client_send, (void *)body, &res);
850  return res;
851 }
static int publisher_client_send(void *obj, void *arg, void *data, int flags)
ast_mutex_t lock
Definition: app_meetme.c:1091
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1743
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
Definition: lock.h:602
struct ao2_container * publishers
Container of all the client publishing objects.

◆ 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 1109 of file res_pjsip_outbound_publish.c.

References ao2_ref, publisher_client_send(), and sip_outbound_publish_client_get_publisher().

Referenced by exten_state_publisher_cb().

1111 {
1112  struct sip_outbound_publisher *publisher;
1113  int res;
1114 
1115  publisher = sip_outbound_publish_client_get_publisher(client, user);
1116  if (!publisher) {
1117  return -1;
1118  }
1119 
1120  publisher_client_send(publisher, (void *)body, &res, 0);
1121  ao2_ref(publisher, -1);
1122  return res;
1123 }
static int publisher_client_send(void *obj, void *arg, void *data, int flags)
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct sip_outbound_publisher * sip_outbound_publish_client_get_publisher(struct ast_sip_outbound_publish_client *client, const char *user)
structure to hold users read from users.conf

◆ 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 614 of file res_pjsip_outbound_publish.c.

References ast_log, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero, ast_sip_event_publisher_handler::event_name, find_publisher_handler_for_event_name(), lock, LOG_ERROR, NULL, SCOPED_LOCK, sip_outbound_publish_synchronize(), ast_sip_event_publisher_handler::start_publishing, ast_sip_event_publisher_handler::stop_publishing, and sub_add_handler().

Referenced by load_module().

615 {
616  struct ast_sip_event_publisher_handler *existing;
618 
619  if (!handler->start_publishing || !handler->stop_publishing) {
620  ast_log(LOG_ERROR, "Handler does not implement required callbacks. Cannot register\n");
621  return -1;
622  } else if (ast_strlen_zero(handler->event_name)) {
623  ast_log(LOG_ERROR, "No event package specified for event publisher handler. Cannot register\n");
624  return -1;
625  }
626 
628  if (existing) {
629  ast_log(LOG_ERROR, "Unable to register event publisher handler for event %s. "
630  "A handler is already registered\n", handler->event_name);
631  return -1;
632  }
633 
634  sub_add_handler(handler);
635 
637 
638  return 0;
639 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int(* start_publishing)(struct ast_sip_outbound_publish *configuration, struct ast_sip_outbound_publish_client *client)
Called when a publisher should start publishing.
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
int(* stop_publishing)(struct ast_sip_outbound_publish_client *client)
Called when a publisher should stop publishing.
#define ast_log
Definition: astobj2.c:42
Callbacks that event publisher handlers will define.
ast_mutex_t lock
Definition: app_meetme.c:1091
const char * event_name
The name of the event this handler deals with.
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:581
static struct ast_sip_event_publisher_handler * find_publisher_handler_for_event_name(const char *event_name)
#define LOG_ERROR
Definition: logger.h:285
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.

◆ ast_sip_unregister_event_publisher_handler()

void ast_sip_unregister_event_publisher_handler ( struct ast_sip_event_publisher_handler handler)

Unregister a publish handler.

Definition at line 641 of file res_pjsip_outbound_publish.c.

References AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, lock, sip_outbound_publish_message::next, SCOPED_LOCK, and sip_outbound_publish_synchronize().

Referenced by load_module(), and unload_module().

642 {
643  struct ast_sip_event_publisher_handler *iter;
646  if (handler == iter) {
648  break;
649  }
650  }
652 
654 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Callbacks that event publisher handlers will define.
ast_mutex_t lock
Definition: app_meetme.c:1091
struct ast_sip_event_publisher_handler * next
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:581
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
static void sip_outbound_publish_synchronize(struct ast_sip_event_publisher_handler *removed)
Helper function which starts or stops publish clients when applicable.
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616