comparison libcoding/timestamp.c @ 6:b831ee7d512c

libcoding: add absolute time encoding function
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 05:45:15 +0000
parents
children
comparison
equal deleted inserted replaced
5:c79d09284c5f 6:b831ee7d512c
1 /*
2 * The function implemented in this module encodes a GSM SMS absolute timestamp
3 * from ASCII representation into PDU octets.
4 */
5
6 #include <sys/types.h>
7 #include <ctype.h>
8
9 encode_gsm_sms_abstime(str, bin)
10 char *str;
11 u_char *bin;
12 {
13 u_char digits[14];
14
15 if (!isdigit(str[0]) || !isdigit(str[1]))
16 return(-1);
17 digits[0] = str[0] - '0';
18 digits[1] = str[1] - '0';
19 if (str[2] != '/')
20 return(-1);
21 if (!isdigit(str[3]) || !isdigit(str[4]))
22 return(-1);
23 digits[2] = str[3] - '0';
24 digits[3] = str[4] - '0';
25 if (str[5] != '/')
26 return(-1);
27 if (!isdigit(str[6]) || !isdigit(str[7]))
28 return(-1);
29 digits[4] = str[6] - '0';
30 digits[5] = str[7] - '0';
31 if (str[8] != ',')
32 return(-1);
33 if (!isdigit(str[9]) || !isdigit(str[10]))
34 return(-1);
35 digits[6] = str[9] - '0';
36 digits[7] = str[10] - '0';
37 if (str[11] != ':')
38 return(-1);
39 if (!isdigit(str[12]) || !isdigit(str[13]))
40 return(-1);
41 digits[8] = str[12] - '0';
42 digits[9] = str[13] - '0';
43 if (str[14] != ':')
44 return(-1);
45 if (!isdigit(str[15]) || !isdigit(str[16]))
46 return(-1);
47 digits[10] = str[15] - '0';
48 digits[11] = str[16] - '0';
49 if (str[17] != '+' && str[17] != '-')
50 return(-1);
51 if (!isdigit(str[18]) || !isdigit(str[19]))
52 return(-1);
53 digits[12] = str[18] - '0';
54 digits[13] = str[19] - '0';
55 if (str[20])
56 return(-1);
57 if (str[17] == '-')
58 digits[12] |= 8;
59 pack_digit_bytes(digits, bin, 7);
60 return(0);
61 }