dbtool -> audio file selector renaming
[paraslash.git] / recv_common.c
1 /*
2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
17 */
18
19 /** \file recv_common.c common functions of para_recv and para_audiod */
20
21 #include "para.h"
22
23 #include "recv.h"
24 #include "string.h"
25
26 void (*crypt_function_recv)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
27 void (*crypt_function_send)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
28
29 DEFINE_RECEIVER_ARRAY;
30 static void *parse_receiver_args(int receiver_num, char *options)
31 {
32 struct receiver *r = &receivers[receiver_num];
33 char **argv;
34 int argc, i;
35 void *conf;
36
37
38 // PARA_DEBUG_LOG("%s, options: %s\n", r->name,
39 // options? options : "(none)");
40 if (options) {
41 // PARA_DEBUG_LOG("%s options: %s\n", name, options);
42 argc = split_args(options, &argv, ' ');
43 // PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", fn->argc, fn->argv[0]);
44 for (i = argc; i >= 0; i--)
45 argv[i + 1] = argv[i];
46 argc += 2;
47 } else {
48 argc = 1;
49 argv = para_malloc(2 * sizeof(char*));
50 argv[0] = NULL;
51 argv[1] = NULL;
52 }
53 conf = r->parse_config(argc, argv);
54 if (!conf) {
55 for (i = 0; i < argc; i++)
56 free(argv[i]);
57 free(argv);
58 return NULL;
59 }
60 return conf;
61 }
62
63 void *check_receiver_arg(char *ra, int *receiver_num)
64 {
65 int j;
66
67 // PARA_DEBUG_LOG("checking %s\n", ra);
68 for (j = 0; receivers[j].name; j++) {
69 const char *name = receivers[j].name;
70 size_t len = strlen(name);
71 char c;
72 if (strlen(ra) < len)
73 continue;
74 if (strncmp(name, ra, len))
75 continue;
76 c = ra[len];
77 if (c && c != ' ')
78 continue;
79 if (c && !receivers[j].parse_config)
80 return NULL;
81 *receiver_num = j;
82 return parse_receiver_args(j, c? ra + len + 1: NULL);
83 }
84 PARA_ERROR_LOG("%s", "receiver not found\n");
85 return NULL;
86 }