-rw-r--r-- | libical/src/libical/sspm.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/libical/src/libical/sspm.c b/libical/src/libical/sspm.c index 2df581b..17f12ee 100644 --- a/libical/src/libical/sspm.c +++ b/libical/src/libical/sspm.c @@ -1,163 +1,160 @@ /* -*- Mode: C -*- ====================================================================== FILE: sspm.c Parse Mime CREATOR: eric 25 June 2000 $Id$ $Locker$ The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. This program is free software; you can redistribute it and/or modify it under the terms of either: The LGPL as published by the Free Software Foundation, version 2.1, available at: http://www.fsf.org/copyleft/lesser.html Or: The Mozilla Public License Version 1.0. You may obtain a copy of the License at http://www.mozilla.org/MPL/ The Initial Developer of the Original Code is Eric Busboom (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org ======================================================================*/ #include <stdio.h> #include <string.h> #include "sspm.h" #include <assert.h> #include <ctype.h> /* for tolower */ #include <stdlib.h> /* for malloc, free */ #include <string.h> /* for strcasecmp */ -// Eugen C. <eug@thekompany.com> -#ifdef _WIN32 -#define strcasecmp _stricmp -#endif -// Eugen C. <eug@thekompany.com> - -int snprintf(char *str, size_t n, char const *fmt, ...); - #ifdef DMALLOC #include "dmalloc.h" #endif +#ifdef WIN32 +#define snprintf _snprintf +#define strcasecmp stricmp +#endif + #define TMP_BUF_SIZE 1024 enum mime_state { UNKNOWN_STATE, IN_HEADER, END_OF_HEADER, IN_BODY, OPENING_PART, END_OF_PART, TERMINAL_END_OF_PART, END_OF_INPUT }; struct mime_impl{ struct sspm_part *parts; size_t max_parts; int part_no; int level; struct sspm_action_map *actions; char* (*get_string)(char *s, size_t size, void* data); void* get_string_data; char temp[TMP_BUF_SIZE]; enum mime_state state; }; void sspm_free_header(struct sspm_header *header); void* sspm_make_multipart_part(struct mime_impl *impl,struct sspm_header *header); void sspm_read_header(struct mime_impl *impl,struct sspm_header *header); char* sspm_strdup(char* str){ char* s; s = strdup(str); return s; } -struct major_content_type_map +static struct major_content_type_map { enum sspm_major_type type; char* str; } major_content_type_map[] = { {SSPM_MULTIPART_MAJOR_TYPE,"multipart" }, {SSPM_TEXT_MAJOR_TYPE,"text" }, {SSPM_TEXT_MAJOR_TYPE,"text" }, {SSPM_IMAGE_MAJOR_TYPE,"image" }, {SSPM_AUDIO_MAJOR_TYPE,"audio" }, {SSPM_VIDEO_MAJOR_TYPE,"video" }, {SSPM_APPLICATION_MAJOR_TYPE,"application" }, {SSPM_MULTIPART_MAJOR_TYPE,"multipart" }, {SSPM_MESSAGE_MAJOR_TYPE,"message" }, {SSPM_UNKNOWN_MAJOR_TYPE,"" }, }; -struct minor_content_type_map +static struct minor_content_type_map { enum sspm_minor_type type; char* str; } minor_content_type_map[] = { {SSPM_ANY_MINOR_TYPE,"*" }, {SSPM_PLAIN_MINOR_TYPE,"plain" }, {SSPM_RFC822_MINOR_TYPE,"rfc822" }, {SSPM_DIGEST_MINOR_TYPE,"digest" }, {SSPM_CALENDAR_MINOR_TYPE,"calendar" }, {SSPM_MIXED_MINOR_TYPE,"mixed" }, {SSPM_RELATED_MINOR_TYPE,"related" }, {SSPM_ALTERNATIVE_MINOR_TYPE,"alternative" }, {SSPM_PARALLEL_MINOR_TYPE, "parallel" }, {SSPM_UNKNOWN_MINOR_TYPE,"" } }; struct encoding_map { enum sspm_encoding encoding; char* str; } sspm_encoding_map[] = { {SSPM_NO_ENCODING,""}, {SSPM_QUOTED_PRINTABLE_ENCODING,"quoted-printable"}, {SSPM_8BIT_ENCODING,"8bit"}, {SSPM_7BIT_ENCODING,"7bit"}, {SSPM_BINARY_ENCODING,"binary"}, {SSPM_BASE64_ENCODING,"base64"}, {SSPM_UNKNOWN_ENCODING,""} }; char* sspm_get_parameter(char* line, char* parameter) { char *p,*s,*q; static char name[1024]; /* Find where the parameter name is in the line */ p = strstr(line,parameter); if( p == 0){ return 0; } @@ -196,97 +193,97 @@ char* sspm_get_parameter(char* line, char* parameter) return name; } char* sspm_property_name(char* line) { static char name[1024]; char *c = strchr(line,':'); if(c != 0){ strncpy(name,line,(size_t)c-(size_t)line); name[(size_t)c-(size_t)line] = '\0'; return name; } else { return 0; } } char* sspm_value(char* line) { static char value[1024]; char *c,*s, *p; /* Find the first colon and the next semicolon */ c = strchr(line,':'); s = strchr(c,';'); /* Skip the colon */ c++; if (s == 0){ s = c+strlen(line); } for(p=value; c != s; c++){ if(*c!=' ' && *c!='\n'){ *(p++) = *c; } } *p='\0'; return value; } -char *mime_headers[] = { +static char *mime_headers[] = { "Content-Type", "Content-Transfer-Encoding", "Content-Disposition", "Content-Id", "Mime-Version", 0 }; void* sspm_default_new_part() { return 0; } void sspm_default_add_line(void *part, struct sspm_header *header, char* line, size_t size) { } void* sspm_default_end_part(void* part) { return 0; } void sspm_default_free_part(void *part) { } struct sspm_action_map sspm_action_map[] = { {SSPM_UNKNOWN_MAJOR_TYPE,SSPM_UNKNOWN_MINOR_TYPE,sspm_default_new_part,sspm_default_add_line,sspm_default_end_part,sspm_default_free_part}, }; int sspm_is_mime_header(char *line) { char *name = sspm_property_name(line); int i; if(name == 0){ return 0; } for(i = 0; mime_headers[i] != 0; i++){ if(strcasecmp(name, mime_headers[i]) == 0) return 1; } @@ -321,121 +318,121 @@ int sspm_is_blank(char* line) } return 0; } int sspm_is_continuation_line(char* line) { if (line[0] == ' '|| line[0] == '\t' ) { return 1; } return 0; } int sspm_is_mime_boundary(char *line) { if( line[0] == '-' && line[1] == '-') { return 1; } return 0; } int sspm_is_mime_terminating_boundary(char *line) { if (sspm_is_mime_boundary(line) && strstr(line,"--\n")){ return 1; } return 0; } enum line_type { EMPTY, BLANK, MIME_HEADER, MAIL_HEADER, HEADER_CONTINUATION, BOUNDARY, TERMINATING_BOUNDARY, UNKNOWN_TYPE }; -enum line_type get_line_type(char* line){ +static enum line_type get_line_type(char* line){ if (line == 0){ return EMPTY; } else if(sspm_is_blank(line)){ return BLANK; } else if (sspm_is_mime_header(line)){ return MIME_HEADER; } else if (sspm_is_mail_header(line)){ return MAIL_HEADER; } else if (sspm_is_continuation_line(line)){ return HEADER_CONTINUATION; } else if (sspm_is_mime_terminating_boundary(line)){ return TERMINATING_BOUNDARY; } else if (sspm_is_mime_boundary(line)) { return BOUNDARY; } else { return UNKNOWN_TYPE; } } -struct sspm_action_map get_action(struct mime_impl *impl, +static struct sspm_action_map get_action(struct mime_impl *impl, enum sspm_major_type major, enum sspm_minor_type minor) { int i; /* Read caller suppled action map */ if (impl->actions != 0){ for(i=0; impl->actions[i].major != SSPM_UNKNOWN_MAJOR_TYPE; i++){ if((major == impl->actions[i].major && minor == impl->actions[i].minor) || (major == impl->actions[i].major && minor == SSPM_ANY_MINOR_TYPE)){ return impl->actions[i]; } } } /* Else, read default action map */ for(i=0; sspm_action_map[i].major != SSPM_UNKNOWN_MAJOR_TYPE; i++){ if((major == sspm_action_map[i].major && minor == sspm_action_map[i].minor) || (major == sspm_action_map[i].major && minor == SSPM_ANY_MINOR_TYPE)){ break; } } return sspm_action_map[i]; } char* sspm_lowercase(char* str) { char* p = 0; char* new = sspm_strdup(str); if(str ==0){ return 0; } for(p = new; *p!=0; p++){ *p = tolower(*p); } return new; } |