jcs
/subtext
/amendments
/321
fidopkt: Parse MSGID line to break out zone/net/node/point/hex id
jcs made amendment 321 about 1 year ago
--- fidopkt.c Thu Feb 23 09:48:06 2023
+++ fidopkt.c Fri Feb 24 14:11:23 2023
@@ -82,6 +82,7 @@ static const char *months[] = {
size_t fidopkt_read_until(char **buf, size_t *buf_len, char delim,
size_t max_len, char *ret, bool terminate);
+bool fidopkt_parse_msgid(struct fidopkt *pkt);
size_t
fidopkt_read_until(char **buf, size_t *buf_len, char delim,
@@ -110,6 +111,60 @@ fidopkt_read_until(char **buf, size_t *buf_len, char d
return retpos;
}
+bool
+fidopkt_parse_msgid(struct fidopkt *pkt)
+{
+ unsigned short zone, net, node, point = 0;
+ char garbage[member_size(struct fidopkt, msgid_orig) + 1];
+ unsigned long id;
+
+ /* 37246.fsxnet_fsx_gen@21:1/137.1 28583dba */
+ if (sscanf(pkt->msgid_orig, "%[^@]@%d:%d/%d.%d %lx",
+ &garbage, &zone, &net, &node, &point, &id) == 6)
+ goto found;
+
+ /* 37246.fsxnet_fsx_gen@21:1/137 28583dba */
+ if (sscanf(pkt->msgid_orig, "%[^@]@%d:%d/%d %lx",
+ &garbage, &zone, &net, &node, &id) == 5)
+ goto found;
+
+ /* 21:3/110.10@fsxnet 05996db9 */
+ if (sscanf(pkt->msgid_orig, "%d:%d/%d.%d@%s %lx",
+ &zone, &net, &node, &point, &garbage, &id) == 6)
+ goto found;
+
+ /* 21:3/110@fsxnet 05996db9 */
+ if (sscanf(pkt->msgid_orig, "%d:%d/%d@%s %lx",
+ &zone, &net, &node, &garbage, &id) == 5)
+ goto found;
+
+ /* 21:3/102.1 63f277aa */
+ if (sscanf(pkt->msgid_orig, "%d:%d/%d.%d %lx",
+ &zone, &net, &node, &point, &id) == 5)
+ goto found;
+
+ /* 21:3/102 63f277aa */
+ if (sscanf(pkt->msgid_orig, "%d:%d/%d %lx",
+ &zone, &net, &node, &id) == 4)
+ goto found;
+
+ logger_printf("[fidopkt] failed parsing msgid \"%s\"", pkt->msgid_orig);
+ return false;
+
+found:
+ pkt->msgid = id;
+ pkt->msgid_zone = zone;
+ pkt->msgid_net = net;
+ pkt->msgid_node = node;
+ pkt->msgid_point = point;
+
+#ifdef FIDOPKT_DEBUG
+ logger_printf("[fidopkt] %s -> zone:%d net:%d node:%d point:%d id:%lu",
+ pkt->msgid_orig, zone, net, node, point, id);
+#endif
+ return true;
+}
+
struct fidopkt *
fidopkt_parse(char *packet_filename, char *buf, size_t len)
{
@@ -251,9 +306,16 @@ fidopkt_parse(char *packet_filename, char *buf, size_t
strlcpy(tz, line + 1 + 7, sizeof(tz));
#endif
}
- else if (strncmp(line + 1, "MSGID: ", 7) == 0)
- strlcpy(ret->msgid, line + 1 + 7, sizeof(ret->msgid));
- else if (strncmp(line + 1, "REPLY: ", 7) == 0)
+ else if (strncmp(line + 1, "MSGID: ", 7) == 0) {
+ /*
+ * FTS-0009.001 says: ^AMSGID: origaddr serialno
+ * serialno is an 8 char hexadecimal string unique to the
+ * sending node
+ */
+ strlcpy(ret->msgid_orig, line + 1 + 7,
+ sizeof(ret->msgid_orig));
+ fidopkt_parse_msgid(ret);
+ } else if (strncmp(line + 1, "REPLY: ", 7) == 0)
strlcpy(ret->reply, line + 1 + 7, sizeof(ret->reply));
} else if (tear && strncmp(line, " * Origin: ", 11) == 0) {
line[llen] = '\0';
@@ -297,7 +359,9 @@ fidopkt_parse(char *packet_filename, char *buf, size_t
ret->time -= tzoff;
#ifdef FIDOPKT_DEBUG
- logger_printf("[fidopkt] ID: %s", ret->msgid);
+ logger_printf("[fidopkt] ID: %d:%d/%d.%d %08lx (%s)", ret->msgid_zone,
+ ret->msgid_net, ret->msgid_node, ret->msgid_point, ret->msgid,
+ ret->msgid_orig);
logger_printf("[fidopkt] Origin: %s", ret->origin);
logger_printf("[fidopkt] Reply To: %s", ret->reply);
logger_printf("[fidopkt] Area: %s", ret->area);
--- fidopkt.h Wed Feb 22 15:54:38 2023
+++ fidopkt.h Fri Feb 24 12:50:46 2023
@@ -26,8 +26,13 @@ struct fidopkt {
char subject[72];
char area[16];
char origin[72];
- char msgid[32];
char reply[32];
+ char msgid_orig[32];
+ unsigned long msgid;
+ u_int16_t msgid_zone;
+ u_int16_t msgid_net;
+ u_int16_t msgid_node;
+ u_int16_t msgid_point;
char *message;
size_t message_len;
};