]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
(closes issue #13480)
authorJeff Peeler <jpeeler@digium.com>
Fri, 19 Dec 2008 19:48:00 +0000 (19:48 +0000)
committerJeff Peeler <jpeeler@digium.com>
Fri, 19 Dec 2008 19:48:00 +0000 (19:48 +0000)
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: https://origsvn.digium.com/svn/asterisk/branches/1.4@165991 65c4cc65-6c06-0410-ace0-fbb531ad65f3

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

index 853f2853e8c403fdfeb212018cc8acd0d65bd449..cba85a9b64a4764b704df53e8ff1a32316f5cc1d 100644 (file)
@@ -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;
index e1b8694e14bc9fa8de478a14732b6387312421f0..6a600756edd313c837475616cb4805873afefabd 100644 (file)
@@ -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;
index f526279ef9e08c313c9e3b682e509b037bf1e31f..2503b0f380e4761598c89f81984a49ba6e6c534c 100644 (file)
@@ -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;
index 1b6b070de59b2362ab5e6be0e72c2a22116a372c..ee1f136d5e3b2fcf117dc682deb1649b652992f9 100644 (file)
@@ -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;
                                }
 
index 3ce3e67f3f7ace165562d50f61ee5b9046f39287..aefc0b26ef4696257ed7c1afafe124254fbd279a 100644 (file)
@@ -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));
 
index a68b3dcab375b6fadc5458523f5b63d86785bf65..347fc80126eb5eca8fa7976957ddaec09edcf0a5 100644 (file)
@@ -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)
index b1dc8d02c802161506aafce57f254b2b7fd8c585..a8f602af1fa9504b3258cd33116dd2fed82f761a 100644 (file)
 
 #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)
 
 #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 */
index 3ed7fff225de727ec1f2138b45fa0a3362520e08..2afe01a81d7a91264f62a424ad6ab7c69f713af3 100644 (file)
@@ -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();
index 6870d5338ff20a14481644b0b4bee1893e8778cc..34e31ab4a5f18f449ceff1eec74c4690bafaade6 100644 (file)
@@ -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
index 8bbf2ec67ca7dc52b26cb512382f9ae103e6f79b..ca2a0435a6c4b22a17164a85e87790ca45b96b14 100644 (file)
@@ -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 {