From 383f245d39b8b806a4b6ce4dea7b0ab7f1658450 Mon Sep 17 00:00:00 2001 From: NotZed Date: Thu, 20 Apr 2000 23:48:45 +0000 Subject: MERGE NEW_PARSER branch into HEAD, fixed conflicts. 2000-04-20 NotZed * MERGE NEW_PARSER branch into HEAD, fixed conflicts. * gmime-content-field.c (_print_parameter): Duh, removed again (@@#$@ cvs merge). * camel-mime-utils.c (header_content_type_is): Constify. (header_content_type_unref): Killed a couple warnings. * camel-folder.c (_init): Removed more log crap. * providers/Makefile.am (SUBDIRS): Removed nntp, pending fixes for summary changes. * providers/mbox/camel-mbox-folder.c (_get_message_by_number): Fixed for new summary interface. Added a warning for using this broken api. (_get_message_by_uid): Fixed for message new with session vanishing. svn path=/trunk/; revision=2531 --- camel/gmime-content-field.c | 228 +++++++++++--------------------------------- 1 file changed, 55 insertions(+), 173 deletions(-) (limited to 'camel/gmime-content-field.c') diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c index 02b44ab7be..6d0abce4e8 100644 --- a/camel/gmime-content-field.c +++ b/camel/gmime-content-field.c @@ -28,7 +28,7 @@ #include "gmime-content-field.h" #include "string-utils.h" #include -#include "hash-table-utils.h" +#include "camel-mime-utils.h" /** * gmime_content_field_new: Creates a new GMimeContentField object @@ -49,44 +49,13 @@ gmime_content_field_new (const gchar *type, const gchar *subtype) GMimeContentField *ctf; ctf = g_new (GMimeContentField, 1); - ctf->type = g_strdup (type); - ctf->subtype = g_strdup (subtype); - ctf->parameters = g_hash_table_new (g_strcase_hash, g_strcase_equal); + ctf->content_type = header_content_type_new(type, subtype); + ctf->type = ctf->content_type->type; + ctf->subtype = ctf->content_type->subtype; ctf->ref = 1; - return ctf; } - -static void -_free_parameter (gpointer name, gpointer value, gpointer user_data) -{ - g_free (name); - g_free (value); -} - -/** - * gmime_content_field_free: free a GMimeContentField object - * @content_field: GMimeContentField object - * - * This method destroys the object and should be used very carefully. - * Use gmime_content_field_unref instead. - * - **/ -void -gmime_content_field_free (GMimeContentField *content_field) -{ - if (!content_field) return; - - g_assert (content_field->ref <= 0); - - g_hash_table_foreach (content_field->parameters, _free_parameter, NULL); - g_free (content_field->type); - g_free (content_field->subtype); - g_hash_table_destroy (content_field->parameters); - g_free (content_field); -} - /** * gmime_content_field_ref: add a reference to a GMimeContentField object * @content_field: GMimeContentField object @@ -100,6 +69,7 @@ void gmime_content_field_ref (GMimeContentField *content_field) { content_field->ref += 1; + header_content_type_ref (content_field->content_type); } /** @@ -118,8 +88,9 @@ gmime_content_field_unref (GMimeContentField *content_field) if (!content_field) return; content_field->ref -= 1; + header_content_type_unref (content_field->content_type); if (content_field->ref <= 0) - gmime_content_field_free (content_field); + g_free (content_field); } @@ -139,44 +110,7 @@ gmime_content_field_unref (GMimeContentField *content_field) void gmime_content_field_set_parameter (GMimeContentField *content_field, const gchar *attribute, const gchar *value) { - gboolean attribute_exists; - gchar *old_attribute; - gchar *old_value; - attribute_exists = g_hash_table_lookup_extended (content_field->parameters, - attribute, - (gpointer *) &old_attribute, - (gpointer *) &old_value); - /** CHECK THAT : is normal to free pointers before insertion ? **/ - if (attribute_exists) { - g_hash_table_remove(content_field->parameters, attribute); - g_free (old_value); - g_free (old_attribute); - } - - g_hash_table_insert (content_field->parameters, g_strdup (attribute), g_strdup (value)); -} - - -/** - * _print_parameter: print a parameter/value pair to a stream as described in RFC 2045 - * @name: name of the parameter - * @value: value of the parameter - * @user_data: CamelStream object to write the text to. - * - * - **/ -static void -_print_parameter (gpointer name, gpointer value, gpointer user_data) -{ - CamelStream *stream = (CamelStream *)user_data; - - camel_stream_write_strings (stream, - "; \n ", - (gchar *)name, - "=", - (gchar *)value, - NULL); - + header_content_type_set_param(content_field->content_type, attribute, value); } /** @@ -189,16 +123,21 @@ _print_parameter (gpointer name, gpointer value, gpointer user_data) void gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream) { + struct _header_param *p; + if (!content_field) return; g_assert (stream); - if (content_field->type) { - camel_stream_write_strings (stream, "Content-Type: ", content_field->type, NULL); - if (content_field->subtype) { - camel_stream_write_strings (stream, "/", content_field->subtype, NULL); - } + if (content_field->content_type) { + camel_stream_write_strings (stream, "Content-Type: ", content_field->content_type->type?content_field->content_type->type:"text", + "/", content_field->content_type->subtype?content_field->content_type->subtype:"plain", NULL); + /* print all parameters */ - g_hash_table_foreach (content_field->parameters, _print_parameter, stream); + p = content_field->content_type->params; + while (p) { + camel_stream_write_strings (stream, ";\n ", p->name, "= \"", p->value, "\"", NULL); + p = p->next; + } camel_stream_write_string (stream, "\n"); } } @@ -219,23 +158,15 @@ gmime_content_field_get_mime_type (GMimeContentField *content_field) { gchar *mime_type; - if (!content_field->type) return NULL; + if (!content_field->content_type->type) return NULL; - if (content_field->subtype) - mime_type = g_strdup_printf ("%s/%s", content_field->type, content_field->subtype); + if (content_field->content_type->subtype) + mime_type = g_strdup_printf ("%s/%s", content_field->content_type->type, content_field->content_type->subtype); else - mime_type = g_strdup (content_field->type); + mime_type = g_strdup (content_field->content_type->type); return mime_type; } -static void -___debug_print_parameter (gpointer name, gpointer value, gpointer user_data) -{ - - printf ("****** parameter \"%s\"=\"%s\"\n", (gchar *)name, (gchar *)value); - -} - /** * gmime_content_field_get_parameter: return the value of a mime type parameter * @content_field: content field object @@ -252,22 +183,10 @@ ___debug_print_parameter (gpointer name, gpointer value, gpointer user_data) const gchar * gmime_content_field_get_parameter (GMimeContentField *content_field, const gchar *name) { - const gchar *parameter; - const gchar *old_name; - gboolean parameter_exists; + g_assert (content_field); - g_assert (content_field->parameters); g_assert (name); - /* parameter = (const gchar *)g_hash_table_lookup (content_field->parameters, name); */ - parameter_exists = g_hash_table_lookup_extended (content_field->parameters, - name, - (gpointer *) &old_name, - (gpointer *) ¶meter); - if (!parameter_exists) { - g_hash_table_foreach (content_field->parameters, ___debug_print_parameter, NULL); - return NULL; - } - return parameter; + return header_content_type_param(content_field->content_type, name); } @@ -287,76 +206,39 @@ gmime_content_field_get_parameter (GMimeContentField *content_field, const gchar void gmime_content_field_construct_from_string (GMimeContentField *content_field, const gchar *string) { - gint first, len; - gint i=0; - gchar *type, *subtype; - gchar *param_name, *param_value; - gboolean param_end; - + struct _header_content_type *new; + g_assert (string); g_assert (content_field); - - g_free (content_field->type); - g_free (content_field->subtype); - - - first = 0; - len = strlen (string); - if (!len) - return; - - /* find the type */ - while ( (itype = type; - if (i >= len-1) { - content_field->subtype = NULL; - return; - } - - first = i+1; - /* find the subtype, if any */ - if (string[i++] == '/') { - while ( (isubtype = subtype; - if (i >= len-1) - return; - } - } - first = i+1; - - /* parse parameters list */ - param_end = FALSE; - do { - while ( (icontent_type) + header_content_type_unref(content_field->content_type); + if (new == NULL) { + new = header_content_type_new(NULL, NULL); + g_warning("Cannot parse content-type string: %s", string); + } + content_field->content_type = new; + content_field->type = new->type; + content_field->subtype = new->subtype; } +/** + * gmime_content_field_is_type: + * @content_field: An initialised GMimeContentField. + * @type: MIME Major type name. + * @subtype: MIME subtype. + * + * Returns true if the content_field is of the type @type and subtype @subtype. + * If @subtype is the special wildcard "*", then it will match any type. + * + * If the @content_field is empty, then it will match "text/plain", or "text/ *". + * + * Return value: + **/ +int +gmime_content_field_is_type (GMimeContentField *content_field, const char *type, const char *subtype) +{ + return header_content_type_is(content_field->content_type, type, subtype); +} -- cgit