Asterisk - The Open Source Telephony Project  18.5.0
res_pjsip_pidf_eyebeam_body_supplement.c
Go to the documentation of this file.
1 /*
2  * asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2014, Digium, Inc.
5  *
6  * Mark Michelson <[email protected]>
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  <support_level>core</support_level>
24  ***/
25 
26 #include "asterisk.h"
27 
28 #include <pjsip.h>
29 #include <pjsip_simple.h>
30 #include <pjlib.h>
31 
32 #include "asterisk/module.h"
33 #include "asterisk/res_pjsip.h"
37 
38 /*!
39  * \internal
40  * \brief Adds non standard elements to the xml body
41  *
42  * This is some code that was part of the original chan_sip implementation
43  * that is not part of the RFC 3863 definition, but we are keeping available
44  * for backward compatability. The original comment stated that Eyebeam
45  * supports this format.
46  */
47 static void add_eyebeam(pj_pool_t *pool, pj_xml_node *node, const char *pidfstate)
48 {
49  static const char *XMLNS_DM_PREFIX = "xmlns:dm";
50  static const char *XMLNS_DM = "urn:ietf:params:xml:ns:pidf:data-model";
51 
52  static const char *XMLNS_RPID_PREFIX = "xmlns:rpid";
53  static const char *XMLNS_RPID = "urn:ietf:params:xml:ns:pidf:rpid";
54 
55  pj_xml_node *person = ast_sip_presence_xml_create_node(pool, node, "dm:person");
56 
57  if (pidfstate[0] != '-') {
58  pj_xml_node *activities = ast_sip_presence_xml_create_node(pool, person, "rpid:activities");
59  size_t str_size = sizeof("rpid:") + strlen(pidfstate);
60  char *act_str = ast_alloca(str_size);
61 
62  /* Safe */
63  strcpy(act_str, "rpid:");
64  strcat(act_str, pidfstate);
65 
66  ast_sip_presence_xml_create_node(pool, activities, act_str);
67  }
68 
69  ast_sip_presence_xml_create_attr(pool, node, XMLNS_DM_PREFIX, XMLNS_DM);
70  ast_sip_presence_xml_create_attr(pool, node, XMLNS_RPID_PREFIX, XMLNS_RPID);
71 }
72 
73 static int pidf_supplement_body(void *body, void *data)
74 {
75  pjpidf_pres *pres = body;
76  struct ast_sip_exten_state_data *state_data = data;
77  char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
78  enum ast_sip_pidf_state local_state;
79 
80  ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
81  &pidfstate, &pidfnote, &local_state, 0);
82 
83  add_eyebeam(state_data->pool, pres, pidfstate);
84  return 0;
85 }
86 
88  .type = "application",
89  .subtype = "pidf+xml",
90  .supplement_body = pidf_supplement_body,
91 };
92 
93 static int load_module(void)
94 {
95  if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
97  }
99 }
100 
101 static int unload_module(void)
102 {
104  return 0;
105 }
106 
107 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Eyebeam supplement",
108  .support_level = AST_MODULE_SUPPORT_CORE,
109  .load = load_module,
110  .unload = unload_module,
111  .load_pri = AST_MODPRI_CHANNEL_DEPEND,
112  .requires = "res_pjsip,res_pjsip_pubsub",
113 );
Definition: test_heap.c:38
Asterisk main include file. File version handling, generic pbx functions.
static void add_eyebeam(pj_pool_t *pool, pj_xml_node *node, const char *pidfstate)
static pj_pool_t * pool
Global memory pool for configuration and timers.
pj_xml_attr * ast_sip_presence_xml_create_attr(pj_pool_t *pool, pj_xml_node *node, const char *name, const char *value)
Create XML attribute.
Definition: presence_xml.c:140
enum ast_extension_states exten_state
const char * type
Content type In "plain/text", "plain" is the type.
#define NULL
Definition: resample.c:96
void ast_sip_presence_exten_state_to_str(int state, char **statestring, char **pidfstate, char **pidfnote, enum ast_sip_pidf_state *local_state, unsigned int notify_early_inuse_ringing)
Convert extension state to relevant PIDF strings.
Definition: presence_xml.c:84
static struct ast_sip_pubsub_body_supplement pidf_supplement
static int pidf_supplement_body(void *body, void *data)
static int unload_module(void)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
static int load_module(void)
pj_xml_node * ast_sip_presence_xml_create_node(pj_pool_t *pool, pj_xml_node *parent, const char *name)
Create XML node.
Definition: presence_xml.c:152
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
structure used for presence XML bodies
int ast_sip_pubsub_register_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Register a body generator with the pubsub core.
void ast_sip_pubsub_unregister_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Unregister a body generator with the pubsub core.
ast_sip_pidf_state
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.