jcs
/subtext
/amendments
/403
board: Adapt to fidopkt changes, generate "wider" FTN msgids
jcs made amendment 403 about 1 year ago
--- board.c Sat Mar 11 20:43:53 2023
+++ board.c Mon Mar 13 22:41:54 2023
@@ -205,8 +205,8 @@ board_list_fidonet_boards(struct session *s)
show_help = false;
done = false;
- snprintf(title, sizeof(title), "%s Boards (%s)",
- db->config.fidonet_network, db->config.fidonet_node_addr);
+ snprintf(title, sizeof(title), "%s Boards",
+ db->config.fidonet_network);
while (!done && !s->ending) {
if (show_list) {
@@ -979,7 +979,7 @@ board_post_create(struct board *board, struct board_th
struct board_fidonet_post *fidonet_parent_post, struct board_post *post)
{
struct board_fidonet_post fidonet_post = { 0 };
- struct fidopkt pkt = { 0 };
+ struct fidopkt_message fidomsg = { 0 };
struct username_cache *user;
struct fidopkt_address our_address, hub_address;
struct bile_object *o;
@@ -1042,7 +1042,9 @@ board_post_create(struct board *board, struct board_th
fidonet_post.body_size = post->body_size;
/* make each board's posts have ids unique to our zone/net/node */
- fidonet_post.msgid.id = (board->id << 16) | post->id;
+ fidonet_post.msgid.id = 0x10000000 |
+ ((unsigned long)our_address.node << 24) |
+ ((unsigned long)(board->id) << 16) | post->id;
fidonet_post.msgid.zone = our_address.zone;
fidonet_post.msgid.net = our_address.net;
fidonet_post.msgid.node = our_address.node;
@@ -1053,20 +1055,24 @@ board_post_create(struct board *board, struct board_th
db->config.name, db->config.hostname,
db->config.fidonet_node_addr);
- pkt.time = fidonet_post.time;
- memcpy(&pkt.orig, &our_address, sizeof(pkt.orig));
- memcpy(&pkt.dest, &hub_address, sizeof(pkt.dest));
- strlcpy(pkt.area, board->fidonet_area, sizeof(pkt.area));
- strlcpy(pkt.to, fidonet_post.to, sizeof(pkt.to));
- strlcpy(pkt.from, fidonet_post.from, sizeof(pkt.from));
- strlcpy(pkt.subject, fidonet_post.subject, sizeof(pkt.subject));
- pkt.body = fidonet_post.body;
- pkt.body_len = fidonet_post.body_size - 1;
- strlcpy(pkt.reply, fidonet_post.reply, sizeof(pkt.reply));
- memcpy(&pkt.msgid, &fidonet_post.msgid, sizeof(pkt.msgid));
- strlcpy(pkt.origin, fidonet_post.origin, sizeof(pkt.origin));
+ fidomsg.time = fidonet_post.time;
+ memcpy(&fidomsg.header.orig, &our_address,
+ sizeof(fidomsg.header.orig));
+ memcpy(&fidomsg.header.dest, &hub_address,
+ sizeof(fidomsg.header.dest));
+ strlcpy(fidomsg.area, board->fidonet_area, sizeof(fidomsg.area));
+ strlcpy(fidomsg.to, fidonet_post.to, sizeof(fidomsg.to));
+ strlcpy(fidomsg.from, fidonet_post.from, sizeof(fidomsg.from));
+ strlcpy(fidomsg.subject, fidonet_post.subject,
+ sizeof(fidomsg.subject));
+ fidomsg.body = fidonet_post.body;
+ fidomsg.body_len = fidonet_post.body_size - 1;
+ strlcpy(fidomsg.reply, fidonet_post.reply, sizeof(fidomsg.reply));
+ memcpy(&fidomsg.msgid, &fidonet_post.msgid, sizeof(fidomsg.msgid));
+ strlcpy(fidomsg.origin, fidonet_post.origin,
+ sizeof(fidomsg.origin));
- if (!binkp_store_outbound_fidopkt(&pkt)) {
+ if (!binkp_store_outbound_message(&fidomsg)) {
warn("failed storing outbound fidopkt");
post->id = 0;
goto done;
@@ -1482,7 +1488,8 @@ write_out:
}
short
-board_ingest_fidopkt(struct board *board, struct fidopkt *fidopkt)
+board_ingest_fidopkt_message(struct board *board,
+ struct fidopkt_message *fidomsg)
{
struct board_fidonet_msgid_cache {
unsigned long id;
@@ -1497,13 +1504,13 @@ board_ingest_fidopkt(struct board *board, struct fidop
short n, ret, bret;
bool dirty_cache = false;
- msgid = fidopkt->msgid;
+ msgid = fidomsg->msgid;
o = bile_find(board->bile, BOARD_FIDONET_MSGID_CACHE_RTYPE, 1);
if (o) {
/* allocate its size plus one entry that we may add */
asize = o->size + sizeof(struct board_fidonet_msgid_cache);
- msgid_cache = malloc(asize);
+ msgid_cache = xmalloc(asize);
if (msgid_cache == NULL) {
logger_printf("[board] board_ingest_fidopkt: malloc(%ld) failed",
asize);
@@ -1515,7 +1522,7 @@ board_ingest_fidopkt(struct board *board, struct fidop
} else {
npost_ids = bile_ids_by_type(board->bile, BOARD_FIDONET_POST_RTYPE,
&post_ids);
- msgid_cache = calloc(sizeof(struct board_fidonet_msgid_cache),
+ msgid_cache = xcalloc(sizeof(struct board_fidonet_msgid_cache),
npost_ids + 1);
if (msgid_cache == NULL) {
logger_printf("[board] board_ingest_fidopkt: calloc failed");
@@ -1539,7 +1546,7 @@ board_ingest_fidopkt(struct board *board, struct fidop
for (n = 0; n < npost_ids; n++) {
if (memcmp(&msgid_cache[n].msgid, &msgid, sizeof(msgid)) == 0) {
logger_printf("[board] already have fidonet msg %s in %s "
- "(%ld), skipping", fidopkt->msgid_orig, board->name,
+ "(%ld), skipping", fidomsg->msgid_orig, board->name,
msgid_cache[n].id);
ret = 0;
goto done;
@@ -1547,15 +1554,15 @@ board_ingest_fidopkt(struct board *board, struct fidop
}
memset(&post, 0, sizeof(post));
- post.time = fidopkt->time;
- post.body_size = fidopkt->body_len + 1;
- post.body = fidopkt->body;
- strlcpy(post.reply, fidopkt->reply, sizeof(post.reply));
- strlcpy(post.from, fidopkt->from, sizeof(post.from));
- strlcpy(post.subject, fidopkt->subject, sizeof(post.subject));
- strlcpy(post.to, fidopkt->to, sizeof(post.to));
- strlcpy(post.origin, fidopkt->origin, sizeof(post.origin));
- strlcpy(post.msgid_orig, fidopkt->msgid_orig, sizeof(post.msgid_orig));
+ post.time = fidomsg->time;
+ post.body_size = fidomsg->body_len + 1;
+ post.body = fidomsg->body;
+ strlcpy(post.reply, fidomsg->reply, sizeof(post.reply));
+ strlcpy(post.from, fidomsg->from, sizeof(post.from));
+ strlcpy(post.subject, fidomsg->subject, sizeof(post.subject));
+ strlcpy(post.to, fidomsg->to, sizeof(post.to));
+ strlcpy(post.origin, fidomsg->origin, sizeof(post.origin));
+ strlcpy(post.msgid_orig, fidomsg->msgid_orig, sizeof(post.msgid_orig));
post.msgid = msgid;
post.id = bile_next_id(board->bile, BOARD_FIDONET_POST_RTYPE);
@@ -1570,14 +1577,14 @@ board_ingest_fidopkt(struct board *board, struct fidop
&post, &pdata, &psize);
if (bret != 0 || psize == 0) {
logger_printf("[board] failed to marshall new post %s %s",
- fidopkt->area, fidopkt->msgid_orig);
+ fidomsg->area, fidomsg->msgid_orig);
ret = -1;
goto done;
}
if (bile_write(board->bile, BOARD_FIDONET_POST_RTYPE, post.id, pdata,
psize) != psize) {
logger_printf("[fidopkt] failed to save new post %s %s: %d",
- fidopkt->area, fidopkt->msgid_orig, bile_error(board->bile));
+ fidomsg->area, fidomsg->msgid_orig, bile_error(board->bile));
ret = -1;
xfree(&pdata);
goto done;
@@ -1597,7 +1604,7 @@ board_ingest_fidopkt(struct board *board, struct fidop
BILE_DELETE_FLAG_PURGE);
logger_printf("[board] imported %s %s as %ld",
- fidopkt->area, fidopkt->msgid_orig, post.id);
+ fidomsg->area, fidomsg->msgid_orig, post.id);
uthread_yield();
done:
@@ -1606,7 +1613,7 @@ done:
if (bile_write(board->bile, BOARD_FIDONET_MSGID_CACHE_RTYPE, 1,
msgid_cache, cache_size) != cache_size) {
logger_printf("[board] failed to save msgid cache for %s: %d",
- fidopkt->area, bile_error(board->bile));
+ fidomsg->area, bile_error(board->bile));
ret = -1;
}
}
--- board.h Thu Mar 9 15:27:08 2023
+++ board.h Mon Mar 13 10:24:21 2023
@@ -90,6 +90,7 @@ void board_delete_fidonet_post(struct session *s, stru
struct board_fidonet_post *post);
size_t board_index_sorted_post_ids(struct board *board,
unsigned long **sorted_ids);
-short board_ingest_fidopkt(struct board *board, struct fidopkt *fidopkt);
+short board_ingest_fidopkt_message(struct board *board,
+ struct fidopkt_message *fidomsg);
#endif