mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 18:55:19 +00:00 
			
		
		
		
	res_http_media_cache.c: Compare unaltered MIME types.
Rather than stripping parameters from Content-Type headers before comparison, first try to compare the whole string. If no match is found, strip the parameters and try that way. ASTERISK-29275 #close Change-Id: I2963c8ecbb3a9605b78b6421c415108d77a66a0f
This commit is contained in:
		
				
					committed by
					
						 Friendly Automation
						Friendly Automation
					
				
			
			
				
	
			
			
			
						parent
						
							148f8355a0
						
					
				
				
					commit
					02f54e2751
				
			| @@ -176,8 +176,10 @@ static char *file_extension_from_string(const char *str, char *buffer, size_t ca | |||||||
|  * \brief Normalize the value of a Content-Type header |  * \brief Normalize the value of a Content-Type header | ||||||
|  * |  * | ||||||
|  * This will trim off any optional parameters after the type/subtype. |  * This will trim off any optional parameters after the type/subtype. | ||||||
|  |  * | ||||||
|  |  * \return 0 if no normalization occurred, otherwise true (non-zero) | ||||||
|  */ |  */ | ||||||
| static void normalize_content_type_header(char *content_type) | static int normalize_content_type_header(char *content_type) | ||||||
| { | { | ||||||
| 	char *params = strchr(content_type, ';'); | 	char *params = strchr(content_type, ';'); | ||||||
|  |  | ||||||
| @@ -186,7 +188,27 @@ static void normalize_content_type_header(char *content_type) | |||||||
| 		while (params > content_type && (*params == ' ' || *params == '\t')) { | 		while (params > content_type && (*params == ' ' || *params == '\t')) { | ||||||
| 			*params-- = 0; | 			*params-- = 0; | ||||||
| 		} | 		} | ||||||
|  | 		return 1; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int derive_extension_from_mime_type(const char *mime_type, char *buffer, size_t capacity) | ||||||
|  | { | ||||||
|  | 	int res = 0; | ||||||
|  |  | ||||||
|  | 	/* Compare the provided Content-Type directly, parameters and all */ | ||||||
|  | 	res = ast_get_extension_for_mime_type(mime_type, buffer, sizeof(buffer)); | ||||||
|  | 	if (!res) { | ||||||
|  | 		char *m = ast_strdupa(mime_type); | ||||||
|  | 		/* Strip MIME type parameters and then check */ | ||||||
|  | 		if (normalize_content_type_header(m)) { | ||||||
|  | 			res = ast_get_extension_for_mime_type(m, buffer, sizeof(buffer)); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return res; | ||||||
| } | } | ||||||
|  |  | ||||||
| static char *file_extension_from_content_type(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity) | static char *file_extension_from_content_type(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity) | ||||||
| @@ -198,28 +220,20 @@ static char *file_extension_from_content_type(struct ast_bucket_file *bucket_fil | |||||||
| 	 * corresponding to the mime-type and use that to rename the file */ | 	 * corresponding to the mime-type and use that to rename the file */ | ||||||
|  |  | ||||||
| 	struct ast_bucket_metadata *header; | 	struct ast_bucket_metadata *header; | ||||||
| 	char *mime_type; |  | ||||||
|  |  | ||||||
| 	header = ast_bucket_file_metadata_get(bucket_file, "content-type"); | 	header = ast_bucket_file_metadata_get(bucket_file, "content-type"); | ||||||
| 	if (!header) { | 	if (!header) { | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	mime_type = ast_strdup(header->value); | 	if (derive_extension_from_mime_type(header->value, buffer, capacity)) { | ||||||
| 	if (mime_type) { | 		ast_debug(3, "Derived extension '%s' from MIME type %s\n", | ||||||
| 		normalize_content_type_header(mime_type); | 			buffer, | ||||||
| 		if (!ast_strlen_zero(mime_type)) { | 			header->value); | ||||||
| 			if (ast_get_extension_for_mime_type(mime_type, buffer, sizeof(buffer))) { | 		ao2_ref(header, -1); | ||||||
| 				ast_debug(3, "Derived extension '%s' from MIME type %s\n", | 		return buffer; | ||||||
| 					buffer, |  | ||||||
| 					mime_type); |  | ||||||
| 				ast_free(mime_type); |  | ||||||
| 				ao2_ref(header, -1); |  | ||||||
| 				return buffer; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 	ast_free(mime_type); |  | ||||||
| 	ao2_ref(header, -1); | 	ao2_ref(header, -1); | ||||||
|  |  | ||||||
| 	return NULL; | 	return NULL; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user