commit 4f3f7e57405383a6b1ebcaf935fe4274e85b7ef4
parent 1b608a4b7082f4560ada5a4adcb78a6143a16ba2
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Wed, 4 Aug 2021 14:58:22 -0500
atc: add sms submission
Diffstat:
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/atc.c b/atc.c
@@ -28,6 +28,8 @@ main(int argc, char *argv[])
cmd = CMD_HANGUP;
} else if (strcmp(argv[1], "callevents") == 0) {
cmd = CMD_CALL_EVENTS;
+ } else if (strcmp(argv[1], "submit") == 0) {
+ cmd = CMD_SUBMIT;
}
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -58,6 +60,8 @@ main(int argc, char *argv[])
case CMD_CALL_EVENTS:
atd_cmd_call_events(sock);
break;
+ case CMD_SUBMIT:
+ atd_cmd_submit(sock, argv[2], argv[3]);
}
char op;
diff --git a/encdec.c b/encdec.c
@@ -27,11 +27,12 @@ dec_str(char *in, char **out)
len = dec_short(in);
ptr += 2;
- *out = malloc(len);
+ *out = malloc(len+1);
if (!(*out))
return -1;
memcpy(*out, ptr, len);
+ out[len] = 0;
return len + 2;
}
@@ -109,6 +110,18 @@ atd_cmd_call_events(int fd)
}
int
+atd_cmd_submit(int fd, char *num, char *msg)
+{
+ size_t len = strlen(num) + strlen(msg) + 5; // 5 = op + length + length
+ char buf[len];
+ buf[0] = CMD_SUBMIT;
+ enc_str(buf + 1, num);
+ enc_str(buf + 3 + strlen(num), msg);
+
+ return xwrite(fd, buf, len);
+}
+
+int
atd_status_call(int fd, enum callstatus status, char *num)
{
char buf[4 + strlen(num)];
diff --git a/encdec.h b/encdec.h
@@ -2,6 +2,7 @@ int atd_cmd_dial(int fd, char *num);
int atd_cmd_hangup(int fd);
int atd_cmd_answer(int fd);
int atd_cmd_call_events(int fd);
+int atd_cmd_submit(int fd, char *num, char *msg);
int atd_status_call(int fd, enum callstatus status, char *num);
ssize_t dec_str(char *in, char **out);
int dec_call_status(int fd, struct call *calls);