changeset 353:3bcc56883b17

fcup-smdump: -d delete-after-dump option implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 05 Feb 2018 17:35:49 +0000
parents 02d6c8469535
children ec0d6d58e043
files uptools/atcmd/smdump.c
diffstat 1 files changed, 44 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/uptools/atcmd/smdump.c	Mon Feb 05 08:47:45 2018 +0000
+++ b/uptools/atcmd/smdump.c	Mon Feb 05 17:35:49 2018 +0000
@@ -13,12 +13,34 @@
 
 extern char at_response[];
 
+struct delafter {
+	unsigned	msgid;
+	struct delafter	*next;
+};
+
+int delete_after_flag;
+struct delafter *delafter_head, **delafter_tail = &delafter_head;
+
 int pdu_state;
 char *msgtype;
 u_char pbname_gsm[40];
 unsigned pbname_len, header_len;
 u_char pdu_bin[176];
 
+add_delafter_record(msgid)
+	unsigned msgid;
+{
+	struct delafter *rec;
+
+	rec = malloc(sizeof(struct delafter));
+	if (!rec)
+		return;
+	rec->msgid = msgid;
+	rec->next = 0;
+	*delafter_tail = rec;
+	delafter_tail = &rec->next;
+}
+
 validate_pbname_7bit()
 {
 	unsigned n;
@@ -53,7 +75,8 @@
 	if (fields[2].type != RESP_FIELD_STRING &&
 	    fields[2].type != RESP_FIELD_EMPTY)
 		goto malformed;
-	/* we'll handle the message number when we add delete after dump */
+	if (delete_after_flag)
+		add_delafter_record(fields[0].num);
 	switch (fields[1].num) {
 	case 0:
 	case 1:
@@ -124,17 +147,33 @@
 		cmgl_header();
 }
 
+delete_after_process()
+{
+	struct delafter *rec;
+	char cmgd_cmd[32];
+
+	for (rec = delafter_head; rec; rec = rec->next) {
+		sprintf(cmgd_cmd, "AT+CMGD=%u", rec->msgid);
+		atinterf_exec_cmd_needok(cmgd_cmd, 0, 0);
+	}
+}
+
 main(argc, argv)
 	char **argv;
 {
 	int c;
 	extern int optind;
 
-	while ((c = getopt(argc, argv, "B:np:RX:")) != EOF)
-		if (!atinterf_cmdline_opt(c)) {
+	while ((c = getopt(argc, argv, "B:dnp:RX:")) != EOF) {
+		if (atinterf_cmdline_opt(c))
+			continue;
+		else if (c == 'd')
+			delete_after_flag = 1;
+		else {
 			/* error msg already printed */
 			exit(ERROR_USAGE);
 		}
+	}
 	if (argc != optind) {
 		fprintf(stderr, "usage: %s [options]\n", argv[0]);
 		exit(ERROR_USAGE);
@@ -150,6 +189,7 @@
 		fprintf(stderr, "error: wrong state at the end of +CMGL\n");
 		exit(ERROR_TARGET);
 	}
-	/* delete-after-dump will go here */
+	if (delete_after_flag)
+		delete_after_process();
 	exit(0);
 }