From 50bc9229d375852de44e332a8af151b109ab2f92 Mon Sep 17 00:00:00 2001 From: Harish Krishnaswamy Date: Mon, 12 Dec 2005 16:58:32 +0000 Subject: Remove dead files. Refer 2005-12-12 Harish Krishnaswamy Remove dead files. Refer http://cvs.gnome.org/bonsai/cvsquery.cgi?branch=&dir=evolution&who=vvaradan&date=explicit&mindate=2005-12-12%2011:23&maxdate=2005-12-12%2011:25 for more information. svn path=/trunk/; revision=30759 --- e-util/e-component-listener.c | 171 ------------ e-util/e-component-listener.h | 47 ---- e-util/e-iconv.c | 623 ------------------------------------------ e-util/e-iconv.h | 49 ---- e-util/e-iterator.c | 183 ------------- e-util/e-iterator.h | 71 ----- e-util/e-list-iterator.c | 249 ----------------- e-util/e-list-iterator.h | 46 ---- e-util/e-list.c | 191 ------------- e-util/e-list.h | 71 ----- e-util/e-time-utils.c | 492 --------------------------------- e-util/e-time-utils.h | 58 ---- e-util/e-uid.c | 61 ----- e-util/e-uid.h | 28 -- e-util/md5-utils.c | 355 ------------------------ e-util/md5-utils.h | 52 ---- 16 files changed, 2747 deletions(-) delete mode 100644 e-util/e-component-listener.c delete mode 100644 e-util/e-component-listener.h delete mode 100644 e-util/e-iconv.c delete mode 100644 e-util/e-iconv.h delete mode 100644 e-util/e-iterator.c delete mode 100644 e-util/e-iterator.h delete mode 100644 e-util/e-list-iterator.c delete mode 100644 e-util/e-list-iterator.h delete mode 100644 e-util/e-list.c delete mode 100644 e-util/e-list.h delete mode 100644 e-util/e-time-utils.c delete mode 100644 e-util/e-time-utils.h delete mode 100644 e-util/e-uid.c delete mode 100644 e-util/e-uid.h delete mode 100644 e-util/md5-utils.c delete mode 100644 e-util/md5-utils.h (limited to 'e-util') diff --git a/e-util/e-component-listener.c b/e-util/e-component-listener.c deleted file mode 100644 index 1e7027f33d..0000000000 --- a/e-util/e-component-listener.c +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Component listener. - * - * Author: - * Rodrigo Moya - * - * Copyright 2002, Ximian, Inc. - */ - -#include -#include -#include "e-component-listener.h" -#include - -#define PARENT_TYPE GTK_TYPE_OBJECT - -struct _EComponentListenerPrivate { - Bonobo_Unknown component; -}; - -static void e_component_listener_class_init (EComponentListenerClass *klass); -static void e_component_listener_init (EComponentListener *cl, EComponentListenerClass *klass); -static void e_component_listener_finalize (GObject *object); - -static GObjectClass *parent_class = NULL; -static GList *watched_connections = NULL; - -enum { - COMPONENT_DIED, - LAST_SIGNAL -}; - -static guint comp_listener_signals[LAST_SIGNAL]; - -static void -connection_listen_cb (gpointer object, gpointer user_data) -{ - GList *l, *next = NULL; - EComponentListener *cl; - - for (l = watched_connections; l != NULL; l = next) { - next = l->next; - cl = l->data; - - switch (ORBit_small_get_connection_status (cl->priv->component)) { - case ORBIT_CONNECTION_DISCONNECTED : - watched_connections = g_list_delete_link (watched_connections, l); - - g_object_ref (cl); - g_signal_emit (cl, comp_listener_signals[COMPONENT_DIED], 0); - cl->priv->component = CORBA_OBJECT_NIL; - g_object_unref (cl); - break; - default : - break; - } - } -} - -static void -e_component_listener_class_init (EComponentListenerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = e_component_listener_finalize; - klass->component_died = NULL; - - comp_listener_signals[COMPONENT_DIED] = - g_signal_new ("component_died", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EComponentListenerClass, component_died), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -e_component_listener_init (EComponentListener *cl, EComponentListenerClass *klass) -{ - /* allocate internal structure */ - cl->priv = g_new (EComponentListenerPrivate, 1); - cl->priv->component = CORBA_OBJECT_NIL; -} - -static void -e_component_listener_finalize (GObject *object) -{ - EComponentListener *cl = (EComponentListener *) object; - - g_return_if_fail (E_IS_COMPONENT_LISTENER (cl)); - - watched_connections = g_list_remove (watched_connections, cl); - - if (cl->priv->component != CORBA_OBJECT_NIL) - cl->priv->component = CORBA_OBJECT_NIL; - - /* free memory */ - g_free (cl->priv); - cl->priv = NULL; - - if (G_OBJECT_CLASS (parent_class)->finalize) - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -GType -e_component_listener_get_type (void) -{ - static GType type = 0; - - if (!type) { - static GTypeInfo info = { - sizeof (EComponentListenerClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) e_component_listener_class_init, - NULL, NULL, - sizeof (EComponentListener), - 0, - (GInstanceInitFunc) e_component_listener_init - }; - type = g_type_register_static (G_TYPE_OBJECT, "EComponentListener", &info, 0); - } - - return type; -} - -/** - * e_component_listener_new - * @comp: Component to listen for. - * - * Create a new #EComponentListener object, which allows to listen - * for a given component and get notified when that component dies. - * - * Returns: a component listener object. - */ -EComponentListener * -e_component_listener_new (Bonobo_Unknown comp) -{ - EComponentListener *cl; - - g_return_val_if_fail (comp != NULL, NULL); - - cl = g_object_new (E_COMPONENT_LISTENER_TYPE, NULL); - cl->priv->component = comp; - - /* watch the connection */ - ORBit_small_listen_for_broken (comp, G_CALLBACK (connection_listen_cb), cl); - watched_connections = g_list_prepend (watched_connections, cl); - - return cl; -} - -Bonobo_Unknown -e_component_listener_get_component (EComponentListener *cl) -{ - g_return_val_if_fail (E_IS_COMPONENT_LISTENER (cl), CORBA_OBJECT_NIL); - return cl->priv->component; -} - -void -e_component_listener_set_component (EComponentListener *cl, Bonobo_Unknown comp) -{ - g_return_if_fail (E_IS_COMPONENT_LISTENER (cl)); - - cl->priv->component = comp; - ORBit_small_listen_for_broken (comp, G_CALLBACK (connection_listen_cb), cl); -} diff --git a/e-util/e-component-listener.h b/e-util/e-component-listener.h deleted file mode 100644 index 3f5694ecd0..0000000000 --- a/e-util/e-component-listener.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Component listener - * - * Author: - * Rodrigo Moya - * - * Copyright 2002, Ximian, Inc. - */ - -#ifndef __E_COMPONENT_LISTENER_H__ -#define __E_COMPONENT_LISTENER_H__ - -#include -#include - -G_BEGIN_DECLS - -#define E_COMPONENT_LISTENER_TYPE (e_component_listener_get_type ()) -#define E_COMPONENT_LISTENER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), E_COMPONENT_LISTENER_TYPE, EComponentListener)) -#define E_COMPONENT_LISTENER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), E_COMPONENT_LISTENER_TYPE, EComponentListenerClass)) -#define E_IS_COMPONENT_LISTENER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_COMPONENT_LISTENER_TYPE)) -#define E_IS_COMPONENT_LISTENER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), E_COMPONENT_LISTENER_TYPE)) - -typedef struct _EComponentListenerPrivate EComponentListenerPrivate; - -typedef struct { - GObject object; - EComponentListenerPrivate *priv; -} EComponentListener; - -typedef struct { - GObjectClass parent_class; - - void (* component_died) (EComponentListener *cl); -} EComponentListenerClass; - -GType e_component_listener_get_type (void); -EComponentListener *e_component_listener_new (Bonobo_Unknown comp); - -Bonobo_Unknown e_component_listener_get_component (EComponentListener *cl); -void e_component_listener_set_component (EComponentListener *cl, - Bonobo_Unknown comp); - -G_END_DECLS - -#endif diff --git a/e-util/e-iconv.c b/e-util/e-iconv.c deleted file mode 100644 index 65f19b3b4a..0000000000 --- a/e-util/e-iconv.c +++ /dev/null @@ -1,623 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-iconv.c - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Michael Zucchi - * Jeffery Stedfast - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library 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. - */ - -#include - -#include -#include -#include -#include -#include -#ifdef HAVE_CODESET -#include -#endif - -#include - -#include "iconv-detect.h" -#include "e-iconv.h" - -#define cd(x) - -#ifdef G_THREADS_ENABLED -static GStaticMutex lock = G_STATIC_MUTEX_INIT; -#define LOCK() g_static_mutex_lock(&lock) -#define UNLOCK() g_static_mutex_unlock(&lock) -#else -#define LOCK() -#define UNLOCK() -#endif - -typedef struct _EDListNode { - struct _EDListNode *next; - struct _EDListNode *prev; -} EDListNode; - -typedef struct _EDList { - struct _EDListNode *head; - struct _EDListNode *tail; - struct _EDListNode *tailpred; -} EDList; - -#define E_DLIST_INITIALISER(l) { (EDListNode *)&l.tail, 0, (EDListNode *)&l.head } - -struct _iconv_cache_node { - struct _iconv_cache_node *next; - struct _iconv_cache_node *prev; - - struct _iconv_cache *parent; - - int busy; - iconv_t ip; -}; - -struct _iconv_cache { - struct _iconv_cache *next; - struct _iconv_cache *prev; - - char *conv; - - EDList open; /* stores iconv_cache_nodes, busy ones up front */ -}; - -#define E_ICONV_CACHE_SIZE (16) - -static EDList iconv_cache_list; -static GHashTable *iconv_cache; -static GHashTable *iconv_cache_open; -static unsigned int iconv_cache_size = 0; - -static GHashTable *iconv_charsets = NULL; -static char *locale_charset = NULL; -static char *locale_lang = NULL; - -struct { - char *charset; - char *iconv_name; -} known_iconv_charsets[] = { -#if 0 - /* charset name, iconv-friendly charset name */ - { "iso-8859-1", "iso-8859-1" }, - { "iso8859-1", "iso-8859-1" }, - /* the above mostly serves as an example for iso-style charsets, - but we have code that will populate the iso-*'s if/when they - show up in e_iconv_charset_name() so I'm - not going to bother putting them all in here... */ - { "windows-cp1251", "cp1251" }, - { "windows-1251", "cp1251" }, - { "cp1251", "cp1251" }, - /* the above mostly serves as an example for windows-style - charsets, but we have code that will parse and convert them - to their cp#### equivalents if/when they show up in - e_iconv_charset_name() so I'm not going to bother - putting them all in here either... */ -#endif - /* charset name (lowercase!), iconv-friendly name (sometimes case sensitive) */ - { "utf-8", "UTF-8" }, - - /* 10646 is a special case, its usually UCS-2 big endian */ - /* This might need some checking but should be ok for solaris/linux */ - { "iso-10646-1", "UCS-2BE" }, - { "iso_10646-1", "UCS-2BE" }, - { "iso10646-1", "UCS-2BE" }, - { "iso-10646", "UCS-2BE" }, - { "iso_10646", "UCS-2BE" }, - { "iso10646", "UCS-2BE" }, - - { "ks_c_5601-1987", "EUC-KR" }, - - /* FIXME: Japanese/Korean/Chinese stuff needs checking */ - { "euckr-0", "EUC-KR" }, - { "5601", "EUC-KR" }, - { "zh_TW-euc", "EUC-TW" }, - { "zh_CN.euc", "gb2312" }, - { "zh_TW-big5", "BIG5" }, - { "euc-cn", "gb2312" }, - { "big5-0", "BIG5" }, - { "big5.eten-0", "BIG5" }, - { "big5hkscs-0", "BIG5HKSCS" }, - { "gb2312-0", "gb2312" }, - { "gb2312.1980-0", "gb2312" }, - { "gb-2312", "gb2312" }, - { "gb18030-0", "gb18030" }, - { "gbk-0", "GBK" }, - - { "eucjp-0", "eucJP" }, - { "ujis-0", "ujis" }, - { "jisx0208.1983-0","SJIS" }, - { "jisx0212.1990-0","SJIS" }, - { "pck", "SJIS" }, - { NULL, NULL } -}; - - - -/* Another copy of this trivial list implementation - Why? This stuff gets called a lot (potentially), should run fast, - and g_list's are f@@#$ed up to make this a hassle */ -static void e_dlist_init(EDList *v) -{ - v->head = (EDListNode *)&v->tail; - v->tail = 0; - v->tailpred = (EDListNode *)&v->head; -} - -static EDListNode *e_dlist_addhead(EDList *l, EDListNode *n) -{ - n->next = l->head; - n->prev = (EDListNode *)&l->head; - l->head->prev = n; - l->head = n; - return n; -} - -static EDListNode *e_dlist_addtail(EDList *l, EDListNode *n) -{ - n->next = (EDListNode *)&l->tail; - n->prev = l->tailpred; - l->tailpred->next = n; - l->tailpred = n; - return n; -} - -static EDListNode *e_dlist_remove(EDListNode *n) -{ - n->next->prev = n->prev; - n->prev->next = n->next; - return n; -} - - -/* fucking glib... */ -static const char * -e_strdown (char *str) -{ - register char *s = str; - - while (*s) { - if (*s >= 'A' && *s <= 'Z') - *s += 0x20; - s++; - } - - return str; -} - -static const char * -e_strup (char *str) -{ - register char *s = str; - - while (*s) { - if (*s >= 'a' && *s <= 'z') - *s -= 0x20; - s++; - } - - return str; -} - - -static void -locale_parse_lang (const char *locale) -{ - char *codeset, *lang; - - if ((codeset = strchr (locale, '.'))) - lang = g_strndup (locale, codeset - locale); - else - lang = g_strdup (locale); - - /* validate the language */ - if (strlen (lang) >= 2) { - if (lang[2] == '-' || lang[2] == '_') { - /* canonicalise the lang */ - e_strdown (lang); - - /* validate the country code */ - if (strlen (lang + 3) > 2) { - /* invalid country code */ - lang[2] = '\0'; - } else { - lang[2] = '-'; - e_strup (lang + 3); - } - } else if (lang[2] != '\0') { - /* invalid language */ - g_free (lang); - lang = NULL; - } - - locale_lang = lang; - } else { - /* invalid language */ - locale_lang = NULL; - g_free (lang); - } -} - -/* NOTE: Owns the lock on return if keep is TRUE ! */ -static void -e_iconv_init(int keep) -{ - char *from, *to, *locale; - int i; - - LOCK(); - - if (iconv_charsets != NULL) { - if (!keep) - UNLOCK(); - return; - } - - iconv_charsets = g_hash_table_new(g_str_hash, g_str_equal); - - for (i = 0; known_iconv_charsets[i].charset != NULL; i++) { - from = g_strdup(known_iconv_charsets[i].charset); - to = g_strdup(known_iconv_charsets[i].iconv_name); - e_strdown (from); - g_hash_table_insert(iconv_charsets, from, to); - } - - e_dlist_init(&iconv_cache_list); - iconv_cache = g_hash_table_new(g_str_hash, g_str_equal); - iconv_cache_open = g_hash_table_new(NULL, NULL); - -#ifndef G_OS_WIN32 - locale = setlocale (LC_ALL, NULL); -#else - locale = g_win32_getlocale (); -#endif - - if (!locale || !strcmp (locale, "C") || !strcmp (locale, "POSIX")) { - /* The locale "C" or "POSIX" is a portable locale; its - * LC_CTYPE part corresponds to the 7-bit ASCII character - * set. - */ - - locale_charset = NULL; - locale_lang = NULL; - } else { -#ifdef G_OS_WIN32 - g_get_charset (&locale_charset); - locale_charset = g_strdup (locale_charset); - e_strdown (locale_charset); -#else -#ifdef HAVE_CODESET - locale_charset = g_strdup (nl_langinfo (CODESET)); - e_strdown (locale_charset); -#else - /* A locale name is typically of the form language[_terri- - * tory][.codeset][@modifier], where language is an ISO 639 - * language code, territory is an ISO 3166 country code, and - * codeset is a character set or encoding identifier like - * ISO-8859-1 or UTF-8. - */ - char *codeset, *p; - - codeset = strchr (locale, '.'); - if (codeset) { - codeset++; - - /* ; is a hack for debian systems and / is a hack for Solaris systems */ - for (p = codeset; *p && !strchr ("@;/", *p); p++); - locale_charset = g_strndup (codeset, p - codeset); - e_strdown (locale_charset); - } else { - /* charset unknown */ - locale_charset = NULL; - } -#endif -#endif /* !G_OS_WIN32 */ - - /* parse the locale lang */ - locale_parse_lang (locale); - - } - -#ifdef G_OS_WIN32 - g_free (locale); -#endif - if (!keep) - UNLOCK(); -} - -const char *e_iconv_charset_name(const char *charset) -{ - char *name, *ret, *tmp; - - if (charset == NULL) - return NULL; - - name = g_alloca (strlen (charset) + 1); - strcpy (name, charset); - e_strdown (name); - - e_iconv_init(TRUE); - ret = g_hash_table_lookup(iconv_charsets, name); - if (ret != NULL) { - UNLOCK(); - return ret; - } - - /* Unknown, try canonicalise some basic charset types to something that should work */ - if (strncmp(name, "iso", 3) == 0) { - /* Convert iso-nnnn-n or isonnnn-n or iso_nnnn-n to iso-nnnn-n or isonnnn-n */ - int iso, codepage; - char *p; - - tmp = name + 3; - if (*tmp == '-' || *tmp == '_') - tmp++; - - iso = strtoul (tmp, &p, 10); - - if (iso == 10646) { - /* they all become ICONV_10646 */ - ret = g_strdup (ICONV_10646); - } else { - tmp = p; - if (*tmp == '-' || *tmp == '_') - tmp++; - - codepage = strtoul (tmp, &p, 10); - - if (p > tmp) { - /* codepage is numeric */ -#ifdef __aix__ - if (codepage == 13) - ret = g_strdup ("IBM-921"); - else -#endif /* __aix__ */ - ret = g_strdup_printf (ICONV_ISO_D_FORMAT, iso, codepage); - } else { - /* codepage is a string - probably iso-2022-jp or something */ - ret = g_strdup_printf (ICONV_ISO_S_FORMAT, iso, p); - } - } - } else if (strncmp(name, "windows-", 8) == 0) { - /* Convert windows-nnnnn or windows-cpnnnnn to cpnnnn */ - tmp = name+8; - if (!strncmp(tmp, "cp", 2)) - tmp+=2; - ret = g_strdup_printf("CP%s", tmp); - } else if (strncmp(name, "microsoft-", 10) == 0) { - /* Convert microsoft-nnnnn or microsoft-cpnnnnn to cpnnnn */ - tmp = name+10; - if (!strncmp(tmp, "cp", 2)) - tmp+=2; - ret = g_strdup_printf("CP%s", tmp); - } else { - /* Just assume its ok enough as is, case and all */ - ret = g_strdup(charset); - } - - g_hash_table_insert(iconv_charsets, g_strdup(name), ret); - UNLOCK(); - - return ret; -} - -static void -flush_entry(struct _iconv_cache *ic) -{ - struct _iconv_cache_node *in, *nn; - - in = (struct _iconv_cache_node *)ic->open.head; - nn = in->next; - while (nn) { - if (in->ip != (iconv_t)-1) { - g_hash_table_remove(iconv_cache_open, in->ip); - iconv_close(in->ip); - } - g_free(in); - in = nn; - nn = in->next; - } - g_free(ic->conv); - g_free(ic); -} - -/* This should run pretty quick, its called a lot */ -iconv_t e_iconv_open(const char *oto, const char *ofrom) -{ - const char *to, *from; - char *tofrom; - struct _iconv_cache *ic; - struct _iconv_cache_node *in; - int errnosav; - iconv_t ip; - - if (oto == NULL || ofrom == NULL) { - errno = EINVAL; - return (iconv_t) -1; - } - - to = e_iconv_charset_name (oto); - from = e_iconv_charset_name (ofrom); - tofrom = g_alloca (strlen (to) + strlen (from) + 2); - sprintf(tofrom, "%s%%%s", to, from); - - LOCK(); - - ic = g_hash_table_lookup(iconv_cache, tofrom); - if (ic) { - e_dlist_remove((EDListNode *)ic); - } else { - struct _iconv_cache *last = (struct _iconv_cache *)iconv_cache_list.tailpred; - struct _iconv_cache *prev; - - prev = last->prev; - while (prev && iconv_cache_size > E_ICONV_CACHE_SIZE) { - in = (struct _iconv_cache_node *)last->open.head; - if (in->next && !in->busy) { - cd(printf("Flushing iconv converter '%s'\n", last->conv)); - e_dlist_remove((EDListNode *)last); - g_hash_table_remove(iconv_cache, last->conv); - flush_entry(last); - iconv_cache_size--; - } - last = prev; - prev = last->prev; - } - - iconv_cache_size++; - - ic = g_malloc(sizeof(*ic)); - e_dlist_init(&ic->open); - ic->conv = g_strdup(tofrom); - g_hash_table_insert(iconv_cache, ic->conv, ic); - - cd(printf("Creating iconv converter '%s'\n", ic->conv)); - } - e_dlist_addhead(&iconv_cache_list, (EDListNode *)ic); - - /* If we have a free iconv, use it */ - in = (struct _iconv_cache_node *)ic->open.tailpred; - if (in->prev && !in->busy) { - cd(printf("using existing iconv converter '%s'\n", ic->conv)); - ip = in->ip; - if (ip != (iconv_t)-1) { - /* work around some broken iconv implementations - * that die if the length arguments are NULL - */ - size_t buggy_iconv_len = 0; - char *buggy_iconv_buf = NULL; - - /* resets the converter */ - iconv(ip, &buggy_iconv_buf, &buggy_iconv_len, &buggy_iconv_buf, &buggy_iconv_len); - in->busy = TRUE; - e_dlist_remove((EDListNode *)in); - e_dlist_addhead(&ic->open, (EDListNode *)in); - } - } else { - cd(printf("creating new iconv converter '%s'\n", ic->conv)); - ip = iconv_open(to, from); - in = g_malloc(sizeof(*in)); - in->ip = ip; - in->parent = ic; - e_dlist_addhead(&ic->open, (EDListNode *)in); - if (ip != (iconv_t)-1) { - g_hash_table_insert(iconv_cache_open, ip, in); - in->busy = TRUE; - } else { - errnosav = errno; - g_warning("Could not open converter for '%s' to '%s' charset", from, to); - in->busy = FALSE; - errno = errnosav; - } - } - - UNLOCK(); - - return ip; -} - -size_t e_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char ** outbuf, size_t *outbytesleft) -{ - return iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft); -} - -void -e_iconv_close(iconv_t ip) -{ - struct _iconv_cache_node *in; - - if (ip == (iconv_t)-1) - return; - - LOCK(); - in = g_hash_table_lookup(iconv_cache_open, ip); - if (in) { - cd(printf("closing iconv converter '%s'\n", in->parent->conv)); - e_dlist_remove((EDListNode *)in); - in->busy = FALSE; - e_dlist_addtail(&in->parent->open, (EDListNode *)in); - } else { - g_warning("trying to close iconv i dont know about: %p", ip); - iconv_close(ip); - } - UNLOCK(); - -} - -const char *e_iconv_locale_charset(void) -{ - e_iconv_init(FALSE); - - return locale_charset; -} - - -const char * -e_iconv_locale_language (void) -{ - e_iconv_init (FALSE); - - return locale_lang; -} - -/* map CJKR charsets to their language code */ -/* NOTE: only support charset names that will be returned by - * e_iconv_charset_name() so that we don't have to keep track of all - * the aliases too. */ -static struct { - char *charset; - char *lang; -} cjkr_lang_map[] = { - { "Big5", "zh" }, - { "BIG5HKSCS", "zh" }, - { "gb2312", "zh" }, - { "gb18030", "zh" }, - { "gbk", "zh" }, - { "euc-tw", "zh" }, - { "iso-2022-jp", "ja" }, - { "sjis", "ja" }, - { "ujis", "ja" }, - { "eucJP", "ja" }, - { "euc-jp", "ja" }, - { "euc-kr", "ko" }, - { "koi8-r", "ru" }, - { "koi8-u", "uk" } -}; - -#define NUM_CJKR_LANGS (sizeof (cjkr_lang_map) / sizeof (cjkr_lang_map[0])) - -const char * -e_iconv_charset_language (const char *charset) -{ - int i; - - if (!charset) - return NULL; - - charset = e_iconv_charset_name (charset); - for (i = 0; i < NUM_CJKR_LANGS; i++) { - if (!strcasecmp (cjkr_lang_map[i].charset, charset)) - return cjkr_lang_map[i].lang; - } - - return NULL; -} diff --git a/e-util/e-iconv.h b/e-util/e-iconv.h deleted file mode 100644 index 14b93853d5..0000000000 --- a/e-util/e-iconv.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-iconv.h - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Michael Zucchi - * Jeffrey Stedfast - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License, version 2, as published by the Free Software Foundation. - * - * 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library 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. - */ - -#ifndef _E_ICONV_H_ -#define _E_ICONV_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -const char *e_iconv_charset_name(const char *charset); -iconv_t e_iconv_open(const char *oto, const char *ofrom); -size_t e_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char ** outbuf, size_t *outbytesleft); -void e_iconv_close(iconv_t ip); -const char *e_iconv_locale_charset(void); - -/* languages */ -const char *e_iconv_locale_language (void); -const char *e_iconv_charset_language (const char *charset); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* !_E_ICONV_H_ */ diff --git a/e-util/e-iterator.c b/e-util/e-iterator.c deleted file mode 100644 index aa7a338eff..0000000000 --- a/e-util/e-iterator.c +++ /dev/null @@ -1,183 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Christopher James Lahey - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include - -#include "e-iterator.h" -#include "e-util-marshal.h" - -static void e_iterator_init (EIterator *card); -static void e_iterator_class_init (EIteratorClass *klass); - -#define PARENT_TYPE G_TYPE_OBJECT - -static GObjectClass *parent_class; - -enum { - INVALIDATE, - LAST_SIGNAL -}; - -static guint e_iterator_signals [LAST_SIGNAL] = { 0, }; - -/** - * e_iterator_get_type: - * @void: - * - * Registers the &EIterator class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EIterator class. - **/ -GType -e_iterator_get_type (void) -{ - static GType type = 0; - - if (! type) { - GTypeInfo info = { - sizeof (EIteratorClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) e_iterator_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EIterator), - 0, /* n_preallocs */ - (GInstanceInitFunc) e_iterator_init - }; - - type = g_type_register_static (PARENT_TYPE, "EIterator", &info, 0); - } - - return type; -} - -static void -e_iterator_class_init (EIteratorClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS(klass); - - parent_class = g_type_class_ref (PARENT_TYPE); - - e_iterator_signals [INVALIDATE] = - g_signal_new ("invalidate", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EIteratorClass, invalidate), - NULL, NULL, - e_util_marshal_NONE__NONE, /* XXX need a new marshaller here */ - G_TYPE_NONE, 0); - - klass->invalidate = NULL; - klass->get = NULL; - klass->reset = NULL; - klass->last = NULL; - klass->next = NULL; - klass->prev = NULL; - klass->remove = NULL; - klass->insert = NULL; - klass->set = NULL; - klass->is_valid = NULL; -} - -/** - * e_iterator_init: - */ -static void -e_iterator_init (EIterator *card) -{ -} - -/* - * Virtual functions: - */ -const void * -e_iterator_get (EIterator *iterator) -{ - if (E_ITERATOR_GET_CLASS(iterator)->get) - return E_ITERATOR_GET_CLASS(iterator)->get(iterator); - else - return NULL; -} - -void -e_iterator_reset (EIterator *iterator) -{ - if (E_ITERATOR_GET_CLASS(iterator)->reset) - E_ITERATOR_GET_CLASS(iterator)->reset(iterator); -} - -void -e_iterator_last (EIterator *iterator) -{ - if (E_ITERATOR_GET_CLASS(iterator)->last) - E_ITERATOR_GET_CLASS(iterator)->last(iterator); -} - -gboolean -e_iterator_next (EIterator *iterator) -{ - if (E_ITERATOR_GET_CLASS(iterator)->next) - return E_ITERATOR_GET_CLASS(iterator)->next(iterator); - else - return FALSE; -} - -gboolean -e_iterator_prev (EIterator *iterator) -{ - if (E_ITERATOR_GET_CLASS(iterator)->prev) - return E_ITERATOR_GET_CLASS(iterator)->prev(iterator); - else - return FALSE; -} - -void -e_iterator_delete (EIterator *iterator) -{ - if (E_ITERATOR_GET_CLASS(iterator)->remove) - E_ITERATOR_GET_CLASS(iterator)->remove(iterator); -} - -void e_iterator_insert (EIterator *iterator, - const void *object, - gboolean before) -{ - if (E_ITERATOR_GET_CLASS(iterator)->insert) - E_ITERATOR_GET_CLASS(iterator)->insert(iterator, object, before); -} - -void -e_iterator_set (EIterator *iterator, - const void *object) -{ - if (E_ITERATOR_GET_CLASS(iterator)->set) - E_ITERATOR_GET_CLASS(iterator)->set(iterator, object); -} - -gboolean -e_iterator_is_valid (EIterator *iterator) -{ - if (E_ITERATOR_GET_CLASS(iterator)->is_valid) - return E_ITERATOR_GET_CLASS(iterator)->is_valid(iterator); - else - return FALSE; -} - -void -e_iterator_invalidate (EIterator *iterator) -{ - g_return_if_fail (iterator != NULL); - g_return_if_fail (E_IS_ITERATOR (iterator)); - - g_signal_emit (iterator, e_iterator_signals [INVALIDATE], 0); -} diff --git a/e-util/e-iterator.h b/e-util/e-iterator.h deleted file mode 100644 index da25bd8ab6..0000000000 --- a/e-util/e-iterator.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_ITERATOR_H__ -#define __E_ITERATOR_H__ - -#include -#include -#include -#include - -#define E_TYPE_ITERATOR (e_iterator_get_type ()) -#define E_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_ITERATOR, EIterator)) -#define E_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_ITERATOR, EIteratorClass)) -#define E_IS_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_ITERATOR)) -#define E_IS_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_ITERATOR)) -#define E_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_ITERATOR, EIteratorClass)) - -typedef struct _EIterator EIterator; -typedef struct _EIteratorClass EIteratorClass; - -struct _EIterator { - GObject object; -}; - -struct _EIteratorClass { - GObjectClass parent_class; - - /* Signals */ - void (*invalidate) (EIterator *iterator); - - /* Virtual functions */ - const void * (*get) (EIterator *iterator); - void (*reset) (EIterator *iterator); - void (*last) (EIterator *iterator); - gboolean (*next) (EIterator *iterator); - gboolean (*prev) (EIterator *iterator); - void (*remove) (EIterator *iterator); - void (*insert) (EIterator *iterator, - const void *object, - gboolean before); - void (*set) (EIterator *iterator, - const void *object); - gboolean (*is_valid) (EIterator *iterator); -}; - -const void *e_iterator_get (EIterator *iterator); -void e_iterator_reset (EIterator *iterator); -void e_iterator_last (EIterator *iterator); -gboolean e_iterator_next (EIterator *iterator); -gboolean e_iterator_prev (EIterator *iterator); -void e_iterator_delete (EIterator *iterator); -void e_iterator_insert (EIterator *iterator, - const void *object, - gboolean before); -void e_iterator_set (EIterator *iterator, - const void *object); -gboolean e_iterator_is_valid (EIterator *iterator); - -void e_iterator_invalidate (EIterator *iterator); - -/* Standard Glib function */ -GType e_iterator_get_type (void); - -#endif /* ! __E_ITERATOR_H__ */ diff --git a/e-util/e-list-iterator.c b/e-util/e-list-iterator.c deleted file mode 100644 index 2f7e2aa953..0000000000 --- a/e-util/e-list-iterator.c +++ /dev/null @@ -1,249 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Christopher James Lahey - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include - -#include "e-list-iterator.h" -#include "e-list.h" - - -static void e_list_iterator_init (EListIterator *list); -static void e_list_iterator_class_init (EListIteratorClass *klass); - -static void e_list_iterator_invalidate (EIterator *iterator); -static gboolean e_list_iterator_is_valid (EIterator *iterator); -static void e_list_iterator_set (EIterator *iterator, - const void *object); -static void e_list_iterator_remove (EIterator *iterator); -static void e_list_iterator_insert (EIterator *iterator, - const void *object, - gboolean before); -static gboolean e_list_iterator_prev (EIterator *iterator); -static gboolean e_list_iterator_next (EIterator *iterator); -static void e_list_iterator_reset (EIterator *iterator); -static void e_list_iterator_last (EIterator *iterator); -static const void *e_list_iterator_get (EIterator *iterator); -static void e_list_iterator_dispose (GObject *object); - -#define PARENT_TYPE E_TYPE_ITERATOR - -static EIteratorClass *parent_class; - -/** - * e_list_iterator_get_type: - * @void: - * - * Registers the &EListIterator class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EListIterator class. - **/ -GType -e_list_iterator_get_type (void) -{ - static GType type = 0; - - if (! type) { - GTypeInfo info = { - sizeof (EListIteratorClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) e_list_iterator_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EListIterator), - 0, /* n_preallocs */ - (GInstanceInitFunc) e_list_iterator_init - }; - - type = g_type_register_static (PARENT_TYPE, "EListIterator", &info, 0); - } - - return type; -} - -static void -e_list_iterator_class_init (EListIteratorClass *klass) -{ - GObjectClass *object_class; - EIteratorClass *iterator_class; - - object_class = G_OBJECT_CLASS(klass); - iterator_class = E_ITERATOR_CLASS(klass); - - parent_class = g_type_class_ref (PARENT_TYPE); - - object_class->dispose = e_list_iterator_dispose; - - iterator_class->invalidate = e_list_iterator_invalidate; - iterator_class->get = e_list_iterator_get; - iterator_class->reset = e_list_iterator_reset; - iterator_class->last = e_list_iterator_last; - iterator_class->next = e_list_iterator_next; - iterator_class->prev = e_list_iterator_prev; - iterator_class->remove = e_list_iterator_remove; - iterator_class->insert = e_list_iterator_insert; - iterator_class->set = e_list_iterator_set; - iterator_class->is_valid = e_list_iterator_is_valid; -} - - - -/** - * e_list_iterator_init: - */ -static void -e_list_iterator_init (EListIterator *list) -{ -} - -EIterator * -e_list_iterator_new (EList *list) -{ - EListIterator *iterator = g_object_new (E_TYPE_LIST_ITERATOR, NULL); - - iterator->list = list; - g_object_ref(list); - iterator->iterator = list->list; - - return E_ITERATOR(iterator); -} - -/* - * Virtual functions: - */ -static void -e_list_iterator_dispose (GObject *object) -{ - EListIterator *iterator = E_LIST_ITERATOR(object); - e_list_remove_iterator(iterator->list, E_ITERATOR(iterator)); - g_object_unref(iterator->list); - - if (G_OBJECT_CLASS (parent_class)->dispose) - (* G_OBJECT_CLASS (parent_class)->dispose) (object); -} - -static const void * -e_list_iterator_get (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) - return iterator->iterator->data; - else - return NULL; -} - -static void -e_list_iterator_reset (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - iterator->iterator = iterator->list->list; -} - -static void -e_list_iterator_last (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - iterator->iterator = g_list_last(iterator->list->list); -} - -static gboolean -e_list_iterator_next (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) - iterator->iterator = g_list_next(iterator->iterator); - else - iterator->iterator = iterator->list->list; - return (iterator->iterator != NULL); -} - -static gboolean -e_list_iterator_prev (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) - iterator->iterator = g_list_previous(iterator->iterator); - else - iterator->iterator = g_list_last(iterator->list->list); - return (iterator->iterator != NULL); -} - -static void -e_list_iterator_insert (EIterator *_iterator, - const void *object, - gboolean before) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - void *data; - if (iterator->list->copy) - data = iterator->list->copy(object, iterator->list->closure); - else - data = (void *) object; - if (iterator->iterator) { - if (before) { - iterator->list->list = g_list_first(g_list_prepend(iterator->iterator, data)); - iterator->iterator = iterator->iterator->prev; - } else { - if (iterator->iterator->next) - g_list_prepend(iterator->iterator->next, data); - else - g_list_append(iterator->iterator, data); - iterator->iterator = iterator->iterator->next; - } - e_list_invalidate_iterators(iterator->list, E_ITERATOR(iterator)); - } else { - if (before) { - iterator->list->list = g_list_append(iterator->list->list, data); - iterator->iterator = g_list_last(iterator->list->list); - } else { - iterator->list->list = g_list_prepend(iterator->list->list, data); - iterator->iterator = iterator->list->list; - } - e_list_invalidate_iterators(iterator->list, E_ITERATOR(iterator)); - } -} - -static void -e_list_iterator_remove (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) { - e_list_remove_link (iterator->list, iterator->iterator); - } -} - -static void -e_list_iterator_set (EIterator *_iterator, - const void *object) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) { - if (iterator->list->free) - iterator->list->free(iterator->iterator->data, iterator->list->closure); - if (iterator->list->copy) - iterator->iterator->data = iterator->list->copy(object, iterator->list->closure); - else - iterator->iterator->data = (void *) object; - } -} - -static gboolean -e_list_iterator_is_valid (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - return iterator->iterator != NULL; -} - -static void -e_list_iterator_invalidate (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - iterator->iterator = NULL; -} diff --git a/e-util/e-list-iterator.h b/e-util/e-list-iterator.h deleted file mode 100644 index b3a8953d80..0000000000 --- a/e-util/e-list-iterator.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_LIST_ITERATOR_H__ -#define __E_LIST_ITERATOR_H__ - -typedef struct _EListIterator EListIterator; -typedef struct _EListIteratorClass EListIteratorClass; - -#include -#include -#include -#include - -#include -#include - -#define E_TYPE_LIST_ITERATOR (e_list_iterator_get_type ()) -#define E_LIST_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_LIST_ITERATOR, EListIterator)) -#define E_LIST_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_LIST_ITERATOR, EListIteratorClass)) -#define E_IS_LIST_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_LIST_ITERATOR)) -#define E_IS_LIST_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_LIST_ITERATOR)) - -struct _EListIterator { - EIterator parent; - - EList *list; - GList *iterator; -}; - -struct _EListIteratorClass { - EIteratorClass parent_class; -}; - -EIterator *e_list_iterator_new (EList *list); - -/* Standard Glib function */ -GType e_list_iterator_get_type (void); - -#endif /* ! __E_LIST_ITERATOR_H__ */ diff --git a/e-util/e-list.c b/e-util/e-list.c deleted file mode 100644 index f1b190b16a..0000000000 --- a/e-util/e-list.c +++ /dev/null @@ -1,191 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Christopher James Lahey - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include - -#include "e-list.h" -#include "e-list-iterator.h" - -static void e_list_init (EList *list); -static void e_list_class_init (EListClass *klass); -static void e_list_dispose (GObject *object); - -static GObjectClass *parent_class; - -/** - * e_list_get_type: - * @void: - * - * Registers the &EList class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EList class. - **/ -GType -e_list_get_type (void) -{ - static GType type = 0; - - if (! type) { - GTypeInfo info = { - sizeof (EListClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) e_list_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EList), - 0, /* n_preallocs */ - (GInstanceInitFunc) e_list_init - }; - - type = g_type_register_static (G_TYPE_OBJECT, "EList", &info, 0); - } - - return type; -} - -static void -e_list_class_init (EListClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS(klass); - - parent_class = g_type_class_ref (G_TYPE_OBJECT); - - object_class->dispose = e_list_dispose; -} - -/** - * e_list_init: - */ -static void -e_list_init (EList *list) -{ - list->list = NULL; - list->iterators = NULL; -} - -EList * -e_list_new (EListCopyFunc copy, EListFreeFunc free, void *closure) -{ - EList *list = g_object_new (E_TYPE_LIST, NULL); - e_list_construct (list, copy, free, closure); - return list; -} - -void -e_list_construct (EList *list, EListCopyFunc copy, EListFreeFunc free, void *closure) -{ - list->copy = copy; - list->free = free; - list->closure = closure; -} - -EList * -e_list_duplicate (EList *old) -{ - EList *list = g_object_new (E_TYPE_LIST, NULL); - - list->copy = old->copy; - list->free = old->free; - list->closure = old->closure; - list->list = g_list_copy(old->list); - if (list->copy) { - GList *listlist; - for (listlist = list->list; listlist; listlist = listlist->next) { - listlist->data = list->copy (listlist->data, list->closure); - } - } - return list; -} - -EIterator * -e_list_get_iterator (EList *list) -{ - EIterator *iterator = e_list_iterator_new(list); - list->iterators = g_list_append(list->iterators, iterator); - return iterator; -} - -int -e_list_length (EList *list) -{ - return g_list_length(list->list); -} - -void -e_list_append (EList *list, const void *data) -{ - e_list_invalidate_iterators(list, NULL); - if (list->copy) - list->list = g_list_append(list->list, list->copy(data, list->closure)); - else - list->list = g_list_append(list->list, (void *) data); -} - -void -e_list_remove (EList *list, const void *data) -{ - GList *link; - link = g_list_find (list->list, data); - if (link) - e_list_remove_link(list, link); -} - -void -e_list_invalidate_iterators (EList *list, EIterator *skip) -{ - GList *iterators = list->iterators; - for (; iterators; iterators = iterators->next) { - if (iterators->data != skip) { - e_iterator_invalidate(E_ITERATOR(iterators->data)); - } - } -} - -/* FIXME: This doesn't work properly if the iterator is the first - iterator in the list. Well, the iterator doesn't continue on after - the next time next is called, at least. */ -void -e_list_remove_link (EList *list, GList *link) -{ - GList *iterators = list->iterators; - for (; iterators; iterators = iterators->next) { - if (((EListIterator *)iterators->data)->iterator == link) { - e_iterator_prev(iterators->data); - } - } - if (list->free) - list->free(link->data, list->closure); - list->list = g_list_remove_link(list->list, link); - g_list_free_1(link); -} - -void -e_list_remove_iterator (EList *list, EIterator *iterator) -{ - list->iterators = g_list_remove(list->iterators, iterator); -} - -/* - * Virtual functions - */ -static void -e_list_dispose (GObject *object) -{ - EList *list = E_LIST(object); - if (list->free) - g_list_foreach(list->list, (GFunc) list->free, list->closure); - g_list_free(list->list); - - (* G_OBJECT_CLASS (parent_class)->dispose) (object); -} - diff --git a/e-util/e-list.h b/e-util/e-list.h deleted file mode 100644 index d249fcfa4a..0000000000 --- a/e-util/e-list.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_LIST_H__ -#define __E_LIST_H__ - -typedef struct _EList EList; -typedef struct _EListClass EListClass; - -#include -#include -#include -#include -#include - -#define E_TYPE_LIST (e_list_get_type ()) -#define E_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_LIST, EList)) -#define E_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_LIST, EListClass)) -#define E_IS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_LIST)) -#define E_IS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_LIST)) -#define E_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_LIST, EListClass)) - -typedef void *(*EListCopyFunc) (const void *data, void *closure); -typedef void (*EListFreeFunc) (void *data, void *closure); - -struct _EList { - GObject object; - GList *list; - GList *iterators; - EListCopyFunc copy; - EListFreeFunc free; - void *closure; -}; - -struct _EListClass { - GObjectClass parent_class; -}; - -EList *e_list_new (EListCopyFunc copy, - EListFreeFunc free, - void *closure); -void e_list_construct (EList *list, - EListCopyFunc copy, - EListFreeFunc free, - void *closure); -EList *e_list_duplicate (EList *list); -EIterator *e_list_get_iterator (EList *list); -void e_list_append (EList *list, - const void *data); -void e_list_remove (EList *list, - const void *data); -int e_list_length (EList *list); - -/* For iterators to call. */ -void e_list_remove_link (EList *list, - GList *link); -void e_list_remove_iterator (EList *list, - EIterator *iterator); -void e_list_invalidate_iterators (EList *list, - EIterator *skip); - -/* Standard Glib function */ -GType e_list_get_type (void); - -#endif /* ! __E_LIST_H__ */ diff --git a/e-util/e-time-utils.c b/e-util/e-time-utils.c deleted file mode 100644 index 1ff3ed0f78..0000000000 --- a/e-util/e-time-utils.c +++ /dev/null @@ -1,492 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Time utility functions - * - * Author: - * Damon Chaplin (damon@ximian.com) - * - * (C) 2001 Ximian, Inc. - */ - -#include - -#ifdef __linux__ -/* We need this to get a prototype for strptime. */ -#define _GNU_SOURCE -#endif /* __linux__ */ - -#include -#include -#include - -#ifdef __linux__ -#undef _GNU_SOURCE -#endif /* __linux__ */ - -#include -#include -#include -#include -#include -#include "e-time-utils.h" - - -/* Returns whether a string is NULL, empty, or full of whitespace */ -static gboolean -string_is_empty (const char *value) -{ - const char *p; - gboolean empty = TRUE; - - if (value) { - p = value; - while (*p) { - if (!isspace (*p)) { - empty = FALSE; - break; - } - p++; - } - } - return empty; -} - - -/* Takes a number of format strings for strptime() and attempts to parse a - * string with them. - */ -static ETimeParseStatus -parse_with_strptime (const char *value, struct tm *result, const char **formats, int n_formats) -{ - const char *parse_end = NULL, *pos; - gchar *locale_str; - gchar *format_str; - ETimeParseStatus parse_ret; - gboolean parsed = FALSE; - int i; - - if (string_is_empty (value)) { - memset (result, 0, sizeof (*result)); - result->tm_isdst = -1; - return E_TIME_PARSE_NONE; - } - - locale_str = e_utf8_to_locale_string (value); - - pos = (const char *) locale_str; - - /* Skip whitespace */ - while (isspace (*pos)) - pos++; - - /* Try each of the formats in turn */ - - for (i = 0; i < n_formats; i++) { - memset (result, 0, sizeof (*result)); - format_str = e_utf8_to_locale_string (formats[i]); - parse_end = strptime (pos, format_str, result); - g_free (format_str); - if (parse_end) { - parsed = TRUE; - break; - } - } - - result->tm_isdst = -1; - - parse_ret = E_TIME_PARSE_INVALID; - - /* If we parsed something, make sure we parsed the entire string. */ - if (parsed) { - /* Skip whitespace */ - while (isspace (*parse_end)) - parse_end++; - - if (*parse_end == '\0') - parse_ret = E_TIME_PARSE_OK; - } - - g_free (locale_str); - - return (parse_ret); - -} - - -/* Returns TRUE if the locale has 'am' and 'pm' strings defined, in which - case the user can choose between 12 and 24-hour time formats. */ -static gboolean -locale_supports_12_hour_format (void) -{ - struct tm tmp_tm = { 0 }; - char s[16]; - - e_utf8_strftime (s, sizeof (s), "%p", &tmp_tm); - return s[0] != '\0'; -} - - -/* - * Parses a string containing a date and a time. The date is expected to be - * in a format something like "Wed 3/13/00 14:20:00", though we use gettext - * to support the appropriate local formats and we try to accept slightly - * different formats, e.g. the weekday can be skipped and we can accept 12-hour - * formats with an am/pm string. - * - * Returns E_TIME_PARSE_OK if it could not be parsed, E_TIME_PARSE_NONE if it - * was empty, or E_TIME_PARSE_INVALID if it couldn't be parsed. - */ -ETimeParseStatus -e_time_parse_date_and_time (const char *value, - struct tm *result) -{ - struct tm *today_tm; - time_t t; - const char *format[16]; - int num_formats = 0; - gboolean use_12_hour_formats = locale_supports_12_hour_format (); - ETimeParseStatus status; - - if (string_is_empty (value)) { - memset (result, 0, sizeof (*result)); - result->tm_isdst = -1; - return E_TIME_PARSE_NONE; - } - - /* We'll parse the whole date and time in one go, otherwise we get - into i18n problems. We attempt to parse with several formats, - longest first. Note that we only use the '%p' specifier if the - locale actually has 'am' and 'pm' strings defined, otherwise we - will get incorrect results. Note also that we try to use exactly - the same strings as in e_time_format_date_and_time(), to try to - avoid i18n problems. We also use cut-down versions, so users don't - have to type in the weekday or the seconds, for example. - Note that all these formats include the full date, and the time - will be set to 00:00:00 before parsing, so we don't need to worry - about filling in any missing fields after parsing. */ - - /* - * Try the full times, with the weekday. Then try without seconds, - * and without minutes, and finally with no time at all. - */ - if (use_12_hour_formats) { - /* strptime format of a weekday, a date and a time, - in 12-hour format. */ - format[num_formats++] = _("%a %m/%d/%Y %I:%M:%S %p"); - } - - /* strptime format of a weekday, a date and a time, - in 24-hour format. */ - format[num_formats++] = _("%a %m/%d/%Y %H:%M:%S"); - - if (use_12_hour_formats) { - /* strptime format of a weekday, a date and a time, - in 12-hour format, without seconds. */ - format[num_formats++] = _("%a %m/%d/%Y %I:%M %p"); - } - - /* strptime format of a weekday, a date and a time, - in 24-hour format, without seconds. */ - format[num_formats++] = _("%a %m/%d/%Y %H:%M"); - - if (use_12_hour_formats) { - /* strptime format of a weekday, a date and a time, - in 12-hour format, without minutes or seconds. */ - format[num_formats++] = _("%a %m/%d/%Y %I %p"); - } - - /* strptime format of a weekday, a date and a time, - in 24-hour format, without minutes or seconds. */ - format[num_formats++] = _("%a %m/%d/%Y %H"); - - /* strptime format of a weekday and a date. */ - format[num_formats++] = _("%a %m/%d/%Y"); - - - /* - * Now try all the above formats again, but without the weekday. - */ - if (use_12_hour_formats) { - /* strptime format of a date and a time, in 12-hour format. */ - format[num_formats++] = _("%m/%d/%Y %I:%M:%S %p"); - } - - /* strptime format of a date and a time, in 24-hour format. */ - format[num_formats++] = _("%m/%d/%Y %H:%M:%S"); - - if (use_12_hour_formats) { - /* strptime format of a date and a time, in 12-hour format, - without seconds. */ - format[num_formats++] = _("%m/%d/%Y %I:%M %p"); - } - - /* strptime format of a date and a time, in 24-hour format, - without seconds. */ - format[num_formats++] = _("%m/%d/%Y %H:%M"); - - if (use_12_hour_formats) { - /* strptime format of a date and a time, in 12-hour format, - without minutes or seconds. */ - format[num_formats++] = _("%m/%d/%Y %I %p"); - } - - /* strptime format of a date and a time, in 24-hour format, - without minutes or seconds. */ - format[num_formats++] = _("%m/%d/%Y %H"); - - /* strptime format of a weekday and a date. */ - format[num_formats++] = _("%m/%d/%Y"); - - - status = parse_with_strptime (value, result, format, num_formats); - /* Note that we checked if it was empty already, so it is either OK - or INVALID here. */ - if (status == E_TIME_PARSE_OK) { - /* If a 2-digit year was used we use the current century. */ - if (result->tm_year < 0) { - t = time (NULL); - today_tm = localtime (&t); - - /* This should convert it into a value from 0 to 99. */ - result->tm_year += 1900; - - /* Now add on the century. */ - result->tm_year += today_tm->tm_year - - (today_tm->tm_year % 100); - } - } else { - /* Now we try to just parse a time, assuming the current day.*/ - status = e_time_parse_time (value, result); - if (status == E_TIME_PARSE_OK) { - /* We fill in the current day. */ - t = time (NULL); - today_tm = localtime (&t); - result->tm_mday = today_tm->tm_mday; - result->tm_mon = today_tm->tm_mon; - result->tm_year = today_tm->tm_year; - } - } - - return status; -} - -/** - * e_time_parse_date: - * @value: A date string. - * @result: Return value for the parsed date. - * - * Takes in a date string entered by the user and tries to convert it to - * a struct tm. - * - * Return value: Result code indicating whether the @value was an empty - * string, a valid date, or an invalid date. - **/ -ETimeParseStatus -e_time_parse_date (const char *value, struct tm *result) -{ - const char *format[2]; - struct tm *today_tm; - time_t t; - ETimeParseStatus status; - - g_return_val_if_fail (value != NULL, E_TIME_PARSE_INVALID); - g_return_val_if_fail (result != NULL, E_TIME_PARSE_INVALID); - - /* strptime format of a weekday and a date. */ - format[0] = _("%a %m/%d/%Y"); - - /* This is the preferred date format for the locale. */ - format[1] = _("%m/%d/%Y"); - - status = parse_with_strptime (value, result, format, sizeof (format) / sizeof (format[0])); - if (status == E_TIME_PARSE_OK) { - /* If a 2-digit year was used we use the current century. */ - if (result->tm_year < 0) { - t = time (NULL); - today_tm = localtime (&t); - - /* This should convert it into a value from 0 to 99. */ - result->tm_year += 1900; - - /* Now add on the century. */ - result->tm_year += today_tm->tm_year - - (today_tm->tm_year % 100); - } - } - - return status; -} - - -/* - * Parses a string containing a time. It is expected to be in a format - * something like "14:20:00", though we use gettext to support the appropriate - * local formats and we try to accept slightly different formats, e.g. we can - * accept 12-hour formats with an am/pm string. - * - * Returns E_TIME_PARSE_OK if it could not be parsed, E_TIME_PARSE_NONE if it - * was empty, or E_TIME_PARSE_INVALID if it couldn't be parsed. - */ -ETimeParseStatus -e_time_parse_time (const char *value, struct tm *result) -{ - const char *format[6]; - int num_formats = 0; - gboolean use_12_hour_formats = locale_supports_12_hour_format (); - - if (use_12_hour_formats) { - /* strptime format for a time of day, in 12-hour format. */ - format[num_formats++] = _("%I:%M:%S %p"); - } - - /* strptime format for a time of day, in 24-hour format. */ - format[num_formats++] = _("%H:%M:%S"); - - if (use_12_hour_formats) { - /* strptime format for time of day, without seconds, - in 12-hour format. */ - format[num_formats++] = _("%I:%M %p"); - } - - /* strptime format for time of day, without seconds 24-hour format. */ - format[num_formats++] = _("%H:%M"); - - if (use_12_hour_formats) { - /* strptime format for hour and AM/PM, 12-hour format. */ - format[num_formats++] = _("%I %p"); - } - - /* strptime format for hour, 24-hour format. */ - format[num_formats++] = "%H"; - - return parse_with_strptime (value, result, format, num_formats); -} - - -/* Creates a string representation of a time value and stores it in buffer. - buffer_size should be about 64 to be safe. If show_midnight is FALSE, and - the time is midnight, then we just show the date. If show_zero_seconds - is FALSE, then if the time has zero seconds only the hour and minute are - shown. */ -void -e_time_format_date_and_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_midnight, - gboolean show_zero_seconds, - char *buffer, - int buffer_size) -{ - char *format; - - if (!show_midnight && date_tm->tm_hour == 0 - && date_tm->tm_min == 0 && date_tm->tm_sec == 0) { - /* strftime format of a weekday and a date. */ - format = _("%a %m/%d/%Y"); - } else if (use_24_hour_format) { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a weekday, a date and a - time, in 24-hour format, without seconds. */ - format = _("%a %m/%d/%Y %H:%M"); - else - /* strftime format of a weekday, a date and a - time, in 24-hour format. */ - format = _("%a %m/%d/%Y %H:%M:%S"); - } else { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a weekday, a date and a - time, in 12-hour format, without seconds. */ - format = _("%a %m/%d/%Y %I:%M %p"); - else - /* strftime format of a weekday, a date and a - time, in 12-hour format. */ - format = _("%a %m/%d/%Y %I:%M:%S %p"); - } - - /* strftime returns 0 if the string doesn't fit, and leaves the buffer - undefined, so we set it to the empty string in that case. */ - if (e_utf8_strftime (buffer, buffer_size, format, date_tm) == 0) - buffer[0] = '\0'; -} - - -/* Creates a string representation of a time value and stores it in buffer. - buffer_size should be about 64 to be safe. */ -void -e_time_format_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_zero_seconds, - char *buffer, - int buffer_size) -{ - char *format; - - if (use_24_hour_format) { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a time in 24-hour format, - without seconds. */ - format = _("%H:%M"); - else - /* strftime format of a time in 24-hour format. */ - format = _("%H:%M:%S"); - } else { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a time in 12-hour format, - without seconds. */ - format = _("%I:%M %p"); - else - /* strftime format of a time in 12-hour format. */ - format = _("%I:%M:%S %p"); - } - - /* strftime returns 0 if the string doesn't fit, and leaves the buffer - undefined, so we set it to the empty string in that case. */ - if (e_utf8_strftime (buffer, buffer_size, format, date_tm) == 0) - buffer[0] = '\0'; -} - - -/* Like mktime(3), but assumes UTC instead of local timezone. */ -time_t -e_mktime_utc (struct tm *tm) -{ - time_t tt; - - tm->tm_isdst = -1; - tt = mktime (tm); - -#if defined (HAVE_TM_GMTOFF) - tt += tm->tm_gmtoff; -#elif defined (HAVE_TIMEZONE) - if (tm->tm_isdst > 0) { - #if defined (HAVE_ALTZONE) - tt -= altzone; - #else /* !defined (HAVE_ALTZONE) */ - tt -= (timezone - 3600); - #endif - } else - tt -= timezone; -#endif - - return tt; -} - -/* Like localtime_r(3), but also returns an offset in seconds after UTC. - (Calling gmtime with tt + offset would generate the same tm) */ -void -e_localtime_with_offset (time_t tt, struct tm *tm, int *offset) -{ - localtime_r (&tt, tm); - -#if defined (HAVE_TM_GMTOFF) - *offset = tm->tm_gmtoff; -#elif defined (HAVE_TIMEZONE) - if (tm->tm_isdst > 0) { - #if defined (HAVE_ALTZONE) - *offset = -altzone; - #else /* !defined (HAVE_ALTZONE) */ - *offset = -(timezone - 3600); - #endif - } else - *offset = -timezone; -#endif -} diff --git a/e-util/e-time-utils.h b/e-util/e-time-utils.h deleted file mode 100644 index 0b081dadd4..0000000000 --- a/e-util/e-time-utils.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Time utility functions - * - * Author: - * Damon Chaplin (damon@ximian.com) - * - * (C) 2001 Ximian, Inc. - */ - -#ifndef E_TIME_UTILS -#define E_TIME_UTILS - -#include -#include - -typedef enum { - E_TIME_PARSE_OK, - E_TIME_PARSE_NONE, - E_TIME_PARSE_INVALID -} ETimeParseStatus; - -/* Tries to parse a string containing a date and time. */ -ETimeParseStatus e_time_parse_date_and_time (const char *value, - struct tm *result); - -/* Tries to parse a string containing a date. */ -ETimeParseStatus e_time_parse_date (const char *value, - struct tm *result); - -/* Tries to parse a string containing a time. */ -ETimeParseStatus e_time_parse_time (const char *value, - struct tm *result); - -/* Turns a struct tm into a string like "Wed 3/12/00 12:00:00 AM". */ -void e_time_format_date_and_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_midnight, - gboolean show_zero_seconds, - char *buffer, - int buffer_size); - -/* Formats a time from a struct tm, e.g. "01:59 PM". */ -void e_time_format_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_zero_seconds, - char *buffer, - int buffer_size); - - -/* Like mktime(3), but assumes UTC instead of local timezone. */ -time_t e_mktime_utc (struct tm *timeptr); - -/* Like localtime_r(3), but also returns an offset in minutes after UTC. - (Calling gmtime with tt + offset would generate the same tm) */ -void e_localtime_with_offset (time_t tt, struct tm *tm, int *offset); - -#endif /* E_TIME_UTILS */ diff --git a/e-util/e-uid.c b/e-util/e-uid.c deleted file mode 100644 index 90c036e0c1..0000000000 --- a/e-util/e-uid.c +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-uid.c - Unique ID generator. - * - * Copyright (C) 2002 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Dan Winship - */ - -#include "e-uid.h" - -#include - -#include -#include -#include - - -/** - * e_uid_new: - * - * Generate a new unique string for use e.g. in account lists. - * - * Return value: the newly generated UID. The caller should free the string - * when it's done with it. - **/ -char * -e_uid_new (void) -{ - static char *hostname; - static int serial; - - if (!hostname) { - static char buffer [512]; - - if ((gethostname (buffer, sizeof (buffer) - 1) == 0) && - (buffer [0] != 0)) - hostname = buffer; - else - hostname = "localhost"; - } - - return g_strdup_printf ("%lu.%lu.%d@%s", - (unsigned long) time (NULL), - (unsigned long) getpid (), - serial++, - hostname); -} diff --git a/e-util/e-uid.h b/e-util/e-uid.h deleted file mode 100644 index 44ec8c0dd9..0000000000 --- a/e-util/e-uid.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-uid.h - Unique ID generator. - * - * Copyright (C) 2002 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Dan Winship - */ - -#ifndef E_UID_H -#define E_UID_H - -char *e_uid_new (void); - -#endif /* E_UID_H */ diff --git a/e-util/md5-utils.c b/e-util/md5-utils.c deleted file mode 100644 index e550968828..0000000000 --- a/e-util/md5-utils.c +++ /dev/null @@ -1,355 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to md5_init, call md5_update as - * needed on buffers full of bytes, and then call md5_Final, which - * will fill a supplied 16-byte array with the digest. - */ - -/* parts of this file are : - * Written March 1993 by Branko Lankester - * Modified June 1993 by Colin Plumb for altered md5.c. - * Modified October 1995 by Erik Troan for RPM - */ - - -#include -#include -#include "md5-utils.h" - - -static void md5_transform (guint32 buf[4], const guint32 in[16]); - -static gint _ie = 0x44332211; -static union _endian { gint i; gchar b[4]; } *_endian = (union _endian *)&_ie; -#define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') -#define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') - - -/* - * Note: this code is harmless on little-endian machines. - */ -static void -_byte_reverse (guchar *buf, guint32 longs) -{ - guint32 t; - do { - t = (guint32) ((guint32) buf[3] << 8 | buf[2]) << 16 | - ((guint32) buf[1] << 8 | buf[0]); - *(guint32 *) buf = t; - buf += 4; - } while (--longs); -} - -/** - * md5_init: Initialise an md5 context object - * @ctx: md5 context - * - * Initialise an md5 buffer. - * - **/ -void -md5_init (MD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bits[0] = 0; - ctx->bits[1] = 0; - - if (IS_BIG_ENDIAN()) - ctx->doByteReverse = 1; - else - ctx->doByteReverse = 0; -} - - - -/** - * md5_update: add a buffer to md5 hash computation - * @ctx: conetxt object used for md5 computaion - * @buf: buffer to add - * @len: buffer length - * - * Update context to reflect the concatenation of another buffer full - * of bytes. Use this to progressively construct an md5 hash. - **/ -void -md5_update (MD5Context *ctx, const guchar *buf, guint32 len) -{ - guint32 t; - - /* Update bitcount */ - - t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((guint32) len << 3)) < t) - ctx->bits[1]++; /* Carry from low to high */ - ctx->bits[1] += len >> 29; - - t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ - - /* Handle any leading odd-sized chunks */ - - if (t) { - guchar *p = (guchar *) ctx->in + t; - - t = 64 - t; - if (len < t) { - memcpy (p, buf, len); - return; - } - memcpy (p, buf, t); - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 16); - md5_transform (ctx->buf, (guint32 *) ctx->in); - buf += t; - len -= t; - } - /* Process data in 64-byte chunks */ - - while (len >= 64) { - memcpy (ctx->in, buf, 64); - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 16); - md5_transform (ctx->buf, (guint32 *) ctx->in); - buf += 64; - len -= 64; - } - - /* Handle any remaining bytes of data. */ - - memcpy (ctx->in, buf, len); -} - - - - - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -/** - * md5_final: copy the final md5 hash to a bufer - * @digest: 16 bytes buffer - * @ctx: context containing the calculated md5 - * - * copy the final md5 hash to a bufer - **/ -void -md5_final (MD5Context *ctx, guchar digest[16]) -{ - guint32 count; - guchar *p; - - /* Compute number of bytes mod 64 */ - count = (ctx->bits[0] >> 3) & 0x3F; - - /* Set the first char of padding to 0x80. This is safe since there is - always at least one byte free */ - p = ctx->in + count; - *p++ = 0x80; - - /* Bytes of padding needed to make 64 bytes */ - count = 64 - 1 - count; - - /* Pad out to 56 mod 64 */ - if (count < 8) { - /* Two lots of padding: Pad the first block to 64 bytes */ - memset (p, 0, count); - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 16); - md5_transform (ctx->buf, (guint32 *) ctx->in); - - /* Now fill the next block with 56 bytes */ - memset (ctx->in, 0, 56); - } else { - /* Pad block to 56 bytes */ - memset (p, 0, count - 8); - } - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 14); - - /* Append length in bits and transform */ - ((guint32 *) ctx->in)[14] = ctx->bits[0]; - ((guint32 *) ctx->in)[15] = ctx->bits[1]; - - md5_transform (ctx->buf, (guint32 *) ctx->in); - if (ctx->doByteReverse) - _byte_reverse ((guchar *) ctx->buf, 4); - memcpy (digest, ctx->buf, 16); -} - - - - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. md5_Update blocks - * the data and converts bytes into longwords for this routine. - */ -static void -md5_transform (guint32 buf[4], const guint32 in[16]) -{ - register guint32 a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP (F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP (F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP (F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP (F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP (F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP (F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP (F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP (F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP (F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP (F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP (F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP (F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP (F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP (F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP (F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP (F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP (F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP (F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP (F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP (F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP (F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP (F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP (F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP (F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP (F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP (F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP (F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP (F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP (F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP (F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP (F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP (F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP (F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP (F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP (F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP (F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP (F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP (F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP (F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP (F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP (F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP (F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP (F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP (F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP (F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP (F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP (F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP (F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP (F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP (F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP (F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP (F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP (F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP (F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP (F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP (F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP (F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP (F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP (F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP (F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP (F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP (F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP (F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP (F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} - - - - -/** - * md5_get_digest: get the md5 hash of a buffer - * @buffer: byte buffer - * @buffer_size: buffer size (in bytes) - * @digest: 16 bytes buffer receiving the hash code. - * - * Get the md5 hash of a buffer. The result is put in - * the 16 bytes buffer @digest . - **/ -void -md5_get_digest (const gchar *buffer, gint buffer_size, guchar digest[16]) -{ - MD5Context ctx; - - md5_init (&ctx); - md5_update (&ctx, buffer, buffer_size); - md5_final (&ctx, digest); - -} - - -/** - * md5_get_digest_from_file: get the md5 hash of a file - * @filename: file name - * @digest: 16 bytes buffer receiving the hash code. - * - * Get the md5 hash of a file. The result is put in - * the 16 bytes buffer @digest . - **/ -void -md5_get_digest_from_file (const gchar *filename, guchar digest[16]) -{ - MD5Context ctx; - guchar tmp_buf[1024]; - gint nb_bytes_read; - FILE *fp; - - md5_init (&ctx); - fp = fopen(filename, "r"); - if (!fp) { - return; - } - - while ((nb_bytes_read = fread (tmp_buf, sizeof (guchar), 1024, fp)) > 0) - md5_update (&ctx, tmp_buf, nb_bytes_read); - - if (ferror(fp)) { - fclose(fp); - return; - } - - - md5_final (&ctx, digest); -} diff --git a/e-util/md5-utils.h b/e-util/md5-utils.h deleted file mode 100644 index 607471a752..0000000000 --- a/e-util/md5-utils.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to rpmMD5Init, call rpmMD5Update as - * needed on buffers full of bytes, and then call rpmMD5Final, which - * will fill a supplied 16-byte array with the digest. - */ - -/* parts of this file are : - * Written March 1993 by Branko Lankester - * Modified June 1993 by Colin Plumb for altered md5.c. - * Modified October 1995 by Erik Troan for RPM - */ - - -#ifndef MD5_UTILS_H -#define MD5_UTILS_H - -#include - - -typedef struct _MD5Context { - guint32 buf[4]; - guint32 bits[2]; - guchar in[64]; - gint doByteReverse; -} MD5Context; - - -void md5_get_digest (const gchar *buffer, gint buffer_size, guchar digest[16]); - -/* use this one when speed is needed */ -/* for use in provider code only */ -void md5_get_digest_from_file (const gchar *filename, guchar digest[16]); - -/* raw routines */ -void md5_init (MD5Context *ctx); -void md5_update (MD5Context *ctx, const guchar *buf, guint32 len); -void md5_final (MD5Context *ctx, guchar digest[16]); - - -#endif /* MD5_UTILS_H */ -- cgit v1.2.3