[Asterisk-code-review] cdr_syslog: Remove deprecated module. (asterisk[19])

George Joseph asteriskteam at digium.com
Wed Aug 18 11:11:51 CDT 2021


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16297 )

Change subject: cdr_syslog: Remove deprecated module.
......................................................................

cdr_syslog: Remove deprecated module.

ASTERISK-29592

Change-Id: Ic8eb6a2100ad5bc3b48338a6d0a6cfa70ecbc50f
---
D cdr/cdr_syslog.c
D configs/samples/cdr_syslog.conf.sample
A doc/UPGRADE-staging/cdr_syslog_removal.txt
M tests/CI/buildAsterisk.sh
4 files changed, 7 insertions(+), 382 deletions(-)

Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Joshua Colp: Approved for Submit



diff --git a/cdr/cdr_syslog.c b/cdr/cdr_syslog.c
deleted file mode 100644
index 84e19b9..0000000
--- a/cdr/cdr_syslog.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2009, malleable, LLC.
- *
- * Sean Bright <sean at malleable.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*!
- * \file
- * \brief syslog CDR logger
- *
- * \author Sean Bright <sean at malleable.com>
- *
- * See also
- * \arg \ref Config_cdr
- * \ingroup cdr_drivers
- */
-
-/*! \li \ref cdr_syslog.c uses the configuration file \ref cdr_syslog.conf
- * \addtogroup configuration_file Configuration Files
- */
-
-/*!
- * \page cdr_syslog.conf cdr_syslog.conf
- * \verbinclude cdr_syslog.conf.sample
- */
-
-/*** MODULEINFO
-	<depend>syslog</depend>
-	<defaultenabled>no</defaultenabled>
-	<support_level>deprecated</support_level>
-	<deprecated_in>16</deprecated_in>
-	<removed_in>19</removed_in>
-***/
-
-#include "asterisk.h"
-
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/cdr.h"
-#include "asterisk/pbx.h"
-
-#include <syslog.h>
-
-#include "asterisk/syslog.h"
-
-static const char CONFIG[] = "cdr_syslog.conf";
-
-AST_THREADSTORAGE(syslog_buf);
-
-static const char name[] = "cdr-syslog";
-
-struct cdr_syslog_config {
-	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(ident);
-		AST_STRING_FIELD(format);
-	);
-	int facility;
-	int priority;
-	ast_mutex_t lock;
-	AST_LIST_ENTRY(cdr_syslog_config) list;
-};
-
-static AST_RWLIST_HEAD_STATIC(sinks, cdr_syslog_config);
-
-static void free_config(void)
-{
-	struct cdr_syslog_config *sink;
-
-	while ((sink = AST_RWLIST_REMOVE_HEAD(&sinks, list))) {
-		ast_mutex_destroy(&sink->lock);
-		ast_string_field_free_memory(sink);
-		ast_free(sink);
-	}
-}
-
-static int syslog_log(struct ast_cdr *cdr)
-{
-	struct ast_channel *dummy;
-	struct ast_str *str;
-	struct cdr_syslog_config *sink;
-
-	/* Batching saves memory management here.  Otherwise, it's the same as doing an
-	   allocation and free each time. */
-	if (!(str = ast_str_thread_get(&syslog_buf, 16))) {
-		return -1;
-	}
-
-	if (!(dummy = ast_dummy_channel_alloc())) {
-		ast_log(AST_LOG_ERROR, "Unable to allocate channel for variable substitution.\n");
-		return -1;
-	}
-
-	/* We need to dup here since the cdr actually belongs to the other channel,
-	   so when we release this channel we don't want the CDR getting cleaned
-	   up prematurely. */
-	ast_channel_cdr_set(dummy, ast_cdr_dup(cdr));
-
-	AST_RWLIST_RDLOCK(&sinks);
-
-	AST_LIST_TRAVERSE(&sinks, sink, list) {
-
-		ast_str_substitute_variables(&str, 0, dummy, sink->format);
-
-		/* Even though we have a lock on the list, we could be being chased by
-		   another thread and this lock ensures that we won't step on anyone's
-		   toes.  Once each CDR backend gets it's own thread, this lock can be
-		   removed. */
-		ast_mutex_lock(&sink->lock);
-
-		openlog(sink->ident, LOG_CONS, sink->facility);
-		syslog(sink->priority, "%s", ast_str_buffer(str));
-		closelog();
-
-		ast_mutex_unlock(&sink->lock);
-	}
-
-	AST_RWLIST_UNLOCK(&sinks);
-
-	ast_channel_unref(dummy);
-
-	return 0;
-}
-
-static int load_config(int reload)
-{
-	struct ast_config *cfg;
-	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
-	int default_facility = LOG_LOCAL4;
-	int default_priority = LOG_INFO;
-	const char *catg = NULL, *tmp;
-
-	cfg = ast_config_load(CONFIG, config_flags);
-	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
-		ast_log(AST_LOG_ERROR,
-			"Unable to load %s. Not logging custom CSV CDRs to syslog.\n", CONFIG);
-		return -1;
-	} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
-		return 0;
-	}
-
-	if (reload) {
-		free_config();
-	}
-
-	if (!(ast_strlen_zero(tmp = ast_variable_retrieve(cfg, "general", "facility")))) {
-		int facility = ast_syslog_facility(tmp);
-		if (facility < 0) {
-			ast_log(AST_LOG_WARNING,
-				"Invalid facility '%s' specified, defaulting to '%s'\n",
-				tmp, ast_syslog_facility_name(default_facility));
-		} else {
-			default_facility = facility;
-		}
-	}
-
-	if (!(ast_strlen_zero(tmp = ast_variable_retrieve(cfg, "general", "priority")))) {
-		int priority = ast_syslog_priority(tmp);
-		if (priority < 0) {
-			ast_log(AST_LOG_WARNING,
-				"Invalid priority '%s' specified, defaulting to '%s'\n",
-				tmp, ast_syslog_priority_name(default_priority));
-		} else {
-			default_priority = priority;
-		}
-	}
-
-	while ((catg = ast_category_browse(cfg, catg))) {
-		struct cdr_syslog_config *sink;
-
-		if (!strcasecmp(catg, "general")) {
-			continue;
-		}
-
-		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "template"))) {
-			ast_log(AST_LOG_WARNING,
-				"No 'template' parameter found for '%s'.  Skipping.\n", catg);
-			continue;
-		}
-
-		sink = ast_calloc_with_stringfields(1, struct cdr_syslog_config, 1024);
-
-		if (!sink) {
-			ast_log(AST_LOG_ERROR,
-				"Unable to allocate memory for configuration settings.\n");
-			free_config();
-			break;
-		}
-
-		ast_mutex_init(&sink->lock);
-		ast_string_field_set(sink, ident, catg);
-		ast_string_field_set(sink, format, tmp);
-
-		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "facility"))) {
-			sink->facility = default_facility;
-		} else {
-			int facility = ast_syslog_facility(tmp);
-			if (facility < 0) {
-				ast_log(AST_LOG_WARNING,
-					"Invalid facility '%s' specified for '%s,' defaulting to '%s'\n",
-					tmp, catg, ast_syslog_facility_name(default_facility));
-			} else {
-				sink->facility = facility;
-			}
-		}
-
-		if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "priority"))) {
-			sink->priority = default_priority;
-		} else {
-			int priority = ast_syslog_priority(tmp);
-			if (priority < 0) {
-				ast_log(AST_LOG_WARNING,
-					"Invalid priority '%s' specified for '%s,' defaulting to '%s'\n",
-					tmp, catg, ast_syslog_priority_name(default_priority));
-			} else {
-				sink->priority = priority;
-			}
-		}
-
-		AST_RWLIST_INSERT_TAIL(&sinks, sink, list);
-	}
-
-	ast_config_destroy(cfg);
-
-	return AST_RWLIST_EMPTY(&sinks) ? -1 : 0;
-}
-
-static int unload_module(void)
-{
-	if (ast_cdr_unregister(name)) {
-		return -1;
-	}
-
-	if (AST_RWLIST_WRLOCK(&sinks)) {
-		ast_cdr_register(name, ast_module_info->description, syslog_log);
-		ast_log(AST_LOG_ERROR, "Unable to lock sink list.  Unload failed.\n");
-		return -1;
-	}
-
-	free_config();
-	AST_RWLIST_UNLOCK(&sinks);
-	return 0;
-}
-
-static enum ast_module_load_result load_module(void)
-{
-	int res;
-
-	if (AST_RWLIST_WRLOCK(&sinks)) {
-		ast_log(AST_LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-		return AST_MODULE_LOAD_DECLINE;
-	}
-
-	res = load_config(0);
-	AST_RWLIST_UNLOCK(&sinks);
-	if (res) {
-		return AST_MODULE_LOAD_DECLINE;
-	}
-	ast_cdr_register(name, ast_module_info->description, syslog_log);
-	return AST_MODULE_LOAD_SUCCESS;
-}
-
-static int reload(void)
-{
-	int res;
-	if (AST_RWLIST_WRLOCK(&sinks)) {
-		ast_log(AST_LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-		return AST_MODULE_LOAD_DECLINE;
-	}
-
-	if ((res = load_config(1))) {
-		free_config();
-	}
-
-	AST_RWLIST_UNLOCK(&sinks);
-
-	return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
-}
-
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Customizable syslog CDR Backend",
-	.support_level = AST_MODULE_SUPPORT_CORE,
-	.load = load_module,
-	.unload = unload_module,
-	.reload = reload,
-	.load_pri = AST_MODPRI_CDR_DRIVER,
-	.requires = "cdr",
-);
diff --git a/configs/samples/cdr_syslog.conf.sample b/configs/samples/cdr_syslog.conf.sample
deleted file mode 100644
index 3a619be..0000000
--- a/configs/samples/cdr_syslog.conf.sample
+++ /dev/null
@@ -1,83 +0,0 @@
-;
-; Asterisk Call Detail Records (CDR) - Syslog Backend
-;
-
-; The cdr_syslog module writes CDRs using the facilities provided by syslog.
-;
-; Not only must you configure cdr_syslog from this file (cdr_syslog.conf) but
-; you will also need to make changes to your /etc/syslog.conf before CDRs will
-; be written to syslog.
-;
-; As an example, you can add the following to /etc/syslog.conf:
-;
-;    local4.info        /var/log/asterisk-cdr.log
-;
-; And then instruct syslogd to re-read the configuration file by sending it a
-; HUP signal.  On Linux this can be done like this:
-;
-;    kill -HUP `cat /var/run/syslogd.pid`
-;
-; Finally, you will need to uncomment the [cdr-simple] section below, and restart
-; Asterisk.  When calls are placed, you should start seeing records appear in
-; /var/log/asterisk-cdr.log.
-
-[general]
-; Facility
-;
-; The 'facility' keyword specifies the syslog facility to use when writing out
-; CDRs.
-;
-; Accepted values: One of the following:
-;                  user, local0, local1, local2, local3, local4, local5, local6
-;                  and local7.
-;
-;                  Note: Depending on your platform, the following may also be
-;                        available:
-;                        auth, authpriv, cron, daemon, ftp, kern, lpr, mail,
-;                        news, syslog, and uucp.
-;
-; Default value:   local4
-
-;facility=local0
-
-; Priority
-;
-; Use the 'priority' keyword to select which of the syslog priority levels to
-; use when logging CDRs.
-;
-; Accepted values: One of the following:
-;                  alert, crit, debug, emerg, err, info, notice, warning
-; Default value:   info
-
-;priority=warn
-
-; Note: The settings for 'facility' and 'priority' in the [general] section
-;       define the default values for all of the logging locations created
-;       below in separate sections.
-
-;[cdr-master]
-;facility = local5
-;priority = debug
-
-; Template
-;
-; The 'template' value allows you to specify a custom format for messages
-; written to syslog.  This is similar to how cdr_custom is configured.
-;
-; Allowed values: A diaplan style string.
-; Default value:  None, this is required field.
-;
-; Note: Because of the way substitution is done, the only meaningful values
-;       available when the record is logged are those available via the CDR()
-;       dialplan function.  All other channel variables will be unavailable.
-
-;template = "${CDR(clid)}","${CDR(src)}","${CDR(dst)}","${CDR(dcontext)}","${CDR(channel)}","${CDR(dstchannel)}","${CDR(lastapp)}","${CDR(lastdata)}","${CDR(start)}","${CDR(answer)}","${CDR(end)}","${CDR(duration)}","${CDR(billsec)}","${CDR(disposition)}","${CDR(amaflags)}","${CDR(accountcode)}","${CDR(uniqueid)}","${CDR(userfield)}"
-
-; High Resolution Time for billsec and duration fields
-;template = "${CDR(clid)}","${CDR(src)}","${CDR(dst)}","${CDR(dcontext)}","${CDR(channel)}","${CDR(dstchannel)}","${CDR(lastapp)}","${CDR(lastdata)}","${CDR(start)}","${CDR(answer)}","${CDR(end)}","${CDR(duration,f)}","${CDR(billsec,f)}","${CDR(disposition)}","${CDR(amaflags)}","${CDR(accountcode)}","${CDR(uniqueid)}","${CDR(userfield)}"
-;[cdr-simple]
-
-; Since we don't specify a facility or priority for this logging location, the
-; records will use the defaults specified in the [general] section.
-
-;template = "We received a call from ${CDR(src)}"
diff --git a/doc/UPGRADE-staging/cdr_syslog_removal.txt b/doc/UPGRADE-staging/cdr_syslog_removal.txt
new file mode 100644
index 0000000..17f88dd
--- /dev/null
+++ b/doc/UPGRADE-staging/cdr_syslog_removal.txt
@@ -0,0 +1,6 @@
+Subject: cdr_syslog
+Master-Only: True
+
+This module was deprecated in Asterisk 16
+and is now being removed in accordance with
+the Asterisk Module Deprecation policy.
diff --git a/tests/CI/buildAsterisk.sh b/tests/CI/buildAsterisk.sh
index d8bad70..1d280f0 100755
--- a/tests/CI/buildAsterisk.sh
+++ b/tests/CI/buildAsterisk.sh
@@ -145,7 +145,7 @@
 		mod_disables+=" app_readexten app_sms app_speech_utils app_test app_url app_waitforring"
 		mod_disables+=" app_waitforsilence app_waituntil app_zapateller"
 		mod_disables+=" cdr_adaptive_odbc cdr_custom cdr_manager cdr_odbc cdr_pgsql cdr_radius"
-		mod_disables+=" cdr_syslog cdr_tds"
+		mod_disables+=" cdr_tds"
 		mod_disables+=" cel_odbc cel_pgsql cel_radius cel_sqlite3_custom cel_tds"
 		mod_disables+=" chan_alsa chan_console chan_mgcp chan_motif chan_oss chan_rtp chan_skinny chan_unistim"
 		mod_disables+=" func_frame_trace func_pitchshift func_speex func_volume func_dialgroup"

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16297
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: Ic8eb6a2100ad5bc3b48338a6d0a6cfa70ecbc50f
Gerrit-Change-Number: 16297
Gerrit-PatchSet: 3
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210818/8e96549d/attachment-0001.html>


More information about the asterisk-code-review mailing list