Exemple #1
0
/**
 * g_mime_content_type_new_from_string:
 * @str: input string containing a content-type (and params)
 *
 * Constructs a new Content-Type object based on the input string.
 *
 * Returns: a new #GMimeContentType object based on the input string.
 **/
GMimeContentType *
g_mime_content_type_new_from_string (const char *str)
{
	GMimeContentType *mime_type;
	const char *inptr = str;
	char *type, *subtype;
	
	g_return_val_if_fail (str != NULL, NULL);
	
	if (!g_mime_parse_content_type (&inptr, &type, &subtype))
		return g_mime_content_type_new ("application", "octet-stream");
	
	mime_type = g_object_newv (GMIME_TYPE_CONTENT_TYPE, 0, NULL);
	mime_type->subtype = subtype;
	mime_type->type = type;
	
	/* skip past any remaining junk that shouldn't be here... */
	decode_lwsp (&inptr);
	while (*inptr && *inptr != ';')
		inptr++;
	
	if (*inptr++ == ';' && *inptr) {
		GMimeParam *param;
		
		param = mime_type->params = g_mime_param_new_from_string (inptr);
		while (param != NULL) {
			g_hash_table_insert (mime_type->param_hash, param->name, param);
			param = param->next;
		}
	}
	
	return mime_type;
}
Exemple #2
0
GMimeContentType *
_g_mime_content_type_parse (GMimeParserOptions *options, const char *str, gint64 offset)
{
	GMimeContentType *content_type;
	const char *inptr = str;
	GMimeParamList *params;
	char *type, *subtype;
	
	g_return_val_if_fail (str != NULL, NULL);
	
	if (!g_mime_parse_content_type (&inptr, &type, &subtype)) {
		_g_mime_parser_options_warn (options, offset, GMIME_WARN_INVALID_CONTENT_TYPE, str);
		return g_mime_content_type_new ("application", "octet-stream");
	}
	
	content_type = g_object_new (GMIME_TYPE_CONTENT_TYPE, NULL);
	content_type->subtype = subtype;
	content_type->type = type;
	
	/* skip past any remaining junk that shouldn't be here... */
	skip_cfws (&inptr);
	while (*inptr && *inptr != ';')
		inptr++;
	
	if (*inptr++ == ';' && *inptr && (params = _g_mime_param_list_parse (options, inptr, offset))) {
		g_mime_event_add (params->changed, (GMimeEventCallback) param_list_changed, content_type);
		g_object_unref (content_type->params);
		content_type->params = params;
	}
	
	return content_type;
}