FreeCalypso > hg > sms-coding-utils
changeset 28:6e925aa54727
libcoding: more sensible naming of GSM time
encoding and decoding modules
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 13 Jun 2024 02:32:11 +0000 |
parents | 7418ca2e9949 |
children | aae078d9eaa6 |
files | libcoding/Makefile libcoding/gsmtime.c libcoding/gsmtime_dec.c libcoding/gsmtime_enc.c libcoding/timestamp.c |
diffstat | 5 files changed, 91 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/libcoding/Makefile Thu Jun 13 02:29:29 2024 +0000 +++ b/libcoding/Makefile Thu Jun 13 02:32:11 2024 +0000 @@ -1,9 +1,9 @@ OBJS= alpha_addr.o alpha_addr_enc.o check_high_bit.o decode_helpers.o \ grokdcs.o gsm7_decode.o gsm7_decode_qstring.o gsm7_decode_tables.o \ gsm7_encode.o gsm7_encode2.o gsm7_encode_table.o gsm7_pack.o \ - gsm7_unpack.o gsmtime.o hexdecode.o hexdigits.o hexdump.o hexout.o \ - number_decode.o number_encode.o scaddr.o timestamp.o ucs2_bigend.o \ - ucs2_decode.o utf8_decode.o utf8_decode2.o + gsm7_unpack.o gsmtime_dec.o gsmtime_enc.o hexdecode.o hexdigits.o \ + hexdump.o hexout.o number_decode.o number_encode.o scaddr.o \ + ucs2_bigend.o ucs2_decode.o utf8_decode.o utf8_decode2.o LIB= libcoding.a include ../config.defs
--- a/libcoding/gsmtime.c Thu Jun 13 02:29:29 2024 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * This library module implements decoding of GSM timestamps. - */ - -#include <sys/types.h> -#include <stdio.h> - -gsm_timestamp_decode(inbuf, outbuf) - u_char *inbuf; - char *outbuf; -{ - u_char rev[7]; - int i, d1, d2, tzsign; - - for (i = 0; i < 7; i++) { - d1 = inbuf[i] & 0xF; - d2 = inbuf[i] >> 4; - rev[i] = (d1 << 4) | d2; - } - if (rev[6] & 0x80) { - rev[6] &= 0x7F; - tzsign = '-'; - } else - tzsign = '+'; - sprintf(outbuf, "%02X/%02X/%02X,%02X:%02X:%02X%c%02X", rev[0], rev[1], - rev[2], rev[3], rev[4], rev[5], tzsign, rev[6]); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcoding/gsmtime_dec.c Thu Jun 13 02:32:11 2024 +0000 @@ -0,0 +1,27 @@ +/* + * This library module implements decoding of GSM timestamps. + */ + +#include <sys/types.h> +#include <stdio.h> + +gsm_timestamp_decode(inbuf, outbuf) + u_char *inbuf; + char *outbuf; +{ + u_char rev[7]; + int i, d1, d2, tzsign; + + for (i = 0; i < 7; i++) { + d1 = inbuf[i] & 0xF; + d2 = inbuf[i] >> 4; + rev[i] = (d1 << 4) | d2; + } + if (rev[6] & 0x80) { + rev[6] &= 0x7F; + tzsign = '-'; + } else + tzsign = '+'; + sprintf(outbuf, "%02X/%02X/%02X,%02X:%02X:%02X%c%02X", rev[0], rev[1], + rev[2], rev[3], rev[4], rev[5], tzsign, rev[6]); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcoding/gsmtime_enc.c Thu Jun 13 02:32:11 2024 +0000 @@ -0,0 +1,61 @@ +/* + * The function implemented in this module encodes a GSM SMS absolute timestamp + * from ASCII representation into PDU octets. + */ + +#include <sys/types.h> +#include <ctype.h> + +encode_gsm_sms_abstime(str, bin) + char *str; + u_char *bin; +{ + u_char digits[14]; + + if (!isdigit(str[0]) || !isdigit(str[1])) + return(-1); + digits[0] = str[0] - '0'; + digits[1] = str[1] - '0'; + if (str[2] != '/') + return(-1); + if (!isdigit(str[3]) || !isdigit(str[4])) + return(-1); + digits[2] = str[3] - '0'; + digits[3] = str[4] - '0'; + if (str[5] != '/') + return(-1); + if (!isdigit(str[6]) || !isdigit(str[7])) + return(-1); + digits[4] = str[6] - '0'; + digits[5] = str[7] - '0'; + if (str[8] != ',') + return(-1); + if (!isdigit(str[9]) || !isdigit(str[10])) + return(-1); + digits[6] = str[9] - '0'; + digits[7] = str[10] - '0'; + if (str[11] != ':') + return(-1); + if (!isdigit(str[12]) || !isdigit(str[13])) + return(-1); + digits[8] = str[12] - '0'; + digits[9] = str[13] - '0'; + if (str[14] != ':') + return(-1); + if (!isdigit(str[15]) || !isdigit(str[16])) + return(-1); + digits[10] = str[15] - '0'; + digits[11] = str[16] - '0'; + if (str[17] != '+' && str[17] != '-') + return(-1); + if (!isdigit(str[18]) || !isdigit(str[19])) + return(-1); + digits[12] = str[18] - '0'; + digits[13] = str[19] - '0'; + if (str[20]) + return(-1); + if (str[17] == '-') + digits[12] |= 8; + pack_digit_bytes(digits, bin, 7); + return(0); +}
--- a/libcoding/timestamp.c Thu Jun 13 02:29:29 2024 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * The function implemented in this module encodes a GSM SMS absolute timestamp - * from ASCII representation into PDU octets. - */ - -#include <sys/types.h> -#include <ctype.h> - -encode_gsm_sms_abstime(str, bin) - char *str; - u_char *bin; -{ - u_char digits[14]; - - if (!isdigit(str[0]) || !isdigit(str[1])) - return(-1); - digits[0] = str[0] - '0'; - digits[1] = str[1] - '0'; - if (str[2] != '/') - return(-1); - if (!isdigit(str[3]) || !isdigit(str[4])) - return(-1); - digits[2] = str[3] - '0'; - digits[3] = str[4] - '0'; - if (str[5] != '/') - return(-1); - if (!isdigit(str[6]) || !isdigit(str[7])) - return(-1); - digits[4] = str[6] - '0'; - digits[5] = str[7] - '0'; - if (str[8] != ',') - return(-1); - if (!isdigit(str[9]) || !isdigit(str[10])) - return(-1); - digits[6] = str[9] - '0'; - digits[7] = str[10] - '0'; - if (str[11] != ':') - return(-1); - if (!isdigit(str[12]) || !isdigit(str[13])) - return(-1); - digits[8] = str[12] - '0'; - digits[9] = str[13] - '0'; - if (str[14] != ':') - return(-1); - if (!isdigit(str[15]) || !isdigit(str[16])) - return(-1); - digits[10] = str[15] - '0'; - digits[11] = str[16] - '0'; - if (str[17] != '+' && str[17] != '-') - return(-1); - if (!isdigit(str[18]) || !isdigit(str[19])) - return(-1); - digits[12] = str[18] - '0'; - digits[13] = str[19] - '0'; - if (str[20]) - return(-1); - if (str[17] == '-') - digits[12] |= 8; - pack_digit_bytes(digits, bin, 7); - return(0); -}