Asterisk - The Open Source Telephony Project  GIT-master-a24979a
res_pjsip_exten_state.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * Kevin Harwell <kharwell@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*** MODULEINFO
20  <depend>pjproject</depend>
21  <depend>res_pjsip</depend>
22  <depend>res_pjsip_pubsub</depend>
23  <depend>res_pjsip_outbound_publish</depend>
24  <support_level>core</support_level>
25  ***/
26 
27 #include "asterisk.h"
28 
29 #include <regex.h>
30 
31 #include <pjsip.h>
32 #include <pjsip_simple.h>
33 #include <pjlib.h>
34 
35 #include "asterisk/res_pjsip.h"
39 #include "asterisk/module.h"
40 #include "asterisk/logger.h"
41 #include "asterisk/astobj2.h"
42 #include "asterisk/sorcery.h"
43 #include "asterisk/app.h"
44 #include "asterisk/taskprocessor.h"
45 
46 #define BODY_SIZE 1024
47 #define EVENT_TYPE_SIZE 50
48 
49 /*!
50  * \brief The number of buckets to use for storing publishers
51  */
52 #define PUBLISHER_BUCKETS 31
53 
54 /*!
55  * \brief Container of active outbound extension state publishers
56  */
57 static struct ao2_container *publishers;
58 
59 /*! Serializer for outbound extension state publishing. */
61 
62 /*!
63  * \brief A subscription for extension state
64  *
65  * This structure acts as the owner for the underlying SIP subscription. It
66  * also keeps a pointer to an associated "provider" so when a state changes
67  * a notify data creator is quickly accessible.
68  */
70  /*! Watcher id when registering for extension state changes */
71  int id;
72  /*! The SIP subscription */
74  /*! The serializer to use for notifications */
76  /*! Context in which subscription looks for updates */
78  /*! Extension within the context to receive updates from */
80  /*! The subscription's user agent */
81  char *user_agent;
82  /*! The last known extension state */
84  /*! The last known presence state */
86 };
87 
88 /*!
89  * \brief An extension state publisher
90  *
91  */
93  /*! Regular expression for context filtering */
94  regex_t context_regex;
95  /*! Regular expression for extension filtering */
96  regex_t exten_regex;
97  /*! Publish client to use for sending publish messages */
99  /*! Datastores container to hold persistent information */
101  /*! Whether context filtering is active */
102  unsigned int context_filter;
103  /*! Whether extension filtering is active */
104  unsigned int exten_filter;
105  /*! The body type to use for this publisher - stored after the name */
106  char *body_type;
107  /*! The body subtype to use for this publisher - stored after the body type */
109  /*! The name of this publisher */
110  char name[0];
111 };
112 
113 #define DEFAULT_PRESENCE_BODY "application/pidf+xml"
114 #define DEFAULT_DIALOG_BODY "application/dialog-info+xml"
115 
116 static void subscription_shutdown(struct ast_sip_subscription *sub);
117 static int new_subscribe(struct ast_sip_endpoint *endpoint, const char *resource);
119 static void *get_notify_data(struct ast_sip_subscription *sub);
120 static int get_resource_display_name(struct ast_sip_endpoint *endpoint, const char *resource, char *display_name, int display_name_size);
121 static void to_ami(struct ast_sip_subscription *sub,
122  struct ast_str **buf);
123 static int publisher_start(struct ast_sip_outbound_publish *configuration,
124  struct ast_sip_outbound_publish_client *client);
126 
129  .new_subscribe = new_subscribe,
130  .subscription_established = subscription_established,
131  .get_notify_data = get_notify_data,
132  .get_resource_display_name = get_resource_display_name,
133 };
134 
137  .new_subscribe = new_subscribe,
138  .subscription_established = subscription_established,
139  .get_notify_data = get_notify_data,
140  .get_resource_display_name = get_resource_display_name,
141 };
142 
144  .event_name = "presence",
145  .body_type = AST_SIP_EXTEN_STATE_DATA,
146  .accept = { DEFAULT_PRESENCE_BODY, },
147  .subscription_shutdown = subscription_shutdown,
148  .to_ami = to_ami,
149  .notifier = &presence_notifier,
150 };
151 
153  .event_name = "presence",
154  .start_publishing = publisher_start,
155  .stop_publishing = publisher_stop,
156 };
157 
159  .event_name = "dialog",
160  .body_type = AST_SIP_EXTEN_STATE_DATA,
161  .accept = { DEFAULT_DIALOG_BODY, },
162  .subscription_shutdown = subscription_shutdown,
163  .to_ami = to_ami,
164  .notifier = &dialog_notifier,
165 };
166 
168  .event_name = "dialog",
169  .start_publishing = publisher_start,
170  .stop_publishing = publisher_stop,
171 };
172 
174 {
175  struct exten_state_subscription *sub = obj;
176 
177  ast_free(sub->user_agent);
179  ast_taskprocessor_unreference(sub->serializer);
180 }
181 
182 static char *get_user_agent(const struct ast_sip_subscription *sip_sub)
183 {
184  size_t size;
185  char *user_agent = NULL;
186  pjsip_user_agent_hdr *user_agent_hdr = ast_sip_subscription_get_header(
187  sip_sub, "User-Agent");
188 
189  if (!user_agent_hdr) {
190  return NULL;
191  }
192 
193  size = pj_strlen(&user_agent_hdr->hvalue) + 1;
194  user_agent = ast_malloc(size);
195  ast_copy_pj_str(user_agent, &user_agent_hdr->hvalue, size);
197 }
198 
199 /*!
200  * \internal
201  * \brief Initialize the last extension state to something outside
202  * its usual states.
203  */
204 #define INITIAL_LAST_EXTEN_STATE -3
205 
206 /*!
207  * \internal
208  * \brief Allocates an exten_state_subscription object.
209  *
210  * Creates the underlying SIP subscription for the given request. First makes
211  * sure that there are registered handler and provider objects available.
212  */
214  struct ast_sip_subscription *sip_sub, struct ast_sip_endpoint *endpoint)
215 {
216  struct exten_state_subscription * exten_state_sub;
217 
218  exten_state_sub = ao2_alloc(sizeof(*exten_state_sub), exten_state_subscription_destructor);
219  if (!exten_state_sub) {
220  return NULL;
221  }
222 
223  exten_state_sub->sip_sub = sip_sub;
224 
225  /* We keep our own reference to the serializer as there is no guarantee in state_changed
226  * that the subscription tree is still valid when it is called. This can occur when
227  * the subscription is terminated at around the same time as the state_changed
228  * callback is invoked.
229  */
231  exten_state_sub->last_exten_state = INITIAL_LAST_EXTEN_STATE;
232  exten_state_sub->last_presence_state = AST_PRESENCE_NOT_SET;
233  exten_state_sub->user_agent = get_user_agent(sip_sub);
234  return exten_state_sub;
235 }
236 
241 };
242 
243 static void notify_task_data_destructor(void *obj)
244 {
245  struct notify_task_data *task_data = obj;
246 
247  ao2_ref(task_data->exten_state_sub, -1);
248  ao2_cleanup(task_data->exten_state_data.device_state_info);
249  ast_free(task_data->exten_state_data.presence_subtype);
250  ast_free(task_data->exten_state_data.presence_message);
251  ast_free(task_data->exten_state_data.user_agent);
252 }
253 
254 static struct notify_task_data *alloc_notify_task_data(const char *exten,
256  struct ast_state_cb_info *info)
257 {
258  struct notify_task_data *task_data =
260 
261  if (!task_data) {
262  ast_log(LOG_WARNING, "Unable to create notify task data\n");
263  return NULL;
264  }
265 
266  task_data->exten_state_sub = exten_state_sub;
267  task_data->exten_state_sub->last_exten_state = info->exten_state;
268  task_data->exten_state_sub->last_presence_state = info->presence_state;
269  ao2_ref(task_data->exten_state_sub, +1);
270 
271  task_data->exten_state_data.exten = exten_state_sub->exten;
272  task_data->exten_state_data.exten_state = info->exten_state;
273  task_data->exten_state_data.presence_state = info->presence_state;
274  task_data->exten_state_data.presence_subtype = ast_strdup(info->presence_subtype);
275  task_data->exten_state_data.presence_message = ast_strdup(info->presence_message);
276  task_data->exten_state_data.user_agent = ast_strdup(exten_state_sub->user_agent);
277  task_data->exten_state_data.device_state_info = ao2_bump(info->device_state_info);
278  task_data->exten_state_data.sub = exten_state_sub->sip_sub;
279  task_data->exten_state_data.datastores = ast_sip_subscription_get_datastores(exten_state_sub->sip_sub);
280 
281  if ((info->exten_state == AST_EXTENSION_DEACTIVATED) ||
282  (info->exten_state == AST_EXTENSION_REMOVED)) {
283  ast_verb(2, "Watcher for hint %s %s\n", exten, info->exten_state
284  == AST_EXTENSION_REMOVED ? "removed" : "deactivated");
285  task_data->terminate = 1;
286  }
287 
288  return task_data;
289 }
290 
291 static int notify_task(void *obj)
292 {
294  struct ast_sip_body_data data = {
296  .body_data = &task_data->exten_state_data,
297  };
298 
299  /* Terminated subscriptions are no longer associated with a valid tree, and sending
300  * NOTIFY messages on a subscription which has already been terminated won't work.
301  */
302  if (ast_sip_subscription_is_terminated(task_data->exten_state_sub->sip_sub)) {
303  return 0;
304  }
305 
306  /* All access to the subscription must occur within a task executed within its serializer */
307  ast_sip_subscription_get_local_uri(task_data->exten_state_sub->sip_sub,
308  task_data->exten_state_data.local, sizeof(task_data->exten_state_data.local));
309  ast_sip_subscription_get_remote_uri(task_data->exten_state_sub->sip_sub,
310  task_data->exten_state_data.remote, sizeof(task_data->exten_state_data.remote));
311 
312  /* Pool allocation has to happen here so that we allocate within a PJLIB thread */
313  task_data->exten_state_data.pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(),
314  "exten_state", 1024, 1024);
315  if (!task_data->exten_state_data.pool) {
316  return -1;
317  }
318 
319  task_data->exten_state_data.sub = task_data->exten_state_sub->sip_sub;
320  task_data->exten_state_data.datastores = ast_sip_subscription_get_datastores(task_data->exten_state_sub->sip_sub);
321 
322  ast_sip_subscription_notify(task_data->exten_state_sub->sip_sub, &data,
323  task_data->terminate);
324 
325  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(),
326  task_data->exten_state_data.pool);
327  return 0;
328 }
329 
330 /*!
331  * \internal
332  * \brief Callback for exten/device state changes.
333  *
334  * Upon state change, send the appropriate notification to the subscriber.
335  */
336 static int state_changed(const char *context, const char *exten,
337  struct ast_state_cb_info *info, void *data)
338 {
339  struct notify_task_data *task_data;
340  struct exten_state_subscription *exten_state_sub = data;
341 
342  if (!(task_data = alloc_notify_task_data(exten, exten_state_sub, info))) {
343  return -1;
344  }
345 
346  /* safe to push this async since we copy the data from info and
347  add a ref for the device state info */
348  if (ast_sip_push_task(task_data->exten_state_sub->serializer, notify_task,
349  task_data)) {
351  return -1;
352  }
353  return 0;
354 }
355 
356 static void state_changed_destroy(int id, void *data)
357 {
358  struct exten_state_subscription *exten_state_sub = data;
359  ao2_cleanup(exten_state_sub);
360 }
361 
362 static struct ast_datastore_info ds_info = { };
363 static const char ds_name[] = "exten state datastore";
364 
365 /*!
366  * \internal
367  * \brief Add a datastore for exten exten_state_subscription.
368  *
369  * Adds the exten_state_subscription wrapper object to a datastore so it can be retrieved
370  * later based upon its association with the ast_sip_subscription.
371  */
372 static int add_datastore(struct exten_state_subscription *exten_state_sub)
373 {
374  RAII_VAR(struct ast_datastore *, datastore,
376 
377  if (!datastore) {
378  return -1;
379  }
380 
381  datastore->data = exten_state_sub;
382  ast_sip_subscription_add_datastore(exten_state_sub->sip_sub, datastore);
383  ao2_ref(exten_state_sub, +1);
384  return 0;
385 }
386 
387 /*!
388  * \internal
389  * \brief Get the exten_state_subscription object associated with the given
390  * ast_sip_subscription in the datastore.
391  */
393  struct ast_sip_subscription *sub)
394 {
395  RAII_VAR(struct ast_datastore *, datastore,
397 
398  return datastore ? datastore->data : NULL;
399 }
400 
402 {
403  struct exten_state_subscription *exten_state_sub = get_exten_state_sub(sub);
404 
405  if (!exten_state_sub) {
406  return;
407  }
408 
409  ast_extension_state_del(exten_state_sub->id, state_changed);
411  /* remove data store reference */
412  ao2_cleanup(exten_state_sub);
413 }
414 
415 static int new_subscribe(struct ast_sip_endpoint *endpoint,
416  const char *resource)
417 {
418  const char *context = S_OR(endpoint->subscription.context, endpoint->context);
419 
420  if (!ast_exists_extension(NULL, context, resource, PRIORITY_HINT, NULL)) {
421  ast_log(LOG_NOTICE, "Endpoint '%s' state subscription failed: "
422  "Extension '%s' does not exist in context '%s' or has no associated hint\n",
423  ast_sorcery_object_get_id(endpoint), resource, context);
424  return 404;
425  }
426 
427  return 200;
428 }
429 
430 static int get_resource_display_name(struct ast_sip_endpoint *endpoint,
431  const char *resource, char *display_name, int display_name_size)
432 {
433  const char *context;
434 
435  if (!endpoint || ast_strlen_zero(resource) || !display_name || display_name_size <= 0) {
436  return -1;
437  }
438 
439  context = S_OR(endpoint->subscription.context, endpoint->context);
440 
441  if (!ast_get_hint(NULL, 0, display_name, display_name_size, NULL, context, resource)) {
442  ast_log(LOG_NOTICE, "Endpoint '%s': "
443  "Extension '%s' does not exist in context '%s' or has no associated hint\n",
444  ast_sorcery_object_get_id(endpoint), resource, context);
445  return -1;
446  }
447 
448  return 0;
449 }
450 
452 {
453  struct ast_sip_endpoint *endpoint = ast_sip_subscription_get_endpoint(sip_sub);
454  const char *resource = ast_sip_subscription_get_resource_name(sip_sub);
455  struct exten_state_subscription *exten_state_sub;
456 
457  if (!(exten_state_sub = exten_state_subscription_alloc(sip_sub, endpoint))) {
458  ao2_cleanup(endpoint);
459  return -1;
460  }
461 
462  ast_copy_string(exten_state_sub->context,
463  S_OR(endpoint->subscription.context, endpoint->context),
464  sizeof(exten_state_sub->context));
465  ast_copy_string(exten_state_sub->exten, resource, sizeof(exten_state_sub->exten));
466 
467  if ((exten_state_sub->id = ast_extension_state_add_destroy_extended(
468  exten_state_sub->context, exten_state_sub->exten,
469  state_changed, state_changed_destroy, exten_state_sub)) < 0) {
470  ast_log(LOG_WARNING, "Unable to subscribe endpoint '%s' to extension '%s@%s'\n",
471  ast_sorcery_object_get_id(endpoint), exten_state_sub->exten,
472  exten_state_sub->context);
473  ao2_cleanup(endpoint);
474  ao2_cleanup(exten_state_sub);
475  return -1;
476  }
477 
478  /* Go ahead and cleanup the endpoint since we don't need it anymore */
479  ao2_cleanup(endpoint);
480 
481  /* bump the ref since ast_extension_state_add holds a reference */
482  ao2_ref(exten_state_sub, +1);
483 
484  if (add_datastore(exten_state_sub)) {
485  ast_log(LOG_WARNING, "Unable to add to subscription datastore.\n");
486  ao2_cleanup(exten_state_sub);
487  return -1;
488  }
489 
490  ao2_cleanup(exten_state_sub);
491  return 0;
492 }
493 
494 static void exten_state_data_destructor(void *obj)
495 {
496  struct ast_sip_exten_state_data *exten_state_data = obj;
497 
498  ao2_cleanup(exten_state_data->device_state_info);
499  ast_free(exten_state_data->presence_subtype);
500  ast_free(exten_state_data->presence_message);
501  if (exten_state_data->pool) {
502  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), exten_state_data->pool);
503  }
504 }
505 
507  struct exten_state_subscription *exten_state_sub)
508 {
509  struct ast_sip_exten_state_data *exten_state_data;
510  char *subtype = NULL;
511  char *message = NULL;
512  int presence_state;
513 
514  exten_state_data = ao2_alloc(sizeof(*exten_state_data), exten_state_data_destructor);
515  if (!exten_state_data) {
516  return NULL;
517  }
518 
519  exten_state_data->exten = exten_state_sub->exten;
520  presence_state = ast_hint_presence_state(NULL, exten_state_sub->context, exten_state_sub->exten, &subtype, &message);
522  ao2_cleanup(exten_state_data);
523  return NULL;
524  }
525  exten_state_data->presence_state = presence_state;
526  exten_state_data->presence_subtype = subtype;
527  exten_state_data->presence_message = message;
528  exten_state_data->user_agent = exten_state_sub->user_agent;
529  ast_sip_subscription_get_local_uri(sip_sub, exten_state_data->local,
530  sizeof(exten_state_data->local));
531  ast_sip_subscription_get_remote_uri(sip_sub, exten_state_data->remote,
532  sizeof(exten_state_data->remote));
533  exten_state_data->sub = sip_sub;
534  exten_state_data->datastores = ast_sip_subscription_get_datastores(sip_sub);
535 
536  exten_state_data->exten_state = ast_extension_state_extended(
537  NULL, exten_state_sub->context, exten_state_sub->exten,
538  &exten_state_data->device_state_info);
539  if (exten_state_data->exten_state < 0) {
540  ao2_cleanup(exten_state_data);
541  return NULL;
542  }
543 
544  exten_state_data->pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(),
545  "exten_state", 1024, 1024);
546  if (!exten_state_data->pool) {
547  ao2_cleanup(exten_state_data);
548  return NULL;
549  }
550 
551  return exten_state_data;
552 }
553 
555 {
556  struct exten_state_subscription *exten_state_sub;
557 
558  exten_state_sub = get_exten_state_sub(sub);
559  if (!exten_state_sub) {
560  return NULL;
561  }
562 
563  return exten_state_data_alloc(sub, exten_state_sub);
564 }
565 
566 static void to_ami(struct ast_sip_subscription *sub,
567  struct ast_str **buf)
568 {
569  struct exten_state_subscription *exten_state_sub =
571 
572  if (!exten_state_sub) {
573  return;
574  }
575 
576  ast_str_append(buf, 0, "SubscriptionType: extension_state\r\n"
577  "Extension: %s\r\nExtensionStates: %s\r\n",
578  exten_state_sub->exten, ast_extension_state2str(
579  exten_state_sub->last_exten_state));
580 }
581 
583  /*! Publishers needing state update */
585  /*! Body generator state data */
587 };
588 
590 {
591  if (!doomed) {
592  return;
593  }
594 
595  ast_free((void *) doomed->exten_state_data.exten);
599 
600  AST_VECTOR_CALLBACK_VOID(&doomed->pubs, ao2_ref, -1);
601  AST_VECTOR_FREE(&doomed->pubs);
602 
603  ast_free(doomed);
604 }
605 
607 {
608  struct exten_state_pub_data *pub_data;
609 
610  pub_data = ast_calloc(1, sizeof(*pub_data));
611  if (!pub_data) {
612  return NULL;
613  }
614 
617  return NULL;
618  }
619 
620  /* Save off currently known information for the body generators. */
621  pub_data->exten_state_data.exten = ast_strdup(exten);
622  pub_data->exten_state_data.exten_state = info->exten_state;
623  pub_data->exten_state_data.presence_state = info->presence_state;
624  pub_data->exten_state_data.presence_subtype = ast_strdup(info->presence_subtype);
625  pub_data->exten_state_data.presence_message = ast_strdup(info->presence_message);
626  pub_data->exten_state_data.device_state_info = ao2_bump(info->device_state_info);
627  if (!pub_data->exten_state_data.exten
628  || !pub_data->exten_state_data.presence_subtype
629  || !pub_data->exten_state_data.presence_message) {
631  return NULL;
632  }
633  return pub_data;
634 }
635 
636 /*!
637  * \internal
638  * \brief Create exten state PUBLISH messages under PJSIP thread.
639  * \since 14.0.0
640  *
641  * \return 0
642  */
643 static int exten_state_publisher_cb(void *data)
644 {
645  struct exten_state_pub_data *pub_data = data;
646  struct exten_state_publisher *publisher;
647  size_t idx;
648  struct ast_str *body_text;
649  pj_pool_t *pool;
650  struct ast_sip_body_data gen_data = {
652  .body_data = &pub_data->exten_state_data,
653  };
654  struct ast_sip_body body;
655 
657  if (!body_text) {
659  return 0;
660  }
661 
662  /* Need a PJSIP memory pool to generate the bodies. */
663  pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "pub_state_body",
664  1024, 1024);
665  if (!pool) {
666  ast_log(LOG_WARNING, "Exten state publishing unable to create memory pool\n");
669  return 0;
670  }
671  pub_data->exten_state_data.pool = pool;
672 
673  for (idx = 0; idx < AST_VECTOR_SIZE(&pub_data->pubs); ++idx) {
674  const char *uri;
675  int res;
676 
677  publisher = AST_VECTOR_GET(&pub_data->pubs, idx);
678 
680  pub_data->exten_state_data.local, sizeof(pub_data->exten_state_data.local));
681  if (ast_strlen_zero(uri)) {
682  ast_log(LOG_WARNING, "PUBLISH client '%s' has no from_uri or server_uri defined.\n",
683  publisher->name);
684  continue;
685  }
686 
688  pub_data->exten_state_data.remote, sizeof(pub_data->exten_state_data.remote));
689  if (ast_strlen_zero(uri)) {
690  ast_log(LOG_WARNING, "PUBLISH client '%s' has no to_uri or server_uri defined.\n",
691  publisher->name);
692  continue;
693  }
694 
695  pub_data->exten_state_data.datastores = publisher->datastores;
696 
698  publisher->body_subtype, &gen_data, &body_text);
699  pj_pool_reset(pool);
700  if (res) {
702  "PUBLISH client '%s' unable to generate %s/%s PUBLISH body.\n",
703  publisher->name, publisher->body_type, publisher->body_subtype);
704  continue;
705  }
706 
707  body.type = publisher->body_type;
708  body.subtype = publisher->body_subtype;
710  ast_sip_publish_client_user_send(publisher->client, pub_data->exten_state_data.exten, &body);
711  }
712 
713  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
714 
717  return 0;
718 }
719 
720 /*!
721  * \brief Global extension state callback function
722  */
723 static int exten_state_publisher_state_cb(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
724 {
725  struct ao2_iterator publisher_iter;
726  struct exten_state_publisher *publisher;
727  struct exten_state_pub_data *pub_data = NULL;
728 
729  ast_debug(5, "Exten state publisher: %s@%s Reason:%s State:%s Presence:%s Subtype:'%s' Message:'%s'\n",
730  exten, context,
731  info->reason == AST_HINT_UPDATE_DEVICE
732  ? "Device"
733  : info->reason == AST_HINT_UPDATE_PRESENCE
734  ? "Presence"
735  : "Unknown",
736  ast_extension_state2str(info->exten_state),
737  ast_presence_state2str(info->presence_state),
738  S_OR(info->presence_subtype, ""),
739  S_OR(info->presence_message, ""));
740  publisher_iter = ao2_iterator_init(publishers, 0);
741  for (; (publisher = ao2_iterator_next(&publisher_iter)); ao2_ref(publisher, -1)) {
742  if ((publisher->context_filter && regexec(&publisher->context_regex, context, 0, NULL, 0)) ||
743  (publisher->exten_filter && regexec(&publisher->exten_regex, exten, 0, NULL, 0))) {
744  continue;
745  }
746 
747  if (!pub_data) {
749  if (!pub_data) {
750  ao2_ref(publisher, -1);
751  break;
752  }
753  }
754 
755  ao2_ref(publisher, +1);
756  if (AST_VECTOR_APPEND(&pub_data->pubs, publisher)) {
757  ao2_ref(publisher, -1);
758  } else {
759  ast_debug(5, "'%s' will publish exten state\n", publisher->name);
760  }
761  }
762  ao2_iterator_destroy(&publisher_iter);
763 
764  if (pub_data
766  pub_data)) {
768  }
769 
770  return 0;
771 }
772 
773 /*!
774  * \brief Hashing function for extension state publisher
775  */
776 static int exten_state_publisher_hash(const void *obj, const int flags)
777 {
778  const struct exten_state_publisher *object;
779  const char *key;
780 
781  switch (flags & OBJ_SEARCH_MASK) {
782  case OBJ_SEARCH_KEY:
783  key = obj;
784  break;
785  case OBJ_SEARCH_OBJECT:
786  object = obj;
787  key = object->name;
788  break;
789  default:
790  ast_assert(0);
791  return 0;
792  }
793  return ast_str_hash(key);
794 }
795 
796 /*!
797  * \brief Comparator function for extension state publisher
798  */
799 static int exten_state_publisher_cmp(void *obj, void *arg, int flags)
800 {
801  const struct exten_state_publisher *object_left = obj;
802  const struct exten_state_publisher *object_right = arg;
803  const char *right_key = arg;
804  int cmp;
805 
806  switch (flags & OBJ_SEARCH_MASK) {
807  case OBJ_SEARCH_OBJECT:
808  right_key = object_right->name;
809  /* Fall through */
810  case OBJ_SEARCH_KEY:
811  cmp = strcmp(object_left->name, right_key);
812  break;
814  /* Not supported by container. */
815  ast_assert(0);
816  return 0;
817  default:
818  cmp = 0;
819  break;
820  }
821  if (cmp) {
822  return 0;
823  }
824  return CMP_MATCH;
825 }
826 
827 /*!
828  * \brief Destructor for extension state publisher
829  */
830 static void exten_state_publisher_destroy(void *obj)
831 {
832  struct exten_state_publisher *publisher = obj;
833 
834  if (publisher->context_filter) {
835  regfree(&publisher->context_regex);
836  }
837 
838  if (publisher->exten_filter) {
839  regfree(&publisher->exten_regex);
840  }
841 
842  ao2_cleanup(publisher->client);
843  ao2_cleanup(publisher->datastores);
844 }
845 
846 static int build_regex(regex_t *regex, const char *text)
847 {
848  int res;
849 
850  if ((res = regcomp(regex, text, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
851  size_t len = regerror(res, regex, NULL, 0);
852  char buf[len];
853  regerror(res, regex, buf, len);
854  ast_log(LOG_ERROR, "Could not compile regex '%s': %s\n", text, buf);
855  return -1;
856  }
857 
858  return 0;
859 }
860 
862 {
863  struct exten_state_publisher *publisher;
864  size_t name_size;
865  size_t body_type_size;
866  size_t body_subtype_size;
867  char *body_subtype;
868  const char *body_full;
869  const char *body_type;
870  const char *name;
871  const char *context;
872  const char *exten;
873 
874  name = ast_sorcery_object_get_id(configuration);
875 
876  body_full = ast_sorcery_object_get_extended(configuration, "body");
877  if (ast_strlen_zero(body_full)) {
878  ast_log(LOG_ERROR, "Outbound extension state publisher '%s': Body not set\n",
879  name);
880  return -1;
881  }
882 
883  body_subtype = ast_strdupa(body_full);
884  body_type = strsep(&body_subtype, "/");
886  ast_log(LOG_ERROR, "Outbound extension state publisher '%s': Body '%s' missing type or subtype\n",
887  name, body_full);
888  return -1;
889  }
890 
892  ast_log(LOG_ERROR, "Outbound extension state publisher '%s': '%s' body generator not registered\n",
893  name, body_full);
894  return -1;
895  }
896 
897  name_size = strlen(name) + 1;
898  body_type_size = strlen(body_type) + 1;
899  body_subtype_size = strlen(body_subtype) + 1;
900 
901  publisher = ao2_alloc_options(
902  sizeof(*publisher) + name_size + body_type_size + body_subtype_size,
904  if (!publisher) {
905  return -1;
906  }
907 
908  ast_copy_string(publisher->name, name, name_size);
909  publisher->body_type = publisher->name + name_size;
910  ast_copy_string(publisher->body_type, body_type, body_type_size);
911  publisher->body_subtype = publisher->body_type + body_type_size;
912  ast_copy_string(publisher->body_subtype, body_subtype, body_subtype_size);
913 
914  context = ast_sorcery_object_get_extended(configuration, "context");
915  if (!ast_strlen_zero(context)) {
916  if (build_regex(&publisher->context_regex, context)) {
917  ast_log(LOG_ERROR, "Outbound extension state publisher '%s': Could not build context filter '%s'\n",
918  name, context);
919  ao2_ref(publisher, -1);
920  return -1;
921  }
922 
923  publisher->context_filter = 1;
924  }
925 
926  exten = ast_sorcery_object_get_extended(configuration, "exten");
927  if (!ast_strlen_zero(exten)) {
928  if (build_regex(&publisher->exten_regex, exten)) {
929  ast_log(LOG_ERROR, "Outbound extension state publisher '%s': Could not build exten filter '%s'\n",
930  name, exten);
931  ao2_ref(publisher, -1);
932  return -1;
933  }
934 
935  publisher->exten_filter = 1;
936  }
937 
938  publisher->datastores = ast_datastores_alloc();
939  if (!publisher->datastores) {
940  ast_log(LOG_ERROR, "Outbound extension state publisher '%s': Could not create datastores container\n",
941  name);
942  ao2_ref(publisher, -1);
943  return -1;
944  }
945 
946  publisher->client = ao2_bump(client);
947 
951  }
952  ao2_link_flags(publishers, publisher, OBJ_NOLOCK);
954 
955  ao2_ref(publisher, -1);
956 
957  return 0;
958 }
959 
961 {
963  return 0;
964 }
965 
966 static int unload_module(void)
967 {
972 
974 
977 
979  publishers = NULL;
980 
981  return 0;
982 }
983 
984 static int load_module(void)
985 {
988  if (!publishers) {
989  ast_log(LOG_WARNING, "Unable to create container to store extension state publishers\n");
991  }
992 
995  unload_module();
997  }
998 
1000  ast_log(LOG_WARNING, "Unable to register subscription handler %s\n",
1002  unload_module();
1003  return AST_MODULE_LOAD_DECLINE;
1004  }
1005 
1007  ast_log(LOG_WARNING, "Unable to register presence publisher %s\n",
1009  unload_module();
1010  return AST_MODULE_LOAD_DECLINE;
1011  }
1012 
1014  ast_log(LOG_WARNING, "Unable to register subscription handler %s\n",
1016  unload_module();
1017  return AST_MODULE_LOAD_DECLINE;
1018  }
1019 
1021  ast_log(LOG_WARNING, "Unable to register presence publisher %s\n",
1023  unload_module();
1024  return AST_MODULE_LOAD_DECLINE;
1025  }
1026 
1027  return AST_MODULE_LOAD_SUCCESS;
1028 }
1029 
1030 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State Notifications",
1031  .support_level = AST_MODULE_SUPPORT_CORE,
1032  .load = load_module,
1033  .unload = unload_module,
1034  .load_pri = AST_MODPRI_CHANNEL_DEPEND + 5,
1035  .requires = "res_pjsip,res_pjsip_pubsub,res_pjsip_outbound_publish",
1036 );
char * text
Definition: app_queue.c:1641
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
#define ast_log
Definition: astobj2.c:42
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
@ CMP_MATCH
Definition: astobj2.h:1027
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
Definition: astobj2.h:1554
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
@ 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_NOLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1063
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1072
@ OBJ_UNLINK
Definition: astobj2.h:1039
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
#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 char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:122
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
#define AST_MAX_CONTEXT
Definition: channel.h:135
#define AST_MAX_EXTENSION
Definition: channel.h:134
struct ao2_container * ast_datastores_alloc(void)
Allocate a specialized data stores container.
Definition: datastore.c:95
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char name[]
Definition: format_mp3.c:68
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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:1933
struct ast_taskprocessor * ast_sip_create_serializer(const char *name)
Create a new serializer for SIP tasks.
Definition: res_pjsip.c:1928
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
char * strsep(char **str, const char *delims)
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:317
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ AST_MODPRI_CHANNEL_DEPEND
Definition: module.h:326
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ 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
def info(msg)
int ast_hint_presence_state(struct ast_channel *c, const char *context, const char *exten, char **subtype, char **message)
Uses hint and presence state callback to get the presence state of an extension.
Definition: pbx.c:3233
int ast_extension_state_add_destroy_extended(const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data)
Add watcher for extended extension states with destructor.
Definition: pbx.c:3836
const char * ast_extension_state2str(int extension_state)
Return string representation of the state of an extension.
Definition: pbx.c:3133
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4182
ast_extension_states
Extension states.
Definition: pbx.h:61
@ AST_EXTENSION_REMOVED
Definition: pbx.h:62
@ AST_EXTENSION_DEACTIVATED
Definition: pbx.h:63
int ast_extension_state_del(int id, ast_state_cb_type change_cb)
Deletes a state change watcher by ID.
Definition: pbx.c:3863
@ AST_HINT_UPDATE_DEVICE
Definition: pbx.h:91
@ AST_HINT_UPDATE_PRESENCE
Definition: pbx.h:93
int ast_extension_state_add(const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
Add watcher for extension states.
Definition: pbx.c:3830
int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
If an extension hint exists, return non-zero.
Definition: pbx.c:4144
#define PRIORITY_HINT
Definition: pbx.h:54
int ast_extension_state_extended(struct ast_channel *c, const char *context, const char *exten, struct ao2_container **device_state_info)
Uses hint and devicestate callback to get the extended state of an extension.
Definition: pbx.c:3183
ast_presence_state
Definition: presencestate.h:26
@ AST_PRESENCE_INVALID
Definition: presencestate.h:39
@ AST_PRESENCE_NOT_SET
Definition: presencestate.h:27
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.
struct stasis_forward * sub
Definition: res_corosync.c:240
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:513
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
Definition: res_pjsip.c:2035
static struct exten_state_pub_data * exten_state_pub_data_alloc(const char *exten, struct ast_state_cb_info *info)
static int exten_state_publisher_hash(const void *obj, const int flags)
Hashing function for extension state publisher.
static void exten_state_subscription_destructor(void *obj)
static int get_resource_display_name(struct ast_sip_endpoint *endpoint, const char *resource, char *display_name, int display_name_size)
static int publisher_start(struct ast_sip_outbound_publish *configuration, struct ast_sip_outbound_publish_client *client)
static void exten_state_data_destructor(void *obj)
static void notify_task_data_destructor(void *obj)
static void exten_state_publisher_destroy(void *obj)
Destructor for extension state publisher.
static int exten_state_publisher_cb(void *data)
static void exten_state_pub_data_destroy(struct exten_state_pub_data *doomed)
static int exten_state_publisher_cmp(void *obj, void *arg, int flags)
Comparator function for extension state publisher.
struct ast_sip_event_publisher_handler dialog_publisher
static int state_changed(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
static int publisher_stop(struct ast_sip_outbound_publish_client *client)
struct ast_sip_notifier dialog_notifier
static void subscription_shutdown(struct ast_sip_subscription *sub)
static struct ast_sip_exten_state_data * exten_state_data_alloc(struct ast_sip_subscription *sip_sub, struct exten_state_subscription *exten_state_sub)
static struct exten_state_subscription * exten_state_subscription_alloc(struct ast_sip_subscription *sip_sub, struct ast_sip_endpoint *endpoint)
static int subscription_established(struct ast_sip_subscription *sub)
static void * get_notify_data(struct ast_sip_subscription *sub)
#define PUBLISHER_BUCKETS
The number of buckets to use for storing publishers.
static struct ast_taskprocessor * publish_exten_state_serializer
static struct exten_state_subscription * get_exten_state_sub(struct ast_sip_subscription *sub)
static void state_changed_destroy(int id, void *data)
static struct notify_task_data * alloc_notify_task_data(const char *exten, struct exten_state_subscription *exten_state_sub, struct ast_state_cb_info *info)
static int build_regex(regex_t *regex, const char *text)
static int load_module(void)
static int unload_module(void)
#define INITIAL_LAST_EXTEN_STATE
static const char ds_name[]
struct ast_sip_subscription_handler presence_handler
static struct ao2_container * publishers
Container of active outbound extension state publishers.
struct ast_sip_event_publisher_handler presence_publisher
static int add_datastore(struct exten_state_subscription *exten_state_sub)
#define DEFAULT_DIALOG_BODY
static struct ast_datastore_info ds_info
static void to_ami(struct ast_sip_subscription *sub, struct ast_str **buf)
static int notify_task(void *obj)
static int new_subscribe(struct ast_sip_endpoint *endpoint, const char *resource)
static int exten_state_publisher_state_cb(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
Global extension state callback function.
#define DEFAULT_PRESENCE_BODY
struct ast_sip_subscription_handler dialog_handler
struct ast_sip_notifier presence_notifier
static char * get_user_agent(const struct ast_sip_subscription *sip_sub)
void ast_sip_unregister_event_publisher_handler(struct ast_sip_event_publisher_handler *handler)
Unregister a publish handler.
int ast_sip_register_event_publisher_handler(struct ast_sip_event_publisher_handler *handler)
Register an event publisher handler.
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.
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.
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.
void ast_sip_subscription_get_remote_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
Retrive the remote URI for this subscription.
void ast_sip_unregister_subscription_handler(struct ast_sip_subscription_handler *handler)
Unregister a subscription handler.
int ast_sip_register_subscription_handler(struct ast_sip_subscription_handler *handler)
Register a subscription handler.
const char * ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub)
Get the name of the subscribed resource.
void ast_sip_subscription_destroy(struct ast_sip_subscription *sub)
Alert the pubsub core that the subscription is ready for destruction.
void ast_sip_subscription_remove_datastore(struct ast_sip_subscription *subscription, const char *name)
Remove a subscription datastore from the subscription.
void * ast_sip_subscription_get_header(const struct ast_sip_subscription *sub, const char *header)
Get a header value for a subscription.
int ast_sip_pubsub_generate_body_content(const char *content_type, const char *content_subtype, struct ast_sip_body_data *data, struct ast_str **str)
Generate body content for a PUBLISH or NOTIFY.
struct ast_datastore * ast_sip_subscription_get_datastore(struct ast_sip_subscription *subscription, const char *name)
Retrieve a subscription datastore.
int ast_sip_subscription_notify(struct ast_sip_subscription *sub, struct ast_sip_body_data *notify_data, int terminate)
Notify a SIP subscription of a state change.
struct ast_datastore * ast_sip_subscription_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
Alternative for ast_datastore_alloc()
int ast_sip_subscription_add_datastore(struct ast_sip_subscription *subscription, struct ast_datastore *datastore)
Add a datastore to a SIP subscription.
struct ast_taskprocessor * ast_sip_subscription_get_serializer(struct ast_sip_subscription *sub)
Get the serializer for the subscription.
struct ast_sip_endpoint * ast_sip_subscription_get_endpoint(struct ast_sip_subscription *sub)
Get the endpoint that is associated with this subscription.
int ast_sip_pubsub_is_body_generator_registered(const char *type, const char *subtype)
Is a body generator registered for the given type/subtype.
struct ao2_container * ast_sip_subscription_get_datastores(const struct ast_sip_subscription *subscription)
Get the datastores container for a subscription.
#define AST_SIP_EXTEN_STATE_DATA
int ast_sip_subscription_is_terminated(const struct ast_sip_subscription *sub)
Get whether the subscription has been terminated or not.
void ast_sip_subscription_get_local_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
Retrieve the local URI for this subscription.
#define NULL
Definition: resample.c:96
Sorcery Data Access Layer API.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
const char * ast_sorcery_object_get_extended(const void *object, const char *name)
Get an extended field value from a sorcery object.
Definition: sorcery.c:2330
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1117
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
#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
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1237
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
static force_inline char * ast_str_to_lower(char *str)
Convert a string to all lower-case.
Definition: strings.h:1299
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
Structure for a data store type.
Definition: datastore.h:31
Structure for a data store object.
Definition: datastore.h:64
Data used to create bodies for NOTIFY/PUBLISH requests.
const char * body_type
SIP body description.
Definition: res_pjsip.h:2108
const char * type
Definition: res_pjsip.h:2110
const char * body_text
Definition: res_pjsip.h:2114
const char * subtype
Definition: res_pjsip.h:2112
An entity with which Asterisk communicates.
Definition: res_pjsip.h:854
const ast_string_field context
Definition: res_pjsip.h:883
struct ast_sip_endpoint_subscription_configuration subscription
Definition: res_pjsip.h:889
Callbacks that event publisher handlers will define.
const char * event_name
The name of the event this handler deals with.
structure used for presence XML bodies
struct ast_sip_subscription * sub
enum ast_extension_states exten_state
struct ao2_container * device_state_info
enum ast_presence_state presence_state
const char * default_accept
Default body type defined for the event package this notifier handles.
Outbound publish client state information (persists for lifetime of a publish)
Outbound publish information.
Structure representing a "virtual" SIP subscription.
Support for dynamic strings.
Definition: strings.h:604
A ast_taskprocessor structure is a singleton by name.
Definition: taskprocessor.c:69
struct ast_sip_exten_state_data exten_state_data
struct exten_state_pub_data::name pubs
An extension state publisher.
struct ast_sip_outbound_publish_client * client
struct ao2_container * datastores
A subscription for extension state.
enum ast_presence_state last_presence_state
struct ast_sip_subscription * sip_sub
enum ast_extension_states last_exten_state
char exten[AST_MAX_EXTENSION]
struct ast_taskprocessor * serializer
char context[AST_MAX_CONTEXT]
struct exten_state_subscription * exten_state_sub
struct ast_sip_exten_state_data exten_state_data
userdata associated with baseline taskprocessor test
An API for managing task processing threads that can be shared across modules.
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
#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:936
#define ast_assert(a)
Definition: utils.h:734
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:862
#define AST_VECTOR(name, type)
Define a vector structure.
Definition: vector.h:44
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680