[svn-commits] murf: branch group/http_mods r60068 - in /team/group/http_mods/main: ./ minim...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Apr 4 09:24:11 MST 2007


Author: murf
Date: Wed Apr  4 11:24:10 2007
New Revision: 60068

URL: http://svn.digium.com/view/asterisk?view=rev&rev=60068
Log:
OK. The API has been changed to replace the content-type object with the more generic 'content' object.This is not a huge shift, but it does change several comments, and adds the Content-Disposition info to the 'content' structure. All the special fields for Content-Disposition that were for Content-Disposition were removed from the mimepart structure. Now they will all be stored in the content struct in the disposition_params list. The content params are now the content type_params. All the API funcs that deal with this are updated, and the mm.h file reflects the new and modified functions. BTW, you get the Content-Disposition type via the mm_content_getdispositiontype() func now. So What Does All This Mean\? Simply that the API is now updated and frozen. The mytest program has been updated, as well as the parser, to reflect the new API updates. It's really not that much different. I also added a params list to the mimeheader, although the parser is not updated for this yet,
  as it was not in the current syntax. But it should be, shouldn't it\? Can't the current example input have 'Myheader1: blah1 evilParam=badstuff' in it\? Wouldn't you want to be able to get at the evilParam=badstuff info\? At any rate, you can now write code around the API without fear, and help get rid of any bugs I may have introduced. I will continue and reorganize the current parser to be thread-safe, which will be a pretty big job, methinks.

Modified:
    team/group/http_mods/main/http.c
    team/group/http_mods/main/minimime/mimeparser.y
    team/group/http_mods/main/minimime/mm.h
    team/group/http_mods/main/minimime/mm_contenttype.c
    team/group/http_mods/main/minimime/mm_context.c
    team/group/http_mods/main/minimime/mm_header.c
    team/group/http_mods/main/minimime/mm_mimepart.c
    team/group/http_mods/main/minimime/mytest_files/mytest.c

Modified: team/group/http_mods/main/http.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/http.c?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/http.c (original)
+++ team/group/http_mods/main/http.c Wed Apr  4 11:24:10 2007
@@ -382,7 +382,7 @@
 		return;
 	}
 	body_len = mm_mimepart_getlength(part);
-	ast_log(LOG_DEBUG, "Body length is %ld\n", body_len);	
+	ast_log(LOG_DEBUG, "Body length is %d\n", body_len);	
 
 	fwrite(body, 1, body_len, f);
 

Modified: team/group/http_mods/main/minimime/mimeparser.y
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mimeparser.y?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/minimime/mimeparser.y (original)
+++ team/group/http_mods/main/minimime/mimeparser.y Wed Apr  4 11:24:10 2007
@@ -174,7 +174,7 @@
 			param->name = xstrdup("charset");
 			param->value = xstrdup("us-ascii");
 
-			mm_content_attachparam(ct, param);
+			mm_content_attachtypeparam(ct, param);
 			mm_mimepart_attachcontenttype(current_mimepart, ct);
 		}	
 		have_contenttype = 0;
@@ -310,13 +310,13 @@
 	CONTENTDISPOSITION_HEADER COLON content_disposition EOL
 	{
 		dprintf2("Content-Disposition -> %s\n", $3);
-		current_mimepart->disposition_type = xstrdup($3);
+		ctype->disposition_type = xstrdup($3);
 	}
 	|
 	CONTENTDISPOSITION_HEADER COLON content_disposition content_disposition_parameters EOL
 	{
 		dprintf2("Content-Disposition (P) -> %s; params\n", $3);
-		current_mimepart->disposition_type = xstrdup($3);
+		ctype->disposition_type = xstrdup($3);
 	}
 	;
 
@@ -439,41 +439,21 @@
 		param->name = xstrdup($1);
 		param->value = xstrdup($3);
 
-		mm_content_attachparam(ctype, param);
+		mm_content_attachtypeparam(ctype, param);
 	}
 	;
 
 content_disposition_parameter:
 	WORD EQUAL contenttype_parameter_value
 	{
-		if (!strcasecmp($1, "filename") 
-		    && current_mimepart->filename == NULL) {
-			current_mimepart->filename = xstrdup($3);
-		} else if (!strcasecmp($1, "name")
-		    && current_mimepart->the_name == NULL) {
-			current_mimepart->the_name = xstrdup($3);
-		} else if (!strcasecmp($1, "creation-date")
-		    && current_mimepart->creation_date == NULL) {
-			current_mimepart->creation_date = xstrdup($3);
-		} else if (!strcasecmp($1, "modification-date")
-		    && current_mimepart->modification_date == NULL) {
-			current_mimepart->modification_date = xstrdup($3);
-		} else if (!strcasecmp($1, "read-date")
-		    && current_mimepart->read_date == NULL) {
-		    	current_mimepart->read_date = xstrdup($3);
-		} else if (!strcasecmp($1, "size")
-		    && current_mimepart->disposition_size == NULL) {
-		    	current_mimepart->disposition_size = xstrdup($3);
-		} else {
-			if (parsemode != MM_PARSE_LOOSE) {
-				mm_errno = MM_ERROR_MIME;
-				mm_error_setmsg("invalid disposition "
-				    "parameter");
-				return -1;
-			} else {
-				/* TODO: attach MM_WARNING_INVPARAM */
-			}	
-		}	
+		struct mm_param *param;
+		param = mm_param_new();
+		
+		param->name = xstrdup($1);
+		param->value = xstrdup($3);
+
+		mm_content_attachdispositionparam(ctype, param);
+
 	}
 	;
 

Modified: team/group/http_mods/main/minimime/mm.h
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mm.h?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/minimime/mm.h (original)
+++ team/group/http_mods/main/minimime/mm.h Wed Apr  4 11:24:10 2007
@@ -174,6 +174,17 @@
 };
 
 /*
+ * Representation of a MIME Content-Type parameter
+ */
+struct mm_param
+{
+	char *name; 
+	char *value; 
+
+	TAILQ_ENTRY(mm_param) next;
+};
+
+/*
  * Representation of a mail or MIME header field
  */
 struct mm_mimeheader
@@ -181,18 +192,9 @@
 	char *name; 
 	char *value;
 
+	struct mm_params params;
+
 	TAILQ_ENTRY(mm_mimeheader) next;
-};
-
-/*
- * Representation of a MIME Content-Type parameter
- */
-struct mm_param
-{
-	char *name; 
-	char *value; 
-
-	TAILQ_ENTRY(mm_param) next;
 };
 
 /*
@@ -202,8 +204,10 @@
 {
 	char *maintype;
 	char *subtype;
-
-	struct mm_params params;
+	char *disposition_type;
+
+	struct mm_params type_params;
+	struct mm_params disposition_params;
 
 	char *encstring;
 	enum mm_encoding encoding;
@@ -224,14 +228,6 @@
 
 	struct mm_content *type;
 
-	char *the_name;
-	char *disposition_type;
-	char *filename;
-	char *creation_date;
-	char *modification_date;
-	char *read_date;
-	char *disposition_size;
-	
 	TAILQ_ENTRY(mm_mimepart) next;
 };
 
@@ -286,6 +282,8 @@
 int mm_mimeheader_uncommentbyname(struct mm_mimepart *, const char *);
 int mm_mimeheader_uncommentall(struct mm_mimepart *);
 int mm_mimeheader_tostring(struct mm_mimeheader *);
+char *mm_mimeheader_getparambyname(struct mm_mimeheader *hdr, const char *name);
+int mm_mimeheader_attachparam(struct mm_mimeheader *hdr, struct mm_param *param);
 
 struct mm_mimepart *mm_mimepart_new(void);
 void mm_mimepart_free(struct mm_mimepart *);
@@ -297,7 +295,7 @@
 int mm_mimepart_headers_start(struct mm_mimepart *, struct mm_mimeheader **);
 struct mm_mimeheader *mm_mimepart_headers_next(struct mm_mimepart *, struct mm_mimeheader **);
 char *mm_mimepart_decode(struct mm_mimepart *);
-struct mm_content *mm_mimepart_gettype(struct mm_mimepart *);
+struct mm_content *mm_mimepart_getcontent(struct mm_mimepart *);
 size_t mm_mimepart_getlength(struct mm_mimepart *);
 char *mm_mimepart_getbody(struct mm_mimepart *, int);
 void mm_mimepart_attachcontenttype(struct mm_mimepart *, struct mm_content *);
@@ -307,20 +305,26 @@
 
 struct mm_content *mm_content_new(void);
 void mm_content_free(struct mm_content *);
-int mm_content_attachparam(struct mm_content *, struct mm_param *);
+int mm_content_attachtypeparam(struct mm_content *, struct mm_param *);
+int mm_content_attachdispositionparam(struct mm_content *, struct mm_param *);
 struct mm_content *mm_content_parse(const char *, int);
-char *mm_content_getparambyname(struct mm_content *, const char *);
-struct mm_param *mm_content_getparamobjbyname(struct mm_content *, const char *);
+char *mm_content_gettypeparambyname(struct mm_content *, const char *);
+char *mm_content_getdispositionparambyname(struct mm_content *, const char *);
+struct mm_param *mm_content_gettypeparamobjbyname(struct mm_content *, const char *);
+struct mm_param *mm_content_getdispositionparamobjbyname(struct mm_content *, const char *);
 int mm_content_setmaintype(struct mm_content *, char *, int);
 int mm_content_setsubtype(struct mm_content *, char *, int);
 int mm_content_settype(struct mm_content *, const char *, ...);
+int mm_content_setdispositiontype(struct mm_content *ct, char *value, int copy);
 char *mm_content_getmaintype(struct mm_content *);
 char *mm_content_getsubtype(struct mm_content *);
 char *mm_content_gettype(struct mm_content *);
+char *mm_content_getdispositiontype(struct mm_content *ct);
 int mm_content_iscomposite(struct mm_content *);
 int mm_content_isvalidencoding(const char *);
 int mm_content_setencoding(struct mm_content *, const char *);
-char *mm_content_paramstostring(struct mm_content *);
+char *mm_content_typeparamstostring(struct mm_content *);
+char *mm_content_dispositionparamstostring(struct mm_content *);
 char *mm_content_tostring(struct mm_content *);
 
 struct mm_param *mm_param_new(void);

Modified: team/group/http_mods/main/minimime/mm_contenttype.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mm_contenttype.c?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/minimime/mm_contenttype.c (original)
+++ team/group/http_mods/main/minimime/mm_contenttype.c Wed Apr  4 11:24:10 2007
@@ -76,11 +76,11 @@
 };		
 
 /** @{
- * @name Functions for manipulating Content-Type objects
- */
-
-/**
- * Creates a new object to hold a Content-Type representation.
+ * @name Functions for manipulating Content objects
+ */
+
+/**
+ * Creates a new object to hold a Content representation.
  * The allocated memory must later be freed using mm_content_free()
  *
  * @return An object representing a MIME Content-Type
@@ -97,7 +97,8 @@
 	ct->maintype = NULL;
 	ct->subtype = NULL;
 
-	TAILQ_INIT(&ct->params);
+	TAILQ_INIT(&ct->type_params);
+	TAILQ_INIT(&ct->disposition_params);
 
 	ct->encoding = MM_ENCODING_NONE;
 	ct->encstring = NULL;
@@ -106,7 +107,7 @@
 }
 
 /**
- * Releases all memory associated with an Content-Type object
+ * Releases all memory associated with an Content object
  *
  * @param ct A Content-Type object
  * @return Nothing
@@ -132,32 +133,36 @@
 		ct->encstring = NULL;
 	}
 
-	TAILQ_FOREACH(param, &ct->params, next) {
-		TAILQ_REMOVE(&ct->params, param, next);
+	TAILQ_FOREACH(param, &ct->type_params, next) {
+		TAILQ_REMOVE(&ct->type_params, param, next);
 		mm_param_free(param);
 	}	
+	TAILQ_FOREACH(param, &ct->disposition_params, next) {
+		TAILQ_REMOVE(&ct->disposition_params, param, next);
+		mm_param_free(param);
+	}	
 
 	xfree(ct);
 }
 
 /**
- * Attaches a parameter to a Content-Type object
- *
- * @param ct The target Content-Type object
+ * Attaches a content-type parameter to a Content object
+ *
+ * @param ct The target Content object
  * @param param The Content-Type parameter which to attach
  * @return 0 on success and -1 on failure
  * @ingroup contenttype
  */
 int
-mm_content_attachparam(struct mm_content *ct, struct mm_param *param)
+mm_content_attachtypeparam(struct mm_content *ct, struct mm_param *param)
 {
 	assert(ct != NULL);
 	assert(param != NULL);
 
-	if (TAILQ_EMPTY(&ct->params)) {
-		TAILQ_INSERT_HEAD(&ct->params, param, next);
+	if (TAILQ_EMPTY(&ct->type_params)) {
+		TAILQ_INSERT_HEAD(&ct->type_params, param, next);
 	} else {
-		TAILQ_INSERT_TAIL(&ct->params, param, next);
+		TAILQ_INSERT_TAIL(&ct->type_params, param, next);
 	}
 
 	return 0;
@@ -165,21 +170,45 @@
 
 
 /**
- * Gets a parameter value from a Content-Type object.
- *
- * @param ct the Content-Type object
+ * Attaches a content-disposition parameter to a Content-Disposition object
+ *
+ * @param ct The target Content object
+ * @param param The Content-Type parameter which to attach
+ * @return 0 on success and -1 on failure
+ * @ingroup contenttype
+ */
+int
+mm_content_attachdispositionparam(struct mm_content *ct, struct mm_param *param)
+{
+	assert(ct != NULL);
+	assert(param != NULL);
+
+	if (TAILQ_EMPTY(&ct->disposition_params)) {
+		TAILQ_INSERT_HEAD(&ct->disposition_params, param, next);
+	} else {
+		TAILQ_INSERT_TAIL(&ct->disposition_params, param, next);
+	}
+
+	return 0;
+}		
+
+
+/**
+ * Gets a Content-Type parameter value from a Content object.
+ *
+ * @param ct the Content object
  * @param name the name of the parameter to retrieve
  * @return The value of the parameter on success or a NULL pointer on failure
  * @ingroup contenttype
  */
 char *
-mm_content_getparambyname(struct mm_content *ct, const char *name)
+mm_content_gettypeparambyname(struct mm_content *ct, const char *name)
 {
 	struct mm_param *param;
 
 	assert(ct != NULL);
 	
-	TAILQ_FOREACH(param, &ct->params, next) {
+	TAILQ_FOREACH(param, &ct->type_params, next) {
 		if (!strcasecmp(param->name, name)) {
 			return param->value;
 		}
@@ -188,14 +217,38 @@
 	return NULL;
 }
 
+/**
+ * Gets a Content-Disposition parameter value from a Content object.
+ *
+ * @param ct the Content object
+ * @param name the name of the parameter to retrieve
+ * @return The value of the parameter on success or a NULL pointer on failure
+ * @ingroup contenttype
+ */
+char *
+mm_content_getdispositionparambyname(struct mm_content *ct, const char *name)
+{
+	struct mm_param *param;
+
+	assert(ct != NULL);
+	
+	TAILQ_FOREACH(param, &ct->disposition_params, next) {
+		if (!strcasecmp(param->name, name)) {
+			return param->value;
+		}
+	}
+
+	return NULL;
+}
+
 struct mm_param *
-mm_content_getparamobjbyname(struct mm_content *ct, const char *name)
+mm_content_gettypeparamobjbyname(struct mm_content *ct, const char *name)
 {
 	struct mm_param *param;
 
 	assert(ct != NULL);
 	
-	TAILQ_FOREACH(param, &ct->params, next) {
+	TAILQ_FOREACH(param, &ct->type_params, next) {
 		if (!strcasecmp(param->name, name)) {
 			return param;
 		}
@@ -204,10 +257,26 @@
 	return NULL;
 }
 
-/**
- * Sets the MIME main type for a MIME Content-Type object
- *
- * @param ct The MIME Content-Type object
+struct mm_param *
+mm_content_getdispositionparamobjbyname(struct mm_content *ct, const char *name)
+{
+	struct mm_param *param;
+
+	assert(ct != NULL);
+	
+	TAILQ_FOREACH(param, &ct->disposition_params, next) {
+		if (!strcasecmp(param->name, name)) {
+			return param;
+		}
+	}
+
+	return NULL;
+}
+
+/**
+ * Sets the MIME main Content-Type for a MIME Content object
+ *
+ * @param ct The MIME Content object
  * @param value The value which to set the main type to
  * @param copy Whether to make a copy of the value (original value must be
  *        freed afterwards to prevent memory leaks).
@@ -235,23 +304,69 @@
 }
 
 /**
- * Retrieves the main MIME type stored in a Content-Type object
+ * Retrieves the main MIME Content-Type stored in a Content object
+ *
+ * @param ct A valid Content object
+ * @returns A pointer to the string representing the main type
+ * @ingroup contenttype
+ */
+char *
+mm_content_getmaintype(struct mm_content *ct)
+{
+	assert(ct != NULL);
+	assert(ct->maintype != NULL);
+
+	return ct->maintype;
+}
+
+/**
+ * Sets the MIME Content-Disposition type for a MIME Content object
+ *
+ * @param ct The MIME Content object
+ * @param value The value which to set the main type to
+ * @param copy Whether to make a copy of the value (original value must be
+ *        freed afterwards to prevent memory leaks).
+ */
+int
+mm_content_setdispositiontype(struct mm_content *ct, char *value, int copy)
+{
+	assert(ct != NULL);
+	assert(value != NULL);
+
+	if (copy) {
+		/**
+		 * @bug The xfree() call could lead to undesirable results. 
+ 		 * Do we really need it?
+		 */
+		if (ct->disposition_type != NULL) {
+			xfree(ct->disposition_type);
+		}
+		ct->disposition_type = xstrdup(value);
+	} else {
+		ct->disposition_type = value;
+	}
+
+	return 0;
+}
+
+/**
+ * Retrieves the Content-Disposition MIME type stored in a Content object
  *
  * @param ct A valid Content-Type object
  * @returns A pointer to the string representing the main type
  * @ingroup contenttype
  */
 char *
-mm_content_getmaintype(struct mm_content *ct)
-{
-	assert(ct != NULL);
-	assert(ct->maintype != NULL);
-
-	return ct->maintype;
-}
-
-/**
- * Retrieves the sub MIME type stored in a Content-Type object
+mm_content_getdispositiontype(struct mm_content *ct)
+{
+	assert(ct != NULL);
+	assert(ct->disposition_type != NULL);
+
+	return ct->disposition_type;
+}
+
+/**
+ * Retrieves the sub MIME Content-Type stored in a Content object
  *
  * @param ct A valid Content-Type object
  * @return A pointer to the string holding the current sub MIME type
@@ -266,17 +381,8 @@
 	return ct->subtype;
 }
 
-char *
-mm_content_gettype(struct mm_content *ct)
-{
-	assert(ct != NULL);
-	assert(ct->subtype != NULL);
-
-	return ct->subtype;
-}
-
-/**
- * Sets the MIME sub type for a MIME Content-Type object
+/**
+ * Sets the MIME sub Content-Type for a MIME Content object
  *
  * @param ct The MIME Content-Type object
  * @param value The value which to set the sub type to
@@ -453,7 +559,7 @@
  * you need an opaque copy of the current MIME part (e.g. for PGP purposes).
  */
 char *
-mm_content_paramstostring(struct mm_content *ct)
+mm_content_typeparamstostring(struct mm_content *ct)
 {
 	size_t size, new_size;
 	struct mm_param *param;
@@ -470,7 +576,7 @@
 	/* Concatenate all Content-Type parameters attached to the current
 	 * Content-Type object to a single string.
 	 */
-	TAILQ_FOREACH(param, &ct->params, next) {
+	TAILQ_FOREACH(param, &ct->type_params, next) {
 		if (asprintf(&cur_param, "; %s=\"%s\"", param->name, 
 		    param->value) == -1) {
 			goto cleanup;
@@ -512,6 +618,77 @@
 }
 
 /**
+ * Constructs a MIME conformant string of Content-Disposition parameters.
+ *
+ * @param ct A valid Content object
+ * @return A pointer to a string representing the Content-Disposition parameters
+ *         in MIME terminology, or NULL if either the Content object
+ *         is invalid, has no Disposition parameters or no memory could be allocated.
+ *
+ * This function constructs a MIME conforming string including all the parameters
+ * associated with the given Content-Disposition object. It should NOT be used if
+ * you need an opaque copy of the current MIME part (e.g. for PGP purposes).
+ */
+char *
+mm_content_dispositionparamstostring(struct mm_content *ct)
+{
+	size_t size, new_size;
+	struct mm_param *param;
+	char *param_string, *cur_param;
+	char *buf;
+
+	size = 1;
+	param_string = NULL;
+	cur_param = NULL;
+
+	param_string = (char *) xmalloc(size);
+	*param_string = '\0';
+
+	/* Concatenate all Content-Disposition parameters attached to the current
+	 * Content object to a single string.
+	 */
+	TAILQ_FOREACH(param, &ct->disposition_params, next) {
+		if (asprintf(&cur_param, "; %s=\"%s\"", param->name, 
+		    param->value) == -1) {
+			goto cleanup;
+		}
+
+		new_size = size + strlen(cur_param) + 1;
+		
+		if (new_size < 0 || new_size > 1000) {
+			size = 0;
+			goto cleanup;
+		}	
+
+		buf = (char *) xrealloc(param_string, new_size);
+		if (buf == NULL) {
+			size = 0;
+			goto cleanup;
+		}
+
+		param_string = buf;
+		size = new_size;
+		strlcat(param_string, cur_param, size);
+		
+		xfree(cur_param);
+		cur_param = NULL;
+	}
+
+	return param_string;
+
+cleanup:
+	if (param_string != NULL) {
+		xfree(param_string);
+		param_string = NULL;
+	}
+	if (cur_param != NULL) {
+		xfree(cur_param);
+		cur_param = NULL;
+	}	
+	return NULL;
+}
+
+/**
  * Creates a Content-Type header according to the object given
  *
  * @param ct A valid Content-Type object
@@ -540,7 +717,7 @@
 	headerstring = (char *)xmalloc(size);
 	snprintf(headerstring, size, "%s/%s", ct->maintype, ct->subtype);
 
-	paramstring = mm_content_paramstostring(ct);
+	paramstring = mm_content_typeparamstostring(ct);
 	if (paramstring == NULL) {
 		goto cleanup;
 	}

Modified: team/group/http_mods/main/minimime/mm_context.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mm_context.c?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/minimime/mm_context.c (original)
+++ team/group/http_mods/main/minimime/mm_context.c Wed Apr  4 11:24:10 2007
@@ -366,12 +366,12 @@
 		return(0);
 	}
 	if (part->type != NULL) {
-		param = mm_content_getparamobjbyname(part->type, "boundary");
+		param = mm_content_gettypeparamobjbyname(part->type, "boundary");
 		if (param == NULL) {
 			param = mm_param_new();
 			param->name = xstrdup("boundary");
 			param->value = xstrdup(boundary);
-			mm_content_attachparam(part->type, param);
+			mm_content_attachtypeparam(part->type, param);
 		} else {
 			if (param->value != NULL) {
 				xfree(param->value);

Modified: team/group/http_mods/main/minimime/mm_header.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mm_header.c?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/minimime/mm_header.c (original)
+++ team/group/http_mods/main/minimime/mm_header.c Wed Apr  4 11:24:10 2007
@@ -64,6 +64,7 @@
 	
 	header->name = NULL;
 	header->value = NULL;
+	TAILQ_INIT(&header->params);
 
 	return header;
 }
@@ -76,6 +77,7 @@
 void
 mm_mimeheader_free(struct mm_mimeheader *header)
 {
+	struct mm_param *param;
 	assert(header != NULL);
 
 	if (header->name != NULL) {
@@ -87,7 +89,11 @@
 		header->value = NULL;
 	}
 
-	xfree(header);
+	TAILQ_FOREACH(param, &header->params, next) {
+		TAILQ_REMOVE(&header->params, param, next);
+		mm_param_free(param);
+	}	
+xfree(header);
 	header = NULL;
 }
 
@@ -105,6 +111,54 @@
 	header->value = xstrdup(value);
 
 	return header;
+}
+
+/**
+ * Attaches a parameter to a MimeHeader object
+ *
+ * @param hdr The target MimeHeader object
+ * @param param The parameter to attach
+ * @return 0 on success and -1 on failure
+ * @ingroup mimeheader
+ */
+int
+mm_mimeheader_attachparam(struct mm_mimeheader *hdr, struct mm_param *param)
+{
+	assert(hdr != NULL);
+	assert(param != NULL);
+
+	if (TAILQ_EMPTY(&hdr->params)) {
+		TAILQ_INSERT_HEAD(&hdr->params, param, next);
+	} else {
+		TAILQ_INSERT_TAIL(&hdr->params, param, next);
+	}
+
+	return 0;
+}		
+
+
+/**
+ * Gets a parameter value from a MimeHeader object.
+ *
+ * @param hdr the MimeHeader object
+ * @param name the name of the parameter to retrieve
+ * @return The value of the parameter on success or a NULL pointer on failure
+ * @ingroup mimeheader
+ */
+char *
+mm_mimeheader_getparambyname(struct mm_mimeheader *hdr, const char *name)
+{
+	struct mm_param *param;
+
+	assert(hdr != NULL);
+	
+	TAILQ_FOREACH(param, &hdr->params, next) {
+		if (!strcasecmp(param->name, name)) {
+			return param->value;
+		}
+	}
+
+	return NULL;
 }
 
 int

Modified: team/group/http_mods/main/minimime/mm_mimepart.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mm_mimepart.c?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/minimime/mm_mimepart.c (original)
+++ team/group/http_mods/main/minimime/mm_mimepart.c Wed Apr  4 11:24:10 2007
@@ -87,13 +87,6 @@
 	
 	part->type = NULL;
 
-	part->disposition_type = NULL;
-	part->filename = NULL;
-	part->creation_date = NULL;
-	part->modification_date = NULL;
-	part->read_date = NULL;
-	part->disposition_size = NULL;
-
 	return part;
 }
 
@@ -178,31 +171,6 @@
 	if (part->type != NULL) {
 		mm_content_free(part->type);
 		part->type = NULL;
-	}
-
-	if (part->disposition_type != NULL) {
-		xfree(part->disposition_type);
-		part->disposition_type = NULL;
-	}	
-	if (part->filename != NULL) {
-		xfree(part->filename );
-		part->filename = NULL;
-	}	
-	if (part->creation_date != NULL) {
-		xfree(part->creation_date );
-		part->creation_date = NULL;
-	}
-	if (part->modification_date != NULL) {
-		xfree(part->modification_date );
-		part->modification_date = NULL;
-	}
-	if (part->read_date != NULL) {
-		xfree(part->read_date );
-		part->read_date = NULL;
-	}
-	if (part->disposition_size != NULL) {
-		xfree(part->disposition_size);
-		part->read_date = NULL;
 	}
 
 	xfree(part);
@@ -639,7 +607,7 @@
 		param = mm_param_new();
 		param->name = xstrdup("charset");
 		param->value = xstrdup("us-ascii");
-		mm_content_attachparam(type, param);
+		mm_content_attachtypeparam(type, param);
 	}	
 
 	mm_mimepart_attachcontenttype(part, type);
@@ -679,7 +647,7 @@
  * no Content-Type object for the given MIME part currently.
  */
 struct mm_content *
-mm_mimepart_gettype(struct mm_mimepart *part)
+mm_mimepart_getcontent(struct mm_mimepart *part)
 {
 	assert(part != NULL);
 

Modified: team/group/http_mods/main/minimime/mytest_files/mytest.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mytest_files/mytest.c?view=diff&rev=60068&r1=60067&r2=60068
==============================================================================
--- team/group/http_mods/main/minimime/mytest_files/mytest.c (original)
+++ team/group/http_mods/main/minimime/mytest_files/mytest.c Wed Apr  4 11:24:10 2007
@@ -8,6 +8,8 @@
 	const char *filename = "mytest_files/ast_postdata";
 	MM_CTX *ctx;
 	struct mm_mimepart *part;
+	struct mm_content *cont;
+	
 	int res = 0;
 	const char *disp;
 	int i;
@@ -69,5 +71,25 @@
 		mm_context_free(ctx);
 	}
 
+	/* This is where the problems are demonstrated. */
+
+	cont =  mm_mimepart_getcontent(part);
+
+	if ((disp = mm_content_getdispositiontype(cont)))
+		printf("SUCCESS: Got the Content-Disposition: %s\n", disp);
+	else
+		printf("FAILURE: Could not get the Content-Disposition value!\n");
+
+	/* hmmm... strange, headers don't have params, which is really quite not-nice! */
+	/* but the author has been storing Content-Disposition params in the part structure */
+
+	res = mm_mimepart_getlength(part);
+	if (res)
+		printf("SUCCESS: Got a non-zero value for the body length: %d\n", res);
+	else
+		printf("FAILURE: The silly parser says this MIME part has 0 length!\n");
+
+cleanup:
+	mm_context_free(ctx);
 	exit(res);
 }



More information about the svn-commits mailing list