/* -*- Mode: C ; c-basic-offset: 4 -*- */ /* Copyright (C) 2007,2008 Nedko Arnaudov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #if defined(HAVE_CONFIG_H) #include "config.h" #endif #include #include #include #include #include #include #include #include #include #include #include "controller_internal.h" #include "jackdbus.h" bool jack_controller_settings_init() { return true; } void jack_controller_settings_uninit() { } #define PARSE_CONTEXT_ROOT 0 #define PARSE_CONTEXT_JACK 1 #define PARSE_CONTEXT_ENGINE 1 #define PARSE_CONTEXT_DRIVERS 2 #define PARSE_CONTEXT_DRIVER 3 #define PARSE_CONTEXT_OPTION 4 #define PARSE_CONTEXT_INTERNALS 5 #define PARSE_CONTEXT_INTERNAL 6 #define MAX_STACK_DEPTH 10 struct parse_context { struct jack_controller *controller_ptr; XML_Bool error; unsigned int element[MAX_STACK_DEPTH]; signed int depth; jackctl_driver_t *driver; jackctl_internal_t *internal; char option[JACK_PARAM_STRING_MAX+1]; int option_used; char *name; }; #define context_ptr ((struct parse_context *)data) void jack_controller_settings_callback_chrdata(void *data, const XML_Char *s, int len) { if (context_ptr->error) { return; } if (context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_OPTION) { if (context_ptr->option_used + len >= JACK_PARAM_STRING_MAX) { jack_error("xml parse max char data length reached"); context_ptr->error = XML_TRUE; return; } memcpy(context_ptr->option + context_ptr->option_used, s, len); context_ptr->option_used += len; } } void jack_controller_settings_callback_elstart(void *data, const char *el, const char **attr) { jackctl_driver_t *driver; jackctl_internal_t *internal; if (context_ptr->error) { return; } if (context_ptr->depth + 1 >= MAX_STACK_DEPTH) { jack_error("xml parse max stack depth reached"); context_ptr->error = XML_TRUE; return; } if (strcmp(el, "jack") == 0) { //jack_info(""); context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_JACK; return; } if (strcmp(el, "engine") == 0) { //jack_info(""); context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_ENGINE; return; } if (strcmp(el, "drivers") == 0) { //jack_info(""); context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_DRIVERS; return; } if (strcmp(el, "internals") == 0) { //jack_info(""); context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_INTERNALS; return; } if (strcmp(el, "driver") == 0) { if ((attr[0] == NULL || attr[2] != NULL) || strcmp(attr[0], "name") != 0) { jack_error(" XML element must contain exactly one attribute, named \"name\""); context_ptr->error = XML_TRUE; return; } //jack_info(""); context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_DRIVER; driver = jack_controller_find_driver(context_ptr->controller_ptr->server, attr[1]); if (driver == NULL) { jack_error("ignoring settings for unknown driver \"%s\"", attr[1]); } else { jack_info("setting for driver \"%s\" found", attr[1]); } context_ptr->driver = driver; return; } if (strcmp(el, "internal") == 0) { if ((attr[0] == NULL || attr[2] != NULL) || strcmp(attr[0], "name") != 0) { jack_error(" XML element must contain exactly one attribute, named \"name\""); context_ptr->error = XML_TRUE; return; } //jack_info(""); context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_INTERNAL; internal = jack_controller_find_internal(context_ptr->controller_ptr->server, attr[1]); if (internal == NULL) { jack_error("ignoring settings for unknown internal \"%s\"", attr[1]); } else { jack_info("setting for internal \"%s\" found", attr[1]); } context_ptr->internal = internal; return; } if (strcmp(el, "option") == 0) { //jack_info("