audiod: Allow regular expressions in writer config.
authorAndre Noll <maan@systemlinux.org>
Tue, 19 Apr 2011 18:58:11 +0000 (20:58 +0200)
committerAndre Noll <maan@systemlinux.org>
Fri, 3 Jun 2011 06:39:20 +0000 (08:39 +0200)
audiod.c

index 1f1f1aa666ffa0a63dfbd8bb72e591b264c3a20e..8d8c46b0fbb53019144a3670d3a01e93fe4bc5ee 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -732,19 +732,19 @@ static int update_item(int itemnum, char *buf)
 
 static int parse_stream_command(const char *txt, char **cmd)
 {
-       char *p = strchr(txt, ':');
-       int i;
+       int ret, len;
+       char *re, *p = strchr(txt, ':');
 
        if (!p)
                return -E_MISSING_COLON;
-       p++;
-       FOR_EACH_AUDIO_FORMAT(i) {
-               if (strncmp(txt, audio_formats[i], strlen(audio_formats[i])))
-                       continue;
-               *cmd = p;
-               return i;
-       }
-       return -E_UNSUPPORTED_AUDIO_FORMAT;
+       *cmd = p + 1;
+       len = p - txt;
+       re = malloc(len + 1);
+       strncpy(re, txt, len);
+       re[len] = '\0';
+       ret = get_matching_audio_format_nums(re);
+       free(re);
+       return ret;
 }
 
 static int add_filter(int format, char *cmdline)
@@ -764,36 +764,35 @@ static int add_filter(int format, char *cmdline)
 
 static int parse_writer_args(void)
 {
-       int i, ret, nw;
+       int i, ret;
        char *cmd;
        struct audio_format_info *a;
 
-       nw = PARA_MAX(1U, conf.writer_given);
-       PARA_INFO_LOG("maximal number of writers: %d\n", nw);
-       FOR_EACH_AUDIO_FORMAT(i) {
-               a = &afi[i];
-               a->writer_conf = para_malloc(nw * sizeof(void *));
-               a->writer_nums = para_malloc(nw * sizeof(int));
-               a->num_writers = 0;
-       }
        for (i = 0; i < conf.writer_given; i++) {
                void *wconf;
-               int writer_num;
+               int j, nw, writer_num, af_mask;
+
                ret = parse_stream_command(conf.writer_arg[i], &cmd);
                if (ret < 0)
                        goto out;
-               a = &afi[ret];
-               nw = a->num_writers;
-               wconf = check_writer_arg(cmd, &writer_num);
-               if (!wconf) {
-                       ret = writer_num;
-                       goto out;
+               af_mask = ret;
+               FOR_EACH_AUDIO_FORMAT(j) {
+                       a = afi + j;
+                       if ((af_mask & (1 << j)) == 0) /* no match */
+                               continue;
+                       ret = -E_WRITE_COMMON_SYNTAX;
+                       wconf = check_writer_arg(cmd, &writer_num);
+                       if (!wconf)
+                               goto out;
+                       nw = a->num_writers;
+                       a->writer_nums = para_realloc(a->writer_nums, (nw + 1) * sizeof(int));
+                       a->writer_conf = para_realloc(a->writer_conf, (nw + 1) * sizeof(void *));
+                       a->writer_nums[nw] = writer_num;
+                       a->writer_conf[nw] = wconf;
+                       PARA_INFO_LOG("%s writer #%d: %s\n", audio_formats[writer_num],
+                               nw, writer_names[writer_num]);
+                       a->num_writers++;
                }
-               a->writer_nums[nw] = writer_num;
-               a->writer_conf[nw] = wconf;
-               PARA_INFO_LOG("%s writer #%d: %s\n", audio_formats[ret],
-                       nw, writer_names[writer_num]);
-               a->num_writers++;
        }
        ret = 1;
 out: