AmendHub

Download:

jcs

/

subtext

/

amendments

/

405

binkp: Adapt to fidopkt parsing multiple messages per packet


jcs made amendment 405 about 1 year ago
--- binkp.c Thu Mar 9 21:53:21 2023 +++ binkp.c Mon Mar 13 22:33:09 2023 @@ -648,6 +648,9 @@ binkp_deliver_inbox(void) unsigned long started = Time, elapsed; size_t data_size; char *data; + + binkp_fidopkt_skipped = 0; + binkp_fidopkt_imported = 0; fpb->ioVRefNum = 0; fpb->ioNamePtr = (StringPtr)&binkp_inbox_dir; @@ -685,10 +688,11 @@ binkp_deliver_inbox(void) binkp_fidopkt_skipped = 0; binkp_fidopkt_imported = 0; - if (zip_is_zip_file(path)) - zip_read_file(path, binkp_zip_decider, - binkp_fidopkt_processor); - else if (strstr((char *)file_name_c, ".pkt")) { + if (zip_is_zip_file(path)) { + if (!zip_read_file(path, binkp_zip_decider, + binkp_fidopkt_processor)) + binkp_temp_fail = true; + } else if (strstr((char *)file_name_c, ".pkt")) { data_size = binkp_buffer_file(path, &data); if (data_size == 0) binkp_temp_fail = true; @@ -767,54 +771,69 @@ binkp_zip_decider(char *filename, size_t size) void binkp_fidopkt_processor(char *filename, unsigned char *data, size_t size) { - struct fidopkt *fidopkt; + struct fidopkt_message *msg = NULL; + struct fidopkt_header *header = NULL; struct board *board = NULL; short n, ret; uthread_yield(); - fidopkt = fidopkt_parse(filename, (char *)data, size); - if (fidopkt == NULL) - return; - - if (fidopkt->time) - /* convert to local time zone */ - fidopkt->time += - (((long)db->config.timezone_utcoff * 60 * 60) / 100); - else - fidopkt->time = Time; - - if (fidopkt->area[0]) { - for (n = 0; n < db->nboards; n++) { - if (db->boards[n].fidonet_area[0] && - strcasecmp(fidopkt->area, db->boards[n].fidonet_area) == 0) { - board = &db->boards[n]; - break; - } - } + while (size != 0 && (msg = fidopkt_parse_message(filename, header, + (char **)&data, &size)) != NULL) { + if (msg->time) + /* convert to local time zone */ + msg->time += + (((long)db->config.timezone_utcoff * 60 * 60) / 100); + else + msg->time = Time; - if (!board) { + if (msg->area[0]) { + for (n = 0; n < db->nboards; n++) { + if (db->boards[n].fidonet_area[0] && + strcasecmp(msg->area, db->boards[n].fidonet_area) == 0) { + board = &db->boards[n]; + break; + } + } + + if (!board) { #ifdef BINKP_DEBUG - logger_printf("[fidopkt] no local board for %s, skipping", - fidopkt->area); + logger_printf("[fidopkt] no local board for %s, skipping", + msg->area); #endif - binkp_fidopkt_skipped++; - fidopkt_free(&fidopkt); - return; + binkp_fidopkt_skipped++; + goto next_message; + } + + ret = board_ingest_fidopkt_message(board, msg); + } else + ret = mail_ingest_fidopkt_message(msg); + + if (ret == -1) { + binkp_temp_fail = true; + fidopkt_message_free(&msg); + break; } + if (ret == 0) + binkp_fidopkt_skipped++; + else + binkp_fidopkt_imported++; - ret = board_ingest_fidopkt(board, fidopkt); - } else - ret = mail_ingest_fidopkt(fidopkt); +next_message: + if (header == NULL && size > 0) { + header = xmalloc(sizeof(msg->header)); + if (header == NULL) { + fidopkt_message_free(&msg); + binkp_temp_fail = true; + break; + } + memcpy(header, &msg->header, sizeof(struct fidopkt_header)); + } + fidopkt_message_free(&msg); + } - if (ret == -1) - binkp_temp_fail = true; - else if (ret == 0) - binkp_fidopkt_skipped++; - else - binkp_fidopkt_imported++; - - fidopkt_free(&fidopkt); + if (header) + xfree(&header); } size_t @@ -983,7 +1002,7 @@ done: } bool -binkp_store_outbound_fidopkt(struct fidopkt *pkt) +binkp_store_outbound_message(struct fidopkt_message *msg) { Str255 path; char filename[32]; @@ -992,13 +1011,13 @@ binkp_store_outbound_fidopkt(struct fidopkt *pkt) size_t size, asize; bool ret = false; - size = fidopkt_encode(pkt, &buf, db->config.fidonet_pkt_password, - db->config.timezone_utcoff); + size = fidopkt_encode_message(msg, &buf, + db->config.fidonet_pkt_password, db->config.timezone_utcoff); if (size == 0) return false; snprintf(filename, sizeof(filename), "%c%07lx.pkt", - pkt->area[0] ? 'b' : 'm', pkt->msgid.id & 0x0fffffff); + msg->area[0] ? 'b' : 'm', msg->msgid.id & 0x0fffffff); PtoCstr(binkp_outbox_dir); snprintf((char *)path, sizeof(path), "%s:%s", binkp_outbox_dir, --- binkp.h Wed Mar 8 16:22:05 2023 +++ binkp.h Mon Mar 13 10:18:07 2023 @@ -71,6 +71,6 @@ struct binkp_connection { extern struct uthread *binkp_thread; void binkp_process(struct uthread *uthread, void *arg); void binkp_atexit(void); -bool binkp_store_outbound_fidopkt(struct fidopkt *pkt); +bool binkp_store_outbound_message(struct fidopkt_message *msg); #endif