Debian Codegraph @

src/ezconfig0.c

raw symbols SCIP
1 /*
2 * ezstream - source client for Icecast with external en-/decoder support
3 * Copyright (C) 2003, 2004, 2005, 2006 Ed Zaleski <[email protected]>
4 * Copyright (C) 2007, 2009, 2015 Moritz Grimm <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include "compat.h"
25
26 #include <ctype.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "ezconfig0.h"
32 #include "log.h"
33 #include "util.h"
34
35 #include <libxml/parser.h>
36
37 #define XML_CHAR(s) (const xmlChar *)(s)
38 #define STD_CHAR(s) (const char *)(s)
39
40 static EZCONFIG ezConfig;
41 static const char *blankString = "";
42
43 unsigned int checkDecoderLine(const char *, const char *, long);
44 unsigned int checkEncoderLine(const char *, const char *, long);
45 unsigned int checkFormatLine(const char *, const char *, long);
46
47 EZCONFIG *
48 getEZConfig(void)
49 {
50 return (&ezConfig);
51 }
52
53 const char *
54 getFormatEncoder(const char *format)
55 {
56 int i;
57
58 for (i = 0; i < ezConfig.numEncoderDecoders; i++) {
59 if (ezConfig.encoderDecoders[i] != NULL &&
60 ezConfig.encoderDecoders[i]->format != NULL &&
61 strcmp(ezConfig.encoderDecoders[i]->format, format) == 0) {
62 if (ezConfig.encoderDecoders[i]->encoder != NULL)
63 return (ezConfig.encoderDecoders[i]->encoder);
64 else
65 return (blankString);
66 }
67 }
68
69 return (blankString);
70 }
71
72 const char *
73 getFormatDecoder(const char *match)
74 {
75 int i;
76
77 for (i = 0; i < ezConfig.numEncoderDecoders; i++) {
78 if (ezConfig.encoderDecoders[i] != NULL &&
79 ezConfig.encoderDecoders[i]->match != NULL &&
80 strcmp(ezConfig.encoderDecoders[i]->match, match) == 0) {
81 if (ezConfig.encoderDecoders[i]->decoder != NULL)
82 return (ezConfig.encoderDecoders[i]->decoder);
83 else
84 return (blankString);
85 }
86 }
87
88 return (blankString);
89 }
90
91 int
92 parseConfig(const char *fileName)
93 {
94 xmlDocPtr doc;
95 xmlNodePtr cur;
96 xmlChar *ls_xmlContentPtr;
97 int program_set, reconnect_set, shuffle_set,
98 streamOnce_set, svrinfopublic_set,
99 refresh_set;
100 unsigned int config_error;
101
102 xmlLineNumbersDefault(1);
103 if ((doc = xmlParseFile(fileName)) == NULL) {
104 log_error("%s: Parse error (not well-formed XML.)\n", fileName);
105 return (0);
106 }
107
108 cur = xmlDocGetRootElement(doc);
109
110 if (cur == NULL) {
111 log_error("%s: Parse error (empty XML document.)\n", fileName);
112 xmlFreeDoc(doc);
113 return (0);
114 }
115
116 memset(&ezConfig, 0, sizeof(ezConfig));
117 ezConfig.metadataRefreshInterval = -1;
118
119 config_error = 0;
120 program_set = 0;
121 reconnect_set = 0;
122 refresh_set = 0;
123 shuffle_set = 0;
124 streamOnce_set = 0;
125 svrinfopublic_set = 0;
126
127 for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
128 if (!xmlStrcmp(cur->name, (const xmlChar *)"url")) {
129 if (ezConfig.URL != NULL) {
130 log_error("%s[%ld]: Error: Cannot have multiple <url> elements\n",
131 fileName, xmlGetLineNo(cur));
132 config_error++;
133 continue;
134 }
135 if (cur->xmlChildrenNode != NULL) {
136 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
137 ezConfig.URL = strdup(STD_CHAR(ls_xmlContentPtr));
138 xmlFree(ls_xmlContentPtr);
139 }
140 }
141 if (!xmlStrcmp(cur->name, (const xmlChar *)"sourceuser")) {
142 if (ezConfig.username != NULL) {
143 log_error("%s[%ld]: Error: Cannot have multiple <sourceuser> elements\n",
144 fileName, xmlGetLineNo(cur));
145 config_error++;
146 continue;
147 }
148 if (cur->xmlChildrenNode != NULL) {
149 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
150 ezConfig.username = strdup(STD_CHAR(ls_xmlContentPtr));
151 xmlFree(ls_xmlContentPtr);
152 }
153 }
154 if (!xmlStrcmp(cur->name, (const xmlChar *)"sourcepassword")) {
155 if (ezConfig.password != NULL) {
156 log_error("%s[%ld]: Error: Cannot have multiple <sourcepassword> elements\n",
157 fileName, xmlGetLineNo(cur));
158 config_error++;
159 continue;
160 }
161 if (cur->xmlChildrenNode != NULL) {
162 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
163 ezConfig.password = strdup(STD_CHAR(ls_xmlContentPtr));
164 xmlFree(ls_xmlContentPtr);
165 }
166 }
167 if (!xmlStrcmp(cur->name, (const xmlChar *)"format")) {
168 if (ezConfig.format != NULL) {
169 log_error("%s[%ld]: Error: Cannot have multiple <format> elements\n",
170 fileName, xmlGetLineNo(cur));
171 config_error++;
172 continue;
173 }
174 if (cur->xmlChildrenNode != NULL) {
175 char *p;
176
177 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
178 ezConfig.format = strdup(STD_CHAR(ls_xmlContentPtr));
179 xmlFree(ls_xmlContentPtr);
180 for (p = ezConfig.format; *p != '\0'; p++)
181 *p = (char)toupper((int)*p);
182 }
183 }
184 if (!xmlStrcmp(cur->name, (const xmlChar *)"filename")) {
185 if (ezConfig.fileName != NULL) {
186 log_error("%s[%ld]: Error: Cannot have multiple <filename> elements\n",
187 fileName, xmlGetLineNo(cur));
188 config_error++;
189 continue;
190 }
191 if (cur->xmlChildrenNode != NULL) {
192 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
193 if (strlen(STD_CHAR(ls_xmlContentPtr)) > PATH_MAX - 1) {
194 log_error("%s[%ld]: Error: Path or filename in <filename> is too long\n",
195 fileName, xmlGetLineNo(cur));
196 config_error++;
197 continue;
198 }
199 ezConfig.fileName = strdup(STD_CHAR(ls_xmlContentPtr));
200 xmlFree(ls_xmlContentPtr);
201 }
202 }
203 if (!xmlStrcmp(cur->name, (const xmlChar *)"metadata_progname")) {
204 if (ezConfig.metadataProgram != NULL) {
205 log_error("%s[%ld]: Error: Cannot have multiple <metadata_progname> elements\n",
206 fileName, xmlGetLineNo(cur));
207 config_error++;
208 continue;
209 }
210 if (cur->xmlChildrenNode != NULL) {
211 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
212 if (strlen(STD_CHAR(ls_xmlContentPtr)) > PATH_MAX - 1) {
213 log_error("%s[%ld]: Error: Path or filename in <metadata_progname> is too long\n",
214 fileName, xmlGetLineNo(cur));
215 config_error++;
216 continue;
217 }
218 ezConfig.metadataProgram = strdup(STD_CHAR(ls_xmlContentPtr));
219 xmlFree(ls_xmlContentPtr);
220 }
221 }
222 if (!xmlStrcmp(cur->name, (const xmlChar *)"metadata_format")) {
223 if (ezConfig.metadataFormat != NULL) {
224 log_error("%s[%ld]: Error: Cannot have multiple <metadata_format> elements\n",
225 fileName, xmlGetLineNo(cur));
226 config_error++;
227 continue;
228 }
229 if (cur->xmlChildrenNode != NULL) {
230 unsigned int ret;
231
232 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
233 ezConfig.metadataFormat = strdup(STD_CHAR(ls_xmlContentPtr));
234 xmlFree(ls_xmlContentPtr);
235 if ((ret = checkFormatLine(ezConfig.metadataFormat,
236 fileName, xmlGetLineNo(cur)))
237 > 0) {
238 config_error += ret;
239 continue;
240 }
241 }
242 }
243 if (!xmlStrcmp(cur->name, (const xmlChar *)"metadata_refreshinterval")) {
244 if (refresh_set) {
245 log_error("%s[%ld]: Error: Cannot have multiple <metadata_refreshinterval> elements\n",
246 fileName, xmlGetLineNo(cur));
247 config_error++;
248 continue;
249 }
250 if (cur->xmlChildrenNode != NULL) {
251 const char *errstr;
252 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
253 ezConfig.metadataRefreshInterval = (int)strtonum(STD_CHAR(ls_xmlContentPtr), -1LL, (long long)INT_MAX, &errstr);
254 if (errstr) {
255 log_error("%s[%ld]: Error: In <metadata_refreshinterval>: '%s' is %s\n",
256 fileName, xmlGetLineNo(cur), STD_CHAR(ls_xmlContentPtr), errstr);
257 config_error++;
258 continue;
259 }
260 xmlFree(ls_xmlContentPtr);
261 refresh_set = 1;
262 }
263 }
264 if (!xmlStrcmp(cur->name, (const xmlChar *)"playlist_program")) {
265 if (program_set) {
266 log_error("%s[%ld]: Error: Cannot have multiple <playlist_program> elements\n",
267 fileName, xmlGetLineNo(cur));
268 config_error++;
269 continue;
270 }
271 if (cur->xmlChildrenNode != NULL) {
272 const char *errstr;
273
274 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
275 ezConfig.fileNameIsProgram = (int)strtonum(STD_CHAR(ls_xmlContentPtr), 0LL, 1LL, &errstr);
276 if (errstr) {
277 log_error("%s[%ld]: Error: <playlist_program> may only contain 1 or 0\n",
278 fileName, xmlGetLineNo(cur));
279 config_error++;
280 continue;
281 }
282 xmlFree(ls_xmlContentPtr);
283 program_set = 1;
284 }
285 }
286 if (!xmlStrcmp(cur->name, (const xmlChar *)"shuffle")) {
287 if (shuffle_set) {
288 log_error("%s[%ld]: Error: Cannot have multiple <shuffle> elements\n",
289 fileName, xmlGetLineNo(cur));
290 config_error++;
291 continue;
292 }
293 if (cur->xmlChildrenNode != NULL) {
294 const char *errstr;
295
296 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
297 ezConfig.shuffle = (int)strtonum(STD_CHAR(ls_xmlContentPtr), 0LL, 1LL, &errstr);
298 if (errstr) {
299 log_error("%s[%ld]: Error: <shuffle> may only contain 1 or 0\n",
300 fileName, xmlGetLineNo(cur));
301 config_error++;
302 continue;
303 }
304 xmlFree(ls_xmlContentPtr);
305 shuffle_set = 1;
306 }
307 }
308 if (!xmlStrcmp(cur->name, (const xmlChar *)"stream_once")) {
309 if (streamOnce_set) {
310 log_error("%s[%ld]: Error: Cannot have multiple <stream_once> elements\n",
311 fileName, xmlGetLineNo(cur));
312 config_error++;
313 continue;
314 }
315 if (cur->xmlChildrenNode != NULL) {
316 const char *errstr;
317
318 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
319 ezConfig.streamOnce = (int)strtonum(STD_CHAR(ls_xmlContentPtr), 0LL, 1LL, &errstr);
320 if (errstr) {
321 log_error("%s[%ld]: Error: <stream_once> may only contain 1 or 0\n",
322 fileName, xmlGetLineNo(cur));
323 config_error++;
324 continue;
325 }
326 xmlFree(ls_xmlContentPtr);
327 streamOnce_set = 1;
328 }
329 }
330 if (!xmlStrcmp(cur->name, (const xmlChar *)"reconnect_tries")) {
331 if (reconnect_set) {
332 log_error("%s[%ld]: Error: Cannot have multiple <reconnect_tries> elements\n",
333 fileName, xmlGetLineNo(cur));
334 config_error++;
335 continue;
336 }
337 if (cur->xmlChildrenNode != NULL) {
338 const char *errstr;
339
340 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
341 ezConfig.reconnectAttempts = (unsigned int)strtonum(STD_CHAR(ls_xmlContentPtr), 0LL, (long long)UINT_MAX, &errstr);
342 if (errstr) {
343 log_error("%s[%ld]: Error: In <reconnect_tries>: '%s' is %s\n",
344 fileName, xmlGetLineNo(cur), STD_CHAR(ls_xmlContentPtr), errstr);
345 config_error++;
346 continue;
347 }
348 xmlFree(ls_xmlContentPtr);
349 reconnect_set = 1;
350 }
351 }
352 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfoname")) {
353 if (ezConfig.serverName != NULL) {
354 log_error("%s[%ld]: Error: Cannot have multiple <svrinfoname> elements\n",
355 fileName, xmlGetLineNo(cur));
356 config_error++;
357 continue;
358 }
359 if (cur->xmlChildrenNode != NULL) {
360 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
361 ezConfig.serverName = strdup(STD_CHAR(ls_xmlContentPtr));
362 xmlFree(ls_xmlContentPtr);
363 }
364 }
365 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfourl")) {
366 if (ezConfig.serverURL != NULL) {
367 log_error("%s[%ld]: Error: Cannot have multiple <svrinfourl> elements\n",
368 fileName, xmlGetLineNo(cur));
369 config_error++;
370 continue;
371 }
372 if (cur->xmlChildrenNode != NULL) {
373 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
374 ezConfig.serverURL = strdup(STD_CHAR(ls_xmlContentPtr));
375 xmlFree(ls_xmlContentPtr);
376 }
377 }
378 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfogenre")) {
379 if (ezConfig.serverGenre != NULL) {
380 log_error("%s[%ld]: Error: Cannot have multiple <svrinfogenre> elements\n",
381 fileName, xmlGetLineNo(cur));
382 config_error++;
383 continue;
384 }
385 if (cur->xmlChildrenNode != NULL) {
386 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
387 ezConfig.serverGenre = strdup(STD_CHAR(ls_xmlContentPtr));
388 xmlFree(ls_xmlContentPtr);
389 }
390 }
391 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfodescription")) {
392 if (ezConfig.serverDescription != NULL) {
393 log_error("%s[%ld]: Error: Cannot have multiple <svrinfodescription> elements\n",
394 fileName, xmlGetLineNo(cur));
395 config_error++;
396 continue;
397 }
398 if (cur->xmlChildrenNode != NULL) {
399 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
400 ezConfig.serverDescription = strdup(STD_CHAR(ls_xmlContentPtr));
401 xmlFree(ls_xmlContentPtr);
402 }
403 }
404 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfobitrate")) {
405 if (ezConfig.serverBitrate != NULL) {
406 log_error("%s[%ld]: Error: Cannot have multiple <svrinfobitrate> elements\n",
407 fileName, xmlGetLineNo(cur));
408 config_error++;
409 continue;
410 }
411 if (cur->xmlChildrenNode != NULL) {
412 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
413 ezConfig.serverBitrate = strdup(STD_CHAR(ls_xmlContentPtr));
414 xmlFree(ls_xmlContentPtr);
415 }
416 }
417
418 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfochannels")) {
419 if (ezConfig.serverChannels != NULL) {
420 log_error("%s[%ld]: Error: Cannot have multiple <svrinfochannels> elements\n",
421 fileName, xmlGetLineNo(cur));
422 config_error++;
423 continue;
424 }
425 if (cur->xmlChildrenNode != NULL) {
426 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
427 ezConfig.serverChannels = strdup(STD_CHAR(ls_xmlContentPtr));
428 xmlFree(ls_xmlContentPtr);
429 }
430 }
431 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfosamplerate")) {
432 if (ezConfig.serverSamplerate != NULL) {
433 log_error("%s[%ld]: Error: Cannot have multiple <svrinfosamplerate> elements\n",
434 fileName, xmlGetLineNo(cur));
435 config_error++;
436 continue;
437 }
438 if (cur->xmlChildrenNode != NULL) {
439 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
440 ezConfig.serverSamplerate = strdup(STD_CHAR(ls_xmlContentPtr));
441 xmlFree(ls_xmlContentPtr);
442 }
443 }
444 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfoquality")) {
445 if (ezConfig.serverQuality != NULL) {
446 log_error("%s[%ld]: Error: Cannot have multiple <svrinfoquality> elements\n",
447 fileName, xmlGetLineNo(cur));
448 config_error++;
449 continue;
450 }
451 if (cur->xmlChildrenNode != NULL) {
452 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
453 ezConfig.serverQuality = strdup(STD_CHAR(ls_xmlContentPtr));
454 xmlFree(ls_xmlContentPtr);
455 }
456 }
457 if (!xmlStrcmp(cur->name, (const xmlChar *)"svrinfopublic")) {
458 if (svrinfopublic_set) {
459 log_error("%s[%ld]: Error: Cannot have multiple <svrinfopublic> elements\n",
460 fileName, xmlGetLineNo(cur));
461 config_error++;
462 continue;
463 }
464 if (cur->xmlChildrenNode != NULL) {
465 const char *errstr;
466
467 ls_xmlContentPtr = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
468 ezConfig.serverPublic = (int)strtonum(STD_CHAR(ls_xmlContentPtr), 0LL, 1LL, &errstr);
469 if (errstr) {
470 log_error("%s[%ld]: Error: <svrinfopublic> may only contain 1 or 0\n",
471 fileName, xmlGetLineNo(cur));
472 config_error++;
473 continue;
474 }
475 xmlFree(ls_xmlContentPtr);
476 svrinfopublic_set = 1;
477 }
478 }
479 if (!xmlStrcmp(cur->name, (const xmlChar *)"reencode")) {
480 xmlNodePtr cur2;
481 int enable_set;
482
483 enable_set = 0;
484 for (cur2 = cur->xmlChildrenNode; cur2 != NULL;
485 cur2 = cur2->next) {
486 if (!xmlStrcmp(cur2->name, (const xmlChar *)"enable")) {
487 if (enable_set) {
488 log_error("%s[%ld]: Error: Cannot have multiple <enable> elements\n",
489 fileName, xmlGetLineNo(cur));
490 config_error++;
491 continue;
492 }
493 if (cur2->xmlChildrenNode != NULL) {
494 const char *errstr;
495
496 ls_xmlContentPtr = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
497 ezConfig.reencode = (int)strtonum(STD_CHAR(ls_xmlContentPtr), 0LL, 1LL, &errstr);
498 if (errstr) {
499 log_error("%s[%ld]: Error: <enable> may only contain 1 or 0\n",
500 fileName, xmlGetLineNo(cur));
501 config_error++;
502 continue;
503 }
504 xmlFree(ls_xmlContentPtr);
505 enable_set = 1;
506 }
507 }
508 if (!xmlStrcmp(cur2->name, (const xmlChar *)"encdec")) {
509 xmlNodePtr cur3;
510 FORMAT_ENCDEC *pformatEncDec;
511
512 pformatEncDec = calloc(1UL, sizeof(FORMAT_ENCDEC));
513
514 for (cur3 = cur2->xmlChildrenNode;
515 cur3 != NULL; cur3 = cur3->next) {
516 if (!xmlStrcmp(cur3->name, (const xmlChar *)"format")) {
517 if (pformatEncDec->format != NULL) {
518 log_error("%s[%ld]: Error: Cannot have multiple <format> elements\n",
519 fileName, xmlGetLineNo(cur3));
520 config_error++;
521 continue;
522 }
523 if (cur3->xmlChildrenNode != NULL) {
524 char *p;
525
526 ls_xmlContentPtr = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
527 pformatEncDec->format = strdup(STD_CHAR(ls_xmlContentPtr));
528 xmlFree(ls_xmlContentPtr);
529 for (p = pformatEncDec->format; *p != '\0'; p++)
530 *p = (char)toupper((int)*p);
531 }
532 }
533 if (!xmlStrcmp(cur3->name, (const xmlChar *)"match")) {
534 if (pformatEncDec->match != NULL) {
535 log_error("%s[%ld]: Error: Cannot have multiple <match> elements\n",
536 fileName, xmlGetLineNo(cur3));
537 config_error++;
538 continue;
539 }
540 if (cur3->xmlChildrenNode != NULL) {
541 char *p;
542
543 ls_xmlContentPtr = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
544 pformatEncDec->match = strdup(STD_CHAR(ls_xmlContentPtr));
545 xmlFree(ls_xmlContentPtr);
546 for (p = pformatEncDec->match; *p != '\0'; p++)
547 *p = (char)tolower((int)*p);
548 }
549 }
550 if (!xmlStrcmp(cur3->name, (const xmlChar *)"decode")) {
551 if (pformatEncDec->decoder != NULL) {
552 log_error("%s[%ld]: Error: Cannot have multiple <decode> elements\n",
553 fileName, xmlGetLineNo(cur3));
554 config_error++;
555 continue;
556 }
557 if (cur3->xmlChildrenNode != NULL) {
558 unsigned int ret;
559
560 ls_xmlContentPtr = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
561 pformatEncDec->decoder = strdup(STD_CHAR(ls_xmlContentPtr));
562 xmlFree(ls_xmlContentPtr);
563 if ((ret = checkDecoderLine(pformatEncDec->decoder,
564 fileName, xmlGetLineNo(cur3)))
565 > 0) {
566 config_error += ret;
567 continue;
568 }
569 }
570 }
571 if (!xmlStrcmp(cur3->name, (const xmlChar *)"encode")) {
572 if (pformatEncDec->encoder != NULL) {
573 log_error("%s[%ld]: Error: Cannot have multiple <encode> elements\n",
574 fileName, xmlGetLineNo(cur3));
575 config_error++;
576 continue;
577 }
578 if (cur3->xmlChildrenNode != NULL) {
579 unsigned int ret;
580
581 ls_xmlContentPtr = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
582 pformatEncDec->encoder = strdup(STD_CHAR(ls_xmlContentPtr));
583 xmlFree(ls_xmlContentPtr);
584 if ((ret = checkEncoderLine(pformatEncDec->encoder,
585 fileName, xmlGetLineNo(cur3)))
586 > 0) {
587 config_error += ret;
588 continue;
589 }
590 }
591 }
592 }
593 ezConfig.encoderDecoders[ezConfig.numEncoderDecoders] = pformatEncDec;
594 ezConfig.numEncoderDecoders++;
595 }
596 }
597 }
598 }
599
600 xmlFreeDoc(doc);
601
602 if (config_error == 0)
603 return (1);
604
605 freeConfig(&ezConfig);
606 log_error("%u configuration error(s) in %s\n",
607 config_error, fileName);
608
609 return (0);
610 }
611
612 void
613 freeConfig(EZCONFIG *cfg)
614 {
615 unsigned int i;
616
617 if (cfg == NULL)
618 return;
619
620 free(cfg->URL);
621 free(cfg->password);
622 free(cfg->format);
623 free(cfg->fileName);
624 free(cfg->metadataProgram);
625 free(cfg->metadataFormat);
626 free(cfg->serverName);
627 free(cfg->serverURL);
628 free(cfg->serverGenre);
629 free(cfg->serverDescription);
630 free(cfg->serverBitrate);
631 free(cfg->serverChannels);
632 free(cfg->serverSamplerate);
633 free(cfg->serverQuality);
634 for (i = 0; i < MAX_FORMAT_ENCDEC; i++) {
635 if (NULL == cfg->encoderDecoders[i])
636 continue;
637 free(cfg->encoderDecoders[i]->format);
638 free(cfg->encoderDecoders[i]->match);
639 free(cfg->encoderDecoders[i]->encoder);
640 free(cfg->encoderDecoders[i]->decoder);
641 free(cfg->encoderDecoders[i]);
642 }
643
644 memset(cfg, 0, sizeof(*cfg));
645 }
646
647 unsigned int
648 checkDecoderLine(const char *str, const char *file, long line)
649 {
650 unsigned int errors;
651 char *p;
652 int have_track = 0;
653
654 errors = 0;
655 if ((p = strstr(str, STRING_PLACEHOLDER)) != NULL) {
656 log_error("%s[%ld]: Error: `%s' placeholder not allowed in decoder command\n",
657 file, line, STRING_PLACEHOLDER);
658 errors++;
659 }
660 if ((p = strstr(str, TRACK_PLACEHOLDER)) != NULL) {
661 p += strlen(TRACK_PLACEHOLDER);
662 if ((p = strstr(p, TRACK_PLACEHOLDER)) != NULL) {
663 log_error("%s[%ld]: Error: Multiple `%s' placeholders in decoder command\n",
664 file, line, TRACK_PLACEHOLDER);
665 errors++;
666 } else
667 have_track = 1;
668 }
669 if ((p = strstr(str, METADATA_PLACEHOLDER)) != NULL) {
670 p += strlen(METADATA_PLACEHOLDER);
671 if ((p = strstr(p, METADATA_PLACEHOLDER)) != NULL) {
672 log_error("%s[%ld]: Error: Multiple `%s' placeholders in decoder command\n",
673 file, line, METADATA_PLACEHOLDER);
674 errors++;
675 }
676 }
677 if ((p = strstr(str, ARTIST_PLACEHOLDER)) != NULL) {
678 p += strlen(ARTIST_PLACEHOLDER);
679 if ((p = strstr(p, ARTIST_PLACEHOLDER)) != NULL) {
680 log_error("%s[%ld]: Error: Multiple `%s' placeholders in decoder command\n",
681 file, line, ARTIST_PLACEHOLDER);
682 errors++;
683 }
684 }
685 if ((p = strstr(str, TITLE_PLACEHOLDER)) != NULL) {
686 p += strlen(TITLE_PLACEHOLDER);
687 if ((p = strstr(p, TITLE_PLACEHOLDER)) != NULL) {
688 log_error("%s[%ld]: Error: Multiple `%s' placeholders in decoder command\n",
689 file, line, TITLE_PLACEHOLDER);
690 errors++;
691 }
692 }
693
694 if (!have_track) {
695 log_error("%s[%ld]: Error: The decoder command requires the '%s' track placeholder\n",
696 file, line, TRACK_PLACEHOLDER);
697 errors++;
698 }
699
700 return (errors);
701 }
702
703 unsigned int
704 checkEncoderLine(const char *str, const char *file, long line)
705 {
706 unsigned int errors;
707 char *p;
708
709 errors = 0;
710 if ((p = strstr(str, TRACK_PLACEHOLDER)) != NULL) {
711 log_error("%s[%ld]: Error: `%s' placeholder not allowed in encoder command\n",
712 file, line, TRACK_PLACEHOLDER);
713 errors++;
714 }
715 if ((p = strstr(str, STRING_PLACEHOLDER)) != NULL) {
716 log_error("%s[%ld]: Error: `%s' placeholder not allowed in encoder command\n",
717 file, line, STRING_PLACEHOLDER);
718 errors++;
719 }
720 if ((p = strstr(str, METADATA_PLACEHOLDER)) != NULL) {
721 p += strlen(METADATA_PLACEHOLDER);
722 if ((p = strstr(p, METADATA_PLACEHOLDER)) != NULL) {
723 log_error("%s[%ld]: Error: Multiple `%s' placeholders in encoder command\n",
724 file, line, METADATA_PLACEHOLDER);
725 errors++;
726 }
727 }
728 if ((p = strstr(str, ARTIST_PLACEHOLDER)) != NULL) {
729 p += strlen(ARTIST_PLACEHOLDER);
730 if ((p = strstr(p, ARTIST_PLACEHOLDER)) != NULL) {
731 log_error("%s[%ld]: Error: Multiple `%s' placeholders in encoder command\n",
732 file, line, ARTIST_PLACEHOLDER);
733 errors++;
734 }
735 }
736 if ((p = strstr(str, TITLE_PLACEHOLDER)) != NULL) {
737 p += strlen(TITLE_PLACEHOLDER);
738 if ((p = strstr(p, TITLE_PLACEHOLDER)) != NULL) {
739 log_error("%s[%ld]: Error: Multiple `%s' placeholders in encoder command\n",
740 file, line, TITLE_PLACEHOLDER);
741 errors++;
742 }
743 }
744
745 return (errors);
746 }
747
748 unsigned int
749 checkFormatLine(const char *str, const char *file, long line)
750 {
751 unsigned int errors;
752 char *p;
753
754 errors = 0;
755 if ((p = strstr(str, METADATA_PLACEHOLDER)) != NULL) {
756 log_error("%s[%ld]: Error: `%s' placeholder not allowed in <metadata_format>\n",
757 file, line, METADATA_PLACEHOLDER);
758 errors++;
759 }
760 if ((p = strstr(str, TRACK_PLACEHOLDER)) != NULL) {
761 p += strlen(TRACK_PLACEHOLDER);
762 if ((p = strstr(p, TRACK_PLACEHOLDER)) != NULL) {
763 log_error("%s[%ld]: Error: Multiple `%s' placeholders in <metadata_format>\n",
764 file, line, TRACK_PLACEHOLDER);
765 errors++;
766 }
767 }
768 if ((p = strstr(str, STRING_PLACEHOLDER)) != NULL) {
769 p += strlen(STRING_PLACEHOLDER);
770 if ((p = strstr(p, STRING_PLACEHOLDER)) != NULL) {
771 log_error("%s[%ld]: Error: Multiple `%s' placeholders in <metadata_format>\n",
772 file, line, STRING_PLACEHOLDER);
773 errors++;
774 }
775 }
776 if ((p = strstr(str, ARTIST_PLACEHOLDER)) != NULL) {
777 p += strlen(ARTIST_PLACEHOLDER);
778 if ((p = strstr(p, ARTIST_PLACEHOLDER)) != NULL) {
779 log_error("%s[%ld]: Error: Multiple `%s' placeholders in <metadata_format>\n",
780 file, line, ARTIST_PLACEHOLDER);
781 errors++;
782 }
783 }
784 if ((p = strstr(str, TITLE_PLACEHOLDER)) != NULL) {
785 p += strlen(TITLE_PLACEHOLDER);
786 if ((p = strstr(p, TITLE_PLACEHOLDER)) != NULL) {
787 log_error("%s[%ld]: Error: Multiple `%s' placeholders in <metadata_format>\n",
788 file, line, TITLE_PLACEHOLDER);
789 errors++;
790 }
791 }
792
793 return (errors);
794 }