res_pjsip: Fix leak on error in ast_sip_auth_vector_init.
[asterisk/asterisk.git] / res / res_pjsip_pidf_body_generator.c
index 3181b29..29c9e6b 100644 (file)
@@ -58,7 +58,7 @@ static int pidf_generate_body_content(void *body, void *data)
        struct ast_sip_exten_state_data *state_data = data;
 
        ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
-                       &pidfstate, &pidfnote, &local_state);
+                       &pidfstate, &pidfnote, &local_state, 0);
 
        if (!pjpidf_pres_add_note(state_data->pool, pres, pj_cstr(&note, pidfnote))) {
                ast_log(LOG_WARNING, "Unable to add note to PIDF presence\n");
@@ -75,7 +75,7 @@ static int pidf_generate_body_content(void *body, void *data)
        pjpidf_tuple_set_contact(state_data->pool, tuple, pj_cstr(&contact, sanitized));
        pjpidf_tuple_set_contact_prio(state_data->pool, tuple, pj_cstr(&priority, "1"));
        pjpidf_status_set_basic_open(pjpidf_tuple_get_status(tuple),
-                       local_state == NOTIFY_OPEN);
+                       local_state == NOTIFY_OPEN || local_state == NOTIFY_INUSE);
 
        return 0;
 }
@@ -84,19 +84,18 @@ static int pidf_generate_body_content(void *body, void *data)
 
 static void pidf_to_string(void *body, struct ast_str **str)
 {
-       int size;
-       int growths = 0;
        pjpidf_pres *pres = body;
+       int growths = 0;
+       int size;
 
        do {
                size = pjpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1);
-               if (size == AST_PJSIP_XML_PROLOG_LEN) {
+               if (size <= AST_PJSIP_XML_PROLOG_LEN) {
                        ast_str_make_space(str, ast_str_size(*str) * 2);
                        ++growths;
                }
-       } while (size == AST_PJSIP_XML_PROLOG_LEN && growths < MAX_STRING_GROWTHS);
-
-       if (size == AST_PJSIP_XML_PROLOG_LEN) {
+       } while (size <= AST_PJSIP_XML_PROLOG_LEN && growths < MAX_STRING_GROWTHS);
+       if (size <= AST_PJSIP_XML_PROLOG_LEN) {
                ast_log(LOG_WARNING, "PIDF body text too large\n");
                return;
        }
@@ -108,6 +107,7 @@ static void pidf_to_string(void *body, struct ast_str **str)
 static struct ast_sip_pubsub_body_generator pidf_body_generator = {
        .type = "application",
        .subtype = "pidf+xml",
+       .body_type = AST_SIP_EXTEN_STATE_DATA,
        .allocate_body = pidf_allocate_body,
        .generate_body_content = pidf_generate_body_content,
        .to_string = pidf_to_string,
@@ -116,6 +116,8 @@ static struct ast_sip_pubsub_body_generator pidf_body_generator = {
 
 static int load_module(void)
 {
+       CHECK_PJSIP_PUBSUB_MODULE_LOADED();
+
        if (ast_sip_pubsub_register_body_generator(&pidf_body_generator)) {
                return AST_MODULE_LOAD_DECLINE;
        }
@@ -129,8 +131,8 @@ static int unload_module(void)
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State PIDF Provider",
-               .support_level = AST_MODULE_SUPPORT_CORE,
-               .load = load_module,
-               .unload = unload_module,
-               .load_pri = AST_MODPRI_CHANNEL_DEPEND,
+       .support_level = AST_MODULE_SUPPORT_CORE,
+       .load = load_module,
+       .unload = unload_module,
+       .load_pri = AST_MODPRI_CHANNEL_DEPEND,
 );