Commits (1)
  • Rob Swindell's avatar
    Add getnodeclient() to read a node's client.ini file · 12a11b6b
    Rob Swindell authored
    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
......@@ -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);