[asterisk-commits] mmichelson: branch mmichelson/pubsub_bodies r405978 - in /team/mmichelson/pub...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 20 16:36:11 CST 2014
Author: mmichelson
Date: Mon Jan 20 16:36:09 2014
New Revision: 405978
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405978
Log:
Expand primary body generators to have more callbacks.
This pretty much obsoletes the exten state providers. I have
not removed all traces of them yet, but I will in the next commit.
I'll also be rearranging files some in the process.
Modified:
team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h
team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h
team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c
team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c
team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c
Modified: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h?view=diff&rev=405978&r1=405977&r2=405978
==============================================================================
--- team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h (original)
+++ team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_exten_state.h Mon Jan 20 16:36:09 2014
@@ -75,6 +75,13 @@
AST_LIST_ENTRY(ast_sip_exten_state_provider) next;
};
+struct exten_state_body_generator_data {
+ struct ast_sip_exten_state_data *exten_data;
+ const char *local;
+ const char *remote;
+ pj_pool_t *pool;
+};
+
/*!
* \brief Registers an extension state provider.
*
Modified: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h?view=diff&rev=405978&r1=405977&r2=405978
==============================================================================
--- team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h (original)
+++ team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h Mon Jan 20 16:36:09 2014
@@ -585,6 +585,20 @@
*/
enum ast_sip_pubsub_body_generator_type generator_type;
/*!
+ * \brief allocate body structure.
+ *
+ * Primary body generators will have this method called when a NOTIFY
+ * or PUBLISH body needs to be created. The type returned depends on
+ * the type of content being produced for the body. The data parameter
+ * is provided by the subscription handler and will vary between different
+ * event types.
+ *
+ * \param data The subscription data provided by the event handler
+ * \retval non-NULL The allocated body
+ * \retval NULL Failure
+ */
+ void *(*allocate_body)(void *data);
+ /*!
* \brief Add content to the body of a SIP request
*
* The body of the request has already been allocated. Primary body
@@ -598,6 +612,22 @@
* determined by the content type.
*/
int (*generate_body_content)(void *body, void *data);
+ /*!
+ * \brief Convert the body to a string.
+ *
+ * \param body The request body.
+ * \param str The converted string form of the request body
+ */
+ void (*to_string)(void *body, struct ast_str **str);
+ /*!
+ * \brief Deallocate resources created for the body
+ *
+ * Optional callback to destroy resources allocated for the
+ * message body.
+ *
+ * \param body Body to be destroyed
+ */
+ void (*destroy_body)(void *body);
AST_LIST_ENTRY(ast_sip_pubsub_body_generator) list;
};
@@ -612,11 +642,13 @@
*
* \param content_type The content type of the body
* \param content_subtype The content subtype of the body
- * \param body The pre-allocated body.
* \param data The data associated with body generation.
- */
-int ast_sip_pubsub_generate_body_content(struct ast_sip_subscription *sub,
- void *body, void *data);
+ * \param[out] str The string representation of the generated body
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+int ast_sip_pubsub_generate_body_content(const char *content_type,
+ const char *content_subtype, void *data, struct ast_str **str);
/*!
* \since 13.0.0
@@ -640,4 +672,16 @@
*/
void ast_sip_pubsub_unregister_body_generator(struct ast_sip_pubsub_body_generator *generator);
+/*!
+ * \since 13.0.0
+ * \brief Get the body type used for this subscription
+ */
+const char *ast_sip_subscription_get_body_type(struct ast_sip_subscription *sub);
+
+/*!
+ * \since 13.0.0
+ * \brief Get the body subtype used for this subscription
+ */
+const char *ast_sip_subscription_get_body_subtype(struct ast_sip_subscription *sub);
+
#endif /* RES_PJSIP_PUBSUB_H */
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c?view=diff&rev=405978&r1=405977&r2=405978
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_exten_state.c Mon Jan 20 16:36:09 2014
@@ -193,6 +193,29 @@
return exten_state_sub;
}
+static int exten_state_body_generator_data_init(struct ast_sip_exten_state_data *exten_data,
+ const char *local, const char *remote,
+ struct exten_state_body_generator_data *gen_data)
+{
+ gen_data->pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(),
+ "pidf", 1024, 1024);
+
+ if (!gen_data->pool) {
+ return -1;
+ }
+
+ gen_data->local = local;
+ gen_data->remote = remote;
+ gen_data->exten_data = exten_data;
+
+ return 0;
+}
+
+static void exten_state_body_generator_data_release(struct exten_state_body_generator_data *gen_data)
+{
+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), gen_data->pool);
+}
+
/*!
* \internal
* \brief Create and send a NOTIFY request to the subscriber.
@@ -207,26 +230,24 @@
pjsip_dialog *dlg;
char local[PJSIP_MAX_URL_SIZE], remote[PJSIP_MAX_URL_SIZE];
struct ast_sip_body body;
-
- struct ast_sip_exten_state_provider *provider = provider_by_types(
- exten_state_sub->event_name, exten_state_sub->body_types,
- exten_state_sub->body_types_count);
-
- if (!provider) {
- ast_log(LOG_ERROR, "Unable to locate provider for subscription\n");
- return;
- }
-
- body.type = provider->type;
- body.subtype = provider->subtype;
+ struct exten_state_body_generator_data gen_data;
+
+ body.type = ast_sip_subscription_get_body_type(exten_state_sub->sip_sub);
+ body.subtype = ast_sip_subscription_get_body_subtype(exten_state_sub->sip_sub);
dlg = ast_sip_subscription_get_dlg(exten_state_sub->sip_sub);
ast_copy_pj_str(local, &dlg->local.info_str, sizeof(local));
ast_copy_pj_str(remote, &dlg->remote.info_str, sizeof(remote));
- if (provider->create_body(exten_state_data, local, remote, &body_text)) {
+ if (exten_state_body_generator_data_init(exten_state_data, local, remote, &gen_data)) {
+ ast_log(LOG_ERROR, "Unable to allocate resources for sending presence NOTIFY request\n");
+ return;
+ }
+
+ if (ast_sip_pubsub_generate_body_content(body.type, body.subtype,
+ &gen_data, &body_text)) {
ast_log(LOG_ERROR, "Unable to create body on NOTIFY request\n");
- return;
+ goto end;
}
body.body_text = ast_str_buffer(body_text);
@@ -239,18 +260,21 @@
if (pjsip_evsub_notify(ast_sip_subscription_get_evsub(exten_state_sub->sip_sub),
evsub_state, NULL, reason_str_ptr, &tdata) != PJ_SUCCESS) {
ast_log(LOG_WARNING, "Unable to create NOTIFY request\n");
- return;
+ goto end;
}
if (ast_sip_add_body(tdata, &body)) {
ast_log(LOG_WARNING, "Unable to add body to NOTIFY request\n");
pjsip_tx_data_dec_ref(tdata);
- return;
+ goto end;
}
if (ast_sip_subscription_send_request(exten_state_sub->sip_sub, tdata) != PJ_SUCCESS) {
ast_log(LOG_WARNING, "Unable to send NOTIFY request\n");
}
+
+end:
+ exten_state_body_generator_data_release(&gen_data);
}
/*!
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c?view=diff&rev=405978&r1=405977&r2=405978
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c Mon Jan 20 16:36:09 2014
@@ -75,13 +75,19 @@
.to_ami = mwi_to_ami,
};
+static void *mwi_allocate_body(void *data);
static int mwi_generate_body_content(void *body, void *data);
+static void mwi_to_string(void *body, struct ast_str **str);
+static void mwi_destroy_body(void *body);
static struct ast_sip_pubsub_body_generator mwi_generator = {
.type = MWI_TYPE,
.subtype = MWI_SUBTYPE,
.generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = mwi_allocate_body,
.generate_body_content = mwi_generate_body_content,
+ .to_string = mwi_to_string,
+ .destroy_body = mwi_destroy_body,
};
/*!
@@ -376,24 +382,53 @@
}
}
+static void *mwi_allocate_body(void *data)
+{
+ struct ast_str **mwi_str;
+
+ mwi_str = ast_malloc(sizeof(*mwi_str));
+ if (!mwi_str) {
+ return NULL;
+ }
+ *mwi_str = ast_str_create(64);
+ if (*mwi_str) {
+ ast_free(mwi_str);
+ return NULL;
+ }
+ return mwi_str;
+}
+
static int mwi_generate_body_content(void *body, void *data)
{
- struct ast_str **body_str = body;
+ struct ast_str **mwi = body;
struct message_accumulator *counter = data;
- ast_str_append(body_str, 0, "Messages-Waiting: %s\r\n", counter->new_msgs ? "yes" : "no");
- ast_str_append(body_str, 0, "Voice-Message: %d/%d (0/0)\r\n", counter->new_msgs, counter->old_msgs);
-
- return 0;
+ ast_str_append(mwi, 0, "Messages-Waiting: %s\r\n",
+ counter->new_msgs ? "yes" : "no");
+ ast_str_append(mwi, 0, "Voice-Message: %d/%d (0/0)\r\n",
+ counter->new_msgs, counter->old_msgs);
+
+ return 0;
+}
+
+static void mwi_to_string(void *body, struct ast_str **str)
+{
+ struct ast_str **mwi = body;
+
+ ast_str_set(str, 0, "%s", ast_str_buffer(*mwi));
+}
+
+static void mwi_destroy_body(void *body)
+{
+ struct ast_str **mwi = body;
+
+ ast_free(*mwi);
+ ast_free(mwi);
}
static void send_mwi_notify(struct mwi_subscription *sub, pjsip_evsub_state state, const char *reason)
{
const pj_str_t *reason_str_ptr = NULL;
- static pjsip_media_type mwi_type = {
- .type = { MWI_TYPE, sizeof(MWI_TYPE) - 1 },
- .subtype = { MWI_SUBTYPE, sizeof(MWI_SUBTYPE) - 1 },
- };
struct message_accumulator counter = {
.old_msgs = 0,
.new_msgs = 0,
@@ -402,6 +437,13 @@
pjsip_tx_data *tdata;
pj_str_t reason_str;
pj_str_t pj_body;
+ const char *type = sub->is_solicited ?
+ ast_sip_subscription_get_body_type(sub->sip_sub) :
+ MWI_TYPE;
+ const char *subtype = sub->is_solicited ?
+ ast_sip_subscription_get_body_subtype(sub->sip_sub) :
+ MWI_SUBTYPE;
+ pjsip_media_type mwi_type;
ao2_callback(sub->stasis_subs, OBJ_NODATA, get_message_count, &counter);
@@ -410,12 +452,14 @@
reason_str_ptr = &reason_str;
}
- if (ast_sip_pubsub_generate_body_content(sub->sip_sub, &body, &counter)) {
+ if (ast_sip_pubsub_generate_body_content(type, subtype, &counter, &body)) {
ast_log(LOG_WARNING, "Unable to generate SIP MWI NOTIFY body.\n");
return;
}
pj_cstr(&pj_body, ast_str_buffer(body));
+ pj_cstr(&mwi_type.type, type);
+ pj_cstr(&mwi_type.subtype, subtype);
ast_debug(5, "Sending %s MWI NOTIFY to endpoint %s, new messages: %d, old messages: %d\n",
sub->is_solicited ? "solicited" : "unsolicited", sub->id, counter.new_msgs,
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c?view=diff&rev=405978&r1=405977&r2=405978
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c Mon Jan 20 16:36:09 2014
@@ -208,34 +208,15 @@
}
}
-struct exten_state_body_generator_data {
- struct ast_sip_exten_state_data *exten_data;
- const char *local;
- const char *remote;
- pj_pool_t *pool;
-};
-
-static int exten_state_body_generator_data_init(struct ast_sip_exten_state_data *exten_data,
- const char *local, const char *remote,
- struct exten_state_body_generator_data *gen_data)
-{
- gen_data->pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(),
- "pidf", 1024, 1024);
-
- if (!gen_data->pool) {
- return -1;
- }
-
- gen_data->local = local;
- gen_data->remote = remote;
- gen_data->exten_data = exten_data;
-
- return 0;
-}
-
-static void exten_state_body_generator_data_release(struct exten_state_body_generator_data *gen_data)
-{
- pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), gen_data->pool);
+static void *pidf_allocate_body(void *data)
+{
+ struct exten_state_body_generator_data *gen_data = data;
+ pjpidf_pres *pres;
+ pj_str_t entity;
+
+ pres = pjpidf_create(gen_data->pool, pj_cstr(&entity, gen_data->local));
+
+ return pres;
}
static int pidf_generate_body_content(void *body, void *data)
@@ -273,61 +254,51 @@
return 0;
}
-static int pidf_xml_create_body(struct ast_sip_exten_state_data *data, const char *local,
- const char *remote, struct ast_str **body_text)
-{
- pjpidf_pres *pres;
- pj_str_t entity;
+#define MAX_STRING_GROWTHS 3
+
+static void pidf_to_string(void *body, struct ast_str **str)
+{
int size;
- struct exten_state_body_generator_data gen_data;
- int res = 0;
-
- if (exten_state_body_generator_data_init(data, local, remote, &gen_data)) {
- ast_log(LOG_WARNING, "Unable to allocate resources for generating PIDF body\n");
- return -1;
- }
-
- if (!(pres = pjpidf_create(gen_data.pool, pj_cstr(&entity, local)))) {
- ast_log(LOG_WARNING, "Unable to create PIDF presence\n");
- res = -1;
- goto end;
- }
-
- /* XXX Get this NULL fixed ASAP */
- if (ast_sip_pubsub_generate_body_content(NULL, pres, &gen_data)) {
- ast_log(LOG_WARNING, "Failed to generate PIDF NOTIFY body\n");
- res = -1;
- goto end;
- }
-
- if (!(size = pjpidf_print(pres, ast_str_buffer(*body_text),
- ast_str_size(*body_text)))) {
+ int growths = 0;
+ pjpidf_pres *pres = body;
+
+ do {
+ size = pjpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1);
+ if (size < 0) {
+ ast_str_make_space(str, ast_str_size(*str) * 2);
+ ++growths;
+ return;
+ }
+ } while (size < 0 && growths < MAX_STRING_GROWTHS);
+
+ if (size < 0) {
ast_log(LOG_WARNING, "PIDF body text too large\n");
- res = -1;
- goto end;
- }
- *(ast_str_buffer(*body_text) + size) = '\0';
- ast_str_update(*body_text);
-
-end:
- exten_state_body_generator_data_release(&gen_data);
- return res;
-}
-
-static struct ast_sip_exten_state_provider pidf_xml_provider = {
- .event_name = "presence",
- .type = "application",
- .subtype = "pidf+xml",
- .body_type = "application/pidf+xml",
- .create_body = pidf_xml_create_body
-};
+ return;
+ }
+
+ *(ast_str_buffer(*str) + size) = '\0';
+ ast_str_update(*str);
+}
static struct ast_sip_pubsub_body_generator pidf_body_generator = {
.type = "application",
.subtype = "pidf+xml",
.generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = pidf_allocate_body,
.generate_body_content = pidf_generate_body_content,
+ .to_string = pidf_to_string,
+ /* No need for a destroy_body callback since we use a pool */
};
+
+static void *xpidf_allocate_body(void *data)
+{
+ struct exten_state_body_generator_data *gen_data = data;
+ pjxpidf_pres *pres;
+ pj_str_t name;
+
+ pres = pjxpidf_create(gen_data->pool, pj_cstr(&name, gen_data->local));
+ return pres;
+}
static int xpidf_generate_body_content(void *body, void *data)
{
@@ -368,114 +339,65 @@
return 0;
}
-static int xpidf_xml_create_body(struct ast_sip_exten_state_data *data, const char *local,
- const char *remote, struct ast_str **body_text)
-{
- pjxpidf_pres *pres;
+static void xpidf_to_string(void *body, struct ast_str **str)
+{
+ pjxpidf_pres *pres = body;
+ int growths = 0;
int size;
- struct exten_state_body_generator_data gen_data;
- int res = 0;
- pj_str_t name;
-
- if (exten_state_body_generator_data_init(data, local, remote, &gen_data)) {
- ast_log(LOG_WARNING, "Unable to allocate resources for generating xpidf XML body\n");
- res = -1;
- goto end;
- }
-
- if (!(pres = pjxpidf_create(gen_data.pool, pj_cstr(&name, local)))) {
- ast_log(LOG_WARNING, "Unable to create XPIDF presence\n");
- res = -1;
- goto end;
- }
-
- /* XXX Get this NULL fixed ASAP */
- if (ast_sip_pubsub_generate_body_content(NULL, pres, &gen_data)) {
- ast_log(LOG_WARNING, "Unable to generate XPIDF NOTIFY body\n");
- res = -1;
- goto end;
- }
-
- if (!(size = pjxpidf_print(pres, ast_str_buffer(*body_text),
- ast_str_size(*body_text)))) {
+
+ do {
+
+ size = pjxpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str));
+ if (size < 0) {
+ ast_str_make_space(str, ast_str_size(*str) * 2);
+ ++growths;
+ return;
+ }
+ } while (size < 0 && growths < MAX_STRING_GROWTHS);
+
+ if (size < 0) {
ast_log(LOG_WARNING, "XPIDF body text too large\n");
- res = -1;
- goto end;
- }
-
- *(ast_str_buffer(*body_text) + size) = '\0';
- ast_str_update(*body_text);
-
-end:
- exten_state_body_generator_data_release(&gen_data);
- return res;
-}
-
-static struct ast_sip_exten_state_provider xpidf_xml_provider = {
- .event_name = "presence",
- .type = "application",
- .subtype = "xpidf+xml",
- .body_type = "application/xpidf+xml",
- .create_body = xpidf_xml_create_body
-};
+ return;
+ }
+
+ *(ast_str_buffer(*str) + size) = '\0';
+ ast_str_update(*str);
+}
static struct ast_sip_pubsub_body_generator xpidf_body_generator = {
.type = "application",
.subtype = "xpidf+xml",
.generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = xpidf_allocate_body,
.generate_body_content = xpidf_generate_body_content,
-};
-
-static struct ast_sip_exten_state_provider cpim_pidf_xml_provider = {
- .event_name = "presence",
- .type = "application",
- .subtype = "cpim-pidf+xml",
- .body_type = "application/cpim-pidf+xml",
- .create_body = xpidf_xml_create_body,
+ .to_string = xpidf_to_string,
+ /* No need for a destroy_body callback since we use a pool */
};
static struct ast_sip_pubsub_body_generator cpim_pidf_body_generator = {
.type = "application",
.subtype = "cpim-pidf+xml",
.generator_type = AST_SIP_PUBSUB_BODY_GENERATOR_PRIMARY,
+ .allocate_body = xpidf_allocate_body,
.generate_body_content = xpidf_generate_body_content,
+ .to_string = xpidf_to_string,
+ /* No need for a destroy_body callback since we use a pool */
};
static void unregister_all(void)
{
- ast_sip_unregister_exten_state_provider(&cpim_pidf_xml_provider);
ast_sip_pubsub_unregister_body_generator(&cpim_pidf_body_generator);
- ast_sip_unregister_exten_state_provider(&xpidf_xml_provider);
ast_sip_pubsub_unregister_body_generator(&xpidf_body_generator);
- ast_sip_unregister_exten_state_provider(&pidf_xml_provider);
ast_sip_pubsub_unregister_body_generator(&pidf_body_generator);
}
static int load_module(void)
{
- if (ast_sip_register_exten_state_provider(&pidf_xml_provider)) {
- ast_log(LOG_WARNING, "Unable to load provider event_name=%s, body_type=%s",
- pidf_xml_provider.event_name, pidf_xml_provider.body_type);
- goto fail;
- }
-
if (ast_sip_pubsub_register_body_generator(&pidf_body_generator)) {
goto fail;
}
- if (ast_sip_register_exten_state_provider(&xpidf_xml_provider)) {
- ast_log(LOG_WARNING, "Unable to load provider event_name=%s, body_type=%s",
- xpidf_xml_provider.event_name, xpidf_xml_provider.body_type);
- goto fail;
- }
-
if (ast_sip_pubsub_register_body_generator(&xpidf_body_generator)) {
- goto fail;
- }
-
- if (ast_sip_register_exten_state_provider(&cpim_pidf_xml_provider)) {
- ast_log(LOG_WARNING, "Unable to load provider event_name=%s, body_type=%s",
- cpim_pidf_xml_provider.event_name, cpim_pidf_xml_provider.body_type);
goto fail;
}
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c?view=diff&rev=405978&r1=405977&r2=405978
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c Mon Jan 20 16:36:09 2014
@@ -1153,31 +1153,62 @@
AST_RWLIST_TRAVERSE_SAFE_END;
}
-int ast_sip_pubsub_generate_body_content(struct ast_sip_subscription *sub,
- void *body, void *data)
-{
- struct ast_sip_pubsub_body_generator *iter;
+const char *ast_sip_subscription_get_body_type(struct ast_sip_subscription *sub)
+{
+ return sub->body_generator->type;
+}
+
+const char *ast_sip_subscription_get_body_subtype(struct ast_sip_subscription *sub)
+{
+ return sub->body_generator->subtype;
+}
+
+int ast_sip_pubsub_generate_body_content(const char *type, const char *subtype,
+ void *data, struct ast_str **str)
+{
+ struct ast_sip_pubsub_body_generator *supplement;
+ struct ast_sip_pubsub_body_generator *primary;
int res;
-
- res = sub->body_generator->generate_body_content(body, data);
- if (res) {
- return res;
+ void *body;
+
+ primary = find_body_generator_type_subtype(type, subtype);
+ if (!primary) {
+ return -1;
+ }
+
+ body = primary->allocate_body(data);
+ if (!body) {
+ return -1;
+ }
+
+ if (primary->generate_body_content(body, data)) {
+ res = -1;
+ goto end;
}
AST_RWLIST_RDLOCK(&body_generators);
- AST_RWLIST_TRAVERSE(&body_generators, iter, list) {
- if (iter->generator_type != AST_SIP_PUBSUB_BODY_GENERATOR_SUPPLEMENTARY) {
+ AST_RWLIST_TRAVERSE(&body_generators, supplement, list) {
+ if (supplement->generator_type != AST_SIP_PUBSUB_BODY_GENERATOR_SUPPLEMENTARY) {
continue;
}
- if (!strcmp(sub->body_generator->type, iter->type) &&
- !strcmp(sub->body_generator->subtype, iter->subtype)) {
- res = iter->generate_body_content(body, data);
+ if (!strcmp(primary->type, supplement->type) &&
+ !strcmp(primary->subtype, supplement->subtype)) {
+ res = supplement->generate_body_content(body, data);
if (res) {
break;
}
}
}
AST_RWLIST_UNLOCK(&body_generators);
+
+ if (!res) {
+ primary->to_string(body, str);
+ }
+
+end:
+ if (primary->destroy_body) {
+ primary->destroy_body(body);
+ }
return res;
}
More information about the asterisk-commits
mailing list