Skip to content
Snippets Groups Projects
Commit 12a11b6b authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
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
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #1019 failed
......@@ -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;
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment