install_prereq: Add SUSE.
[asterisk/asterisk.git] / res / res_pjsip_history.c
index 4e7dbd0..ab035a2 100644 (file)
@@ -42,6 +42,7 @@
 #include "asterisk/netsock2.h"
 #include "asterisk/vector.h"
 #include "asterisk/lock.h"
+#include "asterisk/res_pjproject.h"
 
 #define HISTORY_INITIAL_SIZE 256
 
@@ -705,10 +706,13 @@ static pj_status_t history_on_tx_msg(pjsip_tx_data *tdata)
        pj_sockaddr_cp(&entry->dst, &tdata->tp_info.dst_addr);
 
        ast_mutex_lock(&history_lock);
-       AST_VECTOR_APPEND(&vector_history, entry);
+       if (AST_VECTOR_APPEND(&vector_history, entry)) {
+               ao2_ref(entry, -1);
+               entry = NULL;
+       }
        ast_mutex_unlock(&history_lock);
 
-       if (log_level != -1) {
+       if (log_level != -1 && entry) {
                char line[256];
 
                sprint_list_entry(entry, line, sizeof(line));
@@ -745,10 +749,13 @@ static pj_bool_t history_on_rx_msg(pjsip_rx_data *rdata)
        }
 
        ast_mutex_lock(&history_lock);
-       AST_VECTOR_APPEND(&vector_history, entry);
+       if (AST_VECTOR_APPEND(&vector_history, entry)) {
+               ao2_ref(entry, -1);
+               entry = NULL;
+       }
        ast_mutex_unlock(&history_lock);
 
-       if (log_level != -1) {
+       if (log_level != -1 && entry) {
                char line[256];
 
                sprint_list_entry(entry, line, sizeof(line));
@@ -959,7 +966,9 @@ static int evaluate_history_entry(struct pjsip_history_entry *entry, struct expr
 
                /* If this is not an operator, push it to the stack */
                if (!it_queue->op) {
-                       AST_VECTOR_APPEND(&stack, it_queue);
+                       if (AST_VECTOR_APPEND(&stack, it_queue)) {
+                               goto error;
+                       }
                        continue;
                }
 
@@ -1035,7 +1044,11 @@ static int evaluate_history_entry(struct pjsip_history_entry *entry, struct expr
                if (!result) {
                        goto error;
                }
-               AST_VECTOR_APPEND(&stack, result);
+               if (AST_VECTOR_APPEND(&stack, result)) {
+                       expression_token_free(result);
+
+                       goto error;
+               }
        }
 
        /*
@@ -1056,6 +1069,7 @@ static int evaluate_history_entry(struct pjsip_history_entry *entry, struct expr
        }
        result = final->result;
        ast_free(final);
+       AST_VECTOR_FREE(&stack);
 
        return result;
 
@@ -1098,6 +1112,7 @@ static struct vector_history_t *filter_history(struct ast_cli_args *a)
 
        queue = build_expression_queue(a);
        if (!queue) {
+               AST_VECTOR_PTR_FREE(output);
                return NULL;
        }
 
@@ -1118,7 +1133,9 @@ static struct vector_history_t *filter_history(struct ast_cli_args *a)
                } else if (!res) {
                        continue;
                } else {
-                       AST_VECTOR_APPEND(output, ao2_bump(entry));
+                       if (AST_VECTOR_APPEND(output, ao2_bump(entry))) {
+                               ao2_cleanup(entry);
+                       }
                }
        }
        ast_mutex_unlock(&history_lock);
@@ -1264,7 +1281,7 @@ static char *pjsip_show_history(struct ast_cli_entry *e, int cmd, struct ast_cli
                }
                entry = ao2_bump(AST_VECTOR_GET(vec, 0));
                if (vec == &vector_history) {
-                       ast_mutex_lock(&history_lock);
+                       ast_mutex_unlock(&history_lock);
                }
        }
 
@@ -1348,14 +1365,12 @@ static struct ast_cli_entry cli_pjsip[] = {
 
 static int load_module(void)
 {
-       CHECK_PJSIP_MODULE_LOADED();
-
        log_level = ast_logger_register_level("PJSIP_HISTORY");
        if (log_level < 0) {
                ast_log(LOG_WARNING, "Unable to register history log level\n");
        }
 
-       pj_caching_pool_init(&cachingpool, &pj_pool_factory_default_policy, 0);
+       ast_pjproject_caching_pool_init(&cachingpool, &pj_pool_factory_default_policy, 0);
 
        AST_VECTOR_INIT(&vector_history, HISTORY_INITIAL_SIZE);
 
@@ -1373,7 +1388,7 @@ static int unload_module(void)
        ast_sip_push_task_synchronous(NULL, clear_history_entries, NULL);
        AST_VECTOR_FREE(&vector_history);
 
-       pj_caching_pool_destroy(&cachingpool);
+       ast_pjproject_caching_pool_destroy(&cachingpool);
 
        if (log_level != -1) {
                ast_logger_unregister_level("PJSIP_HISTORY");
@@ -1387,4 +1402,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP History",
                .load = load_module,
                .unload = unload_module,
                .load_pri = AST_MODPRI_APP_DEPEND,
+               .requires = "res_pjsip",
        );