From efdbc232d655709c4b3551dc6434b3a7766c479e Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on Windows)" <rob@synchro.net> Date: Wed, 9 Aug 2023 18:22:08 -0700 Subject: [PATCH] Add some helper functions for modifying node records in node.dab, atomically These should probably be moved (along with other node functions in this file) to nodedat.* some day. --- src/sbbs3/userdat.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ src/sbbs3/userdat.h | 7 +++ 2 files changed, 110 insertions(+) diff --git a/src/sbbs3/userdat.c b/src/sbbs3/userdat.c index fa1bd15ac5..cbc10bd805 100644 --- a/src/sbbs3/userdat.c +++ b/src/sbbs3/userdat.c @@ -1145,6 +1145,109 @@ int putnodedat(scfg_t* cfg, uint number, node_t* node, BOOL closeit, int file) return(0); } +/****************************************************************************/ +/****************************************************************************/ +BOOL set_node_status(scfg_t* cfg, int nodenum, enum node_status status) +{ + node_t node; + int file; + + if(getnodedat(cfg, nodenum, &node, /* lockit: */TRUE, &file) != 0) + return FALSE; + node.status = status; + return putnodedat(cfg, nodenum, &node, /* closeit: */TRUE, file) == 0; +} + +/****************************************************************************/ +/****************************************************************************/ +BOOL set_node_misc(scfg_t* cfg, int nodenum, uint misc) +{ + node_t node; + int file; + + if(getnodedat(cfg, nodenum, &node, /* lockit: */TRUE, &file) != 0) + return FALSE; + node.misc = misc; + return putnodedat(cfg, nodenum, &node, /* closeit: */TRUE, file) == 0; +} + +/****************************************************************************/ +/****************************************************************************/ +BOOL set_node_lock(scfg_t* cfg, int nodenum, BOOL set) +{ + node_t node; + int file; + + if(getnodedat(cfg, nodenum, &node, /* lockit: */TRUE, &file) != 0) + return FALSE; + if(set) + node.misc |= NODE_LOCK; + else + node.misc &= ~NODE_LOCK; + return putnodedat(cfg, nodenum, &node, /* closeit: */TRUE, file) == 0; +} + +/****************************************************************************/ +/****************************************************************************/ +BOOL set_node_interrupt(scfg_t* cfg, int nodenum, BOOL set) +{ + node_t node; + int file; + + if(getnodedat(cfg, nodenum, &node, /* lockit: */TRUE, &file) != 0) + return FALSE; + if(set) + node.misc |= NODE_INTR; + else + node.misc &= ~NODE_INTR; + return putnodedat(cfg, nodenum, &node, /* closeit: */TRUE, file) == 0; +} + +/****************************************************************************/ +/****************************************************************************/ +BOOL set_node_down(scfg_t* cfg, int nodenum, BOOL set) +{ + node_t node; + int file; + + if(getnodedat(cfg, nodenum, &node, /* lockit: */TRUE, &file) != 0) + return FALSE; + if(set) + node.misc |= NODE_DOWN; + else + node.misc &= ~NODE_DOWN; + return putnodedat(cfg, nodenum, &node, /* closeit: */TRUE, file) == 0; +} + +/****************************************************************************/ +/****************************************************************************/ +BOOL set_node_rerun(scfg_t* cfg, int nodenum, BOOL set) +{ + node_t node; + int file; + + if(getnodedat(cfg, nodenum, &node, /* lockit: */TRUE, &file) != 0) + return FALSE; + if(set) + node.misc |= NODE_RRUN; + else + node.misc &= ~NODE_RRUN; + return putnodedat(cfg, nodenum, &node, /* closeit: */TRUE, file) == 0; +} + +/****************************************************************************/ +/****************************************************************************/ +BOOL set_node_errors(scfg_t* cfg, int nodenum, uint errors) +{ + node_t node; + int file; + + if(getnodedat(cfg, nodenum, &node, /* lockit: */TRUE, &file) != 0) + return FALSE; + node.errors = errors; + return putnodedat(cfg, nodenum, &node, /* closeit: */TRUE, file) == 0; +} + /****************************************************************************/ /* Packs the password 'pass' into 5bit ASCII inside node_t. 32bits in */ /* node.extaux, and the other 8bits in the upper byte of node.aux */ diff --git a/src/sbbs3/userdat.h b/src/sbbs3/userdat.h index 1f37a2d240..5ecc043c46 100644 --- a/src/sbbs3/userdat.h +++ b/src/sbbs3/userdat.h @@ -86,6 +86,13 @@ DLLEXPORT int putsmsg(scfg_t*, int usernumber, char *strin); DLLEXPORT char* getnmsg(scfg_t*, int node_num); DLLEXPORT int putnmsg(scfg_t*, int num, char *strin); DLLEXPORT int getnodeclient(scfg_t*, uint number, client_t*, time_t*); +DLLEXPORT BOOL set_node_lock(scfg_t*, int node_num, BOOL); +DLLEXPORT BOOL set_node_interrupt(scfg_t*, int node_num, BOOL); +DLLEXPORT BOOL set_node_down(scfg_t*, int node_num, BOOL); +DLLEXPORT BOOL set_node_rerun(scfg_t*, int node_num, BOOL); +DLLEXPORT BOOL set_node_status(scfg_t*, int node_num, enum node_status); +DLLEXPORT BOOL set_node_misc(scfg_t*, int node_num, uint); +DLLEXPORT BOOL set_node_errors(scfg_t*, int node_num, uint); DLLEXPORT uint finduserstr(scfg_t*, uint usernumber, enum user_field, const char *str ,BOOL del, BOOL next, void (*progress)(void*, int, int), void* cbdata); -- GitLab