2
======================================================================
4
CREATOR: eric 25 June 2000
6
$Id: testmime.c 537971 2006-05-06 11:24:08Z kainhofe $
9
(C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>, http://www.softwarestudio.org
11
The contents of this file are subject to the Mozilla Public License
12
Version 1.0 (the "License"); you may not use this file except in
13
compliance with the License. You may obtain a copy of the License at
14
http://www.mozilla.org/MPL/
16
Software distributed under the License is distributed on an "AS IS"
17
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18
the License for the specific language governing rights and
19
limitations under the License.
22
This program is free software; you can redistribute it and/or modify
23
it under the terms of either:
25
The LGPL as published by the Free Software Foundation, version
26
2.1, available at: http://www.fsf.org/copyleft/lesser.html
30
The Mozilla Public License Version 1.0. You may obtain a copy of
31
the License at http://www.mozilla.org/MPL/
33
The Initial Developer of the Original Code is Eric Busboom
35
(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
36
======================================================================*/
40
#include <stdlib.h> /* For rand */
41
#include <string.h> /* for strrchr, strdup*/
42
#include <unistd.h> /* for getopt */
44
/*int sspm_parse_mime(struct sspm_part *parts,
46
struct sspm_action_map *actions,
47
char* (*get_string)(char *s, size_t size, void* data),
48
void *get_string_data,
49
struct sspm_header *first_header
55
char* major_type_string[] = {
67
char* minor_type_string[] = {
82
char* read_stream(char *s, size_t size, void *d)
84
char *c = fgets(s,size, (FILE*)d);
91
int main(int argc, char* argv[]) {
96
extern int optind, optopt;
110
memset(&opt,0,sizeof(opt));
112
program_name = (char*)strrchr((char*)argv[0],'/');
115
while ((c = getopt(argc, argv, "nsbqi:S:c:")) != -1) {
117
case 'i': { /* Input comes from named file */
118
opt.input_file = strdup(optarg);
121
case 'n':{ /* Normal */
123
if(opt.stress+opt.base64+opt.qp != 0){
125
"%s: Use only one of n,s,b and q\n",
131
case 's':{ /* Stress-test*/
132
if(opt.base64+opt.normal+opt.qp != 0){
134
"%s: Use only one of n,s,b and q\n",
140
case 'b':{ /* test base64 decoding*/
141
if(opt.stress+opt.normal+opt.qp != 0){
143
"%s: Use only one of n,s,b and q\n",
149
case 'q':{ /* test quoted-printable decoding*/
150
if(opt.stress+opt.base64+opt.normal != 0){
152
"%s: Use only one of n,s,b and q\n",
158
case 'S':{ /* sleep at end of run */
159
opt.sleep = atoi(optarg);
163
case 'c':{ /* number of iterations of stress test */
164
opt.count = atoi(optarg);
168
case ':': {/* Option given without an operand */
170
"%s: Option -%c requires an operand\n",
171
program_name,optopt);
182
fprintf(stderr,"Usage: %s [-n|-s|-b|-q] [-i input_file]\n",
187
if(opt.stress+opt.base64+opt.normal+opt.qp == 0){
189
"%s: Must have one of n,s,b or q\n",
194
f = fopen(opt.input_file,"r");
196
fprintf(stderr,"Could not open input file \"%s\"\n",
209
c = icalmime_parse(read_stream,f);
211
printf("%s\n",icalcomponent_as_ical_string(c));
213
icalcomponent_free(c);
215
} else if (opt.stress==1 ){
216
/* Read file in by lines, then randomize the lines into a
234
for(i=0; !feof(f); i++){
236
array[i] = strdup(temp);
237
size += strlen(temp);
241
buf = malloc(size*2);
245
for(j=0; j<opt.count; j++){
248
memset(buf,0,size*2);
249
/* First insert some non-randomized lines */
250
non_rand = ((float)rand()/(float)RAND_MAX) * last;
251
for(i=0;i<non_rand;i++){
252
strcat(buf,array[i]);
255
/* Then, insert some lines at random */
257
rand_lines = last - non_rand;
259
for(i=0;i<rand_lines;i++){
261
r = ((float)rand()/(float)RAND_MAX) * rand_lines;
262
strcat(buf,array[r+non_rand]);
269
c = icalmime_parse(icalparser_string_line_generator,&d);
271
printf("%s\n",icalcomponent_as_ical_string(c));
273
icalcomponent_free(c);
279
for(i=0; i<last; i++){
283
} else if(opt.qp == 1){
289
while(!feof(f) && fgets(str,4096,f)!=0){
294
decode_quoted_printable(conv,str,&size);
301
} else if (opt.base64 == 1) {
307
while(!feof(f) && fgets(str,4096,f)!=0){
312
decode_base64(conv,str,&size);
325
if( opt.input_file != 0){
326
free(opt.input_file);
329
icalmemory_free_ring();