Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_mime_multipart.c File Reference
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "gwlib/gwlib.h"
#include "gwlib/mime.h"

Go to the source code of this file.

Functions

static void help (void)
 
int main (int argc, char **argv)
 

Function Documentation

static void help ( void  )
static

Definition at line 70 of file test_mime_multipart.c.

References info().

Referenced by main().

71 {
72  info(0, "Usage: test_mime_multipart [options] mime-encoded-file ...");
73  info(0, "where options are:");
74  info(0, "-v number");
75  info(0, " set log level for stderr logging");
76  info(0, "-n number");
77  info(0, " perform opertion n times");
78 }
void info(int err, const char *fmt,...)
Definition: log.c:636
int main ( int  argc,
char **  argv 
)

Definition at line 80 of file test_mime_multipart.c.

References error(), filename, getopt(), gwlib_init(), gwlib_shutdown(), help(), info(), log_set_output_level(), mime_entity_destroy(), mime_entity_dump(), mime_entity_to_octstr(), mime_octstr_to_entity(), octstr_compare(), octstr_create, octstr_destroy(), octstr_dump, octstr_get_cstr, octstr_read_file(), optarg, optind, and panic.

81 {
82  Octstr *filename = NULL;
83  unsigned long num = 1, j;
84  int opt;
85  Octstr *mime, *mime2;
86  MIMEEntity *m;
87 
88  gwlib_init();
89 
90  while ((opt = getopt(argc, argv, "hv:n:")) != EOF) {
91  switch (opt) {
92  case 'v':
94  break;
95  case 'n':
96  num = atoi(optarg);
97  break;
98  case '?':
99  default:
100  error(0, "Invalid option %c", opt);
101  help();
102  panic(0, "Stopping.");
103  }
104  }
105 
106  if (optind == argc) {
107  help();
108  exit(0);
109  }
110 
111  filename = octstr_create(argv[argc-1]);
112  mime = octstr_read_file(octstr_get_cstr(filename));
113 
114  for (j = 1; j <= num; j++) {
115 
116  info(0,"MIME Octstr from file `%s':", octstr_get_cstr(filename));
117  octstr_dump(mime, 0);
118 
119  m = mime_octstr_to_entity(mime);
120 
121  mime_entity_dump(m);
122 
123  mime2 = mime_entity_to_octstr(m);
124 
125  info(0, "MIME Octstr after reconstruction:");
126  octstr_dump(mime2, 0);
127 
128  if (octstr_compare(mime, mime2) != 0) {
129  error(0, "MIME content from file `%s' and reconstruction differs!",
130  octstr_get_cstr(filename));
131  } else {
132  info(0, "MIME Octstr compare result has been successfull.");
133  }
134 
135  octstr_destroy(mime2);
137 
138  } /* num times */
139 
140  octstr_destroy(filename);
141 
142  gwlib_shutdown();
143 
144  return 0;
145 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
int optind
Definition: attgetopt.c:80
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
void log_set_output_level(enum output_level level)
Definition: log.c:217
Octstr * mime_entity_to_octstr(MIMEEntity *m)
Definition: mime.c:216
void mime_entity_destroy(MIMEEntity *e)
Definition: mime.c:105
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
char filename[FILENAME_MAX+1]
Definition: log.c:135
#define octstr_create(cstr)
Definition: octstr.h:125
void mime_entity_dump(MIMEEntity *m)
Definition: mime.c:717
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1546
Definition: octstr.c:118
char * optarg
Definition: attgetopt.c:82
#define panic
Definition: log.h:87
static void help(void)
void gwlib_shutdown(void)
Definition: gwlib.c:94
MIMEEntity * mime_octstr_to_entity(Octstr *mime)
Definition: mime.c:453
void gwlib_init(void)
Definition: gwlib.c:78
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.