From b69a5d17e266401901adf5e62ca7d4f4e94d82e0 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 5 Apr 2007 18:23:21 +0200 Subject: Added a new callback. This callback is called when a new entry is registered. The plan is register and call back a plugin loader function. --- src/xine-engine/configfile.c | 49 +++++++++++++++++++++++++++++++++----------- src/xine-engine/configfile.h | 19 ++++++++++++++++- 2 files changed, 55 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 28b44fd51..c7cf30968 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -455,6 +455,8 @@ static void config_reset_value(cfg_entry_t *entry) { entry->num_value = 0; } +static void config_shallow_copy(xine_cfg_entry_t *dest, cfg_entry_t *src); + static cfg_entry_t *config_register_key (config_values_t *this, const char *key, int exp_level, @@ -488,6 +490,14 @@ static cfg_entry_t *config_register_key (config_values_t *this, entry->callback_data = cb_data; } + /* we created a new entry, call the callback */ + if (this->new_entry_cb) { + xine_cfg_entry_t cb_entry; + + config_shallow_copy(&cb_entry, entry); + this->new_entry_cb(this->new_entry_cbdata, &cb_entry); + } + return entry; } @@ -1186,6 +1196,19 @@ static void config_unregister_cb (config_values_t *this, const char *key) { } } +static void config_set_new_entry_callback (config_values_t *this, xine_config_cb_t new_entry_cb, void* cbdata) { + pthread_mutex_lock(&this->config_lock); + this->new_entry_cb = new_entry_cb; + this->new_entry_cbdata = cbdata; + pthread_mutex_unlock(&this->config_lock); +} + +static void config_unset_new_entry_callback (config_values_t *this) { + pthread_mutex_lock(&this->config_lock); + this->new_entry_cb = NULL; + this->new_entry_cbdata = NULL; + pthread_mutex_unlock(&this->config_lock); +} config_values_t *_x_config_init (void) { @@ -1212,18 +1235,20 @@ config_values_t *_x_config_init (void) { pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&this->config_lock, &attr); - this->register_string = config_register_string; - this->register_filename = config_register_filename; - this->register_range = config_register_range; - this->register_enum = config_register_enum; - this->register_num = config_register_num; - this->register_bool = config_register_bool; - this->update_num = config_update_num; - this->update_string = config_update_string; - this->parse_enum = config_parse_enum; - this->lookup_entry = config_lookup_entry; - this->unregister_callback = config_unregister_cb; - this->dispose = config_dispose; + this->register_string = config_register_string; + this->register_filename = config_register_filename; + this->register_range = config_register_range; + this->register_enum = config_register_enum; + this->register_num = config_register_num; + this->register_bool = config_register_bool; + this->update_num = config_update_num; + this->update_string = config_update_string; + this->parse_enum = config_parse_enum; + this->lookup_entry = config_lookup_entry; + this->unregister_callback = config_unregister_cb; + this->dispose = config_dispose; + this->set_new_entry_callback = config_set_new_entry_callback; + this->unset_new_entry_callback = config_unset_new_entry_callback; return this; } diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h index 859214d1c..e98138fa3 100644 --- a/src/xine-engine/configfile.h +++ b/src/xine-engine/configfile.h @@ -50,6 +50,7 @@ extern "C" { typedef struct cfg_entry_s cfg_entry_t; typedef struct config_values_s config_values_t; + struct cfg_entry_s { cfg_entry_t *next; config_values_t *config; @@ -175,7 +176,7 @@ struct config_values_s { cfg_entry_t* (*lookup_entry) (config_values_t *self, const char *key); /* - * unregister callback function + * unregister entry callback function */ void (*unregister_callback) (config_values_t *self, const char *key); @@ -184,11 +185,27 @@ struct config_values_s { */ void (*dispose) (config_values_t *self); + /* + * callback called when a new config entry is registered + */ + void (*set_new_entry_callback) (config_values_t *self, xine_config_cb_t new_entry_cb, void *cb_data); + + /* + * unregister the callback + */ + void (*unset_new_entry_callback) (config_values_t *self); + /* * config values are stored here: */ cfg_entry_t *first, *last, *cur; + /* + * new entry callback + */ + xine_config_cb_t new_entry_cb; + void *new_entry_cbdata; + /* * mutex for modification to the config */ -- cgit v1.2.3 From 54ad01301df2b562e316a7910436ac1ff7494ac3 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 5 Apr 2007 19:00:10 +0200 Subject: Defined a callback for config entry registration. The next step is to add the entries to the node. --- src/xine-engine/load_plugins.c | 25 ++++++++++++++++++++++--- src/xine-engine/plugin_catalog.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index d35eba736..320fc0dd2 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -338,6 +338,7 @@ static void _insert_node (xine_t *this, entry->file = file; entry->ref = 0; entry->priority = 0; /* default priority */ + entry->config_entry_list = NULL; switch (info->type & PLUGIN_TYPE_MASK){ @@ -694,6 +695,17 @@ static inline int _plugin_info_equal(const plugin_info_t *a, return 1; } +/* + * This callback is called by the config entry system when a plugin register a + * new config entry. + */ +static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { + plugin_node_t *node = (plugin_node_t *)user_data; + /* + printf("_new_entry_cb: key %s, plugin id: %s\n", entry->key, node->info->id); + */ +} + static int _load_plugin_class(xine_t *this, plugin_node_t *node, void *data) { @@ -721,9 +733,16 @@ static int _load_plugin_class(xine_t *this, if ((info = dlsym(node->file->lib_handle, "xine_plugin_info"))) { /* TODO: use sigsegv handler */ - while (info->type != PLUGIN_NONE){ - if (_plugin_info_equal(info, target)){ - if ((node->plugin_class = info->init(this, data))) { + while (info->type != PLUGIN_NONE) { + if (_plugin_info_equal(info, target)) { + config_values_t *config = this->config; + + /* the callback is called for each entry registered by this plugin */ + config->set_new_entry_callback(config, _new_entry_cb, node); + node->plugin_class = info->init(this, data); + config->unset_new_entry_callback(config); + + if (node->plugin_class) { inc_file_ref(node->file); return 1; } else { diff --git a/src/xine-engine/plugin_catalog.h b/src/xine-engine/plugin_catalog.h index 5bd1c4701..26905ebff 100644 --- a/src/xine-engine/plugin_catalog.h +++ b/src/xine-engine/plugin_catalog.h @@ -57,6 +57,7 @@ typedef struct { plugin_file_t *file; plugin_info_t *info; void *plugin_class; + xine_list_t *config_entry_list; int ref; /* count intances of plugins */ int priority; } plugin_node_t ; -- cgit v1.2.3 From 90ec5563d6d3ce1abd5fc52d4aee1b0ecf6c7516 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 5 Apr 2007 19:14:48 +0200 Subject: Filled the config entry list when the callback is called. --- src/xine-engine/load_plugins.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 320fc0dd2..f4be27587 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -704,6 +704,12 @@ static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { /* printf("_new_entry_cb: key %s, plugin id: %s\n", entry->key, node->info->id); */ + if (!node->config_entry_list) { + node->config_entry_list = xine_list_new(); + } + + xine_list_push_back(node->config_entry_list, (void *)entry->key); + } static int _load_plugin_class(xine_t *this, @@ -2603,6 +2609,10 @@ static void dispose_plugin_list (xine_sarray_t *list) { /* free info structure and string copies */ free (node->info->id); free (node->info); + + if (node->config_entry_list) { + xine_list_delete(node->config_entry_list); + } free (node); } xine_sarray_delete(list); -- cgit v1.2.3 From 42cbd632976d2c9d5293ad03418dce3c7db2797d Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Fri, 6 Apr 2007 15:28:37 +0200 Subject: - Moved base64 stuff to xine-utils. - Added config entry serialization. - Added serialized config entries to the plugin cache. --HG-- rename : src/input/base64.c => src/xine-utils/base64.c rename : src/input/base64.h => src/xine-utils/base64.h --- src/input/Makefile.am | 2 +- src/input/base64.c | 135 ---------------------------- src/input/base64.h | 95 -------------------- src/xine-engine/configfile.c | 136 ++++++++++++++++++++++++++++ src/xine-engine/configfile.h | 15 ++++ src/xine-engine/load_plugins.c | 45 ++++++---- src/xine-utils/Makefile.am | 6 +- src/xine-utils/base64.c | 198 +++++++++++++++++++++++++++++++++++++++++ src/xine-utils/base64.h | 98 ++++++++++++++++++++ src/xine-utils/xineutils.h | 2 + 10 files changed, 483 insertions(+), 249 deletions(-) delete mode 100644 src/input/base64.c delete mode 100644 src/input/base64.h create mode 100644 src/xine-utils/base64.c create mode 100644 src/xine-utils/base64.h (limited to 'src') diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 68adf84be..1b6378efc 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -126,7 +126,7 @@ xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) libreal/libreal.la lib xineplug_inp_rtsp_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) xineplug_inp_rtsp_la_LDFLAGS = -avoid-version -module -xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h base64.c base64.h +xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h xineplug_inp_cdda_la_LIBADD = $(XINE_LIB) xineplug_inp_cdda_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) xineplug_inp_cdda_la_LDFLAGS = -avoid-version -module diff --git a/src/input/base64.c b/src/input/base64.c deleted file mode 100644 index 0eccbe84e..000000000 --- a/src/input/base64.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2000 Robert Kaye - * - * This file is part of xine, a free video player. - * - * xine 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, or - * (at your option) any later version. - * - * xine 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Base64 encoding modified for Musicbrainz - * relicensed under the GNU General Public License for use in xine-lib - * - */ -/* -------------------------------------------------------------------------- - - MusicBrainz -- The Internet music metadatabase - - Copyright (C) 2000 Robert Kaye - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - $Id: base64.c,v 1.2 2004/05/05 18:44:19 mroi Exp $ - -----------------------------------------------------------------------------*/ -/* - * Program: RFC-822 routines (originally from SMTP) - * - * Author: Mark Crispin - * Networks and Distributed Computing - * Computing & Communications - * University of Washington - * Administration Building, AG-44 - * Seattle, WA 98195 - * Internet: MRC@CAC.Washington.EDU - * - * Date: 27 July 1988 - * Last Edited: 10 September 1998 - * - * Sponsorship: The original version of this work was developed in the - * Symbolic Systems Resources Group of the Knowledge Systems - * Laboratory at Stanford University in 1987-88, and was funded - * by the Biomedical Research Technology Program of the National - * Institutes of Health under grant number RR-00785. - * - * Original version Copyright 1988 by The Leland Stanford Junior University - * Copyright 1998 by the University of Washington - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notices appear in all copies and that both the - * above copyright notices and this permission notice appear in supporting - * documentation, and that the name of the University of Washington or The - * Leland Stanford Junior University not be used in advertising or publicity - * pertaining to distribution of the software without specific, written prior - * permission. This software is made available "as is", and - * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY - * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, - * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF - * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#include -#include -#include -#include - -#include "base64.h" - - -/* NOTE: This is not true RFC822 anymore. The use of the characters - '/', '+', and '=' is no bueno when the ID will be used as part of a URL. - '_', '.', and '-' have been used instead -*/ - -/* Convert binary contents to BASE64 - * Accepts: source - * length of source - * pointer to return destination length - * Returns: destination as BASE64 - */ - -unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len) -{ - unsigned char *ret,*d; - unsigned char *s = (unsigned char *) src; - char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; - unsigned long i = ((srcl + 2) / 3) * 4; - *len = i += 2 * ((i / 60) + 1); - d = ret = (unsigned char *) malloc ((size_t) ++i); - for (i = 0; srcl; s += 3) { /* process tuplets */ - *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ - /* byte 2: low 2 bits (1), high 4 bits (2) */ - *d++ = v[((s[0] << 4) + (--srcl ? (s[1] >> 4) : 0)) & 0x3f]; - /* byte 3: low 4 bits (2), high 2 bits (3) */ - *d++ = srcl ? v[((s[1] << 2) + (--srcl ? (s[2] >> 6) : 0)) & 0x3f] : '-'; - /* byte 4: low 6 bits (3) */ - *d++ = srcl ? v[s[2] & 0x3f] : '-'; - if (srcl) srcl--; /* count third character if processed */ - if ((++i) == 15) { /* output 60 characters? */ - i = 0; /* restart line break count, insert CRLF */ - *d++ = '\015'; *d++ = '\012'; - } - } - *d = '\0'; /* tie off string */ - - return ret; /* return the resulting string */ -} diff --git a/src/input/base64.h b/src/input/base64.h deleted file mode 100644 index 72feef885..000000000 --- a/src/input/base64.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2000 Robert Kaye - * - * This file is part of xine, a free video player. - * - * xine 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, or - * (at your option) any later version. - * - * xine 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Base64 encoding modified for Musicbrainz - * relicensed under the GNU General Public License for use in xine-lib - * - */ -/* -------------------------------------------------------------------------- - - MusicBrainz -- The Internet music metadatabase - - Copyright (C) 2000 Robert Kaye - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - $Id: base64.h,v 1.1 2004/05/05 09:11:39 hadess Exp $ - -----------------------------------------------------------------------------*/ -/* - * Program: RFC-822 routines (originally from SMTP) - * - * Author: Mark Crispin - * Networks and Distributed Computing - * Computing & Communications - * University of Washington - * Administration Building, AG-44 - * Seattle, WA 98195 - * Internet: MRC@CAC.Washington.EDU - * - * Date: 27 July 1988 - * Last Edited: 10 September 1998 - * - * Sponsorship: The original version of this work was developed in the - * Symbolic Systems Resources Group of the Knowledge Systems - * Laboratory at Stanford University in 1987-88, and was funded - * by the Biomedical Research Technology Program of the National - * Institutes of Health under grant number RR-00785. - * - * Original version Copyright 1988 by The Leland Stanford Junior University - * Copyright 1998 by the University of Washington - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notices appear in all copies and that both the - * above copyright notices and this permission notice appear in supporting - * documentation, and that the name of the University of Washington or The - * Leland Stanford Junior University not be used in advertising or publicity - * pertaining to distribution of the software without specific, written prior - * permission. This software is made available "as is", and - * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY - * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, - * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF - * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifndef BASE64_H -#define BASE64_H - -unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len); - -#endif diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index c7cf30968..fce6e4a30 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1210,6 +1210,139 @@ static void config_unset_new_entry_callback (config_values_t *this) { pthread_mutex_unlock(&this->config_lock); } +static void config_register_entry (config_values_t *this, cfg_entry_t* entry) { + /* FIXME: TODO */ +} + +static int put_int(uint8_t *buffer, int pos, int value) { + int32_t value_int32 = (int32_t)value; + + buffer[pos] = value_int32 & 0xFF; + buffer[pos + 1] = (value_int32 >> 8) & 0xFF; + buffer[pos + 2] = (value_int32 >> 16) & 0xFF; + buffer[pos + 3] = (value_int32 >> 24) & 0xFF; + + return 4; +} + +static int put_string(uint8_t *buffer, int pos, const char *value, int value_len) { + pos += put_int(buffer, pos, value_len); + memcpy(&buffer[pos], value, value_len); + + return 4 + value_len; +} + +static unsigned char* config_serialize_entry (config_values_t *this, const char *key) { + unsigned char *output = NULL; + cfg_entry_t *entry, *prev; + + pthread_mutex_lock(&this->config_lock); + config_lookup_entry_int(this, key, &entry, &prev); + + if (entry) { + /* now serialize this stuff + fields to serialize : + int type; + int range_min; + int range_max; + int exp_level; + char *key; + char *str_default; + char *description; + char *help; + char **enum_values; + */ + + int key_len = 0; + int str_default_len = 0; + int description_len = 0; + int help_len = 0; + + if (entry->key) + key_len = strlen(entry->key); + if (entry->str_default) + str_default_len = strlen(entry->str_default); + if (entry->description) + description_len = strlen(entry->description); + if (entry->help) + help_len = strlen(entry->help); + + // integers + // value: 4 bytes + unsigned long total_len = 4 * sizeof(int32_t); + + // strings (size + char buffer) + // length: 4 bytes + // buffer: length bytes + total_len += sizeof(int32_t) + key_len; + total_len += sizeof(int32_t) + str_default_len; + total_len += sizeof(int32_t) + description_len; + total_len += sizeof(int32_t) + help_len; + + /* enum values... */ + // value count: 4 bytes + // for each value: + // length: 4 bytes + // buffer: length bytes + int value_count = 0; + int value_len[10]; + total_len += sizeof(int32_t); /* value count */ + + char **cur_value = entry->enum_values; + if (cur_value) { + while (*cur_value && (value_count < (sizeof(value_len) / sizeof(int) ))) { + value_len[value_count] = strlen(*cur_value); + total_len += sizeof(int32_t) + value_len[value_count]; + value_count++; + cur_value++; + } + } + + /* Now we have the length needed to serialize the entry and the length of each string */ + uint8_t *buffer = malloc (total_len); + if (!buffer) return NULL; + + /* Let's go */ + int pos = 0; + + // the integers + pos += put_int(buffer, pos, entry->type); + pos += put_int(buffer, pos, entry->range_min); + pos += put_int(buffer, pos, entry->range_max); + pos += put_int(buffer, pos, entry->exp_level); + + // the strings + pos += put_string(buffer, pos, entry->key, key_len); + pos += put_string(buffer, pos, entry->str_default, str_default_len); + pos += put_string(buffer, pos, entry->description, description_len); + pos += put_string(buffer, pos, entry->help, help_len); + + // the enum stuff + pos += put_int(buffer, pos, value_count); + cur_value = entry->enum_values; + + int i; + for (i = 0; i < value_count; i++) { + pos += put_string(buffer, pos, *cur_value, value_len[i]); + cur_value++; + } + + // and now the output encoding + unsigned long output_len; + output = base64_encode (buffer, total_len, &output_len); + + free(buffer); + } + pthread_mutex_unlock(&this->config_lock); + + return output; +} + +static cfg_entry_t* config_deserialize_entry (config_values_t *this, const char *value) { + /* FIXME: TODO */ + return NULL; +} + config_values_t *_x_config_init (void) { #ifdef HAVE_IRIXAL @@ -1249,6 +1382,9 @@ config_values_t *_x_config_init (void) { this->dispose = config_dispose; this->set_new_entry_callback = config_set_new_entry_callback; this->unset_new_entry_callback = config_unset_new_entry_callback; + this->register_entry = config_register_entry; + this->serialize_entry = config_serialize_entry; + this->deserialize_entry = config_deserialize_entry; return this; } diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h index e98138fa3..e1416432b 100644 --- a/src/xine-engine/configfile.h +++ b/src/xine-engine/configfile.h @@ -157,6 +157,8 @@ struct config_values_s { xine_config_cb_t changed_cb, void *cb_data); + void (*register_entry) (config_values_t *self, cfg_entry_t* entry); + /* convenience function to update range, enum, num and bool values */ void (*update_num) (config_values_t *self, const char *key, int value); @@ -195,6 +197,19 @@ struct config_values_s { */ void (*unset_new_entry_callback) (config_values_t *self); + /* + * serialize a config entry. + * return a base64 null terminated string. + */ + char* (*serialize_entry) (config_values_t *self, const char *key); + + /* + * deserialize a config entry. + * value is a base 64 encoded string + */ + cfg_entry_t* (*deserialize_entry) (config_values_t *self, const char *value); + + /* * config values are stored here: */ diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index f4be27587..b2d2f1d9d 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -701,15 +701,12 @@ static inline int _plugin_info_equal(const plugin_info_t *a, */ static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { plugin_node_t *node = (plugin_node_t *)user_data; - /* - printf("_new_entry_cb: key %s, plugin id: %s\n", entry->key, node->info->id); - */ + if (!node->config_entry_list) { node->config_entry_list = xine_list_new(); } xine_list_push_back(node->config_entry_list, (void *)entry->key); - } static int _load_plugin_class(xine_t *this, @@ -857,7 +854,7 @@ static void load_required_plugins(xine_t *this) { /* * save plugin list information to file (cached catalog) */ -static void save_plugin_list(FILE *fp, xine_sarray_t *list) { +static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { const plugin_node_t *node; const plugin_file_t *file; @@ -867,7 +864,6 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { const vo_info_t *vo_info; const ao_info_t *ao_info; const post_info_t *post_info; - int i; int list_id = 0; int list_size; @@ -884,9 +880,9 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { fprintf(fp, "api=%d\n", node->info->API ); fprintf(fp, "id=%s\n", node->info->id ); fprintf(fp, "version=%lu\n", (unsigned long) node->info->version ); - + switch (node->info->type & PLUGIN_TYPE_MASK){ - + case PLUGIN_VIDEO_OUT: vo_info = node->info->special_info; fprintf(fp, "visual_type=%d\n", vo_info->visual_type ); @@ -914,7 +910,7 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { demuxer_info = node->info->special_info; fprintf(fp, "demuxer_priority=%d\n", demuxer_info->priority); break; - + case PLUGIN_INPUT: input_info = node->info->special_info; fprintf(fp, "input_priority=%d\n", input_info->priority); @@ -922,10 +918,27 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { case PLUGIN_POST: post_info = node->info->special_info; - fprintf(fp, "post_type=%lu\n", (unsigned long)post_info->type); - break; - } - + fprintf(fp, "post_type=%lu\n", (unsigned long)post_info->type); + break; + } + + if (node->config_entry_list) + { + xine_list_iterator_t ite = xine_list_front(node->config_entry_list); + while (ite) { + char *key = xine_list_get_value(node->config_entry_list, ite); + + /* now get the representation of the config key */ + char *key_value = this->config->serialize_entry(this->config, key); + + printf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); + fprintf(fp, "config_key=%s\n", key_value); + + free (key_value); + ite = xine_list_next(node->config_entry_list, ite); + } + } + fprintf(fp, "\n"); list_id++; } @@ -1120,7 +1133,7 @@ static void save_catalog (xine_t *this) { fprintf(fp, "cache_catalog_version=%d\n\n", CACHE_CATALOG_VERSION); for (i = 0; i < PLUGIN_TYPE_MAX; i++) { - save_plugin_list (fp, this->plugin_catalog->plugin_lists[i]); + save_plugin_list (this, fp, this->plugin_catalog->plugin_lists[i]); } fclose(fp); } @@ -1206,9 +1219,9 @@ void _x_scan_plugins (xine_t *this) { free(pluginpath); free(homedir); - save_catalog (this); - load_required_plugins (this); + + save_catalog (this); map_decoders (this); } diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am index 95de06b9e..8bef77b4c 100644 --- a/src/xine-utils/Makefile.am +++ b/src/xine-utils/Makefile.am @@ -30,7 +30,8 @@ libxineutils_la_SOURCES = $(pppc_files) \ array.c \ sorted_array.c \ pool.c \ - ring_buffer.c + ring_buffer.c \ + base64.c xineinclude_HEADERS = \ attributes.h \ @@ -43,7 +44,8 @@ xineinclude_HEADERS = \ array.h \ sorted_array.h \ pool.h \ - ring_buffer.h + ring_buffer.h \ + base64.h noinst_HEADERS = ppcasm_string.h xine_check.h diff --git a/src/xine-utils/base64.c b/src/xine-utils/base64.c new file mode 100644 index 000000000..358cbbada --- /dev/null +++ b/src/xine-utils/base64.c @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2000 Robert Kaye + * + * This file is part of xine, a free video player. + * + * xine 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, or + * (at your option) any later version. + * + * xine 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * Base64 encoding modified for Musicbrainz + * relicensed under the GNU General Public License for use in xine-lib + * + */ +/* -------------------------------------------------------------------------- + + MusicBrainz -- The Internet music metadatabase + + Copyright (C) 2000 Robert Kaye + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + $Id: base64.c,v 1.2 2004/05/05 18:44:19 mroi Exp $ + +----------------------------------------------------------------------------*/ +/* + * Program: RFC-822 routines (originally from SMTP) + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 27 July 1988 + * Last Edited: 10 September 1998 + * + * Sponsorship: The original version of this work was developed in the + * Symbolic Systems Resources Group of the Knowledge Systems + * Laboratory at Stanford University in 1987-88, and was funded + * by the Biomedical Research Technology Program of the National + * Institutes of Health under grant number RR-00785. + * + * Original version Copyright 1988 by The Leland Stanford Junior University + * Copyright 1998 by the University of Washington + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notices appear in all copies and that both the + * above copyright notices and this permission notice appear in supporting + * documentation, and that the name of the University of Washington or The + * Leland Stanford Junior University not be used in advertising or publicity + * pertaining to distribution of the software without specific, written prior + * permission. This software is made available "as is", and + * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY + * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF + * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include +#include +#include +#include + +#include "base64.h" + + +/* NOTE: This is not true RFC822 anymore. The use of the characters + '/', '+', and '=' is no bueno when the ID will be used as part of a URL. + '_', '.', and '-' have been used instead +*/ + +/* Convert binary contents to BASE64 + * Accepts: source + * length of source + * pointer to return destination length + * Returns: destination as BASE64 + */ + +unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len) +{ + unsigned char *ret,*d; + unsigned char *s = (unsigned char *) src; + char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; + unsigned long i = ((srcl + 2) / 3) * 4; + *len = i += 2 * ((i / 60) + 1); + d = ret = (unsigned char *) malloc ((size_t) ++i); + for (i = 0; srcl; s += 3) { /* process tuplets */ + *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ + /* byte 2: low 2 bits (1), high 4 bits (2) */ + *d++ = v[((s[0] << 4) + (--srcl ? (s[1] >> 4) : 0)) & 0x3f]; + /* byte 3: low 4 bits (2), high 2 bits (3) */ + *d++ = srcl ? v[((s[1] << 2) + (--srcl ? (s[2] >> 6) : 0)) & 0x3f] : '-'; + /* byte 4: low 6 bits (3) */ + *d++ = srcl ? v[s[2] & 0x3f] : '-'; + if (srcl) srcl--; /* count third character if processed */ + if ((++i) == 15) { /* output 60 characters? */ + i = 0; /* restart line break count, insert CRLF */ + *d++ = '\015'; *d++ = '\012'; + } + } + *d = '\0'; /* tie off string */ + + return ret; /* return the resulting string */ +} + +unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len) +{ + unsigned char *ret,*d; + unsigned char *s = (unsigned char *) src; + char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; + unsigned long i = ((srcl + 2) / 3) * 4; + *len = i; + d = ret = (unsigned char *) malloc ((size_t) ++i); + for (i = 0; srcl; s += 3) { /* process tuplets */ + *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ + /* byte 2: low 2 bits (1), high 4 bits (2) */ + *d++ = v[((s[0] << 4) + (--srcl ? (s[1] >> 4) : 0)) & 0x3f]; + /* byte 3: low 4 bits (2), high 2 bits (3) */ + *d++ = srcl ? v[((s[1] << 2) + (--srcl ? (s[2] >> 6) : 0)) & 0x3f] : '-'; + /* byte 4: low 6 bits (3) */ + *d++ = srcl ? v[s[2] & 0x3f] : '-'; + if (srcl) srcl--; /* count third character if processed */ + } + *d = '\0'; /* tie off string */ + + return ret; /* return the resulting string */ +} + +void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len) +{ + void *ret; + unsigned char *d; + unsigned long i = ((srcl + 3) / 4) * 3; + *len = i; + d = ret = (void *) malloc ((size_t)i); + for (i = 0; srcl; src += 4) { /* process tuplets */ + unsigned char tuplet[4]; + int j; + + for (j = 0; j < 4; j += 1) { + if (srcl) { + if ((src[j] >= 'A') && (src[j] <= 'Z')) { + tuplet[j] = src[j] - 'A'; + } else if ((src[j] >= 'a') && (src[j] <= 'z')) { + tuplet[j] = src[j] - 'a' + 26; + } else if ((src[j] >= '0') && (src[j] <= '9')) { + tuplet[j] = src[j] - '0' + 52; + } else if (src[j] == '.') { + tuplet[j] = 62; + } else if (src[j] == '_') { + tuplet[j] = 63; + } else { + tuplet[j] = 64; + } + srcl--; + } else { + tuplet[j] = 64; + } + } + + *d++ = (tuplet[0] << 2) + ((tuplet[1] & 0x3f) >> 4); + *d++ = (tuplet[1] << 4) + ((tuplet[2] & 0x3f) >> 2); + *d++ = (tuplet[2] << 6) + (tuplet[3] & 0x3f); + } + + return ret; /* return the resulting string */ +} diff --git a/src/xine-utils/base64.h b/src/xine-utils/base64.h new file mode 100644 index 000000000..6a45aebc6 --- /dev/null +++ b/src/xine-utils/base64.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2000 Robert Kaye + * + * This file is part of xine, a free video player. + * + * xine 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, or + * (at your option) any later version. + * + * xine 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * Base64 encoding modified for Musicbrainz + * relicensed under the GNU General Public License for use in xine-lib + * + */ +/* -------------------------------------------------------------------------- + + MusicBrainz -- The Internet music metadatabase + + Copyright (C) 2000 Robert Kaye + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + $Id: base64.h,v 1.1 2004/05/05 09:11:39 hadess Exp $ + +----------------------------------------------------------------------------*/ +/* + * Program: RFC-822 routines (originally from SMTP) + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 27 July 1988 + * Last Edited: 10 September 1998 + * + * Sponsorship: The original version of this work was developed in the + * Symbolic Systems Resources Group of the Knowledge Systems + * Laboratory at Stanford University in 1987-88, and was funded + * by the Biomedical Research Technology Program of the National + * Institutes of Health under grant number RR-00785. + * + * Original version Copyright 1988 by The Leland Stanford Junior University + * Copyright 1998 by the University of Washington + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notices appear in all copies and that both the + * above copyright notices and this permission notice appear in supporting + * documentation, and that the name of the University of Washington or The + * Leland Stanford Junior University not be used in advertising or publicity + * pertaining to distribution of the software without specific, written prior + * permission. This software is made available "as is", and + * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY + * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF + * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef BASE64_H +#define BASE64_H + +unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len); + +unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len); +void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len); + +#endif diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 03c5f689a..9985c133b 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -46,6 +46,7 @@ extern "C" { # include "list.h" # include "array.h" # include "sorted_array.h" +# include "base64.h" #else # ifdef WIN32 # include @@ -61,6 +62,7 @@ extern "C" { # include # include # include +# include #endif #include -- cgit v1.2.3 From 0ce330ec329e1d15a49ae5c5ea4741bcfbf924d3 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Tue, 10 Apr 2007 18:45:53 +0200 Subject: Config entry deserialization. --- src/xine-engine/configfile.c | 228 ++++++++++++++++++++++++++++++++++------- src/xine-engine/configfile.h | 5 +- src/xine-engine/load_plugins.c | 73 ++++++++----- src/xine-utils/base64.c | 10 +- src/xine-utils/base64.h | 4 +- 5 files changed, 252 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index fce6e4a30..22d677e0b 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -34,6 +34,7 @@ #include #include #include +#include "bswap.h" #include "configfile.h" #define LOG_MODULE "configfile" @@ -1210,10 +1211,6 @@ static void config_unset_new_entry_callback (config_values_t *this) { pthread_mutex_unlock(&this->config_lock); } -static void config_register_entry (config_values_t *this, cfg_entry_t* entry) { - /* FIXME: TODO */ -} - static int put_int(uint8_t *buffer, int pos, int value) { int32_t value_int32 = (int32_t)value; @@ -1232,8 +1229,8 @@ static int put_string(uint8_t *buffer, int pos, const char *value, int value_len return 4 + value_len; } -static unsigned char* config_serialize_entry (config_values_t *this, const char *key) { - unsigned char *output = NULL; +static char* config_get_serialized_entry (config_values_t *this, const char *key) { + char *output = NULL; cfg_entry_t *entry, *prev; pthread_mutex_lock(&this->config_lock); @@ -1246,6 +1243,8 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char int range_min; int range_max; int exp_level; + int num_default; + int num_value; char *key; char *str_default; char *description; @@ -1257,6 +1256,12 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char int str_default_len = 0; int description_len = 0; int help_len = 0; + unsigned long output_len; + unsigned long total_len; + int value_count; + int value_len[10]; + int pos = 0; + int i; if (entry->key) key_len = strlen(entry->key); @@ -1269,7 +1274,7 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char // integers // value: 4 bytes - unsigned long total_len = 4 * sizeof(int32_t); + total_len = 6 * sizeof(int32_t); // strings (size + char buffer) // length: 4 bytes @@ -1284,8 +1289,7 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char // for each value: // length: 4 bytes // buffer: length bytes - int value_count = 0; - int value_len[10]; + value_count = 0; total_len += sizeof(int32_t); /* value count */ char **cur_value = entry->enum_values; @@ -1303,32 +1307,31 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char if (!buffer) return NULL; /* Let's go */ - int pos = 0; - // the integers + /* the integers */ pos += put_int(buffer, pos, entry->type); pos += put_int(buffer, pos, entry->range_min); pos += put_int(buffer, pos, entry->range_max); pos += put_int(buffer, pos, entry->exp_level); + pos += put_int(buffer, pos, entry->num_default); + pos += put_int(buffer, pos, entry->num_value); - // the strings + /* the strings */ pos += put_string(buffer, pos, entry->key, key_len); pos += put_string(buffer, pos, entry->str_default, str_default_len); pos += put_string(buffer, pos, entry->description, description_len); pos += put_string(buffer, pos, entry->help, help_len); - // the enum stuff + /* the enum stuff */ pos += put_int(buffer, pos, value_count); cur_value = entry->enum_values; - int i; for (i = 0; i < value_count; i++) { pos += put_string(buffer, pos, *cur_value, value_len[i]); cur_value++; } - // and now the output encoding - unsigned long output_len; + /* and now the output encoding */ output = base64_encode (buffer, total_len, &output_len); free(buffer); @@ -1336,10 +1339,166 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char pthread_mutex_unlock(&this->config_lock); return output; + } -static cfg_entry_t* config_deserialize_entry (config_values_t *this, const char *value) { - /* FIXME: TODO */ +static int get_int(uint8_t *buffer, int buffer_size, int pos, int *value) { + int32_t value_int32; + + if ((pos + sizeof(int32_t)) > buffer_size) + return 0; + + value_int32 = LE_32(&buffer[pos]); + *value = (int)value_int32; + return sizeof(int32_t); +} + +static int get_string(uint8_t *buffer, int buffer_size, int pos, char **value) { + int len; + int bytes = get_int(buffer, buffer_size, pos, &len); + *value = NULL; + + if (!bytes || (len < 0) || (len > 1024*64)) + return 0; + + char *str = malloc(len + 1); + pos += bytes; + memcpy(str, &buffer[pos], len); + str[len] = 0; + + *value = str; + return bytes + len; +} + +static char* config_register_serialized_entry (config_values_t *this, const char *value) { + + /* + fields serialized : + int type; + int range_min; + int range_max; + int exp_level; + int num_default; + int num_value; + char *key; + char *str_default; + char *description; + char *help; + char **enum_values; + */ + int type; + int range_min; + int range_max; + int exp_level; + int num_default; + int num_value; + char *key; + char *str_default; + char *description; + char *help; + char **enum_values; + + int bytes; + int pos; + void *output; + unsigned long output_len; + int value_count; + int i; + + output = base64_decode (value, strlen(value), &output_len); + + pos = 0; + pos += bytes = get_int(output, output_len, pos, &type); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &range_min); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &range_max); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &exp_level); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &num_default); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &num_value); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &key); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &str_default); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &description); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &help); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &value_count); + if (!bytes) goto error; + if ((value_count < 0) || (value_count > 256)) goto error; + + enum_values = malloc (sizeof(void*) * value_count + 1); + for (i = 0; i < value_count; i++) { + pos += bytes = get_string(output, output_len, pos, &enum_values[i]); + if (!bytes) goto error; + } + enum_values[value_count] = NULL; + +#if LOG + printf("config entry deserialization:\n"); + printf(" key : %s\n", key); + printf(" type : %d\n", type); + printf(" exp_level : %d\n", exp_level); + printf(" num_default: %d\n", num_default); + printf(" num_value : %d\n", num_value); + printf(" str_default: %s\n", str_default); + printf(" range_min : %d\n", range_min); + printf(" range_max : %d\n", range_max); + printf(" description: %s\n", description); + printf(" help : %s\n", help); + printf(" enum : %d values\n", value_count); + + for (i = 0; i < value_count; i++) { + printf(" enum[%2d]: %s\n", i, enum_values[i]); + } + printf("\n"); +#endif + + switch (type) { + case XINE_CONFIG_TYPE_STRING: + switch (num_value) { + case 0: + this->register_string(this, key, str_default, description, help, exp_level, NULL, NULL); + default: + this->register_filename(this, key, str_default, num_value, description, help, exp_level, NULL, NULL); + } + break; + case XINE_CONFIG_TYPE_RANGE: + this->register_range(this, key, num_default, range_min, range_max, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_ENUM: + this->register_enum(this, key, num_default, enum_values, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_NUM: + this->register_num(this, key, num_default, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_BOOL: + this->register_bool(this, key, num_default, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_UNKNOWN: + break; + } + + + return key; + +error: + /* serialization error */ return NULL; } @@ -1368,23 +1527,22 @@ config_values_t *_x_config_init (void) { pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&this->config_lock, &attr); - this->register_string = config_register_string; - this->register_filename = config_register_filename; - this->register_range = config_register_range; - this->register_enum = config_register_enum; - this->register_num = config_register_num; - this->register_bool = config_register_bool; - this->update_num = config_update_num; - this->update_string = config_update_string; - this->parse_enum = config_parse_enum; - this->lookup_entry = config_lookup_entry; - this->unregister_callback = config_unregister_cb; - this->dispose = config_dispose; - this->set_new_entry_callback = config_set_new_entry_callback; - this->unset_new_entry_callback = config_unset_new_entry_callback; - this->register_entry = config_register_entry; - this->serialize_entry = config_serialize_entry; - this->deserialize_entry = config_deserialize_entry; + this->register_string = config_register_string; + this->register_filename = config_register_filename; + this->register_range = config_register_range; + this->register_enum = config_register_enum; + this->register_num = config_register_num; + this->register_bool = config_register_bool; + this->register_serialized_entry = config_register_serialized_entry; + this->update_num = config_update_num; + this->update_string = config_update_string; + this->parse_enum = config_parse_enum; + this->lookup_entry = config_lookup_entry; + this->unregister_callback = config_unregister_cb; + this->dispose = config_dispose; + this->set_new_entry_callback = config_set_new_entry_callback; + this->unset_new_entry_callback = config_unset_new_entry_callback; + this->get_serialized_entry = config_get_serialized_entry; return this; } diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h index e1416432b..a4f4b34ec 100644 --- a/src/xine-engine/configfile.h +++ b/src/xine-engine/configfile.h @@ -201,13 +201,14 @@ struct config_values_s { * serialize a config entry. * return a base64 null terminated string. */ - char* (*serialize_entry) (config_values_t *self, const char *key); + char* (*get_serialized_entry) (config_values_t *self, const char *key); /* * deserialize a config entry. * value is a base 64 encoded string + * return the key of the serialized entry */ - cfg_entry_t* (*deserialize_entry) (config_values_t *self, const char *value); + char* (*register_serialized_entry) (config_values_t *self, const char *value); /* diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index b2d2f1d9d..2b7177511 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -64,6 +64,8 @@ #include "xineutils.h" #include "compat.h" +#define LINE_MAX_LENGTH (1024 * 32) /* 32 KiB */ + #if 0 static char *plugin_name; @@ -695,6 +697,15 @@ static inline int _plugin_info_equal(const plugin_info_t *a, return 1; } +static void _attach_entry_to_node (plugin_node_t *node, void *key) { + + if (!node->config_entry_list) { + node->config_entry_list = xine_list_new(); + } + + xine_list_push_back(node->config_entry_list, key); +} + /* * This callback is called by the config entry system when a plugin register a * new config entry. @@ -702,11 +713,7 @@ static inline int _plugin_info_equal(const plugin_info_t *a, static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { plugin_node_t *node = (plugin_node_t *)user_data; - if (!node->config_entry_list) { - node->config_entry_list = xine_list_new(); - } - - xine_list_push_back(node->config_entry_list, (void *)entry->key); + _attach_entry_to_node(node, (void *)entry->key); } static int _load_plugin_class(xine_t *this, @@ -922,16 +929,16 @@ static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { break; } - if (node->config_entry_list) - { + /* config entries */ + if (node->config_entry_list) { xine_list_iterator_t ite = xine_list_front(node->config_entry_list); while (ite) { char *key = xine_list_get_value(node->config_entry_list, ite); /* now get the representation of the config key */ - char *key_value = this->config->serialize_entry(this->config, key); + char *key_value = this->config->get_serialized_entry(this->config, key); - printf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); + lprintf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); fprintf(fp, "config_key=%s\n", key_value); free (key_value); @@ -947,7 +954,7 @@ static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { /* * load plugin list information from file (cached catalog) */ -static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { +static void load_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *plugins) { plugin_node_t *node; plugin_file_t *file; @@ -960,20 +967,29 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { int i; uint64_t llu; unsigned long lu; - char line[1024]; + char *line; char *value; + size_t line_len; int version_ok = 0; + line = malloc(LINE_MAX_LENGTH); + if (!line) + return; + node = NULL; file = NULL; - while (fgets (line, 1023, fp)) { + while (fgets (line, LINE_MAX_LENGTH, fp)) { if (line[0] == '#') continue; - - if( (value = strchr(line, '\r')) || (value = strchr(line, '\n')) ) - *value = (char) 0; /* eliminate any cr/lf */ + line_len = strlen(line); + if (line_len < 3) + continue; + + value = &line[line_len - 1]; + if( (*value == '\r') || (*value == '\n') ) + *value-- = (char) 0; /* eliminate any cr/lf */ - if( (value = strchr(line, '\r')) || (value = strchr(line, '\n')) ) + if( (*value == '\r') || (*value == '\n') ) *value = (char) 0; /* eliminate any cr/lf */ if (line[0] == '[' && version_ok) { @@ -1048,11 +1064,11 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { xine_xmalloc(sizeof(decoder_info_t)); break; - case PLUGIN_POST: - node->info->special_info = post_info = - xine_xmalloc(sizeof(post_info_t)); - break; - } + case PLUGIN_POST: + node->info->special_info = post_info = + xine_xmalloc(sizeof(post_info_t)); + break; + } } else if( !strcmp("api",line) ) { sscanf(value," %d",&i); @@ -1092,8 +1108,15 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { sscanf(value," %d",&i); input_info->priority = i; } else if( !strcmp("post_type",line) && post_info ) { - sscanf(value," %lu",&lu); - post_info->type = lu; + sscanf(value," %lu",&lu); + post_info->type = lu; + } else if( !strcmp("config_key",line) ) { + char* cfg_key; + + cfg_key = this->config->register_serialized_entry(this->config, value); + if (cfg_key != NULL) { + _attach_entry_to_node(node, cfg_key); + } } } } @@ -1102,6 +1125,8 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { if( node ) { xine_sarray_add (plugins, node); } + + free (line); } @@ -1154,7 +1179,7 @@ static void load_cached_catalog (xine_t *this) { sprintf(cachefile, "%s/%s", xine_get_homedir(), relname); if( (fp = fopen(cachefile,"r")) != NULL ) { - load_plugin_list (fp, this->plugin_catalog->cache_list); + load_plugin_list (this, fp, this->plugin_catalog->cache_list); fclose(fp); } free(cachefile); diff --git a/src/xine-utils/base64.c b/src/xine-utils/base64.c index 358cbbada..af6e2eadf 100644 --- a/src/xine-utils/base64.c +++ b/src/xine-utils/base64.c @@ -134,14 +134,14 @@ unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len) return ret; /* return the resulting string */ } -unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len) +char *base64_encode (const void *src, unsigned long srcl, unsigned long *len) { - unsigned char *ret,*d; + char *ret, *d; unsigned char *s = (unsigned char *) src; char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; unsigned long i = ((srcl + 2) / 3) * 4; *len = i; - d = ret = (unsigned char *) malloc ((size_t) ++i); + d = ret = (char *) malloc ((size_t) ++i); for (i = 0; srcl; s += 3) { /* process tuplets */ *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ /* byte 2: low 2 bits (1), high 4 bits (2) */ @@ -157,7 +157,7 @@ unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len) return ret; /* return the resulting string */ } -void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len) +void *base64_decode (const char *src, unsigned long srcl, unsigned long *len) { void *ret; unsigned char *d; @@ -185,7 +185,7 @@ void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len) } srcl--; } else { - tuplet[j] = 64; + (*len)--; } } diff --git a/src/xine-utils/base64.h b/src/xine-utils/base64.h index 6a45aebc6..409d4c64e 100644 --- a/src/xine-utils/base64.h +++ b/src/xine-utils/base64.h @@ -92,7 +92,7 @@ unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len); -unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len); -void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len); +char *base64_encode (const void *src, unsigned long srcl, unsigned long *len); +void *base64_decode (const char *src, unsigned long srcl, unsigned long *len); #endif -- cgit v1.2.3 From 3dc931e217272f0781ef8f7d7ed228467fe5604c Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Wed, 11 Apr 2007 14:49:02 +0200 Subject: Released allocated strings. Added some profiling (XINE_PROFILE). --- src/xine-engine/configfile.c | 60 ++++++++++++++++++++++++------------------ src/xine-engine/load_plugins.c | 23 ++++++++++------ src/xine-engine/xine.c | 3 ++- 3 files changed, 52 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 22d677e0b..294da5700 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1371,7 +1371,6 @@ static int get_string(uint8_t *buffer, int buffer_size, int pos, char **value) { } static char* config_register_serialized_entry (config_values_t *this, const char *value) { - /* fields serialized : int type; @@ -1392,60 +1391,60 @@ static char* config_register_serialized_entry (config_values_t *this, const char int exp_level; int num_default; int num_value; - char *key; - char *str_default; - char *description; - char *help; - char **enum_values; + char *key = NULL; + char *str_default = NULL; + char *description = NULL; + char *help = NULL; + char **enum_values = NULL; int bytes; int pos; - void *output; + void *output = NULL; unsigned long output_len; - int value_count; + int value_count = 0; int i; output = base64_decode (value, strlen(value), &output_len); pos = 0; pos += bytes = get_int(output, output_len, pos, &type); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &range_min); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &range_max); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &exp_level); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &num_default); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &num_value); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &key); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &str_default); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &description); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &help); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &value_count); - if (!bytes) goto error; - if ((value_count < 0) || (value_count > 256)) goto error; + if (!bytes) goto exit; + if ((value_count < 0) || (value_count > 256)) goto exit; enum_values = malloc (sizeof(void*) * value_count + 1); for (i = 0; i < value_count; i++) { pos += bytes = get_string(output, output_len, pos, &enum_values[i]); - if (!bytes) goto error; + if (!bytes) goto exit; } enum_values[value_count] = NULL; @@ -1474,8 +1473,10 @@ static char* config_register_serialized_entry (config_values_t *this, const char switch (num_value) { case 0: this->register_string(this, key, str_default, description, help, exp_level, NULL, NULL); + break; default: this->register_filename(this, key, str_default, num_value, description, help, exp_level, NULL, NULL); + break; } break; case XINE_CONFIG_TYPE_RANGE: @@ -1494,12 +1495,21 @@ static char* config_register_serialized_entry (config_values_t *this, const char break; } +exit: + /* cleanup */ + free(str_default); + free(description); + free(help); + free(output); + + if (enum_values) { + for (i = 0; i < value_count; i++) { + free(enum_values[i]); + } + free(enum_values); + } return key; - -error: - /* serialization error */ - return NULL; } config_values_t *_x_config_init (void) { diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 2b7177511..fc708db13 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -48,6 +48,7 @@ /* #define LOG +#define DEBUG */ #define XINE_ENABLE_EXPERIMENTAL_FEATURES 1 @@ -697,7 +698,7 @@ static inline int _plugin_info_equal(const plugin_info_t *a, return 1; } -static void _attach_entry_to_node (plugin_node_t *node, void *key) { +static void _attach_entry_to_node (plugin_node_t *node, char *key) { if (!node->config_entry_list) { node->config_entry_list = xine_list_new(); @@ -713,7 +714,7 @@ static void _attach_entry_to_node (plugin_node_t *node, void *key) { static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { plugin_node_t *node = (plugin_node_t *)user_data; - _attach_entry_to_node(node, (void *)entry->key); + _attach_entry_to_node(node, strdup(entry->key)); } static int _load_plugin_class(xine_t *this, @@ -935,7 +936,7 @@ static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { while (ite) { char *key = xine_list_get_value(node->config_entry_list, ite); - /* now get the representation of the config key */ + /* now serialize the config key */ char *key_value = this->config->get_serialized_entry(this->config, key); lprintf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); @@ -1205,7 +1206,7 @@ void _x_scan_plugins (xine_t *this) { homedir = strdup(xine_get_homedir()); this->plugin_catalog = _new_catalog(); - load_cached_catalog (this); + XINE_PROFILE(load_cached_catalog (this)); if ((pluginpath = getenv("XINE_PLUGIN_PATH")) != NULL) { pluginpath = strdup(pluginpath); @@ -1227,7 +1228,7 @@ void _x_scan_plugins (xine_t *this) { case XINE_PATH_SEPARATOR_CHAR: case '\0': plugindir[j] = '\0'; - collect_plugins(this, plugindir); + XINE_PROFILE(collect_plugins(this, plugindir)); j = 0; break; case '~': @@ -1244,9 +1245,9 @@ void _x_scan_plugins (xine_t *this) { free(pluginpath); free(homedir); - load_required_plugins (this); + /* load_required_plugins (this); */ - save_catalog (this); + XINE_PROFILE(save_catalog (this)); map_decoders (this); } @@ -2649,7 +2650,13 @@ static void dispose_plugin_list (xine_sarray_t *list) { free (node->info); if (node->config_entry_list) { - xine_list_delete(node->config_entry_list); + xine_list_iterator_t ite = xine_list_front (node->config_entry_list); + while (ite) { + char *key = xine_list_get_value (node->config_entry_list, ite); + free (key); + ite = xine_list_next (node->config_entry_list, ite); + } + xine_list_delete(node->config_entry_list); } free (node); } diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index f49a988c9..32c2d7672 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -51,6 +51,7 @@ #define LOG_VERBOSE /* #define LOG +#define DEBUG */ #define XINE_ENABLE_EXPERIMENTAL_FEATURES @@ -1547,7 +1548,7 @@ void xine_init (xine_t *this) { /* * plugins */ - _x_scan_plugins(this); + XINE_PROFILE(_x_scan_plugins(this)); #ifdef HAVE_SETLOCALE if (!setlocale(LC_CTYPE, "")) -- cgit v1.2.3 From ab2c5817538265f0e8411b3ebabf8ad29bce807b Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 12 Apr 2007 17:15:47 +0200 Subject: Fixed double free problem. --- src/xine-engine/configfile.c | 22 +++++++------ src/xine-engine/load_plugins.c | 71 +++++++++++++++++++++++++--------------- src/xine-engine/plugin_catalog.h | 2 +- 3 files changed, 57 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 294da5700..0d3ec4bd1 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1272,23 +1272,25 @@ static char* config_get_serialized_entry (config_values_t *this, const char *key if (entry->help) help_len = strlen(entry->help); - // integers - // value: 4 bytes + /* integers */ + /* value: 4 bytes */ total_len = 6 * sizeof(int32_t); - // strings (size + char buffer) - // length: 4 bytes - // buffer: length bytes + /* strings (size + char buffer) + * length: 4 bytes + * buffer: length bytes + */ total_len += sizeof(int32_t) + key_len; total_len += sizeof(int32_t) + str_default_len; total_len += sizeof(int32_t) + description_len; total_len += sizeof(int32_t) + help_len; - /* enum values... */ - // value count: 4 bytes - // for each value: - // length: 4 bytes - // buffer: length bytes + /* enum values... + * value count: 4 bytes + * for each value: + * length: 4 bytes + * buffer: length bytes + */ value_count = 0; total_len += sizeof(int32_t); /* value count */ diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index fc708db13..f34b3bb66 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -252,26 +252,26 @@ static void _decoder_priority_cb(void *data, xine_cfg_entry_t *cfg) { map_decoders((xine_t *)data); } -static plugin_info_t *_get_cached_info (xine_t *this, +static plugin_node_t *_get_cached_node (xine_t *this, char *filename, off_t filesize, time_t filemtime, - plugin_info_t *previous_info) { + plugin_node_t *previous_node) { xine_sarray_t *list = this->plugin_catalog->cache_list; int list_id, list_size; list_size = xine_sarray_size (list); for (list_id = 0; list_id < list_size; list_id++) { plugin_node_t *node = xine_sarray_get (list, list_id); - if( !previous_info && + if( !previous_node && node->file->filesize == filesize && node->file->filemtime == filemtime && !strcmp( node->file->filename, filename )) { - return node->info; + return node; } /* skip previously returned items */ - if( node->info == previous_info ) - previous_info = NULL; + if( node == previous_node ) + previous_node = NULL; } return NULL; @@ -301,6 +301,7 @@ static plugin_file_t *_insert_file (xine_t *this, static void _insert_node (xine_t *this, xine_sarray_t *list, plugin_file_t *file, + plugin_node_t *node_cache, plugin_info_t *info, int api_version){ @@ -341,7 +342,7 @@ static void _insert_node (xine_t *this, entry->file = file; entry->ref = 0; entry->priority = 0; /* default priority */ - entry->config_entry_list = NULL; + entry->config_entry_list = (node_cache) ? node_cache->config_entry_list : NULL; switch (info->type & PLUGIN_TYPE_MASK){ @@ -489,7 +490,8 @@ static plugin_catalog_t *_new_catalog(void){ return catalog; } -static void _register_plugins_internal(xine_t *this, plugin_file_t *file, plugin_info_t *info) { +static void _register_plugins_internal(xine_t *this, plugin_file_t *file, + plugin_node_t *node_cache, plugin_info_t *info) { _x_assert(this); _x_assert(info); @@ -515,7 +517,7 @@ static void _register_plugins_internal(xine_t *this, plugin_file_t *file, plugin int plugin_type = info->type & PLUGIN_TYPE_MASK; if ((plugin_type > 0) && (plugin_type <= PLUGIN_TYPE_MAX)) { - _insert_node (this, this->plugin_catalog->plugin_lists[plugin_type - 1], file, info, + _insert_node (this, this->plugin_catalog->plugin_lists[plugin_type - 1], file, node_cache, info, plugin_iface_versions[plugin_type - 1]); if ((plugin_type == PLUGIN_AUDIO_DECODER) || @@ -539,15 +541,17 @@ static void _register_plugins_internal(xine_t *this, plugin_file_t *file, plugin /* get next info */ if( file && !file->lib_handle ) { lprintf("get cached info\n"); - info = _get_cached_info (this, file->filename, file->filesize, file->filemtime, info); + node_cache = _get_cached_node (this, file->filename, file->filesize, file->filemtime, node_cache); + info = (node_cache) ? node_cache->info : NULL; } else { + info++; } } } void xine_register_plugins(xine_t *self, plugin_info_t *info) { - _register_plugins_internal(self, NULL, info); + _register_plugins_internal(self, NULL, NULL, info); } /* @@ -578,6 +582,7 @@ static void collect_plugins(xine_t *this, char *path){ size_t new_str_size, d_len; void *lib = NULL; plugin_info_t *info = NULL; + plugin_node_t *node = NULL; struct stat statbuffer; @@ -620,7 +625,8 @@ static void collect_plugins(xine_t *this, char *path){ lib = NULL; /* get the first plugin_info_t */ - info = _get_cached_info (this, str, statbuffer.st_size, statbuffer.st_mtime, NULL); + node = _get_cached_node (this, str, statbuffer.st_size, statbuffer.st_mtime, NULL); + info = (node) ? node->info : NULL; #ifdef LOG if( info ) printf("load_plugins: using cached %s\n", str); @@ -641,7 +647,7 @@ static void collect_plugins(xine_t *this, char *path){ file = _insert_file(this, this->plugin_catalog->file_list, str, &statbuffer, lib); - _register_plugins_internal(this, file, info); + _register_plugins_internal(this, file, node, info); } else { const char *error = dlerror(); @@ -749,6 +755,7 @@ static int _load_plugin_class(xine_t *this, config_values_t *config = this->config; /* the callback is called for each entry registered by this plugin */ + lprintf("plugin init %s\n", node->info->id); config->set_new_entry_callback(config, _new_entry_cb, node); node->plugin_class = info->init(this, data); config->unset_new_entry_callback(config); @@ -832,8 +839,12 @@ static void _load_required_plugins(xine_t *this, xine_sarray_t *list) { while (list_id < list_size) { plugin_node_t *node = xine_sarray_get(list, list_id); - if( (node->info->type & PLUGIN_MUST_PRELOAD) && !node->plugin_class ) { - + /* + * preload plugins if not cached + */ + if( (node->info->type & PLUGIN_MUST_PRELOAD) && !node->plugin_class && + node->file->lib_handle ) { + lprintf("preload plugin %s from %s\n", node->info->id, node->file->filename); if (! _load_plugin_class (this, node, NULL)) { @@ -1115,8 +1126,11 @@ static void load_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *plugins) { char* cfg_key; cfg_key = this->config->register_serialized_entry(this->config, value); - if (cfg_key != NULL) { + if (cfg_key) { + /* this node is a cached node */ _attach_entry_to_node(node, cfg_key); + } else { + lprintf("failed to deserialize config entry key\n"); } } } @@ -1245,7 +1259,7 @@ void _x_scan_plugins (xine_t *this) { free(pluginpath); free(homedir); - /* load_required_plugins (this); */ + load_required_plugins (this); XINE_PROFILE(save_catalog (this)); @@ -2611,7 +2625,7 @@ char *xine_get_demux_for_mime_type (xine_t *self, const char *mime_type) { } -static void dispose_plugin_list (xine_sarray_t *list) { +static void dispose_plugin_list (xine_sarray_t *list, int is_cache) { plugin_node_t *node; decoder_info_t *decoder_info; @@ -2649,14 +2663,17 @@ static void dispose_plugin_list (xine_sarray_t *list) { free (node->info->id); free (node->info); - if (node->config_entry_list) { - xine_list_iterator_t ite = xine_list_front (node->config_entry_list); - while (ite) { - char *key = xine_list_get_value (node->config_entry_list, ite); - free (key); - ite = xine_list_next (node->config_entry_list, ite); + /* don't free the entry list if the node is cache */ + if (!is_cache) { + if (node->config_entry_list) { + xine_list_iterator_t ite = xine_list_front (node->config_entry_list); + while (ite) { + char *key = xine_list_get_value (node->config_entry_list, ite); + free (key); + ite = xine_list_next (node->config_entry_list, ite); + } + xine_list_delete(node->config_entry_list); } - xine_list_delete(node->config_entry_list); } free (node); } @@ -2690,10 +2707,10 @@ void _x_dispose_plugins (xine_t *this) { int i; for (i = 0; i < PLUGIN_TYPE_MAX; i++) { - dispose_plugin_list (this->plugin_catalog->plugin_lists[i]); + dispose_plugin_list (this->plugin_catalog->plugin_lists[i], 0); } - dispose_plugin_list (this->plugin_catalog->cache_list); + dispose_plugin_list (this->plugin_catalog->cache_list, 1); dispose_plugin_file_list (this->plugin_catalog->file_list); for (i = 0; this->plugin_catalog->prio_desc[i]; i++) diff --git a/src/xine-engine/plugin_catalog.h b/src/xine-engine/plugin_catalog.h index 26905ebff..909756e2b 100644 --- a/src/xine-engine/plugin_catalog.h +++ b/src/xine-engine/plugin_catalog.h @@ -40,7 +40,7 @@ /* the engine takes this many plugins for one stream type */ #define PLUGINS_PER_TYPE 10 -#define CACHE_CATALOG_VERSION 2 +#define CACHE_CATALOG_VERSION 3 #define CACHE_CATALOG_FILE ".xine/catalog.cache" #define CACHE_CATALOG_DIR ".xine" -- cgit v1.2.3 From 7598a6152ba55ef0ff8dda7f1b7729d2bb22a594 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 6 Jun 2007 23:36:19 +0100 Subject: Correctly check for LOG being defined. --HG-- extra : transplant_source : %DFs%84N%8AG%00%5B%EFv%FF%E6%CD%93%23%D8%E6%A1%C2%18 --- src/xine-engine/configfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 0d3ec4bd1..38f2c5a6c 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1450,7 +1450,7 @@ static char* config_register_serialized_entry (config_values_t *this, const char } enum_values[value_count] = NULL; -#if LOG +#ifdef LOG printf("config entry deserialization:\n"); printf(" key : %s\n", key); printf(" type : %d\n", type); -- cgit v1.2.3