[asterisk-commits] jpeeler: branch 1.4 r165991 - in /branches/1.4: apps/ channels/ codecs/ inclu...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 19 13:48:00 CST 2008


Author: jpeeler
Date: Fri Dec 19 13:48:00 2008
New Revision: 165991

URL: http://svn.digium.com/view/asterisk?view=rev&rev=165991
Log:
(closes issue #13480)
Reported by: tzafrir

Replace a bunch of if defined checks for Zaptel/DAHDI through several new defines in dahdi_compat.h. This removes a lot of code duplication. Example from bug:

#ifdef HAVE_ZAPTEL
  fd = open("/dev/zap/pseudo", O_RDWR);
#else
  fd = open("/dev/dahdi/pseudo", O_RDWR);
#endif

is replaced with:
  fd = open(DAHDI_FILE_PSEUDO, O_RDRW);


Modified:
    branches/1.4/apps/app_dahdibarge.c
    branches/1.4/apps/app_dahdiscan.c
    branches/1.4/apps/app_meetme.c
    branches/1.4/channels/chan_dahdi.c
    branches/1.4/channels/chan_iax2.c
    branches/1.4/codecs/codec_dahdi.c
    branches/1.4/include/asterisk/dahdi_compat.h
    branches/1.4/main/asterisk.c
    branches/1.4/main/channel.c
    branches/1.4/res/res_musiconhold.c

Modified: branches/1.4/apps/app_dahdibarge.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_dahdibarge.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/apps/app_dahdibarge.c (original)
+++ branches/1.4/apps/app_dahdibarge.c Fri Dec 19 13:48:00 2008
@@ -134,11 +134,7 @@
 zapretry:
 	origfd = chan->fds[0];
 	if (retryzap) {
-#ifdef HAVE_ZAPTEL
-		fd = open("/dev/zap/pseudo", O_RDWR);
-#else
-		fd = open("/dev/dahdi/pseudo", O_RDWR);
-#endif
+		fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
 			goto outrun;

Modified: branches/1.4/apps/app_dahdiscan.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_dahdiscan.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/apps/app_dahdiscan.c (original)
+++ branches/1.4/apps/app_dahdiscan.c Fri Dec 19 13:48:00 2008
@@ -135,7 +135,7 @@
  zapretry:
 	origfd = chan->fds[0];
 	if (retryzap) {
-		fd = open("/dev/zap/pseudo", O_RDWR);
+		fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
 			goto outrun;

Modified: branches/1.4/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_meetme.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/apps/app_meetme.c (original)
+++ branches/1.4/apps/app_meetme.c Fri Dec 19 13:48:00 2008
@@ -795,11 +795,7 @@
 	/* Setup a new zap conference */
 	ztc.confno = -1;
 	ztc.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
-#ifdef HAVE_ZAPTEL
-	cnf->fd = open("/dev/zap/pseudo", O_RDWR);
-#else
-	cnf->fd = open("/dev/dahdi/pseudo", O_RDWR);
-#endif
+	cnf->fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 	if (cnf->fd < 0 || ioctl(cnf->fd, DAHDI_SETCONF, &ztc)) {
 		ast_log(LOG_WARNING, "Unable to open pseudo device\n");
 		if (cnf->fd >= 0)
@@ -1732,11 +1728,7 @@
  zapretry:
 	origfd = chan->fds[0];
 	if (retryzap) {
-#ifdef HAVE_ZAPTEL
-		fd = open("/dev/zap/pseudo", O_RDWR);
-#else
-		fd = open("/dev/dahdi/pseudo", O_RDWR);
-#endif
+		fd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
 			goto outrun;

Modified: branches/1.4/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_dahdi.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/channels/chan_dahdi.c (original)
+++ branches/1.4/channels/chan_dahdi.c Fri Dec 19 13:48:00 2008
@@ -915,11 +915,7 @@
 			ast_log(LOG_WARNING, "Invalid channel number '%s'\n", fn);
 			return -1;
 		}
-#ifdef HAVE_ZAPTEL
-		fn = "/dev/zap/channel";
-#else
-		fn = "/dev/dahdi/channel";
-#endif
+		fn = DAHDI_FILE_CHANNEL;
 	}
 	fd = open(fn, O_RDWR | O_NONBLOCK);
 	if (fd < 0) {
@@ -981,11 +977,7 @@
 	struct dahdi_bufferinfo bi;
 	int res;
 	if (p->subs[x].dfd < 0) {
-#ifdef HAVE_ZAPTEL
-		p->subs[x].dfd = dahdi_open("/dev/zap/pseudo");
-#else
-		p->subs[x].dfd = dahdi_open("/dev/dahdi/pseudo");
-#endif
+		p->subs[x].dfd = dahdi_open(DAHDI_FILE_PSEUDO);
 		if (p->subs[x].dfd > -1) {
 			res = ioctl(p->subs[x].dfd, DAHDI_GET_BUFINFO, &bi);
 			if (!res) {
@@ -7222,11 +7214,7 @@
 			break;
 		memset(&si, 0, sizeof(si));
 		memset(&p, 0, sizeof(p));
-#ifdef HAVE_ZAPTEL
-		fd = open("/dev/zap/channel", O_RDWR);
-#else
-		fd = open("/dev/dahdi/channel", O_RDWR);
-#endif
+		fd = open(DAHDI_FILE_CHANNEL, O_RDWR);
 		if (fd < 0) {
 			ast_log(LOG_WARNING, "Failed to open channel: %s\n", strerror(errno));
 			return -1;
@@ -7886,11 +7874,7 @@
 	if ((p = ast_malloc(sizeof(*p)))) {
 		memcpy(p, src, sizeof(struct dahdi_pvt));
 		ast_mutex_init(&p->lock);
-#ifdef HAVE_ZAPTEL
-		p->subs[SUB_REAL].dfd = dahdi_open("/dev/zap/pseudo");
-#else
-		p->subs[SUB_REAL].dfd = dahdi_open("/dev/dahdi/pseudo");
-#endif
+		p->subs[SUB_REAL].dfd = dahdi_open(DAHDI_FILE_PSEUDO);
 		/* Allocate a DAHDI structure */
 		if (p->subs[SUB_REAL].dfd < 0) {
 			ast_log(LOG_ERROR, "Unable to dup channel: %s\n",  strerror(errno));
@@ -9638,11 +9622,7 @@
 	for (i = 0; i < NUM_DCHANS; i++) {
 		if (!pri->dchannels[i])
 			break;
-#ifdef HAVE_ZAPTEL
-		pri->fds[i] = open("/dev/zap/channel", O_RDWR, 0600);
-#else
-		pri->fds[i] = open("/dev/dahdi/channel", O_RDWR, 0600);
-#endif
+		pri->fds[i] = open(DAHDI_FILE_CHANNEL, O_RDWR, 0600);
 		x = pri->dchannels[i];
 		if ((pri->fds[i] < 0) || (ioctl(pri->fds[i],DAHDI_SPECIFY,&x) == -1)) {
 			ast_log(LOG_ERROR, "Unable to open D-channel %d (%s)\n", x, strerror(errno));
@@ -10417,19 +10397,11 @@
 	int ctl;
 	struct dahdi_spaninfo s;
 
-#ifdef HAVE_ZAPTEL
-	if ((ctl = open("/dev/zap/ctl", O_RDWR)) < 0) {
-		ast_log(LOG_WARNING, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
-		ast_cli(fd, "No Zaptel interface found.\n");
+	if ((ctl = open(DAHDI_FILE_CTL, O_RDWR)) < 0) {
+		ast_log(LOG_WARNING, "Unable to open " DAHDI_FILE_CTL ": %s\n", strerror(errno));
+		ast_cli(fd, "No " DAHDI_NAME " interface found.\n");
 		return RESULT_FAILURE;
 	}
-#else
-	if ((ctl = open("/dev/dahdi/ctl", O_RDWR)) < 0) {
-		ast_log(LOG_WARNING, "Unable to open /dev/dahdi/ctl: %s\n", strerror(errno));
-		ast_cli(fd, "No DAHDI interface found.\n");
-		return RESULT_FAILURE;
-	}
-#endif
 	ast_cli(fd, FORMAT2, "Description", "Alarms", "IRQ", "bpviol", "CRC4");
 
 	for (span = 1; span < DAHDI_MAX_SPANS; ++span) {
@@ -11616,14 +11588,10 @@
 				int res;
 				struct dahdi_dialparams dps;
 
-#ifdef HAVE_ZAPTEL
-				ctlfd = open("/dev/zap/ctl", O_RDWR);
-#else
-				ctlfd = open("/dev/dahdi/ctl", O_RDWR);
-#endif
+				ctlfd = open(DAHDI_FILE_CTL, O_RDWR);
 
 				if (ctlfd == -1) {
-					ast_log(LOG_ERROR, "Unable to open /dev/dahdi/ctl to set toneduration\n");
+					ast_log(LOG_ERROR, "Unable to open " DAHDI_FILE_CTL " to set toneduration\n");
 					return -1;
 				}
 

Modified: branches/1.4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_iax2.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/channels/chan_iax2.c (original)
+++ branches/1.4/channels/chan_iax2.c Fri Dec 19 13:48:00 2008
@@ -11231,23 +11231,13 @@
 	iax_set_error(iax_error_output);
 	jb_setoutput(jb_error_output, jb_warning_output, NULL);
 	
-#ifdef HAVE_ZAPTEL
-#ifdef ZAPTEL_TIMERACK
-	timingfd = open("/dev/zap/timer", O_RDWR);
+#ifdef DAHDI_TIMERACK
+	timingfd = open(DAHDI_FILE_TIMER, O_RDWR);
 	if (timingfd < 0)
 #endif
-		timingfd = open("/dev/zap/pseudo", O_RDWR);
+		timingfd = open(DAHDI_FILE_PSEUDO, O_RDWR);
 	if (timingfd < 0) 
 		ast_log(LOG_WARNING, "Unable to open IAX timing interface: %s\n", strerror(errno));
-#elif defined(HAVE_DAHDI)
-#ifdef DAHDI_TIMERACK
-	timingfd = open("/dev/dahdi/timer", O_RDWR);
-	if (timingfd < 0)
-#endif
-		timingfd = open("/dev/dahdi/pseudo", O_RDWR);
-	if (timingfd < 0) 
-		ast_log(LOG_WARNING, "Unable to open IAX timing interface: %s\n", strerror(errno));
-#endif
 
 	memset(iaxs, 0, sizeof(iaxs));
 

Modified: branches/1.4/codecs/codec_dahdi.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/codecs/codec_dahdi.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/codecs/codec_dahdi.c (original)
+++ branches/1.4/codecs/codec_dahdi.c Fri Dec 19 13:48:00 2008
@@ -230,17 +230,10 @@
 	struct pvt *ztp = pvt->pvt;
 	int flags;
 	
-#ifdef HAVE_ZAPTEL
-	if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0) {
-		ast_log(LOG_ERROR, "Failed to open /dev/zap/transcode: %s\n", strerror(errno));
+	if ((fd = open(DAHDI_FILE_TRANSCODE, O_RDWR)) < 0) {
+		ast_log(LOG_ERROR, "Failed to open " DAHDI_FILE_TRANSCODE ": %s\n", strerror(errno));
 		return -1;
 	}
-#else
-	if ((fd = open("/dev/dahdi/transcode", O_RDWR)) < 0) {
-		ast_log(LOG_ERROR, "Failed to open /dev/dahdi/transcode: %s\n", strerror(errno));
-		return -1;
-	}
-#endif
 	
 	ztp->fmts.srcfmt = (1 << source);
 	ztp->fmts.dstfmt = (1 << dest);
@@ -422,17 +415,10 @@
 	int fd, res;
 	unsigned int x, y;
 
-#ifdef HAVE_ZAPTEL
-	if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0) {
-		ast_log(LOG_ERROR, "Failed to open /dev/zap/transcode: %s\n", strerror(errno));
+	if ((fd = open(DAHDI_FILE_TRANSCODE, O_RDWR)) < 0) {
+		ast_log(LOG_ERROR, "Failed to open " DAHDI_FILE_TRANSCODE ": %s\n", strerror(errno));
 		return 0;
 	}
-#else
-	if ((fd = open("/dev/dahdi/transcode", O_RDWR)) < 0) {
-		ast_log(LOG_ERROR, "Failed to open /dev/dahdi/transcode: %s\n", strerror(errno));
-		return 0;
-	}
-#endif
 
 	for (info.tcnum = 0; !(res = ioctl(fd, DAHDI_TC_GETINFO, &info)); info.tcnum++) {
 		if (option_verbose > 1)

Modified: branches/1.4/include/asterisk/dahdi_compat.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/dahdi_compat.h?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/include/asterisk/dahdi_compat.h (original)
+++ branches/1.4/include/asterisk/dahdi_compat.h Fri Dec 19 13:48:00 2008
@@ -26,9 +26,15 @@
 
 #include <dahdi/user.h>
 
+#define DAHDI_DIR_NAME "/dev/dahdi"
+#define DAHDI_NAME "DAHDI"
+
 #elif defined(HAVE_ZAPTEL)
 
 #include <zaptel/zaptel.h>
+
+#define DAHDI_DIR_NAME "/dev/zap"
+#define DAHDI_NAME "DAHDI"
 
 /* Compiling against Zaptel instead of DAHDI */
 
@@ -443,4 +449,10 @@
 
 #endif
 
+#define DAHDI_FILE_CHANNEL   DAHDI_DIR_NAME "/channel"
+#define DAHDI_FILE_CTL       DAHDI_DIR_NAME "/ctl"
+#define DAHDI_FILE_PSEUDO    DAHDI_DIR_NAME "/pseudo"
+#define DAHDI_FILE_TIMER     DAHDI_DIR_NAME "/timer"
+#define DAHDI_FILE_TRANSCODE DAHDI_DIR_NAME "/transcode"
+
 #endif /* DAHDI_COMPAT_H */

Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Fri Dec 19 13:48:00 2008
@@ -3034,53 +3034,35 @@
 	dahdi_chan_name_len = &_dahdi_chan_name_len;
 	dahdi_chan_mode = &_dahdi_chan_mode;
 
-#ifdef HAVE_ZAPTEL
 	{
 		int fd;
 		int x = 160;
-		fd = open("/dev/zap/timer", O_RDWR);
+		fd = open(DAHDI_FILE_TIMER, O_RDWR);
 		if (fd >= 0) {
 			if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) {
-				ast_log(LOG_ERROR, "You have Zaptel built and drivers loaded, but the Zaptel timer test failed to set ZT_TIMERCONFIG to %d.\n", x);
+				ast_log(LOG_ERROR, "You have " DAHDI_NAME
+						" built and drivers loaded, but the "
+						DAHDI_NAME " timer test failed to set DAHDI_TIMERCONFIG to %d.\n", x);
 				exit(1);
 			}
 			if ((x = ast_wait_for_input(fd, 300)) < 0) {
-				ast_log(LOG_ERROR, "You have Zaptel built and drivers loaded, but the Zaptel timer could not be polled during the Zaptel timer test.\n");
-				exit(1);
-			}
-			if (!x) {
-				const char zaptel_timer_error[] = {
-					"Asterisk has detected a problem with your Zaptel configuration and will shutdown for your protection.  You have options:"
-					"\n\t1. You only have to compile Zaptel support into Asterisk if you need it.  One option is to recompile without Zaptel support."
-					"\n\t2. You only have to load Zaptel drivers if you want to take advantage of Zaptel services.  One option is to unload zaptel modules if you don't need them."
-					"\n\t3. If you need Zaptel services, you must correctly configure Zaptel."
-				};
-				ast_log(LOG_ERROR, "%s\n", zaptel_timer_error);
-				exit(1);
-			}
-			close(fd);
-		}
-	}
-#elif defined(HAVE_DAHDI)
-{
-		int fd;
-		int x = 160;
-		fd = open("/dev/dahdi/timer", O_RDWR);
-		if (fd >= 0) {
-			if (ioctl(fd, DAHDI_TIMERCONFIG, &x)) {
-				ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer test failed to set DAHDI_TIMERCONFIG to %d.\n", x);
-				exit(1);
-			}
-			if ((x = ast_wait_for_input(fd, 300)) < 0) {
-				ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer could not be polled during the DAHDI timer test.\n");
+				ast_log(LOG_ERROR, "You have " DAHDI_NAME 
+						"built and drivers loaded, but the " 
+						DAHDI_NAME " timer could not be polled during the " 
+						DAHDI_NAME " timer test.\n");
 				exit(1);
 			}
 			if (!x) {
 				const char dahdi_timer_error[] = {
-					"Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection.  You have options:"
-					"\n\t1. You only have to compile DAHDI support into Asterisk if you need it.  One option is to recompile without DAHDI support."
-					"\n\t2. You only have to load DAHDI drivers if you want to take advantage of DAHDI services.  One option is to unload DAHDI modules if you don't need them."
-					"\n\t3. If you need DAHDI services, you must correctly configure DAHDI."
+					"Asterisk has detected a problem with your " DAHDI_NAME 
+						" configuration and will shutdown for your protection.  You have options:"
+					"\n\t1. You only have to compile " DAHDI_NAME 
+						" support into Asterisk if you need it.  One option is to recompile without " 
+						DAHDI_NAME " support."
+					"\n\t2. You only have to load " DAHDI_NAME " drivers if you want to take advantage of " 
+						DAHDI_NAME " services.  One option is to unload " 
+						DAHDI_NAME " modules if you don't need them."
+					"\n\t3. If you need Zaptel services, you must correctly configure " DAHDI_NAME "."
 				};
 				ast_log(LOG_ERROR, "%s\n", dahdi_timer_error);
 				exit(1);
@@ -3088,8 +3070,6 @@
 			close(fd);
 		}
 	}
-
-#endif
 	threadstorage_init();
 
 	astobj2_init();

Modified: branches/1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/channel.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/main/channel.c (original)
+++ branches/1.4/main/channel.c Fri Dec 19 13:48:00 2008
@@ -744,11 +744,7 @@
 
 #ifdef HAVE_DAHDI
 
-#ifdef HAVE_ZAPTEL
-	tmp->timingfd = open("/dev/zap/timer", O_RDWR);
-#else
-	tmp->timingfd = open("/dev/dahdi/timer", O_RDWR);
-#endif
+	tmp->timingfd = open(DAHDI_FILE_TIMER, O_RDWR);
 
 	if (tmp->timingfd > -1) {
 		/* Check if timing interface supports new

Modified: branches/1.4/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/res/res_musiconhold.c?view=diff&rev=165991&r1=165990&r2=165991
==============================================================================
--- branches/1.4/res/res_musiconhold.c (original)
+++ branches/1.4/res/res_musiconhold.c Fri Dec 19 13:48:00 2008
@@ -923,11 +923,7 @@
 #ifdef HAVE_DAHDI
 		/* Open /dev/zap/pseudo for timing...  Is
 		   there a better, yet reliable way to do this? */
-#ifdef HAVE_ZAPTEL
-		moh->pseudofd = open("/dev/zap/pseudo", O_RDONLY);
-#else
-		moh->pseudofd = open("/dev/dahdi/pseudo", O_RDONLY);
-#endif
+		moh->pseudofd = open(DAHDI_FILE_PSEUDO, O_RDONLY);
 		if (moh->pseudofd < 0) {
 			ast_log(LOG_WARNING, "Unable to open pseudo channel for timing...  Sound may be choppy.\n");
 		} else {




More information about the asterisk-commits mailing list