]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
fix up namespace pollution for dahdi_chan_mode enum
authorKevin P. Fleming <kpfleming@digium.com>
Tue, 22 Jul 2008 22:11:01 +0000 (22:11 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Tue, 22 Jul 2008 22:11:01 +0000 (22:11 +0000)
correct registration of AMI actions in chan_dahdi; in zap-only mode, only register the Zap flavors of the actions (and use Zap prefixes for headers and acks), but in dahdi+zap mode, register both Zap and DAHDI flavors of actions

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@132787 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_dahdibarge.c
apps/app_dahdiras.c
apps/app_flash.c
channels/chan_dahdi.c
include/asterisk/options.h
main/asterisk.c

index 48bc0c62f753c696c2b5c83a7c4cde95578ad4aa..88610cc36d16af3677d7685c233d232192d74deb 100644 (file)
@@ -336,7 +336,7 @@ static int unload_module(void)
 {
        int res = 0;
 
-       if (dahdi_chan_mode == DAHDI_PLUS_ZAP) {
+       if (dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) {
                res |= ast_unregister_application(dahdi_app);
        }
 
@@ -351,7 +351,7 @@ static int load_module(void)
 {
        int res = 0;
 
-       if (dahdi_chan_mode == DAHDI_PLUS_ZAP) {
+       if (dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) {
                res |= ast_register_application(dahdi_app, exec_dahdi, dahdi_synopsis, dahdi_descrip);
        }
 
index 2a9875ed3335d182586134c3681442daf5607c44..1012a5fbeb8dc235b0084f67a9193d2f20caa76b 100644 (file)
@@ -260,7 +260,7 @@ static int unload_module(void)
 {
        int res = 0;
 
-       if (dahdi_chan_mode == DAHDI_PLUS_ZAP) {
+       if (dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) {
                res |= ast_unregister_application(dahdi_app);
        }
 
@@ -275,7 +275,7 @@ static int load_module(void)
 {
        int res = 0;
 
-       if (dahdi_chan_mode == DAHDI_PLUS_ZAP) {
+       if (dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) {
                res |= ast_register_application(dahdi_app, exec, dahdi_synopsis, dahdi_descrip);
        }
 
index 98ea17d03f024340b4b2144d1a7451560f64564e..e6b2db49a2ab5f06ba74225671fe25aed2652317 100644 (file)
@@ -126,7 +126,7 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       if (dahdi_chan_mode == ZAP_ONLY_MODE) {
+       if (dahdi_chan_mode == CHAN_ZAP_MODE) {
                return ast_register_application(app, flash_exec, zap_synopsis, zap_descrip);
        } else {
                return ast_register_application(app, flash_exec, dahdi_synopsis, dahdi_descrip);
index e6c137fa14c0cc1e6475a4b03142ebd369ea2eaa..ddba8016e3825b14bf3b43e5f7447466a4236d52 100644 (file)
@@ -9906,13 +9906,6 @@ static struct ast_cli_entry dahdi_pri_cli[] = {
 
 #endif /* HAVE_PRI */
 
-/* Wrappers for astman operations to use proper channel name prefix */
-
-#define local_astman_ack(s, m, msg) do { if (chan_tech == &dahdi_tech) astman_send_ack(s, m, "DAHDI" msg); else astman_send_ack(s, m, "Zap" msg); } while (0)
-#define local_astman_header(m, hdr) astman_get_header(m, (chan_tech == &dahdi_tech) ? "DAHDI" hdr : "Zap" hdr)
-#define local_astman_register(a, b, c, d) do { if (chan_tech == &dahdi_tech) ast_manager_register("DAHDI" a, b, c, d); else ast_manager_register("Zap" a, b, c, d); } while (0)
-#define local_astman_unregister(a) do { if (chan_tech == &dahdi_tech) ast_manager_unregister("DAHDI" a); else ast_manager_unregister("Zap" a); } while (0)
-
 static int dahdi_destroy_channel(int fd, int argc, char **argv)
 {
        int channel;
@@ -9956,16 +9949,6 @@ static int dahdi_restart_cmd(int fd, int argc, char **argv)
        return RESULT_SUCCESS;
 }
 
-static int action_dahdirestart(struct mansession *s, const struct message *m)
-{
-       if (dahdi_restart() != 0) {
-               astman_send_error(s, m, "Failed to restart chan_dahdi");
-               return 1;
-       }
-       local_astman_ack(s, m, "Restart: Success");
-       return 0;
-}
-
 static int dahdi_show_channels(int fd, int argc, char **argv)
 {
 #define FORMAT "%7s %-10.10s %-15.15s %-10.10s %-20.20s\n"
@@ -10366,86 +10349,109 @@ static struct dahdi_pvt *find_channel(int channel)
        return p;
 }
 
-static int action_dahdidndon(struct mansession *s, const struct message *m)
+#define local_astman_ack(s, m, msg, zap) do { if (!zap) astman_send_ack(s, m, "DAHDI" msg); else astman_send_ack(s, m, "Zap" msg); } while (0)
+#define local_astman_header(m, hdr, zap) astman_get_header(m, (!zap) ? "DAHDI" hdr : "Zap" hdr)
+
+static int __action_dnd(struct mansession *s, const struct message *m, int zap_mode, int dnd)
 {
        struct dahdi_pvt *p = NULL;
-       const char *channel = local_astman_header(m, "Channel");
+       const char *channel = local_astman_header(m, "Channel", zap_mode);
 
        if (ast_strlen_zero(channel)) {
                astman_send_error(s, m, "No channel specified");
                return 0;
        }
-       p = find_channel(atoi(channel));
-       if (!p) {
+       if (!(p = find_channel(atoi(channel)))) {
                astman_send_error(s, m, "No such channel");
                return 0;
        }
-       p->dnd = 1;
-       astman_send_ack(s, m, "DND Enabled");
+       p->dnd = dnd;
+       local_astman_ack(s, m, "DND", zap_mode);
+
        return 0;
 }
 
-static int action_dahdidndoff(struct mansession *s, const struct message *m)
+static int zap_action_dndon(struct mansession *s, const struct message *m)
 {
-       struct dahdi_pvt *p = NULL;
-       const char *channel = local_astman_header(m, "Channel");
+       return __action_dnd(s, m, 1, 1);
+}
 
-       if (ast_strlen_zero(channel)) {
-               astman_send_error(s, m, "No channel specified");
-               return 0;
-       }
-       p = find_channel(atoi(channel));
-       if (!p) {
-               astman_send_error(s, m, "No such channel");
-               return 0;
-       }
-       p->dnd = 0;
-       astman_send_ack(s, m, "DND Disabled");
-       return 0;
+static int dahdi_action_dndon(struct mansession *s, const struct message *m)
+{
+       return __action_dnd(s, m, 0, 1);
+}
+
+static int zap_action_dndoff(struct mansession *s, const struct message *m)
+{
+       return __action_dnd(s, m, 1, 0);
+}
+
+static int dahdi_action_dndoff(struct mansession *s, const struct message *m)
+{
+       return __action_dnd(s, m, 0, 0);
 }
 
-static int action_transfer(struct mansession *s, const struct message *m)
+static int __action_transfer(struct mansession *s, const struct message *m, int zap_mode)
 {
        struct dahdi_pvt *p = NULL;
-       const char *channel = local_astman_header(m, "Channel");
+       const char *channel = local_astman_header(m, "Channel", zap_mode);
 
        if (ast_strlen_zero(channel)) {
                astman_send_error(s, m, "No channel specified");
                return 0;
        }
-       p = find_channel(atoi(channel));
-       if (!p) {
+       if (!(p = find_channel(atoi(channel)))) {
                astman_send_error(s, m, "No such channel");
                return 0;
        }
        dahdi_fake_event(p,TRANSFER);
-       local_astman_ack(s, m, "Transfer");
+       local_astman_ack(s, m, "Transfer", zap_mode);
+
        return 0;
 }
 
-static int action_transferhangup(struct mansession *s, const struct message *m)
+static int zap_action_transfer(struct mansession *s, const struct message *m)
+{
+       return __action_transfer(s, m, 1);
+}
+
+static int dahdi_action_transfer(struct mansession *s, const struct message *m)
+{
+       return __action_transfer(s, m, 0);
+}
+
+static int __action_transferhangup(struct mansession *s, const struct message *m, int zap_mode)
 {
        struct dahdi_pvt *p = NULL;
-       const char *channel = local_astman_header(m, "Channel");
+       const char *channel = local_astman_header(m, "Channel", zap_mode);
 
        if (ast_strlen_zero(channel)) {
                astman_send_error(s, m, "No channel specified");
                return 0;
        }
-       p = find_channel(atoi(channel));
-       if (!p) {
+       if (!(p = find_channel(atoi(channel)))) {
                astman_send_error(s, m, "No such channel");
                return 0;
        }
-       dahdi_fake_event(p,HANGUP);
-       local_astman_ack(s, m, "Hangup");
+       dahdi_fake_event(p, HANGUP);
+       local_astman_ack(s, m, "Hangup", zap_mode);
        return 0;
 }
 
-static int action_dahdidialoffhook(struct mansession *s, const struct message *m)
+static int zap_action_transferhangup(struct mansession *s, const struct message *m)
+{
+       return __action_transferhangup(s, m, 1);
+}
+
+static int dahdi_action_transferhangup(struct mansession *s, const struct message *m)
+{
+       return __action_transferhangup(s, m, 0);
+}
+
+static int __action_dialoffhook(struct mansession *s, const struct message *m, int zap_mode)
 {
        struct dahdi_pvt *p = NULL;
-       const char *channel = local_astman_header(m, "Channel");
+       const char *channel = local_astman_header(m, "Channel", zap_mode);
        const char *number = astman_get_header(m, "Number");
        int i;
 
@@ -10457,30 +10463,41 @@ static int action_dahdidialoffhook(struct mansession *s, const struct message *m
                astman_send_error(s, m, "No number specified");
                return 0;
        }
-       p = find_channel(atoi(channel));
-       if (!p) {
+       if (!(p = find_channel(atoi(channel)))) {
                astman_send_error(s, m, "No such channel");
                return 0;
        }
        if (!p->owner) {
-               astman_send_error(s, m, "Channel does not have it's owner");
+               astman_send_error(s, m, "Channel does not have an owner");
                return 0;
        }
        for (i = 0; i < strlen(number); i++) {
                struct ast_frame f = { AST_FRAME_DTMF, number[i] };
+
                dahdi_queue_frame(p, &f, NULL); 
        }
-       local_astman_ack(s, m, "DialOffhook");
+       local_astman_ack(s, m, "DialOffHook", zap_mode);
+
        return 0;
 }
 
-static int action_dahdishowchannels(struct mansession *s, const struct message *m)
+static int zap_action_dialoffhook(struct mansession *s, const struct message *m)
+{
+       return __action_dialoffhook(s, m, 1);
+}
+
+static int dahdi_action_dialoffhook(struct mansession *s, const struct message *m)
+{
+       return __action_dialoffhook(s, m, 0);
+}
+
+static int __action_showchannels(struct mansession *s, const struct message *m, int zap_mode)
 {
        struct dahdi_pvt *tmp = NULL;
        const char *id = astman_get_header(m, "ActionID");
        char idText[256] = "";
 
-       local_astman_ack(s, m, " channel status will follow");
+       local_astman_ack(s, m, " channel status will follow", zap_mode);
        if (!ast_strlen_zero(id))
                snprintf(idText, sizeof(idText) - 1, "ActionID: %s\r\n", id);
 
@@ -10519,6 +10536,47 @@ static int action_dahdishowchannels(struct mansession *s, const struct message *
        return 0;
 }
 
+static int zap_action_showchannels(struct mansession *s, const struct message *m)
+{
+       return __action_showchannels(s, m, 1);
+}
+
+static int dahdi_action_showchannels(struct mansession *s, const struct message *m)
+{
+       return __action_showchannels(s, m, 0);
+}
+
+static int __action_restart(struct mansession *s, const struct message *m, int zap_mode)
+{
+       if (dahdi_restart() != 0) {
+               if (zap_mode) {
+                       astman_send_error(s, m, "Failed to restart Zap");
+               } else {
+                       astman_send_error(s, m, "Failed to restart DAHDI");
+               }
+               return 1;
+       }
+       local_astman_ack(s, m, "Restart: Success", zap_mode);
+       return 0;
+}
+
+static int zap_action_restart(struct mansession *s, const struct message *m)
+{
+       return __action_restart(s, m, 1);
+}
+
+static int dahdi_action_restart(struct mansession *s, const struct message *m)
+{
+       return __action_restart(s, m, 0);
+}
+
+#define local_astman_unregister(a) do { \
+                                       if (dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) { \
+                                               ast_manager_unregister("DAHDI" a); \
+                                       } \
+                                       ast_manager_unregister("Zap" a); \
+                                  } while (0)
+
 static int __unload_module(void)
 {
        int x;
@@ -10534,7 +10592,7 @@ static int __unload_module(void)
        ast_unregister_application(dahdi_send_keypad_facility_app);
 #endif
        ast_cli_unregister_multiple(dahdi_cli, sizeof(dahdi_cli) / sizeof(struct ast_cli_entry));
-       local_astman_unregister("DialOffhook");
+       local_astman_unregister("DialOffHook");
        local_astman_unregister("Hangup");
        local_astman_unregister("Transfer");
        local_astman_unregister("DNDoff");
@@ -11511,6 +11569,13 @@ static int setup_dahdi(int reload)
        return 0;
 }
 
+#define local_astman_register(a, b, c, d) do { \
+                                               if (dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) { \
+                                                       ast_manager_register("DAHDI" a, b, dahdi_ ## c, d); \
+                                               } \
+                                               ast_manager_register("Zap" a, b, zap_ ## c, d); \
+                                         } while (0)
+
 static int load_module(void)
 {
        int res;
@@ -11533,7 +11598,7 @@ static int load_module(void)
        if ((res = setup_dahdi(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
-       if (!strcmp(dahdi_chan_name, "DAHDI")) {
+       if (dahdi_chan_mode == CHAN_DAHDI_PLUS_ZAP_MODE) {
                chan_tech = &dahdi_tech;
        } else {
                chan_tech = &zap_tech;
@@ -11553,11 +11618,11 @@ static int load_module(void)
        memset(round_robin, 0, sizeof(round_robin));
        local_astman_register("Transfer", 0, action_transfer, "Transfer Channel");
        local_astman_register("Hangup", 0, action_transferhangup, "Hangup Channel");
-       local_astman_register("DialOffhook", 0, action_dahdidialoffhook, "Dial over channel while offhook");
-       local_astman_register("DNDon", 0, action_dahdidndon, "Toggle channel Do Not Disturb status ON");
-       local_astman_register("DNDoff", 0, action_dahdidndoff, "Toggle channel Do Not Disturb status OFF");
-       local_astman_register("ShowChannels", 0, action_dahdishowchannels, "Show status channels");
-       local_astman_register("Restart", 0, action_dahdirestart, "Fully Restart channels (terminates calls)");
+       local_astman_register("DialOffHook", 0, action_dialoffhook, "Dial over channel while offhook");
+       local_astman_register("DNDon", 0, action_dndon, "Toggle channel Do Not Disturb status ON");
+       local_astman_register("DNDoff", 0, action_dndoff, "Toggle channel Do Not Disturb status OFF");
+       local_astman_register("ShowChannels", 0, action_showchannels, "Show status channels");
+       local_astman_register("Restart", 0, action_restart, "Fully Restart channels (terminates calls)");
 
        return res;
 }
index 57e1374fe32e13a7bab3dc9bc858367e33db5947..10c2126c29235ad5149cb95ff15d1d1778f27306 100644 (file)
@@ -124,8 +124,8 @@ extern char record_cache_dir[AST_CACHE_DIR_LEN];
 extern char debug_filename[AST_FILENAME_MAX];
 extern const char *dahdi_chan_name;
 extern enum dahdi_chan_modes {
-       ZAP_ONLY_MODE,
-       DAHDI_PLUS_ZAP,
+       CHAN_ZAP_MODE,
+       CHAN_DAHDI_PLUS_ZAP_MODE,
 } dahdi_chan_mode;
        
 extern int ast_language_is_prefix;
index 36a65c91a8dcac15237143fb0eb2843c3e293126..4bfa450369d8e42fcf878c8ad94349bd5e50c5ac 100644 (file)
@@ -174,10 +174,10 @@ char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR;
 char debug_filename[AST_FILENAME_MAX] = "";
 #ifdef HAVE_ZAPTEL
 char _dahdi_chan_name[AST_CHANNEL_NAME] = "Zap";
-enum dahdi_chan_modes dahdi_chan_mode = ZAP_ONLY_MODE;
+enum dahdi_chan_modes dahdi_chan_mode = CHAN_ZAP_MODE;
 #else
 char _dahdi_chan_name[AST_CHANNEL_NAME] = "DAHDI";
-enum dahdi_chan_modes dahdi_chan_mode = DAHDI_PLUS_ZAP;
+enum dahdi_chan_modes dahdi_chan_mode = CHAN_DAHDI_PLUS_ZAP_MODE;
 #endif
 const char *dahdi_chan_name;
 
@@ -2593,12 +2593,12 @@ static void ast_readconfig(void)
 #ifdef HAVE_ZAPTEL
                        if (ast_true(v->value)) {
                                strcpy(_dahdi_chan_name, "DAHDI");
-                               dahdi_chan_mode = DAHDI_PLUS_ZAP;
+                               dahdi_chan_mode = CHAN_DAHDI_PLUS_ZAP_MODE;
                        }
 #else
                        if (ast_false(v->value)) {
                                strcpy(_dahdi_chan_name, "Zap");
-                               dahdi_chan_mode = ZAP_ONLY_MODE;
+                               dahdi_chan_mode = CHAN_ZAP_MODE;
                        }
 #endif
                }