libkcal

sspm.h

Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: sspm.h Mime Parser
00004   CREATOR: eric 25 June 2000
00005 
00006 
00007  (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
00008      http://www.softwarestudio.org
00009 
00010  The contents of this file are subject to the Mozilla Public License
00011  Version 1.0 (the "License"); you may not use this file except in
00012  compliance with the License. You may obtain a copy of the License at
00013  http://www.mozilla.org/MPL/
00014  
00015  Software distributed under the License is distributed on an "AS IS"
00016  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  the License for the specific language governing rights and
00018  limitations under the License.
00019  
00020 
00021  This program is free software; you can redistribute it and/or modify
00022  it under the terms of either: 
00023 
00024     The LGPL as published by the Free Software Foundation, version
00025     2.1, available at: http://www.fsf.org/copyleft/lesser.html
00026 
00027   Or:
00028 
00029     The Mozilla Public License Version 1.0. You may obtain a copy of
00030     the License at http://www.mozilla.org/MPL/
00031 
00032   The Initial Developer of the Original Code is Eric Busboom
00033 
00034  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
00035  ======================================================================*/
00036 
00037 #ifndef SSPM_H
00038 #define SSPM_H
00039 
00040 enum sspm_major_type {
00041     SSPM_NO_MAJOR_TYPE,
00042     SSPM_TEXT_MAJOR_TYPE,
00043     SSPM_IMAGE_MAJOR_TYPE,
00044     SSPM_AUDIO_MAJOR_TYPE,
00045     SSPM_VIDEO_MAJOR_TYPE,
00046     SSPM_APPLICATION_MAJOR_TYPE,
00047     SSPM_MULTIPART_MAJOR_TYPE,
00048     SSPM_MESSAGE_MAJOR_TYPE,
00049     SSPM_UNKNOWN_MAJOR_TYPE
00050 };
00051 
00052 enum sspm_minor_type {
00053     SSPM_NO_MINOR_TYPE,
00054     SSPM_ANY_MINOR_TYPE,
00055     SSPM_PLAIN_MINOR_TYPE,
00056     SSPM_RFC822_MINOR_TYPE,
00057     SSPM_DIGEST_MINOR_TYPE,
00058     SSPM_CALENDAR_MINOR_TYPE,
00059     SSPM_MIXED_MINOR_TYPE,
00060     SSPM_RELATED_MINOR_TYPE,
00061     SSPM_ALTERNATIVE_MINOR_TYPE,
00062     SSPM_PARALLEL_MINOR_TYPE,
00063     SSPM_UNKNOWN_MINOR_TYPE
00064 };
00065 
00066 enum sspm_encoding {
00067     SSPM_NO_ENCODING,
00068     SSPM_QUOTED_PRINTABLE_ENCODING,
00069     SSPM_8BIT_ENCODING,
00070     SSPM_7BIT_ENCODING,
00071     SSPM_BINARY_ENCODING,
00072     SSPM_BASE64_ENCODING,
00073     SSPM_UNKNOWN_ENCODING
00074 };
00075 
00076 enum sspm_error{
00077     SSPM_NO_ERROR,
00078     SSPM_UNEXPECTED_BOUNDARY_ERROR,
00079     SSPM_WRONG_BOUNDARY_ERROR,
00080     SSPM_NO_BOUNDARY_ERROR,
00081     SSPM_NO_HEADER_ERROR,
00082     SSPM_MALFORMED_HEADER_ERROR
00083 };
00084 
00085 
00086 struct sspm_header
00087 {
00088     int def;
00089     char* boundary;
00090     enum sspm_major_type major;
00091     enum sspm_minor_type minor;
00092     char *minor_text;
00093     char ** content_type_params;
00094     char* charset;
00095     enum sspm_encoding encoding;
00096     char* filename;
00097     char* content_id;
00098     enum sspm_error error;
00099     char* error_text;
00100 };
00101 
00102 struct sspm_part {
00103     struct sspm_header header;
00104     int level;
00105     size_t data_size;
00106     void *data;
00107 };
00108 
00109 struct sspm_action_map {
00110     enum sspm_major_type major;
00111     enum sspm_minor_type minor;
00112     void* (*new_part)();
00113     void (*add_line)(void *part, struct sspm_header *header, 
00114              const char* line, size_t size);
00115     void* (*end_part)(void* part);
00116     void (*free_part)(void *part);
00117 };
00118 
00119 const char* sspm_major_type_string(enum sspm_major_type type);
00120 const char* sspm_minor_type_string(enum sspm_minor_type type);
00121 const char* sspm_encoding_string(enum sspm_encoding type);
00122 
00123 int sspm_parse_mime(struct sspm_part *parts, 
00124             size_t max_parts,
00125             struct sspm_action_map *actions,
00126             char* (*get_string)(char *s, size_t size, void* data),
00127             void *get_string_data,
00128             struct sspm_header *first_header
00129     );
00130 
00131 void sspm_free_parts(struct sspm_part *parts, size_t max_parts);
00132 
00133 char *decode_quoted_printable(char *dest, 
00134                        char *src,
00135                        size_t *size);
00136 char *decode_base64(char *dest, 
00137                  char *src,
00138                  size_t *size);
00139 
00140 
00141 int sspm_write_mime(struct sspm_part *parts,size_t num_parts,
00142             char **output_string, const char* header);
00143 
00144 #endif /*SSPM_H*/