1 /* -*- Mode: C -*- 2 ====================================================================== 3 FILE: sspm.h Mime Parser 4 CREATOR: eric 25 June 2000 5 6 $Id: sspm.h,v 1.5 2008-01-15 23:17:43 dothebart Exp $ 7 $Locker: $ 8 9 (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org> 10 http://www.softwarestudio.org 11 12 The contents of this file are subject to the Mozilla Public License 13 Version 1.0 (the "License"); you may not use this file except in 14 compliance with the License. You may obtain a copy of the License at 15 http://www.mozilla.org/MPL/ 16 17 Software distributed under the License is distributed on an "AS IS" 18 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 19 the License for the specific language governing rights and 20 limitations under the License. 21 22 23 This program is free software; you can redistribute it and/or modify 24 it under the terms of either: 25 26 The LGPL as published by the Free Software Foundation, version 27 2.1, available at: http://www.fsf.org/copyleft/lesser.html 28 29 Or: 30 31 The Mozilla Public License Version 1.0. You may obtain a copy of 32 the License at http://www.mozilla.org/MPL/ 33 34 The Initial Developer of the Original Code is Eric Busboom 35 36 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org 37 ======================================================================*/ 38 39 #ifndef SSPM_H 40 #define SSPM_H 41 42 enum sspm_major_type { 43 SSPM_NO_MAJOR_TYPE, 44 SSPM_TEXT_MAJOR_TYPE, 45 SSPM_IMAGE_MAJOR_TYPE, 46 SSPM_AUDIO_MAJOR_TYPE, 47 SSPM_VIDEO_MAJOR_TYPE, 48 SSPM_APPLICATION_MAJOR_TYPE, 49 SSPM_MULTIPART_MAJOR_TYPE, 50 SSPM_MESSAGE_MAJOR_TYPE, 51 SSPM_UNKNOWN_MAJOR_TYPE 52 }; 53 54 enum sspm_minor_type { 55 SSPM_NO_MINOR_TYPE, 56 SSPM_ANY_MINOR_TYPE, 57 SSPM_PLAIN_MINOR_TYPE, 58 SSPM_RFC822_MINOR_TYPE, 59 SSPM_DIGEST_MINOR_TYPE, 60 SSPM_CALENDAR_MINOR_TYPE, 61 SSPM_MIXED_MINOR_TYPE, 62 SSPM_RELATED_MINOR_TYPE, 63 SSPM_ALTERNATIVE_MINOR_TYPE, 64 SSPM_PARALLEL_MINOR_TYPE, 65 SSPM_UNKNOWN_MINOR_TYPE 66 }; 67 68 enum sspm_encoding { 69 SSPM_NO_ENCODING, 70 SSPM_QUOTED_PRINTABLE_ENCODING, 71 SSPM_8BIT_ENCODING, 72 SSPM_7BIT_ENCODING, 73 SSPM_BINARY_ENCODING, 74 SSPM_BASE64_ENCODING, 75 SSPM_UNKNOWN_ENCODING 76 }; 77 78 enum sspm_error{ 79 SSPM_NO_ERROR, 80 SSPM_UNEXPECTED_BOUNDARY_ERROR, 81 SSPM_WRONG_BOUNDARY_ERROR, 82 SSPM_NO_BOUNDARY_ERROR, 83 SSPM_NO_HEADER_ERROR, 84 SSPM_MALFORMED_HEADER_ERROR 85 }; 86 87 88 struct sspm_header 89 { 90 int def; 91 char* boundary; 92 enum sspm_major_type major; 93 enum sspm_minor_type minor; 94 char *minor_text; 95 char ** content_type_params; 96 char* charset; 97 enum sspm_encoding encoding; 98 char* filename; 99 char* content_id; 100 enum sspm_error error; 101 char* error_text; 102 }; 103 104 struct sspm_part { 105 struct sspm_header header; 106 int level; 107 size_t data_size; 108 void *data; 109 }; 110 111 struct sspm_action_map { 112 enum sspm_major_type major; 113 enum sspm_minor_type minor; 114 void* (*new_part)(void); 115 void (*add_line)(void *part, struct sspm_header *header, 116 const char* line, size_t size); 117 void* (*end_part)(void* part); 118 void (*free_part)(void *part); 119 }; 120 121 const char* sspm_major_type_string(enum sspm_major_type type); 122 const char* sspm_minor_type_string(enum sspm_minor_type type); 123 const char* sspm_encoding_string(enum sspm_encoding type); 124 125 int sspm_parse_mime(struct sspm_part *parts, 126 size_t max_parts, 127 const struct sspm_action_map *actions, 128 char* (*get_string)(char *s, size_t size, void* data), 129 void *get_string_data, 130 struct sspm_header *first_header 131 ); 132 133 void sspm_free_parts(struct sspm_part *parts, size_t max_parts); 134 135 char *decode_quoted_printable(char *dest, 136 char *src, 137 size_t *size); 138 char *decode_base64(char *dest, 139 char *src, 140 size_t *size); 141 142 143 int sspm_write_mime(struct sspm_part *parts,size_t num_parts, 144 char **output_string, const char* header); 145 146 #endif /*SSPM_H*/ 147