dnl Ensure that libcitadel is configured with autoconf 2.52 or newer
AC_PREREQ(2.52)
-AC_INIT(libcitadel, 1.05, https://uncensored.citadel.org)
+AC_INIT(libcitadel, 1.06, https://uncensored.citadel.org)
AC_CONFIG_SRCDIR(Makefile.in)
AC_CONFIG_AUX_DIR(conftools)
-libcitadel (7.24-1) unstable; urgency=low
+libcitadel (1.06-7) stable; urgency=high
+
+ * mime to icon guessing
+ * fixed hash lookups
+
+ -- Wilfried Goesgens <w.goesgens@outgesourced.org> Sat, 23 Feb 2008 0:00:00 +0001
+libcitadel (1.05-4) stable; urgency=high
+
+ * include xdgmime
+
+ -- Wilfried Goesgens <w.goesgens@outgesourced.org> Tue, 12 Feb 2008 0:00:00 +0001
+libcitadel (1.03-3) unstable; urgency=low
* initial debian release
-- Wilfried Goesgens <w.goesgens@outgesourced.org> Sun, 18 Nov 2007 23:55:21 +0100
-
\ No newline at end of file
-libcitadel1_7.24-1_i386.deb libs optional
-libcitadel1-dbg_7.24-1_i386.deb libdevel optional
-libcitadel-dev_7.24-1_i386.deb libdevel optional
+libcitadel1_1.05-4_i386.deb libs optional
+libcitadel1-dbg_1.05-4_i386.deb libdevel optional
+libcitadel-dev_1.05-4_i386.deb libdevel optional
dh_testroot -i
dh_installdocs -i -A README
dh_installchangelogs -i debian/no-upstream-changelog
- dh_install -i --sourcedir=debian/tmp
- dh_link -i
- dh_strip -i
- dh_compress -i
- dh_fixperms -i
- dh_installdeb -i
- dh_shlibdeps -i
- dh_gencontrol -i
- dh_md5sums -i
- dh_builddeb -i
+# dh_install -i --sourcedir=debian/tmp
+# dh_link -i
+# dh_strip -i
+# dh_compress -i
+# dh_fixperms -i
+# dh_installdeb -i
+# dh_shlibdeps -i
+# dh_gencontrol -i
+# dh_md5sums -i
+# dh_builddeb -i
# Build architecture-dependent files here.
binary-arch: build install
struct HashPos {
long Position;
};
-
-int PrintHash(HashList *Hash)
+#define DEBUG
+int PrintHash(HashList *Hash, PrintHashContent First, PrintHashContent Second)
{
- char *foo;
- char *bar;
+ const char *foo;
+ const char *bar;
+ const char *bla = "";
long key;
long i;
if (Hash->MyKeys != NULL)
{
key = Hash->LookupTable[i]->Key;
foo = Hash->LookupTable[i]->HashKey;
- bar = (char*) Hash->Members[Hash->LookupTable[i]->Position]->Data;
+ if (First != NULL)
+ bar = First(Hash->Members[Hash->LookupTable[i]->Position]->Data);
+ if (Second != NULL)
+ bla = Second(Hash->Members[Hash->LookupTable[i]->Position]->Data);
}
#ifdef DEBUG
- printf (" ---- Hashkey[%ld][%ld]: '%s' Value: '%s' \n", i, key, foo, bar);
+ printf (" ---- Hashkey[%ld][%ld]: '%s' Value: '%s' ; %s\n", i, key, foo, bar, bla);
#endif
}
#ifdef DEBUG
NewPayloadArea = (Payload**) malloc(sizeof(Payload*) * Hash->MemberSize * 2);
memset(&NewPayloadArea[Hash->MemberSize], 0, sizeof(Payload*) * Hash->MemberSize);
memcpy(NewPayloadArea, Hash->Members, sizeof(Payload*) * Hash->MemberSize);
+ free(Hash->Members);
+ Hash->Members = NewPayloadArea;
NewTable = malloc(sizeof(HashKey*) * Hash->MemberSize * 2);
memset(&NewTable[Hash->MemberSize], 0, sizeof(HashKey*) * Hash->MemberSize);
- memcpy(NewTable, &Hash->LookupTable, sizeof(HashKey*) * Hash->MemberSize);
+ memcpy(NewTable, Hash->LookupTable, sizeof(HashKey*) * Hash->MemberSize);
+ free(Hash->LookupTable);
+ Hash->LookupTable = NewTable;
Hash->MemberSize *= 2;
}
}
}
-int GetHash(HashList *Hash, char *HKey, long HKLen, void **Data)
+int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data)
{
long HashBinKey;
long HashAt;
- HashBinKey = CalcHashKey(HKey, HKLen);
+ HashBinKey = CalcHashKey((char*)HKey, HKLen);
HashAt = FindInHash(Hash, HashBinKey);
- if ((HashAt < 0) || (HashAt >= Hash->nMembersUsed)) {
+ if ((HashAt < 0) ||
+ (HashAt >= Hash->nMembersUsed) ||
+ (Hash->LookupTable[HashAt]->Key != HashBinKey)) {
*Data = NULL;
return 0;
}
return 0;
}
-int GetHashKeys(HashList *Hash, const char ***List)
+int GetHashKeys(HashList *Hash, char ***List)
{
long i;
if (Hash->MyKeys != NULL)
Hash->MyKeys[i] = Hash->LookupTable[i]->HashKey;
}
- *List = Hash->MyKeys;
+ *List = (char**)Hash->MyKeys;
return Hash->nMembersUsed;
}
* since we reference time_t...
*/
#include <time.h>
-
-#define LIBCITADEL_VERSION_NUMBER 105
+#include <stdlib.h>
+#define LIBCITADEL_VERSION_NUMBER 106
/*
* Here's a bunch of stupid magic to make the MIME parser portable.
const char *GuessMimeType(char *data, size_t dlen);
const char* GuessMimeByFilename(const char *what, size_t len);
+/** Run once at Programstart */
+int LoadIconDir(const char *DirName);
+/** guess an icon to the mimetype */
+const char *GetIconFilename(char *MimeType, size_t len);
+void ShutDownLibCitadel(void);
/* tools */
void vcard_fn_to_n(char *vname, char *n, size_t vname_size);
void remove_charset_attribute(char *strbuf);
+/**
+ * Citadels Hashlist Implementation
+ */
+
typedef struct HashList HashList;
typedef struct HashKey HashKey;
typedef struct HashPos HashPos;
typedef void (*DeleteHashDataFunc)(void * Data);
-
-
+typedef const char *(*PrintHashContent)(void * Data);
HashList *NewHash(void);
-void DeleteHash(HashList **Hash);
+void DeleteHash(HashList **Hash);
-int GetHash(HashList *Hash, char *HKey, long HKLen, void **Data);
+int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data);
void Put(HashList *Hash, char *HKey, long HKLen, void *Data, DeleteHashDataFunc DeleteIt);
int GetKey(HashList *Hash, char *HKey, long HKLen, void **Data);
-int GetHashKeys(HashList *Hash, const char ***List);
+int GetHashKeys(HashList *Hash, char ***List);
-int PrintHash(HashList *Hash);
+int PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
HashPos *GetNewHashPos(void);
+
void DeleteHashPos(HashPos **DelMe);
int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, char **HashKey, void **Data);
#include <ctype.h>
#include <string.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
#include <errno.h>
#include "xdgmime/xdgmime.h"
/* and let xdgmime do the fallback. */
return xdg_mime_get_mime_type_from_file_name(what);
}
+
+static HashList *IconHash = NULL;
+
+typedef struct IconName IconName;
+
+struct IconName {
+ char *FlatName;
+ char *FileName;
+};
+
+static void DeleteIcon(void *IconNamePtr)
+{
+ IconName *Icon = (IconName*) IconNamePtr;
+ free(Icon->FlatName);
+ free(Icon->FileName);
+}
+
+static const char *PrintFlat(void *IconNamePtr)
+{
+ IconName *Icon = (IconName*) IconNamePtr;
+ return Icon->FlatName;
+}
+static const char *PrintFile(void *IconNamePtr)
+{
+ IconName *Icon = (IconName*) IconNamePtr;
+ return Icon->FileName;
+}
+#define GENSTR "x-generic"
+#define IGNORE_PREFIX_1 "gnome-mime"
+int LoadIconDir(const char *DirName)
+{
+ DIR *filedir = NULL;
+ struct dirent *filedir_entry;
+ int d_namelen;
+ int d_without_ext;
+ IconName *Icon;
+
+ filedir = opendir (DirName);
+ IconHash = NewHash();
+ if (filedir == NULL) {
+ return 0;
+ }
+
+ while ((filedir_entry = readdir(filedir)))
+ {
+ char *MinorPtr;
+ char *PStart;
+#ifdef _DIRENT_HAVE_D_NAMELEN
+ d_namelen = filedir_entry->d_namelen;
+#else
+ d_namelen = strlen(filedir_entry->d_name);
+#endif
+ d_without_ext = d_namelen;
+ while ((d_without_ext > 0) && (filedir_entry->d_name[d_without_ext] != '.'))
+ d_without_ext --;
+ if ((d_without_ext == 0) || (d_namelen < 3))
+ continue;
+
+ if ((sizeof(IGNORE_PREFIX_1) < d_namelen) &&
+ (strncmp(IGNORE_PREFIX_1,
+ filedir_entry->d_name,
+ sizeof(IGNORE_PREFIX_1) - 1) == 0)) {
+ PStart = filedir_entry->d_name + sizeof(IGNORE_PREFIX_1);
+ d_without_ext -= sizeof(IGNORE_PREFIX_1);
+ }
+ else {
+ PStart = filedir_entry->d_name;
+ }
+ Icon = malloc(sizeof(IconName));
+
+ Icon->FileName = malloc(d_namelen + 1);
+ memcpy(Icon->FileName, filedir_entry->d_name, d_namelen + 1);
+
+ Icon->FlatName = malloc(d_without_ext + 1);
+ memcpy(Icon->FlatName, PStart, d_without_ext);
+ Icon->FlatName[d_without_ext] = '\0';
+ /* Try to find Minor type in image-jpeg */
+ MinorPtr = strchr(Icon->FlatName, '-');
+ if (MinorPtr != NULL) {
+ size_t MinorLen;
+ MinorLen = 1 + d_without_ext - (MinorPtr - Icon->FlatName + 1);
+ if ((MinorLen == sizeof(GENSTR)) &&
+ (strncmp(MinorPtr + 1, GENSTR, sizeof(GENSTR)) == 0)) {
+ /* ok, we found a generic filename. cut the generic. */
+ *MinorPtr = '\0';
+ d_without_ext = d_without_ext - (MinorPtr - Icon->FlatName);
+ }
+ else { /* Map the major / minor separator to / */
+ *MinorPtr = '/';
+ }
+ }
+
+// PrintHash(IconHash, PrintFlat, PrintFile);
+// printf("%s - %s\n", Icon->FlatName, Icon->FileName);
+ Put(IconHash, Icon->FlatName, d_without_ext, Icon, DeleteIcon);
+// PrintHash(IconHash, PrintFlat, PrintFile);
+ }
+ return 1;
+}
+
+const char *GetIconFilename(char *MimeType, size_t len)
+{
+ IconName *Icon;
+
+ if(IconHash == NULL)
+ return NULL;
+
+ GetHash(IconHash, MimeType, len, (void**)&Icon);
+ /* didn't find the exact mimetype? try major only. */
+ if (Icon == NULL) {
+ char * pMinor;
+ pMinor = strchr(MimeType, '/');
+ if (pMinor != NULL) {
+ *pMinor = '\0';
+ GetHash(IconHash, MimeType, pMinor - MimeType, (void**)&Icon);
+ }
+ }
+ if (Icon == NULL) {
+ return NULL;
+ }
+
+ /*printf("Getting: [%s] == [%s] -> [%s]\n", MimeType, Icon->FlatName, Icon->FileName);*/
+ return Icon->FileName;
+}
+
+void ShutDownLibCitadel(void)
+{
+ DeleteHash(&IconHash);
+}