summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllen Winter <allen.winter@kdab.com>2015-05-07 19:29:57 -0400
committerAllen Winter <allen.winter@kdab.com>2015-05-07 19:29:57 -0400
commitca191ce3076951089f54b878ef6c2ce4ef59c7b4 (patch)
treee731870a69be780b071942817c180d7521a4f943
parent112aef0b3f343d22d0e8d14b7a4cd4b858ff5ce9 (diff)
downloadlibical-git-ca191ce3076951089f54b878ef6c2ce4ef59c7b4.tar.gz
Splint fixes. and unhide some symbols
-rw-r--r--ConfigureChecks.cmake5
-rw-r--r--config.h.cmake23
-rw-r--r--src/libical/ical_file.cmake2
-rw-r--r--src/libical/icalduration.h33
-rw-r--r--src/libical/icalenums.h2
-rw-r--r--src/libical/icalmemory.c110
-rw-r--r--src/libical/icalmemory.h4
-rw-r--r--src/libical/icalparser.c68
-rw-r--r--src/libical/icalparser.h9
-rw-r--r--src/libical/icalrecur.h4
-rw-r--r--src/libical/icaltime.c2
-rw-r--r--src/libical/icaltime.h4
-rw-r--r--src/libical/sspm.c1356
-rw-r--r--src/libical/sspm.h86
-rw-r--r--src/libicalss/icalbdbset.c2
-rw-r--r--src/test/regression.c6
16 files changed, 829 insertions, 887 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 18397475..00448dde 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -51,11 +51,12 @@ check_function_exists(setenv HAVE_SETENV)
check_function_exists(unsetenv HAVE_UNSETENV)
include(CheckTypeSize)
+check_type_size(intptr_t SIZEOF_INTPTR_T)
+check_type_size(pid_t SIZEOF_PID_T)
check_type_size(size_t SIZEOF_SIZE_T)
check_type_size(ssize_t SIZEOF_SSIZE_T)
-check_type_size(intptr_t INTPTR_T) # please do not rename HAVE_INTPTR_T will automatically be defined
-check_type_size(pid_t HAVE_PID_T)
check_type_size(time_t SIZEOF_TIME_T)
+check_type_size(wint_t SIZEOF_WINT_T)
include(FindThreads)
check_library_exists(pthread pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
diff --git a/config.h.cmake b/config.h.cmake
index 5d626807..1a842b48 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -194,6 +194,12 @@
/* Define to empty if `const' does not conform to ANSI C. */
#cmakedefine const
+/* Typedef intptr_t if needed */
+#cmakedefine HAVE_SIZEOF_INTPTR_T 1
+#if !defined(HAVE_SIZEOF_INTPTR_T)
+typedef unsigned int inptr_t;
+#endif
+
/* Typedef size_t if needed */
#cmakedefine HAVE_SIZEOF_SIZE_T
#if !defined(HAVE_SIZEOF_SIZE_T)
@@ -206,11 +212,22 @@ typedef unsigned long size_t;
typedef long ssize_t;
#endif
-#cmakedefine HAVE_PID_T 1
-#if !HAVE_PID_T
+/* Typedef pid_t if needed */
+#cmakedefine HAVE_SIZEOF_PID_T 1
+#if !defined(HAVE_SIZEOF_PID_T)
typedef int pid_t;
#endif
+/* Typedef wint_t if needed */
+#cmakedefine HAVE_SIZEOF_WINT_T 1
+#if !defined(HAVE_SIZEOF_WINT_T)
+#if defined(HAVE_WCTYPE_H)
+#include <wctype.h>
+#else
+typedef unsigned int wint_t;
+#endif
+#endif
+
#cmakedefine SIZEOF_TIME_T ${SIZEOF_TIME_T}
/* whether we have ICU DANGI calendar */
@@ -284,6 +301,8 @@ typedef int pid_t;
#else
#if defined(HAVE_WCTYPE_H)
#include <wctype.h>
+#else
+#include <ctype>
#endif
#endif
diff --git a/src/libical/ical_file.cmake b/src/libical/ical_file.cmake
index b32b29b3..e055645f 100644
--- a/src/libical/ical_file.cmake
+++ b/src/libical/ical_file.cmake
@@ -30,6 +30,7 @@ set(COMBINEDHEADERSICAL
file(WRITE ${ICAL_FILE_H_FILE} "#ifndef LIBICAL_ICAL_H\n")
file(APPEND ${ICAL_FILE_H_FILE} "#define LIBICAL_ICAL_H\n")
+file(APPEND ${ICAL_FILE_H_FILE} "#ifndef S_SPLINT_S\n")
file(APPEND ${ICAL_FILE_H_FILE} "#ifdef __cplusplus\n")
file(APPEND ${ICAL_FILE_H_FILE} "extern \"C\" {\n")
file(APPEND ${ICAL_FILE_H_FILE} "#endif\n")
@@ -49,3 +50,4 @@ file(APPEND ${ICAL_FILE_H_FILE} "#ifdef __cplusplus\n")
file(APPEND ${ICAL_FILE_H_FILE} "}\n")
file(APPEND ${ICAL_FILE_H_FILE} "#endif\n")
file(APPEND ${ICAL_FILE_H_FILE} "#endif\n")
+file(APPEND ${ICAL_FILE_H_FILE} "#endif\n")
diff --git a/src/libical/icalduration.h b/src/libical/icalduration.h
index e5e34115..324dad71 100644
--- a/src/libical/icalduration.h
+++ b/src/libical/icalduration.h
@@ -26,30 +26,29 @@
#include "libical_ical_export.h"
#include "icaltime.h"
-struct icaldurationtype
-{
- int is_neg;
- unsigned int days;
- unsigned int weeks;
- unsigned int hours;
- unsigned int minutes;
- unsigned int seconds;
+struct icaldurationtype {
+ int is_neg;
+ unsigned int days;
+ unsigned int weeks;
+ unsigned int hours;
+ unsigned int minutes;
+ unsigned int seconds;
};
LIBICAL_ICAL_EXPORT struct icaldurationtype icaldurationtype_from_int(int t);
-LIBICAL_ICAL_EXPORT struct icaldurationtype icaldurationtype_from_string(const char*);
+LIBICAL_ICAL_EXPORT struct icaldurationtype icaldurationtype_from_string(const char *);
LIBICAL_ICAL_EXPORT int icaldurationtype_as_int(struct icaldurationtype duration);
-LIBICAL_ICAL_EXPORT char* icaldurationtype_as_ical_string(struct icaldurationtype d);
-char* icaldurationtype_as_ical_string_r(struct icaldurationtype d);
+LIBICAL_ICAL_EXPORT char *icaldurationtype_as_ical_string(struct icaldurationtype d);
+LIBICAL_ICAL_EXPORT char *icaldurationtype_as_ical_string_r(struct icaldurationtype d);
LIBICAL_ICAL_EXPORT struct icaldurationtype icaldurationtype_null_duration(void);
-struct icaldurationtype icaldurationtype_bad_duration(void);
-int icaldurationtype_is_null_duration(struct icaldurationtype d);
-int icaldurationtype_is_bad_duration(struct icaldurationtype d);
+LIBICAL_ICAL_EXPORT struct icaldurationtype icaldurationtype_bad_duration(void);
+LIBICAL_ICAL_EXPORT int icaldurationtype_is_null_duration(struct icaldurationtype d);
+LIBICAL_ICAL_EXPORT int icaldurationtype_is_bad_duration(struct icaldurationtype d);
-LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_add(struct icaltimetype t,
- struct icaldurationtype d);
+LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_add(struct icaltimetype t,
+ struct icaldurationtype d);
LIBICAL_ICAL_EXPORT struct icaldurationtype icaltime_subtract(struct icaltimetype t1,
- struct icaltimetype t2);
+ struct icaltimetype t2);
#endif /* !ICALDURATION_H */
diff --git a/src/libical/icalenums.h b/src/libical/icalenums.h
index bf267d55..b00c7ab0 100644
--- a/src/libical/icalenums.h
+++ b/src/libical/icalenums.h
@@ -125,7 +125,7 @@ LIBICAL_ICAL_EXPORT short icalenum_reqstat_major(icalrequeststatus stat);
LIBICAL_ICAL_EXPORT short icalenum_reqstat_minor(icalrequeststatus stat);
LIBICAL_ICAL_EXPORT icalrequeststatus icalenum_num_to_reqstat(short major, short minor);
char* icalenum_reqstat_code(icalrequeststatus stat);
-char* icalenum_reqstat_code_r(icalrequeststatus stat);
+LIBICAL_ICAL_EXPORT char* icalenum_reqstat_code_r(icalrequeststatus stat);
/***********************************************************************
* Conversion functions
diff --git a/src/libical/icalmemory.c b/src/libical/icalmemory.c
index 37261b5f..52ee97a5 100644
--- a/src/libical/icalmemory.c
+++ b/src/libical/icalmemory.c
@@ -63,31 +63,55 @@ typedef struct {
void *ring[BUFFER_RING_SIZE];
} buffer_ring;
-void icalmemory_free_tmp_buffer (void* buf);
-void icalmemory_free_ring_byval(buffer_ring *br);
-
-#ifndef HAVE_PTHREAD
+#if !defined(HAVE_PTHREAD)
static buffer_ring* global_buffer_ring = 0;
#endif
-#ifdef HAVE_PTHREAD
+/** get rid of this buffer ring */
+static void icalmemory_free_ring_byval(buffer_ring *br)
+{
+ int i;
+ for(i=0; i<BUFFER_RING_SIZE; i++){
+ if ( br->ring[i] != 0){
+ free( br->ring[i]);
+ }
+ }
+ free(br);
+}
+
+#if defined(HAVE_PTHREAD)
#include <pthread.h>
static pthread_key_t ring_key;
static pthread_once_t ring_key_once = PTHREAD_ONCE_INIT;
-static void ring_destroy(void * buf) {
+static void ring_destroy(void * buf)
+{
if (buf) icalmemory_free_ring_byval((buffer_ring *) buf);
pthread_setspecific(ring_key, NULL);
}
-static void ring_key_alloc(void) {
+static void ring_key_alloc(void)
+{
pthread_key_create(&ring_key, ring_destroy);
}
#endif
+#if 0
+/*keep for historical sake*/
+static void icalmemory_free_tmp_buffer (void* buf)
+{
+ if(buf == 0)
+ {
+ return;
+ }
-static buffer_ring * buffer_ring_new(void) {
+ free(buf);
+}
+#endif
+
+static buffer_ring * buffer_ring_new(void)
+{
buffer_ring *br;
int i;
@@ -100,8 +124,7 @@ static buffer_ring * buffer_ring_new(void) {
return(br);
}
-
-#ifdef HAVE_PTHREAD
+#if defined(HAVE_PTHREAD)
static buffer_ring* get_buffer_ring_pthread(void) {
buffer_ring *br;
@@ -125,15 +148,15 @@ static buffer_ring* get_buffer_ring_global(void) {
}
#endif
-static buffer_ring *get_buffer_ring(void) {
-#ifdef HAVE_PTHREAD
- return(get_buffer_ring_pthread());
+static buffer_ring *get_buffer_ring(void)
+{
+#if defined(HAVE_PTHREAD)
+ return(get_buffer_ring_pthread());
#else
- return get_buffer_ring_global();
+ return get_buffer_ring_global();
#endif
}
-
/** Add an existing buffer to the buffer ring */
void icalmemory_add_tmp_buffer(void* buf)
{
@@ -154,14 +177,12 @@ void icalmemory_add_tmp_buffer(void* buf)
br->ring[br->pos] = buf;
}
-
/**
* Create a new temporary buffer on the ring. Libical owns these and
* will deallocate them.
*/
-void*
-icalmemory_tmp_buffer (size_t size)
+void* icalmemory_tmp_buffer (size_t size)
{
char *buf;
@@ -183,36 +204,22 @@ icalmemory_tmp_buffer (size_t size)
return buf;
}
-/** get rid of this buffer ring */
-void icalmemory_free_ring_byval(buffer_ring *br) {
- int i;
- for(i=0; i<BUFFER_RING_SIZE; i++){
- if ( br->ring[i] != 0){
- free( br->ring[i]);
- }
- }
- free(br);
-}
-
void icalmemory_free_ring()
{
- buffer_ring *br;
- br = get_buffer_ring();
+ buffer_ring *br;
+ br = get_buffer_ring();
- icalmemory_free_ring_byval(br);
-#ifdef HAVE_PTHREAD
- pthread_setspecific(ring_key, 0);
+ icalmemory_free_ring_byval(br);
+#if defined(HAVE_PTHREAD)
+ pthread_setspecific(ring_key, 0);
#else
- global_buffer_ring = 0;
+ global_buffer_ring = 0;
#endif
}
-
-
/** Like strdup, but the buffer is on the ring. */
-char*
-icalmemory_tmp_copy(const char* str)
+char* icalmemory_tmp_copy(const char* str)
{
char* b = icalmemory_tmp_buffer(strlen(str)+1);
@@ -227,18 +234,6 @@ char* icalmemory_strdup(const char *s)
return strdup(s);
}
-void
-icalmemory_free_tmp_buffer (void* buf)
-{
- if(buf == 0)
- {
- return;
- }
-
- free(buf);
-}
-
-
/*
* These buffer routines create memory the old fashioned way -- so the
* caller will have to deallocate the new memory
@@ -275,16 +270,14 @@ void icalmemory_free_buffer(void* buf)
free(buf);
}
-void
-icalmemory_append_string(char** buf, char** pos, size_t* buf_size,
- const char* string)
+void icalmemory_append_string(char** buf, char** pos, size_t* buf_size, const char* string)
{
char *new_buf;
char *new_pos;
size_t data_length, final_length, string_length;
-#ifndef ICAL_NO_INTERNAL_DEBUG
+#if !defined(ICAL_NO_INTERNAL_DEBUG)
icalerror_check_arg_rv( (buf!=0),"buf");
icalerror_check_arg_rv( (*buf!=0),"*buf");
icalerror_check_arg_rv( (pos!=0),"pos");
@@ -316,17 +309,14 @@ icalmemory_append_string(char** buf, char** pos, size_t* buf_size,
*pos += string_length;
}
-
-void
-icalmemory_append_char(char** buf, char** pos, size_t* buf_size,
- char ch)
+void icalmemory_append_char(char** buf, char** pos, size_t* buf_size, char ch)
{
char *new_buf;
char *new_pos;
size_t data_length, final_length;
-#ifndef ICAL_NO_INTERNAL_DEBUG
+#if !defined(ICAL_NO_INTERNAL_DEBUG)
icalerror_check_arg_rv( (buf!=0),"buf");
icalerror_check_arg_rv( (*buf!=0),"*buf");
icalerror_check_arg_rv( (pos!=0),"pos");
diff --git a/src/libical/icalmemory.h b/src/libical/icalmemory.h
index c1236081..7c9562cd 100644
--- a/src/libical/icalmemory.h
+++ b/src/libical/icalmemory.h
@@ -42,8 +42,8 @@ LIBICAL_ICAL_EXPORT void icalmemory_free_ring(void);
* allocators in a future version of the library */
LIBICAL_ICAL_EXPORT void* icalmemory_new_buffer(size_t size);
-void* icalmemory_resize_buffer(void* buf, size_t size);
-void icalmemory_free_buffer(void* buf);
+LIBICAL_ICAL_EXPORT void* icalmemory_resize_buffer(void* buf, size_t size);
+LIBICAL_ICAL_EXPORT void icalmemory_free_buffer(void* buf);
/**
icalmemory_append_string will copy the string 'string' to the
diff --git a/src/libical/icalparser.c b/src/libical/icalparser.c
index 70542a8e..6b377001 100644
--- a/src/libical/icalparser.c
+++ b/src/libical/icalparser.c
@@ -39,18 +39,12 @@
#include "icalvalue.h"
#include <ctype.h>
+#include <stddef.h> /* for ptrdiff_h */
#include <stdlib.h>
#define TMP_BUF_SIZE 80
-static char* parser_get_next_char(char c, char *str, int qm);
-static char* parser_get_next_parameter(char* line,char** end);
-static char* parser_get_next_value(char* line, char **end, icalvalue_kind kind);
-static char* parser_get_prop_name(char* line, char** end);
-static char* parser_get_param_name(char* line, char **end);
-
-struct icalparser_impl
-{
+struct icalparser_impl {
int buffer_full; /* flag indicates that temp is smaller that
data being read into it*/
int continuation_line; /* last line read was a continuation line */
@@ -64,14 +58,13 @@ struct icalparser_impl
pvl_list components;
void *line_gen_data;
-
};
/*
* New version of strstrip() that does not move the pointer.
*/
-void strstriplt(char *buf)
+static void strstriplt(char *buf)
{
size_t len;
int a;
@@ -152,8 +145,7 @@ icalvalue* icalvalue_new_From_string_with_error(icalvalue_kind kind,
icalproperty **error);
-static
-char* parser_get_next_char(char c, char *str, int qm)
+static char* parser_get_next_char(char c, char *str, int qm)
{
int quote_mode = 0;
char* p;
@@ -193,7 +185,7 @@ static char* make_segment(char* start, char* end)
tmp = (buf+size);
while ((tmp >= buf) &&
- ((*tmp == '\0') || iswspace(*tmp)))
+ ((*tmp == '\0') || iswspace((wint_t)*tmp)))
{
*tmp = 0;
tmp--;
@@ -202,8 +194,7 @@ static char* make_segment(char* start, char* end)
return buf;
}
-static
-char* parser_get_prop_name(char* line, char** end)
+static char* parser_get_prop_name(char* line, char** end)
{
char* p;
char* v;
@@ -228,8 +219,7 @@ char* parser_get_prop_name(char* line, char** end)
return str;
}
-static
-char* parser_get_param_name(char* line, char **end)
+static char* parser_get_param_name(char* line, char **end)
{
char* next;
char *str;
@@ -259,8 +249,8 @@ char* parser_get_param_name(char* line, char **end)
}
#if 0
-static
-char* parser_get_next_paramvalue(char* line, char **end)
+/*keep for historical sake*/
+static char* parser_get_next_paramvalue(char* line, char **end)
{
char* next;
char *str;
@@ -281,7 +271,7 @@ char* parser_get_next_paramvalue(char* line, char **end)
}
#endif
-char* icalparser_get_value(char* line, char **end, icalvalue_kind kind)
+static char* icalparser_get_value(char* line, char **end, icalvalue_kind kind)
{
char *str;
size_t length = strlen(line);
@@ -298,13 +288,12 @@ char* icalparser_get_value(char* line, char **end, icalvalue_kind kind)
}
/**
- A property may have multiple values, if the values are seperated by
+ A property may have multiple values, if the values are separated by
commas in the content line. This routine will look for the next
comma after line and will set the next place to start searching in
end. */
-static
-char* parser_get_next_value(char* line, char **end, icalvalue_kind kind)
+static char* parser_get_next_value(char* line, char **end, icalvalue_kind kind)
{
char* next = 0;
@@ -532,7 +521,7 @@ char* icalparser_get_line(icalparser *parser,
*(line_p) = '\0';
}
- while ( (*line_p == '\0' || iswspace(*line_p)) && line_p > line )
+ while ( (*line_p == '\0' || iswspace((wint_t)*line_p)) && line_p > line )
{
*line_p = '\0';
line_p--;
@@ -577,8 +566,7 @@ static int line_is_blank(char* line){
}
icalcomponent* icalparser_parse(icalparser *parser,
- char* (*line_gen_func)(char *s, size_t size,
- void* d))
+ char* (*line_gen_func)(char *s, size_t size, void* d))
{
char* line;
@@ -640,8 +628,7 @@ icalcomponent* icalparser_parse(icalparser *parser,
}
-icalcomponent* icalparser_add_line(icalparser* parser,
- char* line)
+icalcomponent* icalparser_add_line(icalparser* parser, char* line)
{
char *str;
char *end;
@@ -756,7 +743,7 @@ icalcomponent* icalparser_add_line(icalparser* parser,
/* There are still components on the stack -- this means
that one of them did not have a proper "END" */
pvl_push(parser->components,parser->root_component);
- icalparser_clean(parser); /* may reset parser->root_component*/
+ (void)icalparser_clean(parser); /* may reset parser->root_component*/
}
assert(pvl_count(parser->components) == 0);
@@ -1059,7 +1046,7 @@ icalcomponent* icalparser_add_line(icalparser* parser,
vcount=0;
while(1) {
- /* Only some properies can have multiple values. This list was taken
+ /* Only some properties can have multiple values. This list was taken
from rfc2445. Also added the x-properties, because the spec actually
says that commas should be escaped. For x-properties, other apps may
depend on that behaviour
@@ -1260,29 +1247,28 @@ char* icalparser_string_line_generator(char *out, size_t buf_size, void *d)
size_t size;
struct slg_data* data = (struct slg_data*)d;
- if(data->pos==0){
- data->pos=data->str;
+ if (data->pos == 0 ) {
+ data->pos = data->str;
}
/* If the pointer is at the end of the string, we are done */
- if (*(data->pos)==0){
- return 0;
+ if (*(data->pos) == 0) {
+ return 0;
}
n = strchr(data->pos,'\n');
- if (n == 0){
- size = strlen(data->pos);
+ if (n == 0) {
+ size = strlen(data->pos);
} else {
- n++; /* include newline in output */
- size = (n-data->pos);
+ n++; /* include newline in output */
+ size = (size_t)(ptrdiff_t)(n - data->pos);
}
- if (size > buf_size-1){
- size = buf_size-1;
+ if (size > buf_size-1) {
+ size = buf_size-1;
}
-
strncpy(out,data->pos,size);
*(out+size) = '\0';
diff --git a/src/libical/icalparser.h b/src/libical/icalparser.h
index ea456e0f..66eb306b 100644
--- a/src/libical/icalparser.h
+++ b/src/libical/icalparser.h
@@ -46,8 +46,8 @@ typedef enum icalparser_state {
LIBICAL_ICAL_EXPORT icalparser* icalparser_new(void);
LIBICAL_ICAL_EXPORT icalcomponent* icalparser_add_line(icalparser* parser, char* str );
-icalcomponent* icalparser_clean(icalparser* parser);
-icalparser_state icalparser_get_state(icalparser* parser);
+LIBICAL_ICAL_EXPORT icalcomponent* icalparser_clean(icalparser* parser);
+LIBICAL_ICAL_EXPORT icalparser_state icalparser_get_state(icalparser* parser);
LIBICAL_ICAL_EXPORT void icalparser_free(icalparser* parser);
@@ -78,8 +78,9 @@ LIBICAL_ICAL_EXPORT icalcomponent* icalparser_parse_string(const char* str);
***********************************************************************/
/** Use the flex/bison parser to turn a string into a value type */
-icalvalue* icalparser_parse_value(icalvalue_kind kind,
- const char* str, icalcomponent** errors);
+LIBICAL_ICAL_EXPORT icalvalue* icalparser_parse_value(icalvalue_kind kind,
+ const char* str,
+ icalcomponent** errors);
/** Given a line generator function, return a single iCal content line.*/
LIBICAL_ICAL_EXPORT char* icalparser_get_line(icalparser* parser,
diff --git a/src/libical/icalrecur.h b/src/libical/icalrecur.h
index 33a12922..be6a6035 100644
--- a/src/libical/icalrecur.h
+++ b/src/libical/icalrecur.h
@@ -156,7 +156,7 @@ struct icalrecurrencetype
* value more than once.
* Each of the lists is terminated with the value
- * ICAL_RECURRENCE_ARRAY_MAX unless the the list is full.
+ * ICAL_RECURRENCE_ARRAY_MAX unless the list is full.
*/
short by_second[ICAL_BY_SECOND_SIZE];
@@ -176,7 +176,7 @@ struct icalrecurrencetype
LIBICAL_ICAL_EXPORT int icalrecurrencetype_rscale_is_supported(void);
-icalarray* icalrecurrencetype_rscale_supported_calendars(void);
+LIBICAL_ICAL_EXPORT icalarray* icalrecurrencetype_rscale_supported_calendars(void);
LIBICAL_ICAL_EXPORT void icalrecurrencetype_clear(struct icalrecurrencetype *r);
diff --git a/src/libical/icaltime.c b/src/libical/icaltime.c
index 9285de7a..a15b451a 100644
--- a/src/libical/icaltime.c
+++ b/src/libical/icaltime.c
@@ -288,7 +288,7 @@ static char* saved_tz = NULL;
/* If you use set_tz(), you must call unset_tz() some time later to restore the
original TZ. Pass unset_tz() the string that set_tz() returns. Call both the functions
locking the tzid mutex as in icaltime_as_timet_with_zone */
-char* set_tz(const char* tzid)
+static char* set_tz(const char* tzid)
{
char *old_tz, *old_tz_copy = NULL, *new_tz;
diff --git a/src/libical/icaltime.h b/src/libical/icaltime.h
index 7be173fc..d7dce3cb 100644
--- a/src/libical/icaltime.h
+++ b/src/libical/icaltime.h
@@ -201,7 +201,7 @@ LIBICAL_ICAL_EXPORT int icaltime_start_doy_of_week(const struct icaltimetype t);
/** Return the day of the year for the first day of the week that the
given time is within. */
-int icaltime_start_doy_week(const struct icaltimetype t, int fdow);
+LIBICAL_ICAL_EXPORT int icaltime_start_doy_week(const struct icaltimetype t, int fdow);
/** Return the week number for the week the given time is within */
int icaltime_week_number(const struct icaltimetype t);
@@ -252,7 +252,7 @@ LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_convert_to_zone(const struct ic
int icaltime_days_in_month(const int month, const int year);
/** Return whether you've specified a leapyear or not. */
-int icaltime_is_leap_year (const int year);
+LIBICAL_ICAL_EXPORT int icaltime_is_leap_year(const int year);
/** Return the number of days in this year */
int icaltime_days_in_year (const int year);
diff --git a/src/libical/sspm.c b/src/libical/sspm.c
index f218b180..a8044028 100644
--- a/src/libical/sspm.c
+++ b/src/libical/sspm.c
@@ -1,10 +1,9 @@
-/* -*- Mode: C -*-
- ======================================================================
- FILE: sspm.c Parse Mime
- CREATOR: eric 25 June 2000
+/*======================================================================
+ FILE: sspm.c Parse Mime
+ CREATOR: eric 25 June 2000
- $Id: sspm.c,v 1.13 2008-01-28 22:34:38 artcancro Exp $
- $Locker: $
+ (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
+ http://www.softwarestudio.org
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
@@ -16,23 +15,19 @@
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
+ 2.1, available at: http://www.gnu.org/licenses/lgpl-2.1.html
- Or:
+ 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 <eric@softwarestudio.org>
- http://www.softwarestudio.org
- ======================================================================*/
+ The Initial Developer of the Original Code is Eric Busboom
+======================================================================*/
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -46,6 +41,17 @@
#define TMP_BUF_SIZE 1024
+enum line_type {
+ EMPTY,
+ BLANK,
+ MIME_HEADER,
+ MAIL_HEADER,
+ HEADER_CONTINUATION,
+ BOUNDARY,
+ TERMINATING_BOUNDARY,
+ UNKNOWN_TYPE
+};
+
enum mime_state {
UNKNOWN_STATE,
IN_HEADER,
@@ -57,182 +63,170 @@ enum mime_state {
END_OF_INPUT
};
-struct mime_impl{
- struct sspm_part *parts;
- size_t max_parts;
- int part_no;
- int level;
- const 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;
+struct mime_impl {
+ struct sspm_part *parts;
+ size_t max_parts;
+ int part_no;
+ int level;
+ const 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(const char* str){
+static void *sspm_make_multipart_part(struct mime_impl *impl, struct sspm_header *header);
+static void *sspm_make_multipart_subpart(struct mime_impl *impl, struct sspm_header *parent_header);
- char* s;
-
- s = strdup(str);
-
- return s;
-}
-
-
-static struct major_content_type_map
-{
+static struct major_content_type_map {
enum sspm_major_type type;
- const 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,"" },
+ const 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, "" },
};
-static struct minor_content_type_map
-{
+static struct minor_content_type_map {
enum sspm_minor_type type;
- const 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,"" }
+ const 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 {
+static struct encoding_map {
enum sspm_encoding encoding;
- const 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,""}
+ const 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, ""}
};
+static char *sspm_strdup(const char *str)
+{
+ char *s;
+ s = strdup(str);
+ return s;
+}
-char* sspm_get_parameter(const char* line, const char* parameter)
+static char *sspm_get_parameter(const char *line, const char *parameter)
{
- char *p,*s,*q;
+ char *p, *s, *q;
static char name[1024];
/* Find where the parameter name is in the line */
- p = strstr(line,parameter);
+ p = strstr(line, parameter);
- if( p == 0){
+ if (p == 0) {
return 0;
}
/* skip over the parameter name, the '=' and any blank spaces */
- p+=strlen(parameter);
+ p += strlen(parameter);
- while(*p==' ' || *p == '='){
+ while (*p == ' ' || *p == '=') {
p++;
}
/*now find the next semicolon*/
- s = strchr(p,';');
+ s = strchr(p, ';');
/* Strip of leading quote */
- q = strchr(p,'\"');
+ q = strchr(p, '\"');
- if(q !=0){
- p = q+1;
+ if (q != 0) {
+ p = q + 1;
}
- if(s != 0){
- strncpy(name,p,(size_t)s-(size_t)p);
+ if (s != 0) {
+ strncpy(name, p, (size_t)s - (size_t)p);
} else {
- strncpy(name,p,sizeof(name)-1);
- name[sizeof(name)-1]='\0';
+ strncpy(name, p, sizeof(name) - 1);
+ name[sizeof(name) - 1] = '\0';
}
/* Strip off trailing quote, if it exists */
- q = strrchr(name,'\"');
+ q = strrchr(name, '\"');
- if (q != 0){
- *q='\0';
+ if (q != 0) {
+ *q = '\0';
}
return name;
}
-char* sspm_property_name(const char* line)
+static char *sspm_property_name(const char *line)
{
static char name[1024];
- char *c = strchr(line,':');
+ char *c = strchr(line, ':');
- if(c != 0){
- strncpy(name,line,(size_t)c-(size_t)line);
- name[(size_t)c-(size_t)line] = '\0';
+ 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 *sspm_value(char *line)
{
static char value[1024];
- char *c,*s, *p;
+ char *c, *s, *p;
/* Find the first colon and the next semicolon */
value[0] = 0;
- c = strchr(line,':');
- if (!c)
- return value;
- s = strchr(c,';');
+ c = strchr(line, ':');
+ if (!c) {
+ return value;
+ }
+ s = strchr(c, ';');
/* Skip the colon */
c++;
- if (s == 0){
- s = c+strlen(line);
+ if (s == 0) {
+ s = c + strlen(line);
}
- for(p=value; c != s; c++){
- if(*c!=' ' && *c!='\n'){
+ for (p = value; c != s; c++) {
+ if (*c != ' ' && *c != '\n') {
*(p++) = *c;
}
}
- *p='\0';
+ *p = '\0';
return value;
-
}
static const char *mime_headers[] = {
@@ -244,13 +238,13 @@ static const char *mime_headers[] = {
0
};
-
-void* sspm_default_new_part(void)
+static void *sspm_default_new_part(void)
{
return 0;
}
-void sspm_default_add_line(void *part, struct sspm_header *header,
- const char* line, size_t size)
+
+static void sspm_default_add_line(void *part, struct sspm_header *header,
+ const char *line, size_t size)
{
_unused(part);
_unused(header);
@@ -258,166 +252,146 @@ void sspm_default_add_line(void *part, struct sspm_header *header,
_unused(size);
}
-void* sspm_default_end_part(void* part)
+static void *sspm_default_end_part(void *part)
{
_unused(part);
return 0;
}
-void sspm_default_free_part(void *part)
+static void sspm_default_free_part(void *part)
{
_unused(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},
+static 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)
+static int sspm_is_mime_header(char *line)
{
char *name = sspm_property_name(line);
int i;
- if(name == 0){
+ if (name == 0) {
return 0;
}
- for(i = 0; mime_headers[i] != 0; i++){
- if(strcasecmp(name, mime_headers[i]) == 0)
+ for (i = 0; mime_headers[i] != 0; i++) {
+ if (strcasecmp(name, mime_headers[i]) == 0) {
return 1;
+ }
}
return 0;
}
-int sspm_is_mail_header(char* line)
+static int sspm_is_mail_header(char *line)
{
char *name = sspm_property_name(line);
- if (name != 0){
+ if (name != 0) {
return 1;
}
return 0;
-
}
-int sspm_is_blank(char* line)
+static int sspm_is_blank(char *line)
{
char *p;
- char c =0;
+ char c = 0;
- for(p=line; *p!=0; p++){
- if( ! (*p == ' '|| *p == '\t' || *p=='\n') ){
+ for (p = line; *p != 0; p++) {
+ if (!(*p == ' ' || *p == '\t' || *p == '\n')) {
c++;
}
}
- if (c==0){
+ if (c == 0) {
return 1;
}
return 0;
-
}
-int sspm_is_continuation_line(char* line)
+static int sspm_is_continuation_line(char *line)
{
- if (line[0] == ' '|| line[0] == '\t' ) {
+ if (line[0] == ' ' || line[0] == '\t') {
return 1;
}
return 0;
}
-int sspm_is_mime_boundary(char *line)
+static int sspm_is_mime_boundary(char *line)
{
- if( line[0] == '-' && line[1] == '-') {
+ if (line[0] == '-' && line[1] == '-') {
return 1;
}
return 0;
}
-int sspm_is_mime_terminating_boundary(char *line)
+static int sspm_is_mime_terminating_boundary(char *line)
{
-
-
if (sspm_is_mime_boundary(line) &&
- strstr(line,"--\n")){
+ strstr(line, "--\n")) {
return 1;
}
return 0;
}
-enum line_type {
- EMPTY,
- BLANK,
- MIME_HEADER,
- MAIL_HEADER,
- HEADER_CONTINUATION,
- BOUNDARY,
- TERMINATING_BOUNDARY,
- UNKNOWN_TYPE
-};
-
-
-static enum line_type get_line_type(char* line){
-
- if (line == 0){
+static enum line_type get_line_type(char *line)
+{
+ if (line == 0) {
return EMPTY;
- } else if(sspm_is_blank(line)){
+ } else if (sspm_is_blank(line)) {
return BLANK;
- } else if (sspm_is_mime_header(line)){
+ } else if (sspm_is_mime_header(line)) {
return MIME_HEADER;
- } else if (sspm_is_mail_header(line)){
+ } else if (sspm_is_mail_header(line)) {
return MAIL_HEADER;
- } else if (sspm_is_continuation_line(line)){
+ } else if (sspm_is_continuation_line(line)) {
return HEADER_CONTINUATION;
- } else if (sspm_is_mime_terminating_boundary(line)){
+ } else if (sspm_is_mime_terminating_boundary(line)) {
return TERMINATING_BOUNDARY;
} else if (sspm_is_mime_boundary(line)) {
return BOUNDARY;
} else {
return UNKNOWN_TYPE;
}
-
-
}
-
static struct sspm_action_map get_action(struct mime_impl *impl,
- enum sspm_major_type major,
- enum sspm_minor_type minor)
-{
+ enum sspm_major_type major,
+ enum sspm_minor_type minor) {
size_t i;
+ size_t len;
/* 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)){
+ 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;
- i<sizeof(sspm_action_map) && 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)){
+ len = sizeof(sspm_action_map) / sizeof(sspm_action_map[0]);
+ for (i = 0; i < len && 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;
}
}
@@ -425,32 +399,31 @@ static struct sspm_action_map get_action(struct mime_impl *impl,
return sspm_action_map[i];
}
-
-char* sspm_lowercase(char* str)
+static char *sspm_lowercase(char *str)
{
- char* p = 0;
- char* new;
+ char *p = 0;
+ char *new;
- if(str ==0){
+ if (str == 0) {
return 0;
}
new = sspm_strdup(str);
- for(p = new; *p!=0; p++){
- *p = tolower((int)*p);
+ for (p = new; *p != 0; p++) {
+ *p = tolower((int) * p);
}
return new;
}
-enum sspm_major_type sspm_find_major_content_type(char* type)
-{
+static enum sspm_major_type sspm_find_major_content_type(char *type) {
int i;
- char* ltype = sspm_lowercase(type);
+ char *ltype = sspm_lowercase(type);
- for (i=0; major_content_type_map[i].type != SSPM_UNKNOWN_MAJOR_TYPE; i++){
- if(strncmp(ltype, major_content_type_map[i].str,
- strlen(major_content_type_map[i].str))==0){
+ for (i = 0; major_content_type_map[i].type != SSPM_UNKNOWN_MAJOR_TYPE; i++)
+ {
+ if (strncmp(ltype, major_content_type_map[i].str,
+ strlen(major_content_type_map[i].str)) == 0) {
free(ltype);
return major_content_type_map[i].type;
}
@@ -459,23 +432,24 @@ enum sspm_major_type sspm_find_major_content_type(char* type)
return major_content_type_map[i].type; /* Should return SSPM_UNKNOWN_MINOR_TYPE */
}
-enum sspm_minor_type sspm_find_minor_content_type(char* type)
-{
+static enum sspm_minor_type sspm_find_minor_content_type(char *type) {
int i;
- char* ltype = sspm_lowercase(type);
+ char *ltype = sspm_lowercase(type);
- char *p = strchr(ltype,'/');
+ char *p = strchr(ltype, '/');
- if (p==0){
+ if (p == 0)
+ {
free(ltype);
return SSPM_UNKNOWN_MINOR_TYPE;
}
p++; /* Skip the '/' */
- for (i=0; minor_content_type_map[i].type != SSPM_UNKNOWN_MINOR_TYPE; i++){
- if(strncmp(p, minor_content_type_map[i].str,
- strlen(minor_content_type_map[i].str))==0){
+ for (i = 0; minor_content_type_map[i].type != SSPM_UNKNOWN_MINOR_TYPE; i++)
+ {
+ if (strncmp(p, minor_content_type_map[i].str,
+ strlen(minor_content_type_map[i].str)) == 0) {
free(ltype);
return minor_content_type_map[i].type;
}
@@ -485,14 +459,13 @@ enum sspm_minor_type sspm_find_minor_content_type(char* type)
return minor_content_type_map[i].type; /* Should return SSPM_UNKNOWN_MINOR_TYPE */
}
-const char* sspm_major_type_string(enum sspm_major_type type)
-{
+const char *sspm_major_type_string(enum sspm_major_type type) {
int i;
- for (i=0; major_content_type_map[i].type != SSPM_UNKNOWN_MAJOR_TYPE;
- i++){
-
- if(type == major_content_type_map[i].type){
+ for (i = 0; major_content_type_map[i].type != SSPM_UNKNOWN_MAJOR_TYPE;
+ i++)
+ {
+ if (type == major_content_type_map[i].type) {
return major_content_type_map[i].str;
}
}
@@ -500,12 +473,12 @@ const char* sspm_major_type_string(enum sspm_major_type type)
return major_content_type_map[i].str; /* Should return SSPM_UNKNOWN_MINOR_TYPE */
}
-const char* sspm_minor_type_string(enum sspm_minor_type type)
-{
+const char *sspm_minor_type_string(enum sspm_minor_type type) {
int i;
- for (i=0; minor_content_type_map[i].type != SSPM_UNKNOWN_MINOR_TYPE;
- i++){
- if(type == minor_content_type_map[i].type){
+ for (i = 0; minor_content_type_map[i].type != SSPM_UNKNOWN_MINOR_TYPE;
+ i++)
+ {
+ if (type == minor_content_type_map[i].type) {
return minor_content_type_map[i].str;
}
}
@@ -513,13 +486,12 @@ const char* sspm_minor_type_string(enum sspm_minor_type type)
return minor_content_type_map[i].str; /* Should return SSPM_UNKNOWN_MINOR_TYPE */
}
-
-const char* sspm_encoding_string(enum sspm_encoding type)
-{
+const char *sspm_encoding_string(enum sspm_encoding type) {
int i;
- for (i=0; sspm_encoding_map[i].encoding != SSPM_UNKNOWN_ENCODING;
- i++){
- if(type == sspm_encoding_map[i].encoding){
+ for (i = 0; sspm_encoding_map[i].encoding != SSPM_UNKNOWN_ENCODING;
+ i++)
+ {
+ if (type == sspm_encoding_map[i].encoding) {
return sspm_encoding_map[i].str;
}
}
@@ -529,7 +501,7 @@ const char* sspm_encoding_string(enum sspm_encoding type)
/* Interpret a header line and add its data to the header
structure. */
-void sspm_build_header(struct sspm_header *header, char* line)
+static void sspm_build_header(struct sspm_header *header, char *line)
{
char *prop;
char *val;
@@ -537,21 +509,21 @@ void sspm_build_header(struct sspm_header *header, char* line)
val = sspm_strdup(sspm_value(line));
prop = sspm_strdup(sspm_property_name(line));
- if(strcasecmp(prop,"Content-Type") == 0){
+ if (strcasecmp(prop, "Content-Type") == 0) {
/* Create a new mime_header, fill in content-type
and possibly boundary */
- char* boundary= sspm_get_parameter(line,"boundary");
+ char *boundary = sspm_get_parameter(line, "boundary");
header->def = 0;
header->major = sspm_find_major_content_type(val);
header->minor = sspm_find_minor_content_type(val);
- if(header->minor == SSPM_UNKNOWN_MINOR_TYPE){
- char *p = strchr(val,'/');
+ if (header->minor == SSPM_UNKNOWN_MINOR_TYPE) {
+ char *p = strchr(val, '/');
- if (p != 0){
+ if (p != 0) {
p++; /* Skip the '/' */
header->minor_text = sspm_strdup(p);
@@ -560,59 +532,55 @@ void sspm_build_header(struct sspm_header *header, char* line)
header->minor_text = sspm_strdup("unknown");
}
}
- if (boundary != 0){
+ if (boundary != 0) {
header->boundary = sspm_strdup(boundary);
}
- } else if(strcasecmp(prop,"Content-Transfer-Encoding")==0){
- char* encoding = sspm_value(line);
- char* lencoding = sspm_lowercase(encoding);
+ } else if (strcasecmp(prop, "Content-Transfer-Encoding") == 0) {
+ char *encoding = sspm_value(line);
+ char *lencoding = sspm_lowercase(encoding);
- if(strcasecmp(lencoding,"base64")==0){
+ if (strcasecmp(lencoding, "base64") == 0) {
header->encoding = SSPM_BASE64_ENCODING;
- } else if(strcasecmp(lencoding,"quoted-printable")==0){
+ } else if (strcasecmp(lencoding, "quoted-printable") == 0) {
header->encoding = SSPM_QUOTED_PRINTABLE_ENCODING;
- } else if(strcasecmp(lencoding,"binary")==0){
+ } else if (strcasecmp(lencoding, "binary") == 0) {
header->encoding = SSPM_BINARY_ENCODING;
- } else if(strcasecmp(lencoding,"7bit")==0){
+ } else if (strcasecmp(lencoding, "7bit") == 0) {
header->encoding = SSPM_7BIT_ENCODING;
- } else if(strcasecmp(lencoding,"8bit")==0){
+ } else if (strcasecmp(lencoding, "8bit") == 0) {
header->encoding = SSPM_8BIT_ENCODING;
} else {
header->encoding = SSPM_UNKNOWN_ENCODING;
}
-
free(lencoding);
header->def = 0;
- } else if(strcasecmp(prop,"Content-Id")==0){
- char* cid = sspm_value(line);
+ } else if (strcasecmp(prop, "Content-Id") == 0) {
+ char *cid = sspm_value(line);
header->content_id = sspm_strdup(cid);
header->def = 0;
-
}
free(val);
free(prop);
}
-char* sspm_get_next_line(struct mime_impl *impl)
+static char *sspm_get_next_line(struct mime_impl *impl)
{
- char* s;
- s = impl->get_string(impl->temp,TMP_BUF_SIZE,impl->get_string_data);
+ char *s;
+ s = impl->get_string(impl->temp, TMP_BUF_SIZE, impl->get_string_data);
- if(s == 0){
+ if (s == 0) {
impl->state = END_OF_INPUT;
}
return s;
}
-
-void sspm_store_part(struct mime_impl *impl, struct sspm_header header,
- int level, void *part, size_t size)
+static void sspm_store_part(struct mime_impl *impl, struct sspm_header header,
+ int level, void *part, size_t size)
{
-
impl->parts[impl->part_no].header = header;
impl->parts[impl->part_no].level = level;
impl->parts[impl->part_no].data = part;
@@ -620,74 +588,164 @@ void sspm_store_part(struct mime_impl *impl, struct sspm_header header,
impl->part_no++;
}
-void sspm_set_error(struct sspm_header* header, enum sspm_error error,
- char* message)
-{
+static void sspm_set_error(struct sspm_header *header, enum sspm_error error, char *message) {
header->error = error;
- if(header->error_text!=0){
+ if (header->error_text != 0)
+ {
free(header->error_text);
}
header->def = 0;
- if(message != 0){
+ if (message != 0)
+ {
header->error_text = sspm_strdup(message);
} else {
header->error_text = 0;
}
-
}
-void* sspm_make_part(struct mime_impl *impl,
- struct sspm_header *header,
- struct sspm_header *parent_header,
- void **end_part,
- size_t *size)
+static void sspm_read_header(struct mime_impl *impl, struct sspm_header *header)
{
+#define MAX_HEADER_LINES 25
+ char *buf;
+ char header_lines[MAX_HEADER_LINES][TMP_BUF_SIZE]; /* HACK, hard limits TODO*/
+ int current_line = -1;
+ int end = 0;
+
+ memset(header_lines, 0, sizeof(header_lines));
+ memset(header, 0, sizeof(struct sspm_header));
+
+ /* Set up default header */
+ header->def = 1;
+ header->major = SSPM_TEXT_MAJOR_TYPE;
+ header->minor = SSPM_PLAIN_MINOR_TYPE;
+ header->error = SSPM_NO_ERROR;
+ header->error_text = 0;
+
+ /* Read all of the lines into memory */
+ while (current_line < (MAX_HEADER_LINES - 2) &&
+ (end == 0) &&
+ ((buf = sspm_get_next_line(impl)) != 0)) {
+
+ enum line_type line_type = get_line_type(buf);
+
+ switch (line_type) {
+ case BLANK: {
+ end = 1;
+ impl->state = END_OF_HEADER;
+ break;
+ }
+
+ case MAIL_HEADER:
+ case MIME_HEADER: {
+ impl->state = IN_HEADER;
+ current_line++;
+
+ assert(strlen(buf) < TMP_BUF_SIZE);
+
+ strncpy(header_lines[current_line], buf, TMP_BUF_SIZE);
+ header_lines[current_line][TMP_BUF_SIZE - 1] = '\0';
+
+ break;
+ }
+
+ case HEADER_CONTINUATION: {
+ char *last_line;
+ char *buf_start;
+
+ if (current_line < 0) {
+ /* This is not really a continuation line, since
+ we have not see any header line yet */
+ sspm_set_error(header, SSPM_MALFORMED_HEADER_ERROR, buf);
+ return;
+ }
+
+ last_line = header_lines[current_line];
+ impl->state = IN_HEADER;
+
+ /* skip over the spaces in buf start, and remove the new
+ line at the end of the lat line */
+ if (last_line[strlen(last_line) - 1] == '\n') {
+ last_line[strlen(last_line) - 1] = '\0';
+ }
+ buf_start = buf;
+ while (*buf_start == ' ' || *buf_start == '\t') {
+ buf_start++;
+ }
+
+ assert(strlen(buf_start) + strlen(last_line) < TMP_BUF_SIZE);
+
+ strncat(last_line, buf_start, TMP_BUF_SIZE - strlen(last_line) - 1);
+
+ break;
+ }
+
+ default: {
+ sspm_set_error(header, SSPM_MALFORMED_HEADER_ERROR, buf);
+ return;
+ }
+ }
+ }
+
+ for (current_line = 0;
+ current_line < MAX_HEADER_LINES && header_lines[current_line][0] != 0;
+ current_line++) {
+
+ sspm_build_header(header, header_lines[current_line]);
+ }
+}
+
+static void sspm_make_part(struct mime_impl *impl,
+ struct sspm_header *header,
+ struct sspm_header *parent_header,
+ void **end_part,
+ size_t *size)
+{
/* For a single part type, read to the boundary, if there is a
- boundary. Otherwise, read until the end of input. This routine
- assumes that the caller has read the header and has left the input
- at the first blank line */
+ boundary. Otherwise, read until the end of input. This routine
+ assumes that the caller has read the header and has left the input
+ at the first blank line */
char *line;
void *part;
int end = 0;
struct sspm_action_map action = get_action(
- impl,
- header->major,
- header->minor);
+ impl,
+ header->major,
+ header->minor);
*size = 0;
- part =action.new_part();
+ part = action.new_part();
impl->state = IN_BODY;
- while(end == 0 && (line = sspm_get_next_line(impl)) != 0){
+ while (end == 0 && (line = sspm_get_next_line(impl)) != 0) {
- if(sspm_is_mime_boundary(line)){
+ if (sspm_is_mime_boundary(line)) {
/* If there is a boundary, then this must be a multipart
part, so there must be a parent_header. */
- if(parent_header == 0){
- char* boundary;
+ if (parent_header == 0) {
+ char *boundary;
end = 1;
*end_part = 0;
- sspm_set_error(header,SSPM_UNEXPECTED_BOUNDARY_ERROR,line);
+ sspm_set_error(header, SSPM_UNEXPECTED_BOUNDARY_ERROR, line);
/* Read until the paired terminating boundary */
- if((boundary = (char*)malloc(strlen(line)+5)) == 0){
- fprintf(stderr,"Out of memory");
+ if ((boundary = (char *)malloc(strlen(line) + 5)) == 0) {
+ fprintf(stderr, "Out of memory");
abort();
}
- strcpy(boundary,line);
- strcat(boundary,"--");
- while((line = sspm_get_next_line(impl)) != 0){
+ strcpy(boundary, line);
+ strcat(boundary, "--");
+ while ((line = sspm_get_next_line(impl)) != 0) {
/*printf("Error: %s\n",line);*/
- if(strcmp(boundary,line)==0){
+ if (strcmp(boundary, line) == 0) {
break;
}
}
@@ -696,12 +754,12 @@ void* sspm_make_part(struct mime_impl *impl,
break;
}
- if(strcmp((line+2),parent_header->boundary) == 0){
+ if (strcmp((line + 2), parent_header->boundary) == 0) {
*end_part = action.end_part(part);
- if(sspm_is_mime_boundary(line)){
+ if (sspm_is_mime_boundary(line)) {
impl->state = END_OF_PART;
- } else if ( sspm_is_mime_terminating_boundary(line)){
+ } else if (sspm_is_mime_terminating_boundary(line)) {
impl->state = TERMINAL_END_OF_PART;
}
end = 1;
@@ -709,125 +767,151 @@ void* sspm_make_part(struct mime_impl *impl,
/* Error, this is not the correct terminating boundary*/
/* read and discard until we get the right boundary. */
- char* boundary;
- char msg[256];
+ char *boundary;
+ char msg[256];
- snprintf(msg,256,
- "Expected: %s--. Got: %s",
- parent_header->boundary,line);
+ snprintf(msg, 256,
+ "Expected: %s--. Got: %s",
+ parent_header->boundary, line);
- sspm_set_error(parent_header,
- SSPM_WRONG_BOUNDARY_ERROR,msg);
+ sspm_set_error(parent_header,
+ SSPM_WRONG_BOUNDARY_ERROR, msg);
- /* Read until the paired terminating boundary */
- if((boundary = (char*)malloc(strlen(line)+5)) == 0){
- fprintf(stderr,"Out of memory");
- abort();
- }
- strcpy(boundary,line);
- strcat(boundary,"--");
- while((line = sspm_get_next_line(impl)) != 0){
- if(strcmp(boundary,line)==0){
- break;
- }
+ /* Read until the paired terminating boundary */
+ if ((boundary = (char *)malloc(strlen(line) + 5)) == 0) {
+ fprintf(stderr, "Out of memory");
+ abort();
+ }
+ strcpy(boundary, line);
+ strcat(boundary, "--");
+ while ((line = sspm_get_next_line(impl)) != 0) {
+ if (strcmp(boundary, line) == 0) {
+ break;
}
- free(boundary);
-
+ }
+ free(boundary);
}
} else {
- char* data=0;
- char* rtrn=0;
+ char *data = 0;
+ char *rtrn = 0;
*size = strlen(line);
- data = (char*)malloc(*size+2);
+ data = (char *)malloc(*size + 2);
assert(data != 0);
- if (header->encoding == SSPM_BASE64_ENCODING){
- rtrn = decode_base64(data,line,size);
- } else if(header->encoding == SSPM_QUOTED_PRINTABLE_ENCODING){
- rtrn = decode_quoted_printable(data,line,size);
+ if (header->encoding == SSPM_BASE64_ENCODING) {
+ rtrn = decode_base64(data, line, size);
+ } else if (header->encoding == SSPM_QUOTED_PRINTABLE_ENCODING) {
+ rtrn = decode_quoted_printable(data, line, size);
}
- if(rtrn == 0){
- strcpy(data,line);
+ if (rtrn == 0) {
+ strcpy(data, line);
}
/* add a end-of-string after the data, just in case binary
data from decode64 gets passed to a tring handling
routine in add_line */
- data[*size+1]='\0';
+ data[*size + 1] = '\0';
- action.add_line(part,header,data,*size);
+ action.add_line(part, header, data, *size);
free(data);
}
}
- if (end == 0){
+ if (end == 0) {
/* End the part if the input is exhausted */
*end_part = action.end_part(part);
}
- return end_part;
+ return;
}
+static void *sspm_make_multipart_part(struct mime_impl *impl, struct sspm_header *header)
+{
+ void *part = 0;
+
+ /* Now descend a level into each of the children of this part */
+ impl->level++;
+
+ /* Now we are working on the CHILD */
+ memset(&(impl->parts[impl->part_no]), 0, sizeof(struct sspm_part));
+
+ do {
+ part = sspm_make_multipart_subpart(impl, header);
+
+ if (part == 0) {
+ /* Clean up the part in progress */
+ impl->parts[impl->part_no].header.major
+ = SSPM_NO_MAJOR_TYPE;
+ impl->parts[impl->part_no].header.minor
+ = SSPM_NO_MINOR_TYPE;
+ }
+
+ } while (get_line_type(impl->temp) != TERMINATING_BOUNDARY &&
+ impl->state != END_OF_INPUT);
+
+ impl->level--;
-void* sspm_make_multipart_subpart(struct mime_impl *impl,
- struct sspm_header *parent_header)
+ return 0;
+}
+
+static void *sspm_make_multipart_subpart(struct mime_impl *impl,
+ struct sspm_header *parent_header)
{
struct sspm_header header;
char *line;
- void* part;
+ void *part;
size_t size;
- if(parent_header->boundary == 0){
+ if (parent_header->boundary == 0) {
/* Error. Multipart headers must have a boundary*/
- sspm_set_error(parent_header,SSPM_NO_BOUNDARY_ERROR,0);
+ sspm_set_error(parent_header, SSPM_NO_BOUNDARY_ERROR, 0);
/* read all of the reamining lines */
- while((line = sspm_get_next_line(impl)) != 0){
+ while ((line = sspm_get_next_line(impl)) != 0) {
}
return 0;
}
-
/* Step 1: Read the opening boundary */
- if(get_line_type(impl->temp) != BOUNDARY){
- while((line=sspm_get_next_line(impl)) != 0 ){
- if(sspm_is_mime_boundary(line)){
+ if (get_line_type(impl->temp) != BOUNDARY) {
+ while ((line = sspm_get_next_line(impl)) != 0) {
+ if (sspm_is_mime_boundary(line)) {
assert(parent_header != 0);
/* Check if it is the right boundary */
- if(!sspm_is_mime_terminating_boundary(line) &&
- strcmp((line+2),parent_header->boundary)
- == 0){
+ if (!sspm_is_mime_terminating_boundary(line) &&
+ strcmp((line + 2), parent_header->boundary)
+ == 0) {
/* The +2 in strncmp skips over the leading "--" */
break;
} else {
/* Got the wrong boundary, so read and discard
until we get the right boundary. */
- char* boundary;
+ char *boundary;
char msg[256];
- snprintf(msg,256,
+ snprintf(msg, 256,
"Expected: %s. Got: %s",
- parent_header->boundary,line);
+ parent_header->boundary, line);
sspm_set_error(parent_header,
- SSPM_WRONG_BOUNDARY_ERROR,msg);
+ SSPM_WRONG_BOUNDARY_ERROR, msg);
/* Read until the paired terminating boundary */
- if((boundary = (char*)malloc(strlen(line)+5)) == 0){
- fprintf(stderr,"Out of memory");
+ if ((boundary = (char *)malloc(strlen(line) + 5)) == 0) {
+ fprintf(stderr, "Out of memory");
abort();
}
- strcpy(boundary,line);
- strcat(boundary,"--");
- while((line = sspm_get_next_line(impl)) != 0){
- if(strcmp(boundary,line)==0){
+ strcpy(boundary, line);
+ strcat(boundary, "--");
+ while ((line = sspm_get_next_line(impl)) != 0) {
+ if (strcmp(boundary, line) == 0) {
break;
}
}
@@ -840,188 +924,59 @@ void* sspm_make_multipart_subpart(struct mime_impl *impl,
}
/* Step 2: Get the part header */
- sspm_read_header(impl,&header);
+ sspm_read_header(impl, &header);
/* If the header is still listed as default, there was probably an
error */
- if(header.def == 1 && header.error != SSPM_NO_ERROR){
- sspm_set_error(&header,SSPM_NO_HEADER_ERROR,0);
+ if (header.def == 1 && header.error != SSPM_NO_ERROR) {
+ sspm_set_error(&header, SSPM_NO_HEADER_ERROR, 0);
return 0;
}
- if(header.error!= SSPM_NO_ERROR){
- sspm_store_part(impl,header,impl->level,0,0);
+ if (header.error != SSPM_NO_ERROR) {
+ sspm_store_part(impl, header, impl->level, 0, 0);
return 0;
}
/* Step 3: read the body */
- if(header.major == SSPM_MULTIPART_MAJOR_TYPE){
+ if (header.major == SSPM_MULTIPART_MAJOR_TYPE) {
struct sspm_header *child_header;
child_header = &(impl->parts[impl->part_no].header);
/* Store the multipart part */
- sspm_store_part(impl,header,impl->level,0,0);
+ sspm_store_part(impl, header, impl->level, 0, 0);
/* now get all of the sub-parts */
- part = sspm_make_multipart_part(impl,child_header);
+ part = sspm_make_multipart_part(impl, child_header);
- if(get_line_type(impl->temp) != TERMINATING_BOUNDARY){
+ if (get_line_type(impl->temp) != TERMINATING_BOUNDARY) {
- sspm_set_error(child_header,SSPM_NO_BOUNDARY_ERROR,impl->temp);
+ sspm_set_error(child_header, SSPM_NO_BOUNDARY_ERROR, impl->temp);
return 0;
}
- sspm_get_next_line(impl); /* Step past the terminating boundary */
+ (void)sspm_get_next_line(impl); /* Step past the terminating boundary */
} else {
- sspm_make_part(impl, &header,parent_header,&part,&size);
+ sspm_make_part(impl, &header, parent_header, &part, &size);
memset(&(impl->parts[impl->part_no]), 0, sizeof(struct sspm_part));
- sspm_store_part(impl,header,impl->level,part,size);
-
+ sspm_store_part(impl, header, impl->level, part, size);
}
return part;
}
-void* sspm_make_multipart_part(struct mime_impl *impl,struct sspm_header *header)
-{
- void *part=0;
-
- /* Now descend a level into each of the children of this part */
- impl->level++;
-
- /* Now we are working on the CHILD */
- memset(&(impl->parts[impl->part_no]), 0, sizeof(struct sspm_part));
-
- do{
- part = sspm_make_multipart_subpart(impl,header);
-
- if (part==0){
- /* Clean up the part in progress */
- impl->parts[impl->part_no].header.major
- = SSPM_NO_MAJOR_TYPE;
- impl->parts[impl->part_no].header.minor
- = SSPM_NO_MINOR_TYPE;
-
- }
-
-
- } while (get_line_type(impl->temp) != TERMINATING_BOUNDARY &&
- impl->state != END_OF_INPUT);
-
- impl->level--;
-
- return 0;
-}
-
-
-void sspm_read_header(struct mime_impl *impl,struct sspm_header *header)
-{
-#define MAX_HEADER_LINES 25
-
- char *buf;
- char header_lines[MAX_HEADER_LINES][TMP_BUF_SIZE]; /* HACK, hard limits TODO*/
- int current_line = -1;
- int end = 0;
-
- memset(header_lines,0,sizeof(header_lines));
- memset(header,0,sizeof(struct sspm_header));
-
- /* Set up default header */
- header->def = 1;
- header->major = SSPM_TEXT_MAJOR_TYPE;
- header->minor = SSPM_PLAIN_MINOR_TYPE;
- header->error = SSPM_NO_ERROR;
- header->error_text = 0;
-
- /* Read all of the lines into memory */
- while(current_line<(MAX_HEADER_LINES-2) &&
- (end==0) &&
- ((buf=sspm_get_next_line(impl)) != 0)){
-
- enum line_type line_type = get_line_type(buf);
-
- switch(line_type){
- case BLANK: {
- end = 1;
- impl->state = END_OF_HEADER;
- break;
- }
-
- case MAIL_HEADER:
- case MIME_HEADER: {
- impl->state = IN_HEADER;
- current_line++;
-
- assert(strlen(buf) < TMP_BUF_SIZE);
-
- strncpy(header_lines[current_line],buf,TMP_BUF_SIZE);
- header_lines[current_line][TMP_BUF_SIZE-1] = '\0';
-
- break;
- }
-
- case HEADER_CONTINUATION: {
- char* last_line;
- char *buf_start;
-
- if(current_line < 0){
- /* This is not really a continuation line, since
- we have not see any header line yet */
- sspm_set_error(header,SSPM_MALFORMED_HEADER_ERROR,buf);
- return;
- }
-
- last_line = header_lines[current_line];
- impl->state = IN_HEADER;
-
-
- /* skip over the spaces in buf start, and remove the new
- line at the end of the lat line */
- if (last_line[strlen(last_line)-1] == '\n'){
- last_line[strlen(last_line)-1] = '\0';
- }
- buf_start = buf;
- while(*buf_start == ' ' ||*buf_start == '\t' ){
- buf_start++;
- }
-
- assert( strlen(buf_start) + strlen(last_line) < TMP_BUF_SIZE);
-
- strncat(last_line,buf_start, TMP_BUF_SIZE-strlen(last_line)-1);
-
- break;
- }
-
- default: {
- sspm_set_error(header,SSPM_MALFORMED_HEADER_ERROR,buf);
- return;
- }
- }
- }
-
-
- for(current_line = 0;
- current_line < MAX_HEADER_LINES && header_lines[current_line][0] != 0;
- current_line++){
-
- sspm_build_header(header,header_lines[current_line]);
- }
-
-
-}
-
/* Root routine for parsing mime entries*/
int sspm_parse_mime(struct sspm_part *parts,
size_t max_parts,
const struct sspm_action_map *actions,
- char* (*get_string)(char *s, size_t size, void* data),
+ char *(*get_string)(char *s, size_t size, void *data),
void *get_string_data,
struct sspm_header *first_header
- )
+ )
{
struct mime_impl impl;
struct sspm_header header;
@@ -1029,10 +984,10 @@ int sspm_parse_mime(struct sspm_part *parts,
_unused(first_header);
/* Initialize all of the data */
- memset(&impl,0,sizeof(struct mime_impl));
- memset(&header,0,sizeof(struct sspm_header));
+ memset(&impl, 0, sizeof(struct mime_impl));
+ memset(&header, 0, sizeof(struct sspm_header));
- for(i = 0; i<(int)max_parts; i++){
+ for (i = 0; i < (int)max_parts; i++) {
parts[i].header.major = SSPM_NO_MAJOR_TYPE;
parts[i].header.minor = SSPM_NO_MINOR_TYPE;
}
@@ -1047,60 +1002,60 @@ int sspm_parse_mime(struct sspm_part *parts,
/* Read the header of the message. This will be the email header,
unless first_header is specified. But ( HACK) that var is not
currently being used */
- sspm_read_header(&impl,&header);
+ sspm_read_header(&impl, &header);
- if(header.major == SSPM_MULTIPART_MAJOR_TYPE){
+ if (header.major == SSPM_MULTIPART_MAJOR_TYPE) {
struct sspm_header *child_header;
child_header = &(impl.parts[impl.part_no].header);
- sspm_store_part(&impl,header,impl.level,0,0);
- sspm_make_multipart_part(&impl,child_header);
+ sspm_store_part(&impl, header, impl.level, 0, 0);
+ (void)sspm_make_multipart_part(&impl, child_header);
} else {
void *part;
size_t size;
- sspm_make_part(&impl, &header, 0,&part,&size);
+ sspm_make_part(&impl, &header, 0, &part, &size);
memset(&(impl.parts[impl.part_no]), 0, sizeof(struct sspm_part));
- sspm_store_part(&impl,header,impl.level,part,size);
+ sspm_store_part(&impl, header, impl.level, part, size);
}
return 0;
}
-void sspm_free_parts(struct sspm_part *parts, size_t max_parts)
+static void sspm_free_header(struct sspm_header *header)
{
- int i;
-
- for(i = 0; i<(int)max_parts && parts[i].header.major != SSPM_NO_MAJOR_TYPE;
- i++){
- sspm_free_header(&(parts[i].header));
- }
-}
-
-void sspm_free_header(struct sspm_header *header)
-{
- if(header->boundary!=0){
+ if (header->boundary != 0) {
free(header->boundary);
}
- if(header->minor_text!=0){
+ if (header->minor_text != 0) {
free(header->minor_text);
}
- if(header->charset!=0){
+ if (header->charset != 0) {
free(header->charset);
}
- if(header->filename!=0){
+ if (header->filename != 0) {
free(header->filename);
}
- if(header->content_id!=0){
+ if (header->content_id != 0) {
free(header->content_id);
}
- if(header->error_text!=0){
+ if (header->error_text != 0) {
free(header->error_text);
}
}
+void sspm_free_parts(struct sspm_part *parts, size_t max_parts)
+{
+ int i;
+
+ for (i = 0; i < (int)max_parts && parts[i].header.major != SSPM_NO_MAJOR_TYPE;
+ i++) {
+ sspm_free_header(&(parts[i].header));
+ }
+}
+
/***********************************************************************
The remaining code is beased on code from the mimelite distribution,
which has the following notice:
@@ -1117,12 +1072,10 @@ The code is heavily modified by Eric Busboom.
***********************************************************************/
-char *decode_quoted_printable(char *dest,
- char *src,
- size_t *size)
+char *decode_quoted_printable(char *dest, char *src, size_t *size)
{
int cc;
- size_t i=0;
+ size_t i = 0;
while (*src != 0 && i < *size) {
if (*src == '=') {
@@ -1133,21 +1086,21 @@ char *decode_quoted_printable(char *dest,
}
/* remove soft line breaks*/
- if ((*src == '\n') || (*src == '\r')){
+ if ((*src == '\n') || (*src == '\r')) {
src++;
- if ((*src == '\n') || (*src == '\r')){
+ if ((*src == '\n') || (*src == '\r')) {
src++;
}
continue;
}
- cc = isdigit((int)*src) ? (*src - '0') : (*src - 55);
+ cc = isdigit((int) * src) ? (*src - '0') : (*src - 55);
cc *= 0x10;
src++;
if (!*src) {
break;
}
- cc += isdigit((int)*src) ? (*src - '0') : (*src - 55);
+ cc += isdigit((int) * src) ? (*src - '0') : (*src - 55);
*dest = cc;
@@ -1163,101 +1116,105 @@ char *decode_quoted_printable(char *dest,
*dest = '\0';
*size = i;
- return(dest);
+ return (dest);
}
-char *decode_base64(char *dest,
- char *src,
- size_t *size)
+char *decode_base64(char *dest, char *src, size_t *size)
{
int cc = 0;
- char buf[4] = {0,0,0,0};
+ char buf[4] = {0, 0, 0, 0};
int p = 0;
int valid_data = 0;
- size_t size_out=0;
+ size_t size_out = 0;
- while (*src && p<(int)*size && (cc!= -1)) {
+ while (*src && p < (int)*size && (cc != -1)) {
/* convert a character into the Base64 alphabet */
cc = *src++;
- if ((cc >= 'A') && (cc <= 'Z')) cc = cc - 'A';
- else if ((cc >= 'a') && (cc <= 'z')) cc = cc - 'a' + 26;
- else if ((cc >= '0') && (cc <= '9')) cc = cc - '0' + 52;
- else if (cc == '/') cc = 63;
- else if (cc == '+') cc = 62;
- else cc = -1;
+ if ((cc >= 'A') && (cc <= 'Z')) {
+ cc = cc - 'A';
+ } else if ((cc >= 'a') && (cc <= 'z')) {
+ cc = cc - 'a' + 26;
+ } else if ((cc >= '0') && (cc <= '9')) {
+ cc = cc - '0' + 52;
+ } else if (cc == '/') {
+ cc = 63;
+ } else if (cc == '+') {
+ cc = 62;
+ } else {
+ cc = -1;
+ }
- assert(cc<64);
+ assert(cc < 64);
/* If we've reached the end, fill the remaining slots in
the bucket and do a final conversion */
- if(cc== -1){
- if(valid_data == 0){
+ if (cc == -1) {
+ if (valid_data == 0) {
return 0;
}
- while(p%4!=3){
+ while (p % 4 != 3) {
p++;
- buf[p%4] = 0;
+ buf[p % 4] = 0;
}
} else {
- buf[p%4] = cc;
+ buf[p % 4] = cc;
size_out++;
valid_data = 1;
}
-
/* When we have 4 base64 letters, convert them into three
bytes */
- if (p%4 == 3) {
- *dest++ =(buf[0]<< 2)|((buf[1] & 0x30) >> 4);
- *dest++ =((buf[1] & 0x0F) << 4)|((buf[2] & 0x3C) >> 2);
- *dest++ =((buf[2] & 0x03) << 6)|(buf[3] & 0x3F);
+ if (p % 4 == 3) {
+ *dest++ = (buf[0] << 2) | ((buf[1] & 0x30) >> 4);
+ *dest++ = ((buf[1] & 0x0F) << 4) | ((buf[2] & 0x3C) >> 2);
+ *dest++ = ((buf[2] & 0x03) << 6) | (buf[3] & 0x3F);
- memset(buf,0,4);
+ memset(buf, 0, 4);
}
p++;
-
}
/* Calculate the size of the converted data*/
- *size = ((int)(size_out/4))*3;
- if(size_out%4 == 2) *size+=1;
- if(size_out%4 == 3) *size+=2;
+ *size = ((size_t)(size_out / 4)) * 3;
+ if (size_out % 4 == 2) {
+ *size += 1;
+ }
+ if (size_out % 4 == 3) {
+ *size += 2;
+ }
- return(dest);
+ return (dest);
}
-
/***********************************************************************
Routines to output MIME
**********************************************************************/
-
struct sspm_buffer {
- char* buffer;
- char* pos;
- size_t buf_size;
- int line_pos;
+ char *buffer;
+ char *pos;
+ size_t buf_size;
+ int line_pos;
};
-void sspm_append_string(struct sspm_buffer* buf, const char* string);
-void sspm_write_part(struct sspm_buffer *buf,struct sspm_part *part, int *part_num);
+static void sspm_append_string(struct sspm_buffer *buf, const char *string);
-void sspm_append_hex(struct sspm_buffer* buf, char ch)
+static void sspm_append_hex(struct sspm_buffer *buf, char ch)
{
char tmp[4];
- snprintf(tmp,sizeof(tmp),"=%02X",ch);
+ snprintf(tmp, sizeof(tmp), "=%02X", (unsigned int)ch);
- sspm_append_string(buf,tmp);
+ sspm_append_string(buf, tmp);
}
/* a copy of icalmemory_append_char */
-void sspm_append_char(struct sspm_buffer* buf, char ch)
+static void sspm_append_char(struct sspm_buffer *buf, char ch)
{
char *new_buf;
char *new_pos;
@@ -1268,13 +1225,13 @@ void sspm_append_char(struct sspm_buffer* buf, char ch)
final_length = data_length + 2;
- if ( final_length > (size_t) buf->buf_size ) {
+ if (final_length > (size_t) buf->buf_size) {
- buf->buf_size = (buf->buf_size) * 2 + final_length +1;
+ buf->buf_size = (buf->buf_size) * 2 + final_length + 1;
- new_buf = realloc(buf->buffer,buf->buf_size);
+ new_buf = realloc(buf->buffer, buf->buf_size);
- new_pos = (void*)((size_t)new_buf + data_length);
+ new_pos = (void *)((size_t)new_buf + data_length);
buf->pos = new_pos;
buf->buffer = new_buf;
@@ -1284,8 +1241,9 @@ void sspm_append_char(struct sspm_buffer* buf, char ch)
buf->pos += 1;
*(buf->pos) = 0;
}
+
/* A copy of icalmemory_append_string */
-void sspm_append_string(struct sspm_buffer* buf, const char* string)
+void sspm_append_string(struct sspm_buffer *buf, const char *string)
{
char *new_buf;
char *new_pos;
@@ -1296,14 +1254,13 @@ void sspm_append_string(struct sspm_buffer* buf, const char* string)
data_length = (size_t)buf->pos - (size_t)buf->buffer;
final_length = data_length + string_length;
- if ( final_length >= (size_t) buf->buf_size) {
-
+ if (final_length >= (size_t) buf->buf_size) {
buf->buf_size = (buf->buf_size) * 2 + final_length;
- new_buf = realloc(buf->buffer,buf->buf_size);
+ new_buf = realloc(buf->buffer, buf->buf_size);
- new_pos = (void*)((size_t)new_buf + data_length);
+ new_pos = (void *)((size_t)new_buf + data_length);
buf->pos = new_pos;
buf->buffer = new_buf;
@@ -1314,106 +1271,100 @@ void sspm_append_string(struct sspm_buffer* buf, const char* string)
buf->pos += string_length;
}
-
-
static int sspm_is_printable(char c)
{
return (c >= 33) && (c <= 126) && (c != '=');
-
}
-
-void sspm_encode_quoted_printable(struct sspm_buffer *buf, char* data)
+static void sspm_encode_quoted_printable(struct sspm_buffer *buf, char *data)
{
char *p;
int lpos = 0;
- for(p = data; *p != 0; p++){
+ for (p = data; *p != 0; p++) {
- if(sspm_is_printable(*p)){
+ if (sspm_is_printable(*p)) {
/* plain characters can represent themselves */
/* RFC2045 Rule #2 */
- sspm_append_char(buf,*p);
- lpos++;
- } else if ( *p == '\t' || *p == ' ' ) {
+ sspm_append_char(buf, *p);
+ lpos++;
+ } else if (*p == '\t' || *p == ' ') {
/* For tabs and spaces, only encode if they appear at the
end of the line */
/* RFC2045 Rule #3 */
- char n = *(p+1);
+ char n = *(p + 1);
- if( n == '\n' || n == '\r'){
- sspm_append_hex(buf,*p);
- lpos += 3;
- } else {
- sspm_append_char(buf,*p);
- lpos++;
- }
+ if (n == '\n' || n == '\r') {
+ sspm_append_hex(buf, *p);
+ lpos += 3;
+ } else {
+ sspm_append_char(buf, *p);
+ lpos++;
+ }
- } else if( *p == '\n' || *p == '\r'){
- sspm_append_char(buf,*p);
+ } else if (*p == '\n' || *p == '\r') {
+ sspm_append_char(buf, *p);
- lpos=0;
+ lpos = 0;
} else {
/* All others need to be encoded */
- sspm_append_hex(buf,*p);
- lpos+=3;
+ sspm_append_hex(buf, *p);
+ lpos += 3;
}
-
/* Add line breaks */
- if (lpos > 72){
+ if (lpos > 72) {
lpos = 0;
- sspm_append_string(buf,"=\n");
+ sspm_append_string(buf, "=\n");
}
}
}
static char BaseTable[64] = {
- 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
- 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
- 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
- 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};
-void sspm_write_base64(struct sspm_buffer *buf, char* inbuf,int size )
+static void sspm_write_base64(struct sspm_buffer *buf, char *inbuf, int size)
{
-
char outbuf[4];
int i;
outbuf[0] = outbuf[1] = outbuf[2] = outbuf[3] = 65;
- switch(size){
+ switch (size) {
- case 4:
- outbuf[3] = inbuf[2] & 0x3F;
+ case 4:
+ outbuf[3] = inbuf[2] & 0x3F;
- case 3:
- outbuf[2] = ((inbuf[1] & 0x0F) << 2) | ((inbuf[2] & 0xC0) >> 6);
+ case 3:
+ outbuf[2] = ((inbuf[1] & 0x0F) << 2) | ((inbuf[2] & 0xC0) >> 6);
- case 2:
- outbuf[0] = (inbuf[0] & 0xFC) >> 2;
- outbuf[1] = ((inbuf[0] & 0x03) << 4) | ((inbuf[1] & 0xF0) >> 4);
- break;
+ case 2:
+ outbuf[0] = (inbuf[0] & 0xFC) >> 2;
+ outbuf[1] = ((inbuf[0] & 0x03) << 4) | ((inbuf[1] & 0xF0) >> 4);
+ break;
- default:
- assert(0);
+ default:
+ assert(0);
}
- for(i = 0; i < 4; i++){
+ for (i = 0; i < 4; i++) {
- if(outbuf[i] == 65){
- sspm_append_char(buf,'=');
+ if (outbuf[i] == 65) {
+ sspm_append_char(buf, '=');
} else {
- sspm_append_char(buf,BaseTable[(int)outbuf[i]]);
+ sspm_append_char(buf, BaseTable[(int)outbuf[i]]);
}
}
}
-void sspm_encode_base64(struct sspm_buffer *buf, char* data, size_t size)
+static void sspm_encode_base64(struct sspm_buffer *buf, char *data, size_t size)
{
char *p;
char inbuf[3];
@@ -1424,103 +1375,122 @@ void sspm_encode_base64(struct sspm_buffer *buf, char* data, size_t size)
inbuf[0] = inbuf[1] = inbuf[2] = 0;
- for (p = data; *p !=0; p++){
+ for (p = data; *p != 0; p++) {
- if (i%3 == 0 && first == 0){
+ if (i % 3 == 0 && first == 0) {
sspm_write_base64(buf, inbuf, 4);
- lpos+=4;
+ lpos += 4;
inbuf[0] = inbuf[1] = inbuf[2] = 0;
}
- assert(lpos%4 == 0);
+ assert(lpos % 4 == 0);
- if (lpos == 72){
- sspm_append_string(buf,"\n");
+ if (lpos == 72) {
+ sspm_append_string(buf, "\n");
lpos = 0;
}
- inbuf[i%3] = *p;
+ inbuf[i % 3] = *p;
i++;
first = 0;
-
}
-
/* If the inbuf was not exactly filled on the last byte, we need
to spit out the odd bytes that did get in -- either one or
two. This will result in an output of two bytes and '==' or
three bytes and '=', respectively */
- if (i%3 == 1 && first == 0){
- sspm_write_base64(buf, inbuf, 2);
- } else if (i%3 == 2 && first == 0){
- sspm_write_base64(buf, inbuf, 3);
+ if (i % 3 == 1 && first == 0) {
+ sspm_write_base64(buf, inbuf, 2);
+ } else if (i % 3 == 2 && first == 0) {
+ sspm_write_base64(buf, inbuf, 3);
}
-
}
-void sspm_write_header(struct sspm_buffer *buf,struct sspm_header *header)
+static void sspm_write_header(struct sspm_buffer *buf, struct sspm_header *header)
{
-
int i;
char temp[TMP_BUF_SIZE];
- const char* major;
- const char* minor;
+ const char *major;
+ const char *minor;
/* Content-type */
major = sspm_major_type_string(header->major);
minor = sspm_minor_type_string(header->minor);
- if(header->minor == SSPM_UNKNOWN_MINOR_TYPE ){
- assert(header->minor_text !=0);
+ if (header->minor == SSPM_UNKNOWN_MINOR_TYPE) {
+ assert(header->minor_text != 0);
minor = header->minor_text;
}
- snprintf(temp,sizeof(temp),"Content-Type: %s/%s",major,minor);
+ snprintf(temp, sizeof(temp), "Content-Type: %s/%s", major, minor);
- sspm_append_string(buf,temp);
+ sspm_append_string(buf, temp);
- if(header->boundary != 0){
- snprintf(temp,sizeof(temp),";boundary=\"%s\"",header->boundary);
- sspm_append_string(buf,temp);
+ if (header->boundary != 0) {
+ snprintf(temp, sizeof(temp), ";boundary=\"%s\"", header->boundary);
+ sspm_append_string(buf, temp);
}
/* Append any content type parameters */
- if(header->content_type_params != 0){
- for(i=0; *(header->content_type_params[i])!= 0;i++){
- snprintf(temp, sizeof(temp),"%s", header->content_type_params[i]);
- sspm_append_char(buf, ';');
- sspm_append_string(buf, temp);
+ if (header->content_type_params != 0) {
+ for (i = 0; * (header->content_type_params[i]) != 0; i++) {
+ snprintf(temp, sizeof(temp), "%s", header->content_type_params[i]);
+ sspm_append_char(buf, ';');
+ sspm_append_string(buf, temp);
}
}
- sspm_append_char(buf,'\n');
+ sspm_append_char(buf, '\n');
/*Content-Transfer-Encoding */
- if(header->encoding != SSPM_UNKNOWN_ENCODING &&
- header->encoding != SSPM_NO_ENCODING){
- snprintf(temp,sizeof(temp),"Content-Transfer-Encoding: %s\n",
- sspm_encoding_string(header->encoding));
+ if (header->encoding != SSPM_UNKNOWN_ENCODING &&
+ header->encoding != SSPM_NO_ENCODING) {
+ snprintf(temp, sizeof(temp), "Content-Transfer-Encoding: %s\n",
+ sspm_encoding_string(header->encoding));
}
- sspm_append_char(buf,'\n');
-
+ sspm_append_char(buf, '\n');
}
-void sspm_write_multipart_part(struct sspm_buffer *buf,
- struct sspm_part *parts,
- int* part_num)
+static void sspm_write_part(struct sspm_buffer *buf, struct sspm_part *part, int *part_num)
{
+ _unused(part_num);
+
+ /* Write header */
+ sspm_write_header(buf, &(part->header));
+
+ /* Write part data */
+
+ if (part->data == 0) {
+ return;
+ }
+
+ if (part->header.encoding == SSPM_BASE64_ENCODING) {
+ assert(part->data_size != 0);
+ sspm_encode_base64(buf, part->data, part->data_size);
+ } else if (part->header.encoding == SSPM_QUOTED_PRINTABLE_ENCODING) {
+ sspm_encode_quoted_printable(buf, part->data);
+ } else {
+ sspm_append_string(buf, part->data);
+ }
+ sspm_append_string(buf, "\n\n");
+}
+
+static void sspm_write_multipart_part(struct sspm_buffer *buf,
+ struct sspm_part *parts,
+ int *part_num)
+{
int parent_level, level;
struct sspm_header *header = &(parts[*part_num].header);
/* Write the header for the multipart part */
- sspm_write_header(buf,header);
+ sspm_write_header(buf, header);
parent_level = parts[*part_num].level;
@@ -1528,15 +1498,15 @@ void sspm_write_multipart_part(struct sspm_buffer *buf,
level = parts[*part_num].level;
- while(parts[*part_num].header.major != SSPM_NO_MAJOR_TYPE &&
- level == parent_level+1){
+ while (parts[*part_num].header.major != SSPM_NO_MAJOR_TYPE &&
+ level == parent_level + 1) {
- assert(header->boundary);
- sspm_append_string(buf,header->boundary);
- sspm_append_char(buf,'\n');
+ assert(header->boundary != NULL);
+ sspm_append_string(buf, header->boundary);
+ sspm_append_char(buf, '\n');
- if (parts[*part_num].header.major == SSPM_MULTIPART_MAJOR_TYPE){
- sspm_write_multipart_part(buf,parts,part_num);
+ if (parts[*part_num].header.major == SSPM_MULTIPART_MAJOR_TYPE) {
+ sspm_write_multipart_part(buf, parts, part_num);
} else {
sspm_write_part(buf, &(parts[*part_num]), part_num);
}
@@ -1545,43 +1515,18 @@ void sspm_write_multipart_part(struct sspm_buffer *buf,
level = parts[*part_num].level;
}
- sspm_append_string(buf,"\n\n--");
- sspm_append_string(buf,header->boundary);
- sspm_append_string(buf,"\n");
+ sspm_append_string(buf, "\n\n--");
+ sspm_append_string(buf, header->boundary);
+ sspm_append_string(buf, "\n");
(*part_num)--; /* undo last, spurious, increment */
}
-void sspm_write_part(struct sspm_buffer *buf,struct sspm_part *part,int *part_num)
-{
- _unused(part_num);
-
- /* Write header */
- sspm_write_header(buf,&(part->header));
-
- /* Write part data */
-
- if(part->data == 0){
- return;
- }
-
- if(part->header.encoding == SSPM_BASE64_ENCODING) {
- assert(part->data_size != 0);
- sspm_encode_base64(buf,part->data,part->data_size);
- } else if(part->header.encoding == SSPM_QUOTED_PRINTABLE_ENCODING) {
- sspm_encode_quoted_printable(buf,part->data);
- } else {
- sspm_append_string(buf,part->data);
- }
-
- sspm_append_string(buf,"\n\n");
-}
-
-int sspm_write_mime(struct sspm_part *parts,size_t num_parts,
- char **output_string, const char* header)
+int sspm_write_mime(struct sspm_part *parts, size_t num_parts,
+ char **output_string, const char *header)
{
struct sspm_buffer buf;
- int part_num =0;
+ int part_num = 0;
size_t slen;
_unused(num_parts);
@@ -1592,24 +1537,24 @@ int sspm_write_mime(struct sspm_part *parts,size_t num_parts,
buf.line_pos = 0;
/* write caller's header */
- if(header != 0){
- sspm_append_string(&buf,header);
+ if (header != 0) {
+ sspm_append_string(&buf, header);
}
slen = strlen(buf.buffer);
- if(slen > 0 && buf.buffer[slen-1] != '\n'){
- sspm_append_char(&buf,'\n');
+ if (slen > 0 && buf.buffer[slen - 1] != '\n') {
+ sspm_append_char(&buf, '\n');
}
/* write mime-version header */
- sspm_append_string(&buf,"Mime-Version: 1.0\n");
+ sspm_append_string(&buf, "Mime-Version: 1.0\n");
/* End of header */
/* Write body parts */
- while(parts[part_num].header.major != SSPM_NO_MAJOR_TYPE){
- if (parts[part_num].header.major == SSPM_MULTIPART_MAJOR_TYPE){
- sspm_write_multipart_part(&buf,parts,&part_num);
+ while (parts[part_num].header.major != SSPM_NO_MAJOR_TYPE) {
+ if (parts[part_num].header.major == SSPM_MULTIPART_MAJOR_TYPE) {
+ sspm_write_multipart_part(&buf, parts, &part_num);
} else {
sspm_write_part(&buf, &(parts[part_num]), &part_num);
}
@@ -1617,7 +1562,6 @@ int sspm_write_mime(struct sspm_part *parts,size_t num_parts,
part_num++;
}
-
*output_string = buf.buffer;
return 0;
diff --git a/src/libical/sspm.h b/src/libical/sspm.h
index e7de6ae2..24098cec 100644
--- a/src/libical/sspm.h
+++ b/src/libical/sspm.h
@@ -15,7 +15,6 @@
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:
@@ -71,7 +70,7 @@ enum sspm_encoding {
SSPM_UNKNOWN_ENCODING
};
-enum sspm_error{
+enum sspm_error {
SSPM_NO_ERROR,
SSPM_UNEXPECTED_BOUNDARY_ERROR,
SSPM_WRONG_BOUNDARY_ERROR,
@@ -80,63 +79,62 @@ enum sspm_error{
SSPM_MALFORMED_HEADER_ERROR
};
-
-struct sspm_header
-{
- int def;
- char* boundary;
- enum sspm_major_type major;
- enum sspm_minor_type minor;
- char *minor_text;
- char ** content_type_params;
- char* charset;
- enum sspm_encoding encoding;
- char* filename;
- char* content_id;
- enum sspm_error error;
- char* error_text;
+struct sspm_header {
+ int def;
+ char *boundary;
+ enum sspm_major_type major;
+ enum sspm_minor_type minor;
+ char *minor_text;
+ char **content_type_params;
+ char *charset;
+ enum sspm_encoding encoding;
+ char *filename;
+ char *content_id;
+ enum sspm_error error;
+ char *error_text;
};
struct sspm_part {
- struct sspm_header header;
- int level;
- size_t data_size;
- void *data;
+ struct sspm_header header;
+ int level;
+ size_t data_size;
+ void *data;
};
struct sspm_action_map {
- enum sspm_major_type major;
- enum sspm_minor_type minor;
- void* (*new_part)(void);
- void (*add_line)(void *part, struct sspm_header *header,
- const char* line, size_t size);
- void* (*end_part)(void* part);
- void (*free_part)(void *part);
+ enum sspm_major_type major;
+ enum sspm_minor_type minor;
+ void *(*new_part)(void);
+ void (*add_line)(void *part, struct sspm_header *header,
+ const char *line, size_t size);
+ void *(*end_part)(void *part);
+ void (*free_part)(void *part);
};
-const char* sspm_major_type_string(enum sspm_major_type type);
-const char* sspm_minor_type_string(enum sspm_minor_type type);
-const char* sspm_encoding_string(enum sspm_encoding type);
+LIBICAL_ICAL_EXPORT const char *sspm_major_type_string(enum sspm_major_type type);
+
+LIBICAL_ICAL_EXPORT const char *sspm_minor_type_string(enum sspm_minor_type type);
-int sspm_parse_mime(struct sspm_part *parts,
- size_t max_parts,
- const struct sspm_action_map *actions,
- char* (*get_string)(char *s, size_t size, void* data),
- void *get_string_data,
- struct sspm_header *first_header
- );
+LIBICAL_ICAL_EXPORT const char *sspm_encoding_string(enum sspm_encoding type);
-void sspm_free_parts(struct sspm_part *parts, size_t max_parts);
+LIBICAL_ICAL_EXPORT int sspm_parse_mime(struct sspm_part *parts,
+ size_t max_parts,
+ const struct sspm_action_map *actions,
+ char *(*get_string)(char *s, size_t size, void *data),
+ void *get_string_data,
+ struct sspm_header *first_header);
+
+LIBICAL_ICAL_EXPORT void sspm_free_parts(struct sspm_part *parts, size_t max_parts);
LIBICAL_ICAL_EXPORT char *decode_quoted_printable(char *dest,
- char *src,
- size_t *size);
+ char *src,
+ size_t *size);
+
LIBICAL_ICAL_EXPORT char *decode_base64(char *dest,
char *src,
size_t *size);
-
-int sspm_write_mime(struct sspm_part *parts,size_t num_parts,
- char **output_string, const char* header);
+LIBICAL_ICAL_EXPORT int sspm_write_mime(struct sspm_part *parts, size_t num_parts,
+ char **output_string, const char *header);
#endif /* ICAL_SSPM_H */
diff --git a/src/libicalss/icalbdbset.c b/src/libicalss/icalbdbset.c
index e0a16c9e..f00bdc4f 100644
--- a/src/libicalss/icalbdbset.c
+++ b/src/libicalss/icalbdbset.c
@@ -1585,7 +1585,6 @@ int icalbdbset_commit_transaction(DB_TXN *txnid)
static int _compare_keys(DB *dbp, const DBT *a, const DBT *b)
{
- _unused(dbp);
/*
* Returns:
* < 0 if a < b
@@ -1595,5 +1594,6 @@ static int _compare_keys(DB *dbp, const DBT *a, const DBT *b)
char *ac = (char *)a->data;
char *bc = (char *)b->data;
+ _unused(dbp);
return strncmp(ac, bc, a->size);
}
diff --git a/src/test/regression.c b/src/test/regression.c
index ee8a68c4..ae71aa9a 100644
--- a/src/test/regression.c
+++ b/src/test/regression.c
@@ -3762,6 +3762,10 @@ int main(int argc, char *argv[])
extern char *optarg;
extern int optopt;
#endif
+#ifndef _WIN32
+ int errflg=0;
+ int c;
+#endif
/* char* program_name = strrchr(argv[0],'/'); */
int do_test = 0;
int do_header = 0;
@@ -3775,8 +3779,6 @@ int main(int argc, char *argv[])
#ifndef _WIN32
- int errflg=0;
- int c;
while ((c = getopt(argc, argv, "lvq")) != -1) {
switch (c) {
case 'v': {