diff options
author | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-19 19:48:00 +0000 |
---|---|---|
committer | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-19 19:48:00 +0000 |
commit | f2eeca3bed9fef3110ee1946504e3b382341d7fc (patch) | |
tree | f32d0af75adb1ba287d025ed312df096422a910a | |
parent | a78774210ab8a62f2f675688748a02a227f67aef (diff) |
(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);
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@165991 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | apps/app_dahdibarge.c | 6 | ||||
-rw-r--r-- | apps/app_dahdiscan.c | 2 | ||||
-rw-r--r-- | apps/app_meetme.c | 12 | ||||
-rw-r--r-- | channels/chan_dahdi.c | 52 | ||||
-rw-r--r-- | channels/chan_iax2.c | 14 | ||||
-rw-r--r-- | codecs/codec_dahdi.c | 22 | ||||
-rw-r--r-- | include/asterisk/dahdi_compat.h | 12 | ||||
-rw-r--r-- | main/asterisk.c | 54 | ||||
-rw-r--r-- | main/channel.c | 6 | ||||
-rw-r--r-- | res/res_musiconhold.c | 6 |
10 files changed, 51 insertions, 135 deletions
diff --git a/apps/app_dahdibarge.c b/apps/app_dahdibarge.c index 853f2853e..cba85a9b6 100644 --- a/apps/app_dahdibarge.c +++ b/apps/app_dahdibarge.c @@ -134,11 +134,7 @@ static int conf_run(struct ast_channel *chan, int confno, int confflags) 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; diff --git a/apps/app_dahdiscan.c b/apps/app_dahdiscan.c index e1b8694e1..6a600756e 100644 --- a/apps/app_dahdiscan.c +++ b/apps/app_dahdiscan.c @@ -135,7 +135,7 @@ static int conf_run(struct ast_channel *chan, int confno, int confflags) 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; diff --git a/apps/app_meetme.c b/apps/app_meetme.c index f526279ef..2503b0f38 100644 --- a/apps/app_meetme.c +++ b/apps/app_meetme.c @@ -795,11 +795,7 @@ static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin /* 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 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c 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; diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 1b6b070de..ee1f136d5 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -915,11 +915,7 @@ static int dahdi_open(char *fn) 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 @@ static int alloc_sub(struct dahdi_pvt *p, int x) 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 @@ static int pri_create_trunkgroup(int trunkgroup, int *channels) 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 @@ static struct dahdi_pvt *chandup(struct dahdi_pvt *src) 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 @@ static int start_pri(struct dahdi_pri *pri) 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 @@ static int dahdi_show_status(int fd, int argc, char *argv[]) { 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 @@ static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct 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; } diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 3ce3e67f3..aefc0b26e 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -11231,23 +11231,13 @@ static int load_module(void) 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); - if (timingfd < 0) -#endif - timingfd = open("/dev/zap/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); + timingfd = open(DAHDI_FILE_TIMER, O_RDWR); if (timingfd < 0) #endif - timingfd = open("/dev/dahdi/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)); -#endif memset(iaxs, 0, sizeof(iaxs)); diff --git a/codecs/codec_dahdi.c b/codecs/codec_dahdi.c index a68b3dcab..347fc8012 100644 --- a/codecs/codec_dahdi.c +++ b/codecs/codec_dahdi.c @@ -230,17 +230,10 @@ static int zap_translate(struct ast_trans_pvt *pvt, int dest, int source) 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 @@ static int find_transcoders(void) 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)); - 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)); + 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; } -#endif for (info.tcnum = 0; !(res = ioctl(fd, DAHDI_TC_GETINFO, &info)); info.tcnum++) { if (option_verbose > 1) diff --git a/include/asterisk/dahdi_compat.h b/include/asterisk/dahdi_compat.h index b1dc8d02c..a8f602af1 100644 --- a/include/asterisk/dahdi_compat.h +++ b/include/asterisk/dahdi_compat.h @@ -26,10 +26,16 @@ #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 */ #if defined(__ZT_SIG_FXO) @@ -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 */ diff --git a/main/asterisk.c b/main/asterisk.c index 3ed7fff22..2afe01a81 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -3034,53 +3034,35 @@ int main(int argc, char *argv[]) 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); - 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); - 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); + fd = open(DAHDI_FILE_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); + 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 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 @@ int main(int argc, char *argv[]) close(fd); } } - -#endif threadstorage_init(); astobj2_init(); diff --git a/main/channel.c b/main/channel.c index 6870d5338..34e31ab4a 100644 --- a/main/channel.c +++ b/main/channel.c @@ -744,11 +744,7 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_ #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 diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 8bbf2ec67..ca2a0435a 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -923,11 +923,7 @@ static int moh_register(struct mohclass *moh, int reload) #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 { |