summaryrefslogtreecommitdiff
path: root/main/logger.c
diff options
context:
space:
mode:
authorJonathan Rose <jrose@digium.com>2012-05-17 16:28:20 +0000
committerJonathan Rose <jrose@digium.com>2012-05-17 16:28:20 +0000
commitcd37bec058f821f2777407eb9e99cc561bafdef5 (patch)
tree308553e9e2806f90a4087bea76745bbd03761a02 /main/logger.c
parente240b2159acc159a531fc8398e67a1755084eae0 (diff)
logger: Adds additional support for call id logging and chan_sip specific stuff
This patch improves the handling of call id logging significantly with regard to transfers and adding APIs to better handle specific aspects of logging. Also, changes have been made to chan_sip in order to better handle the creation of callids and to enable the monitor thread to bind itself to a particular call id when a dialog is determined to be related to a callid. It then unbinds itself before returning to normal monitoring. review: https://reviewboard.asterisk.org/r/1886/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366842 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/logger.c')
-rw-r--r--main/logger.c62
1 files changed, 60 insertions, 2 deletions
diff --git a/main/logger.c b/main/logger.c
index dcef76218..cdced2701 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -1236,6 +1236,11 @@ void close_logger(void)
AST_RWLIST_UNLOCK(&logchannels);
}
+void ast_callid_strnprint(char *buffer, size_t buffer_size, struct ast_callid *callid)
+{
+ snprintf(buffer, buffer_size, "[C-%08x]", callid->call_identifier);
+}
+
struct ast_callid *ast_create_callid(void)
{
struct ast_callid *call;
@@ -1249,7 +1254,7 @@ struct ast_callid *ast_create_callid(void)
using = ast_atomic_fetchadd_int(&next_unique_callid, +1);
call->call_identifier = using;
- ast_log(LOG_DEBUG, "CALL_ID [C-%08x] created by thread.\n", call->call_identifier);
+ ast_debug(3, "CALL_ID [C-%08x] created by thread.\n", call->call_identifier);
return call;
}
@@ -1279,7 +1284,7 @@ int ast_callid_threadassoc_add(struct ast_callid *callid)
/* callid will be unreffed at thread destruction */
ast_callid_ref(callid);
*pointing = callid;
- ast_log(LOG_DEBUG, "CALL_ID [C-%08x] bound to thread.\n", callid->call_identifier);
+ ast_debug(3, "CALL_ID [C-%08x] bound to thread.\n", callid->call_identifier);
} else {
ast_log(LOG_WARNING, "Attempted to ast_callid_threadassoc_add on thread already associated with a callid.\n");
return 1;
@@ -1288,6 +1293,59 @@ int ast_callid_threadassoc_add(struct ast_callid *callid)
return 0;
}
+int ast_callid_threadassoc_remove()
+{
+ struct ast_callid **pointing;
+ pointing = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
+ if (!(pointing)) {
+ ast_log(LOG_ERROR, "Failed to allocate thread storage.\n");
+ return -1;
+ }
+
+ if (!(*pointing)) {
+ ast_log(LOG_ERROR, "Tried to clean callid thread storage with no callid in thread storage.\n");
+ return -1;
+ } else {
+ ast_debug(3, "Call_ID [C-%08x] being removed from thread.\n", (*pointing)->call_identifier);
+ *pointing = ast_callid_unref(*pointing);
+ return 0;
+ }
+}
+
+int ast_callid_threadstorage_auto(struct ast_callid **callid)
+{
+ struct ast_callid *tmp;
+
+ /* Start by trying to see if a callid is available from thread storage */
+ tmp = ast_read_threadstorage_callid();
+ if (tmp) {
+ *callid = tmp;
+ return 0;
+ }
+
+ /* If that failed, try to create a new one and bind it. */
+ tmp = ast_create_callid();
+ if (tmp) {
+ ast_callid_threadassoc_add(tmp);
+ *callid = tmp;
+ return 1;
+ }
+
+ /* If neither worked, then something must have gone wrong. */
+ return -1;
+}
+
+void ast_callid_threadstorage_auto_clean(struct ast_callid *callid, int callid_created)
+{
+ if (callid) {
+ /* If the callid was created rather than simply grabbed from the thread storage, we need to unbind here. */
+ if (callid_created == 1) {
+ ast_callid_threadassoc_remove();
+ }
+ callid = ast_callid_unref(callid);
+ }
+}
+
/*!
* \internal
* \brief thread storage cleanup function for unique_callid