res_musiconhold: Remove redundant option parsing
authorSean Bright <sean.bright@gmail.com>
Fri, 8 Mar 2019 20:12:24 +0000 (15:12 -0500)
committerSean Bright <sean.bright@gmail.com>
Fri, 8 Mar 2019 20:17:01 +0000 (14:17 -0600)
Change-Id: I481fabd8eaf2e4e7ffb5c8285b294742826e7d12

res/res_musiconhold.c

index d14e209..8fc58a1 100644 (file)
@@ -1088,6 +1088,9 @@ static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclas
                        ast_copy_string(mohclass->dir, var->value, sizeof(mohclass->dir));
                } else if (!strcasecmp(var->name, "application")) {
                        ast_copy_string(mohclass->args, var->value, sizeof(mohclass->args));
+               } else if (!strcasecmp(var->name, "announcement")) {
+                       ast_copy_string(mohclass->announcement, var->value, sizeof(mohclass->announcement));
+                       ast_set_flag(mohclass, MOH_ANNOUNCEMENT);
                } else if (!strcasecmp(var->name, "digit") && (isdigit(*var->value) || strchr("*#", *var->value))) {
                        mohclass->digit = *var->value;
                } else if (!strcasecmp(var->name, "random")) {
@@ -1112,6 +1115,22 @@ static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclas
                                ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value);
                                mohclass->format = ao2_bump(ast_format_slin);
                        }
+               } else if (!strcasecmp(var->name, "kill_escalation_delay")) {
+                       if (sscanf(var->value, "%zu", &mohclass->kill_delay) == 1) {
+                               mohclass->kill_delay *= 1000;
+                       } else {
+                               ast_log(LOG_WARNING, "kill_escalation_delay '%s' is invalid.  Setting to 100ms\n", var->value);
+                               mohclass->kill_delay = 100000;
+                       }
+               } else if (!strcasecmp(var->name, "kill_method")) {
+                       if (!strcasecmp(var->value, "process")) {
+                               mohclass->kill_method = KILL_METHOD_PROCESS;
+                       } else if (!strcasecmp(var->value, "process_group")) {
+                               mohclass->kill_method = KILL_METHOD_PROCESS_GROUP;
+                       } else {
+                               ast_log(LOG_WARNING, "kill_method '%s' is invalid.  Setting to 'process_group'\n", var->value);
+                               mohclass->kill_method = KILL_METHOD_PROCESS_GROUP;
+                       }
                }
        }
 }
@@ -1778,49 +1797,6 @@ static int load_moh_classes(int reload)
                /* For compatibility with the past, we overwrite any name=name
                 * with the context [name]. */
                ast_copy_string(class->name, cat, sizeof(class->name));
-               for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
-                       if (!strcasecmp(var->name, "mode")) {
-                               ast_copy_string(class->mode, var->value, sizeof(class->mode));
-                       } else if (!strcasecmp(var->name, "directory")) {
-                               ast_copy_string(class->dir, var->value, sizeof(class->dir));
-                       } else if (!strcasecmp(var->name, "application")) {
-                               ast_copy_string(class->args, var->value, sizeof(class->args));
-                       } else if (!strcasecmp(var->name, "announcement")) {
-                               ast_copy_string(class->announcement, var->value, sizeof(class->announcement));
-                               ast_set_flag(class, MOH_ANNOUNCEMENT);
-                       } else if (!strcasecmp(var->name, "digit") && (isdigit(*var->value) || strchr("*#", *var->value))) {
-                               class->digit = *var->value;
-                       } else if (!strcasecmp(var->name, "random")) {
-                               ast_set2_flag(class, ast_true(var->value), MOH_RANDOMIZE);
-                       } else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "random")) {
-                               ast_set_flag(class, MOH_RANDOMIZE);
-                       } else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "alpha")) {
-                               ast_set_flag(class, MOH_SORTALPHA);
-                       } else if (!strcasecmp(var->name, "format")) {
-                               ao2_cleanup(class->format);
-                               class->format = ast_format_cache_get(var->value);
-                               if (!class->format) {
-                                       ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value);
-                                       class->format = ao2_bump(ast_format_slin);
-                               }
-                       } else if (!strcasecmp(var->name, "kill_escalation_delay")) {
-                               if (sscanf(var->value, "%zu", &class->kill_delay) == 1) {
-                                       class->kill_delay *= 1000;
-                               } else {
-                                       ast_log(LOG_WARNING, "kill_escalation_delay '%s' is invalid.  Setting to 100ms\n", var->value);
-                                       class->kill_delay = 100000;
-                               }
-                       } else if (!strcasecmp(var->name, "kill_method")) {
-                               if (!strcasecmp(var->value, "process")) {
-                                       class->kill_method = KILL_METHOD_PROCESS;
-                               } else if (!strcasecmp(var->value, "process_group")){
-                                       class->kill_method = KILL_METHOD_PROCESS_GROUP;
-                               } else {
-                                       ast_log(LOG_WARNING, "kill_method '%s' is invalid.  Setting to 'process_group'\n", var->value);
-                                       class->kill_method = KILL_METHOD_PROCESS_GROUP;
-                               }
-                       }
-               }
 
                if (ast_strlen_zero(class->dir)) {
                        if (!strcasecmp(class->mode, "custom")) {