/
mms-dump.c
1502 lines (1420 loc) · 45.5 KB
1
/*
2
3
* Copyright (C) 2013-2019 Jolla Ltd.
* Copyright (C) 2013-2019 Slava Monich <slava.monich@jolla.com>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <glib.h>
#include <wsputil.h>
#include <string.h>
#include <stdio.h>
19
20
#include <ctype.h>
21
22
23
24
25
26
27
28
29
static const char pname[] = "mms-dump";
enum app_ret_value {
RET_OK,
RET_ERR_CMDLINE,
RET_ERR_IO,
RET_ERR_DECODE
};
30
31
#define N_(a) G_N_ELEMENTS(a)
32
#define MMS_DUMP_FLAG_VERBOSE (0x01)
33
#define MMS_DUMP_FLAG_DATA (0x02)
34
35
36
37
38
#define MMS_DUMP_FLAG_EXTRACT (0x04)
#define HEADER_CONTENT_DISPOSITION "Content-Disposition"
#define PARAM_FILENAME "Filename"
#define PARAM_NAME "Name"
39
40
41
42
43
44
45
46
#define WSP_QUOTE (127)
struct mms_named_value {
const char* name;
unsigned int value;
};
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
struct mms_header_param {
char* name;
char* value;
};
struct mms_header {
char* name;
char* value;
char* dump;
struct mms_header_param** params;
unsigned int num_params;
};
struct mms_headers {
struct mms_header** headers;
unsigned int num_headers;
};
65
66
typedef gboolean
(*mms_value_decoder)(
67
struct mms_header* header,
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags);
#define MMS_CONTENT_TYPE "application/vnd.wap.mms-message"
#define MMS_WELL_KNOWN_HEADERS(h) \
h(BCC, "Bcc", 0x01, etext )\
h(CC, "Cc", 0x02, etext )\
h(CONTENT_LOCATION, "X-Mms-Content-Location", 0x03, text )\
h(CONTENT_TYPE, "Content-Type", 0x04, unknown )\
h(DATE, "Date", 0x05, date )\
h(DELIVERY_REPORT, "X-Mms-Delivery-Report", 0x06, bool )\
h(DELIVERY_TIME, "X-Mms-Delivery-Time", 0x07, unknown )\
h(EXPIRY, "X-Mms-Expiry", 0x08, expiry )\
h(FROM, "From", 0x09, from )\
h(MESSAGE_CLASS, "X-Mms-Message-Class", 0x0A, mclass )\
h(MESSAGE_ID, "Message-ID", 0x0B, text )\
h(MESSAGE_TYPE, "X-Mms-Message-Type", 0x0C, mtype )\
h(MMS_VERSION, "X-Mms-MMS-Version", 0x0D, version )\
h(MESSAGE_SIZE, "X-Mms-Message-Size", 0x0E, long )\
h(PRIORITY, "X-Mms-Priority", 0x0F, prio )\
h(READ_REPORT, "X-Mms-Read-Report", 0x10, bool )\
h(REPORT_ALLOWED, "X-Mms-Report-Allowed", 0x11, bool )\
93
h(RESPONSE_STATUS, "X-Mms-Response-Status", 0x12, respstat )\
94
h(RESPONSE_TEXT, "X-Mms-Response-Text", 0x13, etext )\
95
h(SENDER_VISIBILITY, "X-Mms-Sender-Visibility", 0x14, visiblty )\
96
97
98
99
100
101
102
103
104
105
106
h(STATUS, "X-Mms-Status", 0x15, status )\
h(SUBJECT, "Subject", 0x16, etext )\
h(TO, "To", 0x17, etext )\
h(TRANSACTION_ID, "X-Mms-Transaction-Id", 0x18, text )\
h(RETRIEVE_STATUS, "X-Mms-Retrieve-Status", 0x19, retrieve )\
h(RETRIEVE_TEXT, "X-Mms-Retrieve-Text", 0x1A, etext )\
h(READ_STATUS, "X-Mms-Read-Status", 0x1B, rstatus )\
h(REPLY_CHARGING, "X-Mms-Reply-Charging", 0x1C, short )\
h(REPLY_CHARGING_DEADLINE,"X-Mms-Reply-Charging-Deadline",0x1D, unknown )\
h(REPLY_CHARGING_ID, "X-Mms-Reply-Charging-ID", 0x1E, text )\
h(REPLY_CHARGING_SIZE, "X-Mms-Reply-Charging-Size", 0x1F, long )\
107
108
h(PREVIOUSLY_SENT_BY, "X-Mms-Previously-Sent-By", 0x20, prevby )\
h(PREVIOUSLY_SENT_DATE, "X-Mms-Previously-Sent-Date", 0x21, prevdate )
109
110
111
#define WSP_WELL_KNOWN_HEADERS(h) \
h(CONTENT_LOCATION, "Content-Location", 0x0E, text )\
112
h(CONTENT_DISPOSITION, HEADER_CONTENT_DISPOSITION, 0x2E, contdisp )\
113
h(CONTENT_ID, "Content-ID", 0x40, quote )\
114
h(CONTENT_DISPOSITION2, HEADER_CONTENT_DISPOSITION, 0x45, contdisp )
115
116
117
118
#define MMS_HEADER_ID(id) MMS_HEADER_##id
#define MMS_PART_HEADER_ID(id) MMS_PART_HEADER_##id
119
typedef enum mms_header_id {
120
121
122
123
124
125
126
MMS_HEADER_INVALID,
#define h(id,n,x,t) MMS_HEADER_ID(id) = x,
MMS_WELL_KNOWN_HEADERS(h)
#undef h
MMS_HEADER_END,
} MMS_HEADER;
127
typedef enum mms_part_header_id {
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#define h(id,n,x,t) MMS_PART_HEADER_ID(id) = x,
WSP_WELL_KNOWN_HEADERS(h)
#undef h
} MMS_PART_HEADER;
static
const char*
mms_message_well_known_header_name(
int hdr)
{
static char unknown[6];
switch (hdr) {
#define h(id,n,x,t) case MMS_HEADER_ID(id): return n;
MMS_WELL_KNOWN_HEADERS(h)
#undef h
default:
snprintf(unknown, sizeof(unknown), "0x%02X", hdr);
unknown[sizeof(unknown)-1] = 0;
return unknown;
}
}
static
const char*
mms_part_well_known_header_name(
int hdr)
{
static char unknown[6];
switch (hdr) {
#define h(id,n,x,t) case MMS_PART_HEADER_ID(id): return n;
WSP_WELL_KNOWN_HEADERS(h)
#undef h
default:
snprintf(unknown, sizeof(unknown), "0x%02X", hdr);
unknown[sizeof(unknown)-1] = 0;
return unknown;
}
}
static
const struct mms_named_value*
mms_find_named_value(
const struct mms_named_value* values,
unsigned int num_values,
unsigned int value)
{
unsigned int i;
for (i=0; i<num_values; i++) {
if (value == values[i].value) {
return values + i;
}
}
return NULL;
}
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
static
struct mms_header*
mms_header_new(
const char* name)
{
struct mms_header* header = g_slice_new0(struct mms_header);
header->name = g_strdup(name);
return header;
}
static
struct mms_header*
mms_header_new_content_type()
{
return mms_header_new("Content-Type");
}
200
201
static
void
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
mms_header_free(
struct mms_header* header)
{
if (header) {
unsigned int i;
for (i=0; i<header->num_params; i++) {
struct mms_header_param* param = header->params[i];
g_free(param->name);
g_free(param->value);
g_slice_free(struct mms_header_param, param);
}
g_free(header->name);
g_free(header->value);
g_free(header->dump);
g_free(header->params);
g_slice_free(struct mms_header, header);
}
}
static
void
mms_headers_free(
struct mms_headers* headers)
{
if (headers) {
unsigned int i;
for (i=0; i<headers->num_headers; i++) {
mms_header_free(headers->headers[i]);
}
g_free(headers->headers);
g_slice_free(struct mms_headers, headers);
}
}
static
void
mms_header_print(
const struct mms_header* header,
const char* prefix,
241
242
unsigned int flags)
{
243
if (header) {
244
unsigned int i;
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
printf("%s%s: ", prefix, header->name);
if (header->value) printf("%s", header->value);
for (i=0; i<header->num_params; i++) {
struct mms_header_param* param = header->params[i];
printf("; %s=%s", param->name, param->value);
}
if ((flags & MMS_DUMP_FLAG_VERBOSE) && header->dump) {
printf(" (%s)", header->dump);
}
printf("\n");
}
}
static
void
mms_headers_print(
const struct mms_headers* headers,
const char* prefix,
unsigned int flags)
{
if (headers) {
unsigned int i;
for (i=0; i<headers->num_headers; i++) {
mms_header_print(headers->headers[i], prefix, flags);
}
}
}
static
const char*
mms_header_find(
const struct mms_header* header,
const char* name)
{
if (header && name) {
unsigned int i;
for (i=0; i<header->num_params; i++) {
const struct mms_header_param* param = header->params[i];
if (!g_ascii_strcasecmp(param->name, name)) {
return param->value;
}
}
}
return NULL;
}
static
const struct mms_header*
mms_headers_find(
const struct mms_headers* headers,
const char* name)
{
if (headers && name) {
unsigned int i;
for (i=0; i<headers->num_headers; i++) {
const struct mms_header* header = headers->headers[i];
if (!g_ascii_strcasecmp(header->name, name)) {
return header;
}
}
}
return NULL;
}
static
const char*
mms_headers_find_filename(
const struct mms_header* content_type,
const struct mms_headers* headers)
{
const struct mms_header* disp = mms_headers_find(headers,
HEADER_CONTENT_DISPOSITION);
if (disp) {
const char* filename = mms_header_find(disp, PARAM_FILENAME);
if (filename) {
return filename;
}
}
return mms_header_find(content_type, PARAM_NAME);
}
static
void
mms_header_set_count_param(
struct mms_header* header,
unsigned int count)
{
header->num_params = 1;
header->params = g_new(struct mms_header_param*, header->num_params);
header->params[0] = g_slice_new0(struct mms_header_param);
header->params[0]->name = g_strdup("Count");
header->params[0]->value = g_strdup_printf("%u", count);
}
static
char*
mms_hexdump(
const guint8* val,
unsigned int len)
{
if (len > 0) {
unsigned int i;
GString* buf = g_string_new_len(NULL, len*3 - 1);
g_string_append_printf(buf, "%02X", val[0]);
349
for (i=1; i<len; i++) {
350
g_string_append_printf(buf, " %02X", val[i]);
351
}
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
return g_string_free(buf, FALSE);
}
return g_strdup("");
}
static
void
mms_header_dump(
struct mms_header* header,
const guint8* val,
unsigned int len,
unsigned int flags)
{
if ((flags & MMS_DUMP_FLAG_VERBOSE) && len > 0) {
header->dump = mms_hexdump(val, len);
367
368
369
370
371
372
}
}
static
gboolean
mms_value_decode_unknown(
373
struct mms_header* header,
374
375
376
377
378
379
380
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
if (type == WSP_VALUE_TYPE_TEXT) {
if (val[0] == WSP_QUOTE) val++;
381
382
header->value = g_strdup((char*)val);
mms_header_dump(header, val, len, flags);
383
} else if (len == 1) {
384
385
386
header->value = g_strdup_printf("0x%02X", val[0]);
if (flags & MMS_DUMP_FLAG_VERBOSE) {
header->dump = g_strdup_printf("%u", val[0]);
387
}
388
389
} else if (len > 1) {
header->value = mms_hexdump(val, len);
390
391
392
393
394
395
396
}
return TRUE;
}
static
gboolean
mms_value_decode_quote(
397
struct mms_header* header,
398
399
400
401
402
403
404
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
/* Quoted-string = <Octet 34> *TEXT End-of-string */
if (type == WSP_VALUE_TYPE_TEXT && len > 0 && val[0] == 0x22) {
405
406
header->value = g_strdup((char*)val+1);
mms_header_dump(header, val, len, flags);
407
408
409
410
411
412
413
414
return TRUE;
}
return FALSE;
}
static
gboolean
mms_value_decode_enum(
415
struct mms_header* header,
416
417
418
419
420
421
422
423
424
425
426
enum wsp_value_type type,
const guint8* val,
unsigned int len,
const struct mms_named_value* values,
unsigned int num_values,
unsigned int flags)
{
if (type == WSP_VALUE_TYPE_SHORT && len == 1) {
const struct mms_named_value* nv;
nv = mms_find_named_value(values, num_values, val[0]);
if (nv) {
427
428
429
430
header->value = g_strdup(nv->name);
if (flags & MMS_DUMP_FLAG_VERBOSE) {
header->dump = g_strdup_printf("%u", nv->value);
}
431
432
433
return TRUE;
}
}
434
return mms_value_decode_unknown(header, type, val, len, flags);
435
436
437
438
439
}
static
gboolean
mms_value_decode_version(
440
struct mms_header* header,
441
442
443
444
445
446
447
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
if (type == WSP_VALUE_TYPE_SHORT && len == 1) {
const unsigned int value = val[0];
448
449
450
451
452
header->value = g_strdup_printf("%u.%u",
(val[0] & 0x70) >> 4, val[0] & 0x0f);
if (flags & MMS_DUMP_FLAG_VERBOSE) {
header->dump = g_strdup_printf("%u", value);
}
453
454
return TRUE;
}
455
return mms_value_decode_unknown(header, type, val, len, flags);
456
457
458
459
460
}
static
gboolean
mms_value_decode_long(
461
struct mms_header* header,
462
463
464
465
466
467
468
469
470
471
472
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
unsigned long long_val;
if (type == WSP_VALUE_TYPE_LONG && len <= sizeof(long_val)) {
unsigned int i;
for (long_val = 0, i=0; i<len; i++) {
long_val = ((long_val << 8) | val[i]);
}
473
header->value = g_strdup_printf("%lu", long_val);
474
475
return TRUE;
}
476
return mms_value_decode_unknown(header, type, val, len, flags);
477
478
479
}
static
480
481
char*
mms_value_format_date(
482
483
484
485
time_t t)
{
char date[64];
strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%S%z", localtime(&t));
486
return g_strdup(date);
487
488
}
489
490
491
492
493
494
495
496
497
498
499
500
501
502
static
gboolean
mms_value_decode_date_value(
const guint8* val,
unsigned int len,
time_t* t)
{
if (len <= sizeof(t)) {
unsigned int i;
for (*t=0, i=0; i<len; i++) {
*t = (((*t) << 8) | val[i]);
}
return TRUE;
}
503
return FALSE;
504
505
}
506
507
508
static
gboolean
mms_value_decode_date(
509
struct mms_header* header,
510
511
512
513
514
515
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
time_t t;
516
517
if (type == WSP_VALUE_TYPE_LONG &&
mms_value_decode_date_value(val, len, &t)) {
518
519
520
521
header->value = mms_value_format_date(t);
if (flags & MMS_DUMP_FLAG_VERBOSE) {
header->dump = g_strdup_printf("%lu", (unsigned long)t);
}
522
523
return TRUE;
}
524
return mms_value_decode_unknown(header, type, val, len, flags);
525
526
527
528
529
}
static
gboolean
mms_value_decode_bool(
530
struct mms_header* header,
531
532
533
534
535
536
537
538
539
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Yes", 128 },
{ "No", 129 }
};
540
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
541
542
543
544
545
546
}
/* Message-type-value */
static
gboolean
mms_value_decode_mtype(
547
struct mms_header* header,
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "M-Send.req", 128 },
{ "M-Send.conf", 129 },
{ "M-Notification.ind", 130 },
{ "M-Notifyresp.ind", 131 },
{ "M-Retrieve.conf", 132 },
{ "M-Acknowledge.ind", 133 },
{ "M-Delivery.ind", 134 },
{ "M-Read-Rec.ind", 135 },
{ "M-Read-Orig.ind", 136 },
{ "M-Forward.req", 137 },
{ "M-Forward.conf", 138 }
};
566
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
567
568
569
570
571
572
}
/* Message-class-value */
static
gboolean
mms_value_decode_mclass(
573
struct mms_header* header,
574
575
576
577
578
579
580
581
582
583
584
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Personal", 128 },
{ "Advertisement", 129 },
{ "Informational", 130 },
{ "Auto", 131 }
};
585
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
586
587
588
589
590
591
}
/* Priority-value */
static
gboolean
mms_value_decode_prio(
592
struct mms_header* header,
593
594
595
596
597
598
599
600
601
602
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Low", 128 },
{ "Normal", 129 },
{ "High", 130 }
};
603
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
604
605
606
607
608
609
}
/* Retrieve-status-value */
static
gboolean
mms_value_decode_retrieve(
610
struct mms_header* header,
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Ok", 128 },
{ "Error-transient-failure", 192 },
{ "Error-transient-message-not-found", 193 },
{ "Error-transient-network-problem", 194 },
{ "Error-permanent-failure", 224 },
{ "Error-permanent-service-denied", 225 },
{ "Error-permanent-message-not-found", 226 },
{ "Error-permanent-content-unsupported", 227 }
};
626
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
627
628
629
630
631
632
}
/* Read-status-value */
static
gboolean
mms_value_decode_rstatus(
633
struct mms_header* header,
634
635
636
637
638
639
640
641
642
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Read", 128 },
{ "Deleted", 129 }
};
643
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
644
645
646
647
648
649
}
/* Status-value */
static
gboolean
mms_value_decode_status(
650
struct mms_header* header,
651
652
653
654
655
656
657
658
659
660
661
662
663
664
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Expired", 128 },
{ "Retrieved", 129 },
{ "Rejected", 130 },
{ "Deferred", 131 },
{ "Unrecognised", 132 },
{ "Indeterminate", 133 },
{ "Forwarded", 134 }
};
665
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
666
667
}
668
669
670
671
/* Response-status-value */
static
gboolean
mms_value_decode_respstat(
672
struct mms_header* header,
673
674
675
676
677
678
679
680
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Ok", 128 },
{ "Error-unspecified", 129 },
681
{ "Error-service-denied", 130 },
682
683
684
685
{ "Error-message-format-corrupt", 131 },
{ "Error-sending-address-unresolved", 132 },
{ "Error-message-not-found", 133 },
{ "Error-network-problem", 134 },
686
{ "Error-content-not-accepted", 135 },
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
{ "Error-unsupported-message", 136 },
{ "Error-transient-failure", 192 },
{ "Error-transient-sending-address-unresolved", 193 },
{ "Error-transient-message-not-found", 194 },
{ "Error-transient-network-problem", 195 },
{ "Error-transient-partial-success", 196 },
{ "Error-permanent-failure", 224 },
{ "Error-permanent-service-denied", 225 },
{ "Error-permanent-message-format-corrupt", 226 },
{ "Error-permanent-sending-address-unresolved", 227 },
{ "Error-permanent-message-not-found", 228 },
{ "Error-permanent-content-not-accepted", 229 },
{ "Error-permanent-reply-charging-limitations-not-met", 230 },
{ "Error-permanent-reply-charging-request-not-accepted", 231 },
{ "Error-permanent-reply-charging-forwarding-denied", 232 },
{ "Error-permanent-reply-charging-not-supported", 233 },
{ "Error-permanent-address-hiding-not-supported", 234 },
{ "Error-permanent-lack-of-prepaid", 235 }
};
706
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
707
708
}
709
/* Encoded-string-value */
710
711
static
gboolean
712
mms_value_decode_encoded_text(
713
struct mms_header* header,
714
715
enum wsp_value_type type,
const guint8* val,
716
unsigned int len)
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
{
/* http://www.iana.org/assignments/character-sets */
static const struct mms_named_value nv [] = {
{ "US-ASCII", 3},
{ "ISO_8859-1", 4},
{ "ISO_8859-2", 5},
{ "ISO_8859-3", 6},
{ "ISO_8859-4", 7},
{ "ISO_8859-5", 8},
{ "ISO_8859-6", 9},
{ "ISO_8859-7", 10},
{ "ISO_8859-8", 11},
{ "ISO_8859-9", 12},
{ "ISO-8859-10", 13},
{ "Shift_JIS", 17},
{ "EUC-JP", 18},
733
{ "CP949", 36},
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
{ "ISO-2022-KR", 37},
{ "EUC-KR", 38},
{ "ISO-2022-JP", 39},
{ "ISO-2022-JP-2", 40},
{ "ISO_8859-6-E", 81},
{ "ISO_8859-6-I", 82},
{ "ISO_8859-8-E", 84},
{ "ISO_8859-8-I", 85},
{ "UTF-8", 106},
{ "ISO-8859-13", 109},
{ "ISO-8859-14", 110},
{ "ISO-8859-15", 111},
{ "ISO-8859-16", 112},
{ "GBK", 113},
{ "GB18030", 114},
{ "ISO-10646-UCS-2", 1000},
{ "ISO-10646-UCS-4", 1001},
{ "ISO-10646-J-1", 1004},
{ "UTF-7", 1012},
{ "UTF-16BE", 1013},
{ "UTF-16LE", 1014},
{ "UTF-16", 1015},
{ "UTF-32", 1017},
{ "UTF-32BE", 1018},
{ "UTF-32LE", 1019},
{ "GB2312", 2025},
{ "Big5", 2026},
{ "macintosh", 2027},
{ "KOI8-R", 2084},
{ "windows-874", 2109},
{ "windows-1250", 2250},
{ "windows-1251", 2251},
{ "windows-1252", 2252},
{ "windows-1253", 2253},
{ "windows-1254", 2254},
{ "windows-1255", 2255},
{ "windows-1256", 2256},
{ "windows-1257", 2257},
{ "windows-1258", 2258}
};
if (type == WSP_VALUE_TYPE_TEXT) {
776
header->value = g_strdup((char*)val);
777
778
779
780
781
782
return TRUE;
} else if (type == WSP_VALUE_TYPE_LONG) {
unsigned int charset = 0;
unsigned int consumed = 0;
if (wsp_decode_integer(val, len, &charset, &consumed)) {
const struct mms_named_value* cs;
783
cs = mms_find_named_value(nv, N_(nv), charset);
784
785
786
787
788
789
790
791
792
793
794
795
796
if (cs) {
char* tmp = NULL;
const char* text = NULL;
const char* dest_charset = "UTF-8";
if (strcmp(dest_charset, cs->name)) {
gsize bytes_in, bytes_out;
text = tmp = g_convert((char*)val+consumed, len-consumed,
dest_charset, cs->name, &bytes_in, &bytes_out, NULL);
} else {
if (val[consumed] == WSP_QUOTE) consumed++;
if (consumed <= len) text = (char*)val+consumed;
}
if (text) {
797
header->value = g_strdup(text);
798
799
800
801
802
803
g_free(tmp);
return TRUE;
}
}
}
}
804
805
806
807
808
809
return FALSE;
}
static
gboolean
mms_value_decode_etext(
810
struct mms_header* header,
811
812
813
814
815
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
816
817
if (mms_value_decode_encoded_text(header, type, val, len)) {
mms_header_dump(header, val, len, flags);
818
819
return TRUE;
} else {
820
return mms_value_decode_unknown(header, type, val, len, flags);
821
}
822
823
}
824
825
826
827
/* Sender-visibility-value */
static
gboolean
mms_value_decode_visiblty(
828
struct mms_header* header,
829
830
831
832
833
834
835
836
837
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
static const struct mms_named_value nv [] = {
{ "Hide", 128 },
{ "Show", 129 },
};
838
return mms_value_decode_enum(header, type, val, len, nv, N_(nv), flags);
839
840
841
}
/* From-value */
842
843
844
static
gboolean
mms_value_decode_from(
845
struct mms_header* header,
846
847
848
849
850
851
852
853
854
855
856
857
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
/*
* Address-present-token Encoded-string-value | Insert-address-token
* Address-present-token = <Octet 128>
* Insert-address-token = <Octet 129>
*/
if (type == WSP_VALUE_TYPE_LONG && len > 0) {
if (val[0] == 0x81) {
858
859
860
861
header->value = g_strdup("<Insert-address>");
if (flags & MMS_DUMP_FLAG_VERBOSE) {
header->dump = g_strdup_printf("%u", val[0]);
}
862
863
864
865
866
867
return TRUE;
} else if (val[0] == 0x80 && len > 1) {
enum wsp_value_type ftype;
const void* fval = NULL;
unsigned int flen = 0;
if (wsp_decode_field(val+1, len-1, &ftype, &fval, &flen, NULL) &&
868
869
mms_value_decode_etext(header, ftype, fval, flen, 0)) {
mms_header_dump(header, val, len, flags);
870
871
872
873
return TRUE;
}
}
}
874
return mms_value_decode_unknown(header, type, val, len, flags);
875
876
}
877
/* Expiry-value */
878
879
880
static
gboolean
mms_value_decode_expiry(
881
struct mms_header* header,
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
/*
* Absolute-token Date-value | Relative-token Delta-seconds-value
* Absolute-token = <Octet 128>
* Relative-token = <Octet 129>
*/
gboolean ok = FALSE;
enum wsp_value_type ftype;
const void* fval = NULL;
unsigned int flen = 0;
if (type == WSP_VALUE_TYPE_LONG && len > 1 &&
wsp_decode_field(val+1, len-1, &ftype, &fval, &flen, NULL)) {
if (val[0] == 0x80 /* Absolute-token */) {
899
ok = mms_value_decode_date(header, ftype, fval, flen, 0);
900
901
902
903
904
905
906
} else if (val[0] == 0x81 /* Relative-token */) {
time_t t;
if (ftype == WSP_VALUE_TYPE_LONG && flen > 0 && flen <= sizeof(t)) {
unsigned int i;
for (t=0, i=0; i<flen; i++) {
t = ((t << 8) | ((guint8*)fval)[i]);
}
907
header->value = g_strdup_printf("+%u sec", (unsigned int)t);
908
909
910
911
912
ok = TRUE;
}
}
}
if (ok) {
913
mms_header_dump(header, val, len, flags);
914
915
return TRUE;
}
916
return mms_value_decode_unknown(header, type, val, len, flags);
917
918
}
919
920
921
922
/* Previously-sent-by-value */
static
gboolean
mms_value_decode_prevby(
923
struct mms_header* header,
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
/*
* Value-length Forwarded-count-value Encoded-string-value
* Forwarded-count-value = Integer-value
*/
if (type == WSP_VALUE_TYPE_LONG) {
unsigned int count = 0;
unsigned int consumed = 0;
if (wsp_decode_integer(val, len, &count, &consumed)) {
const guint8* ptr = val + consumed;
const unsigned int bytes_left = len - consumed;
939
940
941
942
943
944
945
946
enum wsp_value_type ftype;
const void* fval;
unsigned int flen;
if (wsp_decode_field(ptr, bytes_left, &ftype, &fval, &flen,
&consumed) && consumed == bytes_left &&
mms_value_decode_encoded_text(header, ftype, fval, flen)) {
mms_header_set_count_param(header, count);
mms_header_dump(header, val, len, flags);
947
948
949
950
return TRUE;
}
}
}
951
return mms_value_decode_unknown(header, type, val, len, flags);
952
953
954
955
956
957
}
/* Previously-sent-date-value */
static
gboolean
mms_value_decode_prevdate(
958
struct mms_header* header,
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
enum wsp_value_type type,
const guint8* val,
unsigned int len,
unsigned int flags)
{
/*
* Value-length Forwarded-count-value Date-value
* Forwarded-count-value = Integer-value
*/
if (type == WSP_VALUE_TYPE_LONG) {
unsigned int count = 0;
unsigned int consumed = 0;
if (wsp_decode_integer(val, len, &count, &consumed)) {
const guint8* ptr = val + consumed;
const unsigned int bytes_left = len - consumed;
enum wsp_value_type date_type;
const void* date_val;
unsigned int date_len;
time_t t;
if (wsp_decode_field(ptr, bytes_left, &date_type, &date_val,
&date_len, &consumed) && consumed == bytes_left &&
date_type == WSP_VALUE_TYPE_LONG &&
mms_value_decode_date_value(date_val, date_len, &t)) {
982
983
984
header->value = mms_value_format_date(t);
mms_header_set_count_param(header, count);
mms_header_dump(header, val, len, flags);
985
986
987
988
return TRUE;
}
}
}
989
return mms_value_decode_unknown(header, type, val, len, flags);
990
991
}
992
993
994
static
void
mms_value_decode_wsp_params(
995
struct mms_header* header,
996
997
998
999
1000
const unsigned char* pdu,
unsigned int len)
{
static const struct mms_named_value nv_p [] = {
{ "Q", WSP_PARAMETER_TYPE_Q },