From 12a11b6bc4905c5be3946004744dc0db28ce1667 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Sun, 13 Dec 2020 03:29:47 -0800 Subject: [PATCH] Add getnodeclient() to read a node's client.ini file One weird thing is that client_t: - has just a const char* for the protocol, so that's strdup/free'd here (consider making this a char array to simplify this API) - does not have a socket descriptor, so that value is returned - does not have local addr/port info --- src/sbbs3/userdat.c | 32 ++++++++++++++++++++++++++++++++ src/sbbs3/userdat.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/sbbs3/userdat.c b/src/sbbs3/userdat.c index 1ffd3cd7ca..e5b8f0108e 100644 --- a/src/sbbs3/userdat.c +++ b/src/sbbs3/userdat.c @@ -1538,6 +1538,38 @@ int putnmsg(scfg_t* cfg, int num, char *strin) return(0); } +/* Return node's client's socket descriptor or negative on error */ +int getnodeclient(scfg_t* cfg, uint number, client_t* client) +{ + SOCKET sock = INVALID_SOCKET; + char path[MAX_PATH + 1]; + char value[INI_MAX_VALUE_LEN]; + char* p; + FILE* fp; + + if(!VALID_CFG(cfg) + || client == NULL || number < 1 || number > cfg->sys_nodes) + return -1; + + if(client->size == sizeof(client)) + free((char*)client->protocol); + memset(client, 0, sizeof(*client)); + client->size = sizeof(client); + SAFEPRINTF(path, "%sclient.ini", cfg->node_path[number - 1]); + fp = iniOpenFile(path, /* create: */FALSE); + if(fp == NULL) + return -2; + sock = iniReadShortInt(fp, ROOT_SECTION, "sock", 0); + client->port = iniReadShortInt(fp, ROOT_SECTION, "port", 0); + client->time = iniReadInteger(fp, ROOT_SECTION, "time", 0); + SAFECOPY(client->addr, iniReadString(fp, ROOT_SECTION, "addr", "<none>", value)); + SAFECOPY(client->host, iniReadString(fp, ROOT_SECTION, "host", "<none>", value)); + if((p = iniReadString(fp, ROOT_SECTION, "prot", NULL, value)) != NULL) + client->protocol = strdup(p); + fclose(fp); + return sock; +} + static int getdirnum(scfg_t* cfg, char* code) { size_t i; diff --git a/src/sbbs3/userdat.h b/src/sbbs3/userdat.h index 36c4624402..50f0b5cd6f 100644 --- a/src/sbbs3/userdat.h +++ b/src/sbbs3/userdat.h @@ -76,6 +76,7 @@ DLLEXPORT char* getsmsg(scfg_t*, int usernumber); 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*); DLLEXPORT uint userdatdupe(scfg_t*, uint usernumber, uint offset, uint datlen, char *dat ,BOOL del, BOOL next, void (*progress)(void*, int, int), void* cbdata); -- GitLab