FreeCalypso > hg > themwi-system-sw
diff smpp-send/msg_cmd.c @ 223:f11c3e40c87a
new program smpp-send
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Aug 2023 12:24:31 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/smpp-send/msg_cmd.c Sat Aug 05 12:24:31 2023 -0800 @@ -0,0 +1,69 @@ +/* + * This module implements msg and msg-udh input commands, + * after all settings have been captured. + */ + +#include <sys/types.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "error.h" + +extern int input_lineno; + +static int +decode_hex_digit(c) +{ + if (c >= '0' && c <= '9') + return(c - '0'); + if (c >= 'A' && c <= 'F') + return(c - 'A' + 10); + if (c >= 'a' && c <= 'f') + return(c - 'a' + 10); + return(-1); +} + +static void +cmd_msg_common(arg, udhi) + char *arg; +{ + u_char input[160]; + unsigned input_len; + + for (input_len = 0; ; input_len++) { + while (isspace(*arg)) + arg++; + if (!*arg) + break; + if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { + fprintf(stderr, ERR_PREFIX "invalid hex string\n", + input_lineno); + exit(1); + } + if (input_len >= 160) { + fprintf(stderr, ERR_PREFIX "hex string is too long\n", + input_lineno); + exit(1); + } + input[input_len] = (decode_hex_digit(arg[0]) << 4) | + decode_hex_digit(arg[1]); + arg += 2; + } + build_submit_sm(input, input_len, udhi); +} + +void +cmd_msg_plain(argc, argv) + char **argv; +{ + cmd_msg_common(argv[1], 0); +} + +void +cmd_msg_udh(argc, argv) + char **argv; +{ + cmd_msg_common(argv[1], 1); +}