[Asterisk-code-review] chan dahdi: remove by name support (asterisk[master])

Tzafrir Cohen asteriskteam at digium.com
Tue Oct 18 18:05:26 CDT 2016


Tzafrir Cohen has uploaded a new change for review. ( https://gerrit.asterisk.org/4156 )

Change subject: chan_dahdi: remove by_name support
......................................................................

chan_dahdi: remove by_name support

Support for referring to DAHDI channels by logical names was added in
(FIXME: when? Asterisk 11? 1.8?) and was intended to be part of support
of refering to channels by name.

While technically usable, it has never been properly supported in
dahdi-tools, as using it would require many changes at the Asterisk
level. Instead logical mapping was added at the kernel level.

Thus it seems that refering to DAHDI channels by name is not really used
by anyone, and therefore should probably be removed.

Change-Id: I7d50bbfd9d957586f5cd06570244ef87bd54b485
---
M channels/chan_dahdi.c
M configs/samples/chan_dahdi.conf.sample
2 files changed, 5 insertions(+), 97 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/4156/1

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 8cccf84..dde3c08 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -11979,38 +11979,6 @@
 
 /*!
  * \internal
- * \brief Get file name and channel number from (subdir,number)
- *
- * \param subdir name of the subdirectory under /dev/dahdi/
- * \param channel name of device file under /dev/dahdi/<subdir>/
- * \param path buffer to put file name in
- * \param pathlen maximal length of path
- *
- * \retval minor number of dahdi channel.
- * \retval -errno on error.
- */
-static int device2chan(const char *subdir, int channel, char *path, int pathlen)
-{
-	struct stat	stbuf;
-	int		num;
-
-	snprintf(path, pathlen, "/dev/dahdi/%s/%d", subdir, channel);
-	if (stat(path, &stbuf) < 0) {
-		ast_log(LOG_ERROR, "stat(%s) failed: %s\n", path, strerror(errno));
-		return -errno;
-	}
-	if (!S_ISCHR(stbuf.st_mode)) {
-		ast_log(LOG_ERROR, "%s: Not a character device file\n", path);
-		return -EINVAL;
-	}
-	num = minor(stbuf.st_rdev);
-	ast_debug(1, "%s -> %d\n", path, num);
-	return num;
-
-}
-
-/*!
- * \internal
  * \brief Initialize/create a channel interface.
  *
  * \param channel Channel interface number to initialize/create.
@@ -17426,33 +17394,9 @@
 	return __unload_module();
 }
 
-static void string_replace(char *str, int char1, int char2)
-{
-	for (; *str; str++) {
-		if (*str == char1) {
-			*str = char2;
-		}
-	}
-}
-
-static char *parse_spanchan(char *chanstr, char **subdir)
-{
-	char *p;
-
-	if ((p = strrchr(chanstr, '!')) == NULL) {
-		*subdir = NULL;
-		return chanstr;
-	}
-	*p++ = '\0';
-	string_replace(chanstr, '!', '/');
-	*subdir = chanstr;
-	return p;
-}
-
 static int build_channels(struct dahdi_chan_conf *conf, const char *value, int reload, int lineno)
 {
 	char *c, *chan;
-	char *subdir;
 	int x, start, finish;
 	struct dahdi_pvt *tmp;
 
@@ -17462,7 +17406,6 @@
 	}
 
 	c = ast_strdupa(value);
-	c = parse_spanchan(c, &subdir);
 
 	while ((chan = strsep(&c, ","))) {
 		if (sscanf(chan, "%30d-%30d", &start, &finish) == 2) {
@@ -17484,39 +17427,22 @@
 		}
 
 		for (x = start; x <= finish; x++) {
-			char fn[PATH_MAX];
-			int real_channel = x;
-
-			if (!ast_strlen_zero(subdir)) {
-				real_channel = device2chan(subdir, x, fn, sizeof(fn));
-				if (real_channel < 0) {
-					if (conf->ignore_failed_channels) {
-						ast_log(LOG_WARNING, "Failed configuring %s!%d, (got %d). But moving on to others.\n",
-								subdir, x, real_channel);
-						continue;
-					} else {
-						ast_log(LOG_ERROR, "Failed configuring %s!%d, (got %d).\n",
-								subdir, x, real_channel);
-						return -1;
-					}
-				}
-			}
 			if (conf->wanted_channels_start &&
-				(real_channel < conf->wanted_channels_start ||
-				 real_channel > conf->wanted_channels_end)
+				(x < conf->wanted_channels_start ||
+				 x > conf->wanted_channels_end)
 			   ) {
 				continue;
 			}
-			tmp = mkintf(real_channel, conf, reload);
+			tmp = mkintf(x, conf, reload);
 
 			if (tmp) {
-				ast_verb(3, "%s channel %d, %s signalling\n", reload ? "Reconfigured" : "Registered", real_channel, sig2str(tmp->sig));
+				ast_verb(3, "%s channel %d, %s signalling\n", reload ? "Reconfigured" : "Registered", x, sig2str(tmp->sig));
 			} else {
 				ast_log(LOG_ERROR, "Unable to %s channel '%s'\n",
 						(reload == 1) ? "reconfigure" : "register", value);
 				return -1;
 			}
-			if (real_channel == CHAN_PSEUDO) {
+			if (x == CHAN_PSEUDO) {
 				has_pseudo = 1;
 			}
 		}
diff --git a/configs/samples/chan_dahdi.conf.sample b/configs/samples/chan_dahdi.conf.sample
index e70a2a1..69f7512 100644
--- a/configs/samples/chan_dahdi.conf.sample
+++ b/configs/samples/chan_dahdi.conf.sample
@@ -1330,24 +1330,6 @@
 ; signalling = pri_cpe
 ; group = 2
 ; channel => 1-23
-;
-; Alternatively, the number of the channel may be replaced with a relative
-; path to a device file under /dev/dahdi . The final element of that file
-; must be a number, though. The directory separator is '!', as we can't
-; use '/' in a dial string. So if we have
-;
-;   /dev/dahdi/span-name/pstn/00/1
-;   /dev/dahdi/span-name/pstn/00/2
-;   /dev/dahdi/span-name/pstn/00/3
-;   /dev/dahdi/span-name/pstn/00/4
-;
-; we could use:
-;channel => span-name!pstn!00!1-4
-;
-; or:
-;channel => span-name!pstn!00!1,2,3,4
-;
-; See also ignore_failed_channels above.
 
 ;  Used for distinctive ring support for x100p.
 ;  You can see the dringX patterns is to set any one of the dringXcontext fields

-- 
To view, visit https://gerrit.asterisk.org/4156
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7d50bbfd9d957586f5cd06570244ef87bd54b485
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Tzafrir Cohen <tzafrir.cohen at xorcom.com>



More information about the asterisk-code-review mailing list