2 ======================================================================
4 CREATOR: eric 25 June 2000
6 $Id: testmime.c,v 1.6 2008-02-03 16:10:48 dothebart Exp $
9 The contents of this file are subject to the Mozilla Public License
10 Version 1.0 (the "License"); you may not use this file except in
11 compliance with the License. You may obtain a copy of the License at
12 http://www.mozilla.org/MPL/
14 Software distributed under the License is distributed on an "AS IS"
15 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16 the License for the specific language governing rights and
17 limitations under the License.
20 This program is free software; you can redistribute it and/or modify
21 it under the terms of either:
23 The LGPL as published by the Free Software Foundation, version
24 2.1, available at: http://www.fsf.org/copyleft/lesser.html
28 The Mozilla Public License Version 1.0. You may obtain a copy of
29 the License at http://www.mozilla.org/MPL/
31 The Initial Developer of the Original Code is Eric Busboom
33 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
34 ======================================================================*/
40 #include <libical/ical.h>
42 #include <stdlib.h> /* For rand */
43 #include <string.h> /* for strrchr, strdup*/
44 #if defined(HAVE_UNISTD_H)
45 #include <unistd.h> /* for getopt */
48 /*int sspm_parse_mime(struct sspm_part *parts,
50 struct sspm_action_map *actions,
51 char* (*get_string)(char *s, size_t size, void* data),
52 void *get_string_data,
53 struct sspm_header *first_header
59 char* major_type_string[] = {
71 char* minor_type_string[] = {
86 char* read_stream(char *s, size_t size, void *d)
88 char *c = fgets(s,size, (FILE*)d);
95 int main(int argc, char* argv[]) {
99 #if !defined(HAVE_UNISTD_H)
101 extern int optind, optopt;
116 memset(&opt,0,sizeof(opt));
118 program_name = (char*)strrchr((char*)argv[0],'/');
121 while ((c = getopt(argc, argv, "nsbqi:S:c:")) != -1) {
123 case 'i': { /* Input comes from named file */
124 opt.input_file = strdup(optarg);
127 case 'n':{ /* Normal */
129 if(opt.stress+opt.base64+opt.qp != 0){
131 "%s: Use only one of n,s,b and q\n",
137 case 's':{ /* Stress-test*/
138 if(opt.base64+opt.normal+opt.qp != 0){
140 "%s: Use only one of n,s,b and q\n",
146 case 'b':{ /* test base64 decoding*/
147 if(opt.stress+opt.normal+opt.qp != 0){
149 "%s: Use only one of n,s,b and q\n",
155 case 'q':{ /* test quoted-printable decoding*/
156 if(opt.stress+opt.base64+opt.normal != 0){
158 "%s: Use only one of n,s,b and q\n",
164 case 'S':{ /* sleep at end of run */
165 opt.sleep = atoi(optarg);
169 case 'c':{ /* number of iterations of stress test */
170 opt.count = atoi(optarg);
174 case ':': {/* Option given without an operand */
176 "%s: Option -%c requires an operand\n",
177 program_name,optopt);
188 fprintf(stderr,"Usage: %s [-n|-s|-b|-q] [-i input_file]\n",
193 if(opt.stress+opt.base64+opt.normal+opt.qp == 0){
195 "%s: Must have one of n,s,b or q\n",
200 f = fopen(opt.input_file,"r");
202 fprintf(stderr,"Could not open input file \"%s\"\n",
215 c = icalmime_parse(read_stream,f);
217 printf("%s\n",icalcomponent_as_ical_string(c));
219 icalcomponent_free(c);
221 } else if (opt.stress==1 ){
222 /* Read file in by lines, then randomize the lines into a
240 for(i=0; !feof(f); i++){
242 array[i] = strdup(temp);
243 size += strlen(temp);
247 buf = malloc(size*2);
251 for(j=0; j<opt.count; j++){
254 memset(buf,0,size*2);
255 /* First insert some non-randomized lines */
256 non_rand = ((float)rand()/(float)RAND_MAX) * last;
257 for(i=0;i<non_rand;i++){
258 strcat(buf,array[i]);
261 /* Then, insert some lines at random */
263 rand_lines = last - non_rand;
265 for(i=0;i<rand_lines;i++){
267 r = ((float)rand()/(float)RAND_MAX) * rand_lines;
268 strcat(buf,array[r+non_rand]);
275 c = icalmime_parse(icalparser_string_line_generator,&d);
277 printf("%s\n",icalcomponent_as_ical_string(c));
279 icalcomponent_free(c);
285 for(i=0; i<last; i++){
289 } else if(opt.qp == 1){
295 while(!feof(f) && fgets(str,4096,f)!=0){
300 decode_quoted_printable(conv,str,&size);
307 } else if (opt.base64 == 1) {
313 while(!feof(f) && fgets(str,4096,f)!=0){
318 decode_base64(conv,str,&size);
329 _sleep(opt.sleep*1000);
335 if( opt.input_file != 0){
336 free(opt.input_file);
339 icalmemory_free_ring();