gui.ggo: Kill --auto_decode.
[paraslash.git] / recv_common.c
1 /*
2  * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file recv_common.c common functions of para_recv and para_audiod */
8
9 #include "para.h"
10
11 #include "list.h"
12 #include "sched.h"
13 #include "recv.h"
14 #include "string.h"
15
16 DEFINE_RECEIVER_ARRAY;
17 static void *parse_receiver_args(int receiver_num, char *options)
18 {
19         struct receiver *r = &receivers[receiver_num];
20         char **argv;
21         int argc, i;
22         void *conf;
23
24
25 //      PARA_DEBUG_LOG("%s, options: %s\n", r->name,
26 //              options? options : "(none)");
27         if (options) {
28                 PARA_DEBUG_LOG("options: %s\n", options);
29                 argc = split_args(options, &argv, " \t");
30                 for (i = argc - 1; i >= 0; i--)
31                         argv[i + 1] = argv[i];
32                 argv[0] = para_strdup(r->name);
33                 argc += 1;
34                 PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", argc, argv[0]);
35         } else {
36                 argc = 1;
37                 argv = para_malloc(2 * sizeof(char*));
38                 argv[0] = NULL;
39                 argv[1] = NULL;
40         }
41         conf = r->parse_config(argc, argv);
42         free(argv[0]);
43         free(argv);
44         return conf;
45 }
46
47 /**
48  * check if given string is a valid command line for any receiver
49  *
50  * \param \ra string of the form receiver_name:options
51  * \param receiver_num contains the number of the receiver upon success
52  *
53  * This function checks whether \a ra starts with the name of a supported
54  * paraslash receiver, optinally followed by a colon and any options for that
55  * receiver. If a valid receiver name was found and further are present, the
56  * remaining part of \a ra is passed to that receiver's config parser.
57  *
58  * \return On success, a pointer to the gengetopt args info struct is returned
59  * and \a receiver_num contains the number of the receiver. Otherwise this function
60  * returns \p NULL.
61  */
62 void *check_receiver_arg(char *ra, int *receiver_num)
63 {
64         int j;
65
66         PARA_DEBUG_LOG("checking %s\n", ra);
67         for (j = 0; receivers[j].name; j++) {
68                 const char *name = receivers[j].name;
69                 size_t len = strlen(name);
70                 char c;
71                 if (strlen(ra) < len)
72                         continue;
73                 if (strncmp(name, ra, len))
74                         continue;
75                 c = ra[len];
76                 if (c && c != ' ')
77                         continue;
78                 if (c && !receivers[j].parse_config)
79                         return NULL;
80                 *receiver_num = j;
81                 return parse_receiver_args(j, c? ra + len + 1: NULL);
82         }
83         PARA_ERROR_LOG("%s", "receiver not found\n");
84         return NULL;
85 }