static void camel_offline_journal_init (CamelOfflineJournal *journal, CamelOfflineJournalClass *klass) { journal->folder = NULL; journal->filename = NULL; e_dlist_init (&journal->queue); }
static void ep_init(GObject *o) { EEvent *emp = (EEvent *)o; struct _EEventPrivate *p; p = emp->priv = g_malloc0(sizeof(struct _EEventPrivate)); e_dlist_init(&p->events); }
/** * em_cache_add: * @emc: * @n: * * Add a cache node to the cache, once added the memory is owned by * the cache. If there are conflicts and the old node is still in * use, then the new node is not added, otherwise it is added and any * nodes older than the expire time are flushed. **/ void em_cache_add(EMCache *emc, EMCacheNode *n) { EMCacheNode *old, *prev; EDList old_nodes; e_dlist_init(&old_nodes); g_mutex_lock(emc->lock); old = g_hash_table_lookup(emc->key_table, n->key); if (old != NULL) { if (old->ref_count == 0) { g_hash_table_remove(emc->key_table, old->key); e_dlist_remove((EDListNode *)old); e_dlist_addtail(&old_nodes, (EDListNode *)old); goto insert; } else { e_dlist_addtail(&old_nodes, (EDListNode *)n); } } else { time_t now; insert: now = time(0); g_hash_table_insert(emc->key_table, n->key, n); e_dlist_addhead(&emc->lru_list, (EDListNode *)n); n->stamp = now; emc->node_count++; c(printf("inserting node %s\n", n->key)); old = (EMCacheNode *)emc->lru_list.tailpred; prev = old->prev; while (prev && old->stamp < now - emc->timeout) { if (old->ref_count == 0) { c(printf("expiring node %s\n", old->key)); g_hash_table_remove(emc->key_table, old->key); e_dlist_remove((EDListNode *)old); e_dlist_addtail(&old_nodes, (EDListNode *)old); } old = prev; prev = prev->prev; } } g_mutex_unlock(emc->lock); while ((old = (EMCacheNode *)e_dlist_remhead(&old_nodes))) { emc->node_free(old); g_free(old->key); g_free(old); } }
/** * em_cache_new: * @timeout: * @nodesize: * @nodefree: * * Setup a new timeout cache. @nodesize is the size of nodes in the * cache, and @nodefree will be called to free YOUR content. * * Return value: **/ EMCache * em_cache_new(time_t timeout, size_t nodesize, GFreeFunc nodefree) { struct _EMCache *emc; emc = g_malloc0(sizeof(*emc)); emc->node_size = nodesize; emc->key_table = g_hash_table_new(g_str_hash, g_str_equal); emc->node_free = nodefree; e_dlist_init(&emc->lru_list); emc->lock = g_mutex_new(); emc->timeout = timeout; return emc; }
/** * em_cache_clear: * @emc: * * clear the cache. just for api completeness. **/ void em_cache_clear(EMCache *emc) { EMCacheNode *node; EDList old_nodes; e_dlist_init(&old_nodes); g_mutex_lock(emc->lock); while ((node = (EMCacheNode *)e_dlist_remhead(&emc->lru_list))) e_dlist_addtail(&old_nodes, (EDListNode *)node); g_mutex_unlock(emc->lock); while ((node = (EMCacheNode *)e_dlist_remhead(&old_nodes))) { emc->node_free(node); g_free(node->key); g_free(node); } }
/* 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; to = e_iconv_charset_name (oto); from = e_iconv_charset_name (ofrom); /* e_iconv_charset_name() could return NULL in case of invalid charset. So, we need to check them here. */ if (to == NULL || from == NULL) { errno = EINVAL; return (iconv_t) -1; } 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; }
/* 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(); }
static void ep_base_init(GObjectClass *klass) { e_dlist_init(&((EImportClass *)klass)->importers); }