Commit 12a11b6b authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

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
parent 7a14dbca
Pipeline #1019 failed with stage
in 18 minutes and 1 second
......@@ -1538,6 +1538,38 @@ int putnmsg(scfg_t* cfg, int num, char *strin)
/* Return node's client's socket descriptor or negative on error */
int getnodeclient(scfg_t* cfg, uint number, client_t* client)
char path[MAX_PATH + 1];
char value[INI_MAX_VALUE_LEN];
char* p;
FILE* fp;
|| client == NULL || number < 1 || number > cfg->sys_nodes)
return -1;
if(client->size == sizeof(client))
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);
return sock;
static int getdirnum(scfg_t* cfg, char* code)
size_t i;
......@@ -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);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment