From b7fdcd20770605c95ac54633f2914a0571d25842 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 27 Apr 2010 20:48:26 +0200 Subject: [PATCH] Optional MIME type normalization while message loading Appication can use isds_set_mime_type_normalization() to enable/disable MIME type normalization while loading message. Default is not to normalize. Normalized MIME types are more MIME types than file name extension that often appear on place of MIME type. If application is interrested in usable data, aplication is encouraged to switch this feature on. --- src/isds.c | 31 +++++++++++++++++++++++++++++++ src/isds.h | 6 ++++++ src/isds_priv.h | 1 + 3 files changed, 38 insertions(+) diff --git a/src/isds.c b/src/isds.c index 8c07897..9115af5 100644 --- a/src/isds.c +++ b/src/isds.c @@ -3089,6 +3089,21 @@ static isds_error extract_document(struct isds_ctx *context, /* Extract document metadata */ EXTRACT_STRING_ATTRIBUTE("dmMimeType", (*document)->dmMimeType, 1) + if (context->normalize_mime_type) { + char *normalized_type = + isds_normalize_mime_type((*document)->dmMimeType); + if (normalized_type && normalized_type != (*document)->dmMimeType) { + char *new_type = strdup(normalized_type); + if (!new_type) { + isds_printf_message(context, + _("No enough memory to normalize document MIME type")); + err = IE_NOMEM; + goto leave; + } + free((*document)->dmMimeType); + (*document)->dmMimeType = new_type; + } + } EXTRACT_STRING_ATTRIBUTE("dmFileMetaType", string, 1) err = string2isds_FileMetaType((xmlChar*)string, @@ -8879,6 +8894,22 @@ char *isds_normalize_mime_type(const char* mime_type) { } +/* Switch MIME type normalization while message loading. Default state for new + * context is no normalization. + * @normalize use true to switch normalization on, false to switch off */ +isds_error isds_set_mime_type_normalization(struct isds_ctx *context, + _Bool normalize) { + if (!context) return IE_INVALID_CONTEXT; + zfree(context->long_message); + + context->normalize_mime_type = normalize; + isds_log(ILF_FILE, ILL_INFO, (context->normalize_mime_type) ? + _("MIME type normalization switched on\n") : + _("MIME type normalization switched off\n")); + return IE_SUCCESS; +} + + /*int isds_get_message(struct isds_ctx *context, const unsigned int id, struct isds_message **message); int isds_send_message(struct isds_ctx *context, struct isds_message *message); diff --git a/src/isds.h b/src/isds.h index 73ce5ab..91fd762 100644 --- a/src/isds.h +++ b/src/isds.h @@ -1218,6 +1218,12 @@ const struct isds_document *isds_find_document_by_id( * constant static UTF-8 encoded string with proper MIME type. */ char *isds_normalize_mime_type(const char* mime_type); +/* Switch MIME type normalization while message loading. Default state for new + * context is no normalization. + * @normalize use true to switch normalization on, false to switch off */ +isds_error isds_set_mime_type_normalization(struct isds_ctx *context, + _Bool normalize); + /* Free isds_list with all member data. * @list list to free, on return will be NULL */ void isds_list_free(struct isds_list **list); diff --git a/src/isds_priv.h b/src/isds_priv.h index 362c3d4..e75bca8 100644 --- a/src/isds_priv.h +++ b/src/isds_priv.h @@ -76,6 +76,7 @@ struct isds_ctx { char *tls_ca_file; /* File name with CA certificates */ char *tls_ca_dir; /* Directory name with CA certificates */ char *tls_crl_file; /* File name with CRL in PEM format */ + _Bool normalize_mime_type; /* Normalize document MIME types? */ char *long_message; /* message buffer */ }; -- 2.11.4.GIT