summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThibaut Mattern <thibaut.mattern@gmail.com>2007-04-06 15:28:37 +0200
committerThibaut Mattern <thibaut.mattern@gmail.com>2007-04-06 15:28:37 +0200
commit42cbd632976d2c9d5293ad03418dce3c7db2797d (patch)
treeafa4457113d404226892fcdb9c7d1d6f413f9acf /src
parent90ec5563d6d3ce1abd5fc52d4aee1b0ecf6c7516 (diff)
downloadxine-lib-42cbd632976d2c9d5293ad03418dce3c7db2797d.tar.gz
xine-lib-42cbd632976d2c9d5293ad03418dce3c7db2797d.tar.bz2
- 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
Diffstat (limited to 'src')
-rw-r--r--src/input/Makefile.am2
-rw-r--r--src/xine-engine/configfile.c136
-rw-r--r--src/xine-engine/configfile.h15
-rw-r--r--src/xine-engine/load_plugins.c45
-rw-r--r--src/xine-utils/Makefile.am6
-rw-r--r--src/xine-utils/base64.c (renamed from src/input/base64.c)63
-rw-r--r--src/xine-utils/base64.h (renamed from src/input/base64.h)3
-rw-r--r--src/xine-utils/xineutils.h2
8 files changed, 253 insertions, 19 deletions
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/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);
@@ -196,6 +198,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:
*/
cfg_entry_t *first, *last, *cur;
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/input/base64.c b/src/xine-utils/base64.c
index 0eccbe84e..358cbbada 100644
--- a/src/input/base64.c
+++ b/src/xine-utils/base64.c
@@ -133,3 +133,66 @@ 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)
+{
+ 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/input/base64.h b/src/xine-utils/base64.h
index 72feef885..6a45aebc6 100644
--- a/src/input/base64.h
+++ b/src/xine-utils/base64.h
@@ -92,4 +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);
+
#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 <winsock.h>
@@ -61,6 +62,7 @@ extern "C" {
# include <xine/list.h>
# include <xine/array.h>
# include <xine/sorted_array.h>
+# include <xine/base64.h>
#endif
#include <stdio.h>