trivial loglevel adjustements
[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 "list.h"
24 #include "sched.h"
25 #include "recv.h"
26 #include "string.h"
27
28 void (*crypt_function_recv)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
29 void (*crypt_function_send)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
30
31 DEFINE_RECEIVER_ARRAY;
32 static void *parse_receiver_args(int receiver_num, char *options)
33 {
34 struct receiver *r = &receivers[receiver_num];
35 char **argv;
36 int argc, i;
37 void *conf;
38
39
40 // PARA_DEBUG_LOG("%s, options: %s\n", r->name,
41 // options? options : "(none)");
42 if (options) {
43 PARA_DEBUG_LOG("options: %s\n", options);
44 argc = split_args(options, &argv, " \t");
45 for (i = argc - 1; i >= 0; i--)
46 argv[i + 1] = argv[i];
47 argv[0] = para_strdup(r->name);
48 argc += 1;
49 PARA_DEBUG_LOG("argc = %d, argv[0]: %s\n", argc, argv[0]);
50 } else {
51 argc = 1;
52 argv = para_malloc(2 * sizeof(char*));
53 argv[0] = NULL;
54 argv[1] = NULL;
55 }
56 conf = r->parse_config(argc, argv);
57 if (!conf) {
58 for (i = 0; i < argc; i++)
59 free(argv[i]);
60 free(argv);
61 return NULL;
62 }
63 return conf;
64 }
65
66 void *check_receiver_arg(char *ra, int *receiver_num)
67 {
68 int j;
69
70 PARA_DEBUG_LOG("checking %s\n", ra);
71 for (j = 0; receivers[j].name; j++) {
72 const char *name = receivers[j].name;
73 size_t len = strlen(name);
74 char c;
75 if (strlen(ra) < len)
76 continue;
77 if (strncmp(name, ra, len))
78 continue;
79 c = ra[len];
80 if (c && c != ' ')
81 continue;
82 if (c && !receivers[j].parse_config)
83 return NULL;
84 *receiver_num = j;
85 return parse_receiver_args(j, c? ra + len + 1: NULL);
86 }
87 PARA_ERROR_LOG("%s", "receiver not found\n");
88 return NULL;
89 }