Kannel: Open Source WAP and SMS gateway  svn-r5335
mime_decompiler.h File Reference

Go to the source code of this file.

Functions

int mime_decompile (Octstr *binary_mime, Octstr **mime)
 

Function Documentation

◆ mime_decompile()

int mime_decompile ( Octstr binary_mime,
Octstr **  mime 
)

Definition at line 89 of file mime_decompiler.c.

References boundary, debug(), error(), gwlist_get(), gwlist_len(), octstr_append(), octstr_create, octstr_get_cstr, octstr_imm(), octstr_len(), parse_context_create(), parse_get_octets(), parse_get_uintvar(), parse_octets_left(), warning(), and wsp_headers_unpack().

Referenced by deconvert_multipart_formdata().

90 {
91  char *boundary = "kannel_boundary";
93  long mime_parts;
94  long i, j;
95  unsigned long headers_len, data_len;
96 
97  i = mime_parts = headers_len = data_len = 0;
98 
99  debug("wap.wsp.multipart.form.data", 0, "MIMEDEC: begining decoding");
100 
101  if(binary_mime == NULL || octstr_len(binary_mime) < 1) {
102  warning(0, "MIMEDEC: invalid mime, ending");
103  return -1;
104  }
105  *mime = octstr_create("");
106 
107  /* already dumped in deconvert_content
108  debug("mime", 0, "MMSDEC: binary mime dump:");
109  octstr_dump(binary_mime, 0);
110  */
111 
112  context = parse_context_create(binary_mime);
113  debug("mime", 0, "MIMEDEC: context created");
114 
115  mime_parts = parse_get_uintvar(context);
116  debug("mime", 0, "MIMEDEC: mime has %ld multipart entities", mime_parts);
117  if(mime_parts == 0) {
118  debug("mime", 0, "MIMEDEC: mime has none multipart entities, ending");
119  return 0;
120  }
121 
122  while(parse_octets_left(context) > 0) {
123  Octstr *headers, *data;
124  List *gwlist_headers;
125  i++;
126 
127  octstr_append(*mime, octstr_imm("--"));
129  octstr_append(*mime, octstr_imm("\n"));
130 
131  headers_len = parse_get_uintvar(context);
132  data_len = parse_get_uintvar(context);
133  debug("mime", 0, "MIMEDEC[%ld]: headers length <0x%02lx>, "
134  "data length <0x%02lx>", i, headers_len, data_len);
135 
136  if((headers = parse_get_octets(context, headers_len)) != NULL) {
137  gwlist_headers = wsp_headers_unpack(headers, 1);
138  for(j=0; j<gwlist_len(gwlist_headers);j++) {
139  octstr_append(*mime, gwlist_get(gwlist_headers, j));
140  octstr_append(*mime, octstr_imm("\n"));
141  }
142  } else {
143  error(0, "MIMEDEC[%ld]: headers length is out of range, ending", i);
144  return -1;
145  }
146 
147  if((data = parse_get_octets(context, data_len)) != NULL ||
148  (i = mime_parts && /* XXX SE-T610 eats last byte, which is generally null */
149  (data = parse_get_octets(context, data_len - 1)) != NULL)) {
150  debug("mime", 0, "MMSDEC[%ld]: body [%s]", i, octstr_get_cstr(data));
151  octstr_append(*mime, octstr_imm("\n"));
152  octstr_append(*mime, data);
153  octstr_append(*mime, octstr_imm("\n"));
154  } else {
155  error(0, "MIMEDEC[%ld]: data length is out of range, ending", i);
156  return -1;
157  }
158  }
159  octstr_append(*mime, octstr_imm("--"));
161  octstr_append(*mime, octstr_imm("--\n"));
162 
163  /* already dumped in deconvert_content
164  debug("mime", 0, "MMSDEC: text mime dump:");
165  octstr_dump(*mime, 0);
166  */
167 
168  return 0;
169 }
void error(int err, const char *fmt,...)
Definition: log.c:648
Definition: parse.c:65
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static char * boundary
Definition: test_ppg.c:97
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
Octstr * parse_get_octets(ParseContext *context, long length)
Definition: parse.c:230
void warning(int err, const char *fmt,...)
Definition: log.c:660
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
List * wsp_headers_unpack(Octstr *headers, int content_type_present)
Definition: wsp_headers.c:1331
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
unsigned long parse_get_uintvar(ParseContext *context)
Definition: parse.c:246
ParseContext * parse_context_create(Octstr *str)
Definition: parse.c:74
Definition: list.c:102
long parse_octets_left(ParseContext *context)
Definition: parse.c:159
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.