00001 /* 00002 * Copyright 2008-2010 Arsen Chaloyan 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 * $Id: apt_multipart_content.h 1722 2010-06-01 08:40:35Z achaloyan $ 00017 */ 00018 00019 #ifndef APT_MULTIPART_CONTENT_H 00020 #define APT_MULTIPART_CONTENT_H 00021 00022 /** 00023 * @file apt_multipart_content.h 00024 * @brief Multipart Content Routine 00025 */ 00026 00027 #include "apt_header_field.h" 00028 00029 APT_BEGIN_EXTERN_C 00030 00031 /** Opaque multipart content declaration */ 00032 typedef struct apt_multipart_content_t apt_multipart_content_t; 00033 00034 /** Content part declaration */ 00035 typedef struct apt_content_part_t apt_content_part_t; 00036 00037 /** Content part */ 00038 struct apt_content_part_t { 00039 /** Header section */ 00040 apt_header_section_t header; 00041 /** Body */ 00042 apt_str_t body; 00043 00044 /** Pointer to parsed content-type header field */ 00045 apt_str_t *type; 00046 /** Pointer to parsed content-id header field */ 00047 apt_str_t *id; 00048 /** Pointer to parsed content-length header field */ 00049 apt_str_t *length; 00050 }; 00051 00052 /** 00053 * Create an empty multipart content 00054 * @param max_content_size the max size of the content (body) 00055 * @param boundary the boundary to separate content parts 00056 * @param pool the pool to allocate memory from 00057 * @return an empty multipart content 00058 */ 00059 APT_DECLARE(apt_multipart_content_t*) apt_multipart_content_create(apr_size_t max_content_size, const apt_str_t *boundary, apr_pool_t *pool); 00060 00061 /** 00062 * Add content part to multipart content 00063 * @param multipart_content the multipart content to add content part to 00064 * @param content_part the content part to add 00065 * @return TRUE on success 00066 */ 00067 APT_DECLARE(apt_bool_t) apt_multipart_content_add(apt_multipart_content_t *multipart_content, const apt_content_part_t *content_part); 00068 00069 /** 00070 * Add content part to multipart content by specified header fields and body 00071 * @param multipart_content the multipart content to add content part to 00072 * @param content_type the type of content part 00073 * @param content_id the identifier of content part 00074 * @param body the body of content part 00075 * @return TRUE on success 00076 */ 00077 APT_DECLARE(apt_bool_t) apt_multipart_content_add2(apt_multipart_content_t *multipart_content, const apt_str_t *content_type, const apt_str_t *content_id, const apt_str_t *body); 00078 00079 /** 00080 * Finalize multipart content generation 00081 * @param multipart_content the multipart content to finalize 00082 * @return generated multipart content 00083 */ 00084 APT_DECLARE(apt_str_t*) apt_multipart_content_finalize(apt_multipart_content_t *multipart_content); 00085 00086 00087 /** 00088 * Assign body to multipart content to get (parse) each content part from 00089 * @param body the body of multipart content to parse 00090 * @param boundary the boundary to separate content parts 00091 * @param pool the pool to allocate memory from 00092 * @return multipart content with assigned body 00093 */ 00094 APT_DECLARE(apt_multipart_content_t*) apt_multipart_content_assign(const apt_str_t *body, const apt_str_t *boundary, apr_pool_t *pool); 00095 00096 /** 00097 * Get the next content part 00098 * @param multipart_content the multipart content to get the next content part from 00099 * @param content_part the parsed content part 00100 * @param is_final indicates the final boundary is reached 00101 * @return TRUE on success 00102 */ 00103 APT_DECLARE(apt_bool_t) apt_multipart_content_get(apt_multipart_content_t *multipart_content, apt_content_part_t *content_part, apt_bool_t *is_final); 00104 00105 00106 APT_END_EXTERN_C 00107 00108 #endif /* APT_MULTIPART_CONTENT_H */