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