Commit 65e11f0b authored by Claes's avatar Claes Committed by Esteban Blanc

pwrp_alias, alias tag modification

parent 5107b0a0
...@@ -49,7 +49,8 @@ ...@@ -49,7 +49,8 @@
#include "rt_ini_msg.h" #include "rt_ini_msg.h"
#include "rt_ini_alias.h" #include "rt_ini_alias.h"
static FILE* ini_datafile; static FILE* ini_datafile = 0;
static ini_sAlias *ini_aliaslist = 0;
static int ini_datafile_init(char* filename); static int ini_datafile_init(char* filename);
...@@ -57,6 +58,8 @@ static int ini_datafile_close(); ...@@ -57,6 +58,8 @@ static int ini_datafile_close();
static int ini_datafile_get_next(char* parameter, char** data, int* elements); static int ini_datafile_get_next(char* parameter, char** data, int* elements);
static int ini_datafile_get_next_alias(char* node, char *alias, char* addr);
static int ini_parse(char* instring, char* parse_char, char* inc_parse_char, static int ini_parse(char* instring, char* parse_char, char* inc_parse_char,
char* outstr, int max_rows, int max_cols); char* outstr, int max_rows, int max_cols);
...@@ -68,28 +71,52 @@ static int ini_set_nodeattribute(char* attribute_str, char* value_str); ...@@ -68,28 +71,52 @@ static int ini_set_nodeattribute(char* attribute_str, char* value_str);
static int ini_set_plcscan(char* value_str); static int ini_set_plcscan(char* value_str);
pwr_tStatus ini_GetAlias(char* filename, char* nodename, char* aliasname) pwr_tStatus ini_LoadAlias(char* filename)
{ {
pwr_tStatus sts; pwr_tStatus sts;
char* aliasname_ptr; ini_sAlias a, *ap;
int elements;
sts = ini_datafile_init(filename); sts = ini_datafile_init(filename);
if (EVEN(sts)) if (EVEN(sts))
return sts; return sts;
sts = ini_datafile_get_next(nodename, &aliasname_ptr, &elements); while (ODD(ini_datafile_get_next_alias(a.nodename, a.alias, a.addr))) {
if (EVEN(sts)) ap = (ini_sAlias *)calloc(1, sizeof(*ap));
return sts; memcpy(ap, &a, sizeof(*ap));
strcpy(aliasname, (char*)aliasname_ptr);
free(aliasname_ptr);
ap->next = ini_aliaslist;
ini_aliaslist = ap;
}
ini_datafile_close(); ini_datafile_close();
return INI__SUCCESS; return INI__SUCCESS;
} }
void ini_FreeAlias(void)
{
ini_sAlias *ap, *nextap;
for (ap = ini_aliaslist; ap; ap = nextap) {
nextap = ap->next;
free(ap);
}
ini_aliaslist = 0;
}
pwr_tStatus ini_GetAlias(char* nodename, char* alias, char *addr)
{
ini_sAlias *ap;
for (ap = ini_aliaslist; ap; ap = ap->next) {
if (strcmp(nodename, ap->nodename) == 0) {
strcpy(alias, ap->alias);
if (addr)
strcpy(addr, ap->addr);
return INI__SUCCESS;
}
}
return 0; /* INI__PARNOTFOUND; */
}
pwr_tStatus ini_SetAttributeAfterPlc(char* filename, char* nodename, int output) pwr_tStatus ini_SetAttributeAfterPlc(char* filename, char* nodename, int output)
{ {
pwr_tStatus sts; pwr_tStatus sts;
...@@ -336,6 +363,59 @@ static int ini_datafile_get_next(char* parameter, char** data, int* elements) ...@@ -336,6 +363,59 @@ static int ini_datafile_get_next(char* parameter, char** data, int* elements)
return INI__SUCCESS; return INI__SUCCESS;
} }
/****************************************************************************
* Name: ini_datafile_get_next_alias()
*
* Type int
*
* Type Parameter IOGF Description
*
* Description:
*
**************************************************************************/
static int ini_datafile_get_next_alias(char* node, char *alias, char* addr)
{
char line[256];
char data_array[4][80];
int found, nr = 0, sts;
if (ini_datafile == 0)
return 0;
found = 0;
while (1) {
/* Read one line */
sts = ini_read_line(line, sizeof(line), ini_datafile);
if (EVEN(sts))
break;
if (line[0] == '!')
continue;
/* Parse the line */
nr = ini_parse(line, "=, ", "", (char*)data_array,
sizeof(data_array) / sizeof(data_array[0]), sizeof(data_array[0]));
if (nr == 0)
continue;
if (str_NoCaseStrcmp(data_array[0], "alias") == 0 && nr > 2) {
found = 1;
break;
}
}
if (!found)
return 0; /* INI__PARNOTFOUND; */
strcpy(node, data_array[1]);
strcpy(alias, data_array[2]);
if (nr > 3)
strcpy(addr, data_array[3]);
else
strcpy(addr, "");
return INI__SUCCESS;
}
/************************************************************************* /*************************************************************************
* *
* Name: ini_parse() * Name: ini_parse()
......
...@@ -37,8 +37,17 @@ ...@@ -37,8 +37,17 @@
#ifndef rt_ini_alias_h #ifndef rt_ini_alias_h
#define rt_ini_alias_h #define rt_ini_alias_h
int ini_GetAlias(char* filename, char* nodename, char* aliasname); typedef struct s_alias {
int ini_SetAttributeAfterPlc(char* filename, char* nodename, int output); char nodename[80];
int ini_SetAttribute(char* filename, char* nodename, int output); char alias[80];
char addr[80];
struct s_alias *next;
} ini_sAlias;
pwr_tStatus ini_LoadAlias(char* filename);
void ini_FreeAlias(void);
pwr_tStatus ini_GetAlias(char* nodename, char* alias, char *addr);
pwr_tStatus ini_SetAttributeAfterPlc(char* filename, char* nodename, int output);
pwr_tStatus ini_SetAttribute(char* filename, char* nodename, int output);
#endif #endif
...@@ -686,31 +686,27 @@ ini_sContext* ini_CheckContext(pwr_tStatus* status, ini_sContext* cp) ...@@ -686,31 +686,27 @@ ini_sContext* ini_CheckContext(pwr_tStatus* status, ini_sContext* cp)
{ {
pwr_dStatus(sts, status, INI__SUCCESS); pwr_dStatus(sts, status, INI__SUCCESS);
if (!cp->flags.b.aliasfile)
sprintf(cp->aliasfile.name, dbs_cNameAlias, cp->dir);
// str_ToLower(cp->aliasfile.name, cp->aliasfile.name);
ini_LoadDirectory(sts, cp); ini_LoadDirectory(sts, cp);
cp->nodefile.errcount = NULL; cp->nodefile.errcount = NULL;
cp->nodefile.logOpenFail = errh_LogInfo; cp->nodefile.logOpenFail = errh_LogInfo;
if (!cp->flags.b.applfile) if (!cp->flags.b.applfile)
sprintf(cp->applfile.name, dbs_cNameAppl, cp->dir, cdh_Low(cp->nodename), sprintf(cp->applfile.name, dbs_cNameAppl, cp->dir, cdh_Low(cp->origname),
cp->busid); cp->busid);
// str_ToLower(cp->applfile.name, cp->applfile.name); // str_ToLower(cp->applfile.name, cp->applfile.name);
cp->applfile.errcount = NULL; cp->applfile.errcount = NULL;
cp->applfile.logOpenFail = errh_LogInfo; cp->applfile.logOpenFail = errh_LogInfo;
if (!cp->flags.b.bootfile) if (!cp->flags.b.bootfile)
sprintf(cp->bootfile.name, dbs_cNameBoot, cp->dir, cdh_Low(cp->nodename), sprintf(cp->bootfile.name, dbs_cNameBoot, cp->dir, cdh_Low(cp->origname),
cp->busid); cp->busid);
// str_ToLower(cp->bootfile.name, cp->bootfile.name); // str_ToLower(cp->bootfile.name, cp->bootfile.name);
cp->bootfile.errcount = &cp->fatals; cp->bootfile.errcount = &cp->fatals;
cp->bootfile.logOpenFail = errh_LogFatal; cp->bootfile.logOpenFail = errh_LogFatal;
if (!cp->flags.b.nodefile) if (!cp->flags.b.nodefile)
sprintf(cp->nodefile.name, dbs_cNameNode, cp->dir, cdh_Low(cp->nodename), sprintf(cp->nodefile.name, dbs_cNameNode, cp->dir, cdh_Low(cp->origname),
cp->busid); cp->busid);
// str_ToLower(cp->nodefile.name, cp->nodefile.name); // str_ToLower(cp->nodefile.name, cp->nodefile.name);
cp->nodefile.errcount = &cp->fatals; cp->nodefile.errcount = &cp->fatals;
...@@ -755,9 +751,7 @@ ini_sContext* ini_CreateContext(pwr_tStatus* status) ...@@ -755,9 +751,7 @@ ini_sContext* ini_CreateContext(pwr_tStatus* status)
return cp; return cp;
} }
FILE* ini_OpenFile(pwr_tStatus* status, ini_sContext* cp, ini_sFile* fp FILE* ini_OpenFile(pwr_tStatus* status, ini_sContext* cp, ini_sFile* fp)
)
{ {
FILE* f; FILE* f;
...@@ -787,6 +781,8 @@ char* ini_LoadDirectory(pwr_tStatus* status, ini_sContext* cp) ...@@ -787,6 +781,8 @@ char* ini_LoadDirectory(pwr_tStatus* status, ini_sContext* cp)
if (!cp->flags.b.hostname) if (!cp->flags.b.hostname)
syi_HostName(sts, cp->hostname, sizeof(cp->hostname)); syi_HostName(sts, cp->hostname, sizeof(cp->hostname));
strcpy(cp->origname, cp->nodename);
syi_NodeSpec(sts, cp->nodespec, sizeof(cp->nodespec)); syi_NodeSpec(sts, cp->nodespec, sizeof(cp->nodespec));
syi_HostSpec(sts, cp->hostspec, sizeof(cp->hostspec)); syi_HostSpec(sts, cp->hostspec, sizeof(cp->hostspec));
syi_BootDisk(sts, cp->bootdisk, sizeof(cp->bootdisk)); syi_BootDisk(sts, cp->bootdisk, sizeof(cp->bootdisk));
...@@ -813,8 +809,12 @@ char* ini_LoadDirectory(pwr_tStatus* status, ini_sContext* cp) ...@@ -813,8 +809,12 @@ char* ini_LoadDirectory(pwr_tStatus* status, ini_sContext* cp)
cp->busid = atoi(s); cp->busid = atoi(s);
} }
} }
if (!cp->flags.b.aliasfile)
sprintf(cp->aliasfile.name, dbs_cNameAlias, cp->dir);
*sts = ini_GetAlias(cp->aliasfile.name, cp->nodename, cp->alias); *sts = ini_LoadAlias(cp->aliasfile.name);
if (ODD(*sts))
*sts = ini_GetAlias(cp->nodename, cp->alias, 0);
if (ODD(*sts)) { if (ODD(*sts)) {
errh_LogInfo(&cp->log, "Alias defined to %s for this node %s", cp->alias, errh_LogInfo(&cp->log, "Alias defined to %s for this node %s", cp->alias,
cp->nodename); cp->nodename);
......
...@@ -124,6 +124,7 @@ typedef struct { ...@@ -124,6 +124,7 @@ typedef struct {
ini_mContext flags; ini_mContext flags;
char alias[80]; char alias[80];
char nodename[80]; char nodename[80];
char origname[80];
char nodespec[80]; char nodespec[80];
char hostname[80]; char hostname[80];
char hostspec[80]; char hostspec[80];
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "rt_errh.h" #include "rt_errh.h"
#include "rt_qini.h" #include "rt_qini.h"
#include "rt_net.h" #include "rt_net.h"
#include "rt_ini_alias.h"
static qdb_sNode* addNode(qini_sNode* nep) static qdb_sNode* addNode(qini_sNode* nep)
{ {
...@@ -145,6 +146,8 @@ int qini_ParseFile( ...@@ -145,6 +146,8 @@ int qini_ParseFile(
char s_is_secondary[20]; char s_is_secondary[20];
char secondary_name[80]; char secondary_name[80];
char s_secondary_naddr[80]; char s_secondary_naddr[80];
char alias[80];
char alias_naddr[80];
pwr_tNodeId nid; pwr_tNodeId nid;
struct in_addr naddr; struct in_addr naddr;
qini_sNode* nep; qini_sNode* nep;
...@@ -168,6 +171,12 @@ int qini_ParseFile( ...@@ -168,6 +171,12 @@ int qini_ParseFile(
continue; continue;
} }
sts = ini_GetAlias(name, alias, alias_naddr);
if (ODD(sts)) {
strcpy(name, alias);
strcpy(s_naddr, alias_naddr);
}
sts = cdh_StringToVolumeId(s_nid, (pwr_tVolumeId*)&nid); sts = cdh_StringToVolumeId(s_nid, (pwr_tVolumeId*)&nid);
if (EVEN(sts)) { if (EVEN(sts)) {
errh_Error( errh_Error(
......
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