Skip to content
Snippets Groups Projects
Commit 5fcc9090 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Detect and reject duplicate internal code prefixes

Don't let (or at least try to prevent) a sysop create a duplicate message group or file library internal code prefix (which could lead to duplicate internal codes for subs and dirs, pretty easily and accidentally).
parent 1329ab93
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2663 passed
......@@ -68,8 +68,10 @@
"For a complete list of the supported command-line specifiers, see:\n" \
"`http://wiki.synchro.net/config:cmdline`\n"
#define strInvalidCode "Invalid Internal Code Rejected!"
#define strDuplicateCode "Duplicate Internal Code Rejected!"
#define strInvalidCode "Invalid Internal Code Rejected!"
#define strInvalidCodePrefix "Invalid Internal Code Prefix Rejected!"
#define strDuplicateCode "Duplicate Internal Code Rejected!"
#define strDuplicateCodePrefix "Duplicate Internal Code Prefix Rejected!"
/*************/
/* Constants */
......
......@@ -40,6 +40,16 @@ char *utos(char *str)
return(out);
}
static bool code_prefix_exists(const char* prefix)
{
size_t i;
for(i=0; i < cfg.total_grps; i++)
if(cfg.grp[i]->code_prefix[0] && stricmp(cfg.grp[i]->code_prefix, prefix) == 0)
return true;
return false;
}
static bool new_grp(unsigned new_grpnum)
{
grp_t* new_group = malloc(sizeof(grp_t));
......@@ -546,9 +556,13 @@ void msgs_cfg()
uifc.helpbuf=grp_code_prefix_help;
if(uifc.input(WIN_MID|WIN_SAV,0,0,"Internal Code Prefix", code_prefix, LEN_CODE, K_EDIT|K_UPPER) < 0)
continue;
if (code_prefix_exists(code_prefix)) {
uifc.msg(strDuplicateCodePrefix);
continue;
}
if (code_prefix[0] != 0 && !code_ok(code_prefix)) {
uifc.helpbuf=invalid_code;
uifc.msg("Invalid Code Prefix");
uifc.msg(strInvalidCodePrefix);
continue;
}
if (!new_grp(grpnum))
......@@ -682,11 +696,15 @@ void msgs_cfg()
if(uifc.input(WIN_MID|WIN_SAV,0,17,"Internal Code Prefix"
,code_prefix,LEN_CODE,K_EDIT|K_UPPER) < 0)
continue;
if(code_prefix[0] == 0 || code_ok(code_prefix)) {
if(stricmp(code_prefix, cfg.grp[grpnum]->code_prefix) == 0)
break;
if(code_prefix_exists(code_prefix))
uifc.msg(strDuplicateCodePrefix);
else if(code_prefix[0] == 0 || code_ok(code_prefix)) {
SAFECOPY(cfg.grp[grpnum]->code_prefix, code_prefix);
} else {
uifc.helpbuf = invalid_code;
uifc.msg("Invalid Code Prefix");
uifc.msg(strInvalidCodePrefix);
}
break;
}
......
......@@ -74,6 +74,16 @@ static bool new_dir(unsigned new_dirnum, unsigned libnum)
return true;
}
static bool code_prefix_exists(const char* prefix)
{
size_t i;
for(i=0; i < cfg.total_libs; i++)
if(cfg.lib[i]->code_prefix[0] && stricmp(cfg.lib[i]->code_prefix, prefix) == 0)
return true;
return false;
}
static bool new_lib(unsigned new_libnum)
{
lib_t* new_library = malloc(sizeof(lib_t));
......@@ -284,9 +294,13 @@ void xfer_cfg()
uifc.helpbuf=lib_code_prefix_help;
if(uifc.input(WIN_MID|WIN_SAV,0,0,"Internal Code Prefix", code_prefix, LEN_CODE, K_EDIT|K_UPPER) < 0)
continue;
if (code_prefix_exists(code_prefix)) {
uifc.msg(strDuplicateCodePrefix);
continue;
}
if (code_prefix[0] != 0 && !code_ok(code_prefix)) {
uifc.helpbuf=invalid_code;
uifc.msg("Invalid Code Prefix");
uifc.msg(strInvalidCodePrefix);
continue;
}
......@@ -429,11 +443,15 @@ void xfer_cfg()
if(uifc.input(WIN_MID|WIN_SAV,0,17,"Internal Code Prefix"
,code_prefix,LEN_CODE,K_EDIT|K_UPPER) < 0)
continue;
if(code_prefix[0] == 0 || code_ok(code_prefix)) {
if(stricmp(code_prefix, cfg.lib[i]->code_prefix) == 0)
break;
if(code_prefix_exists(code_prefix))
uifc.msg(strDuplicateCodePrefix);
else if(code_prefix[0] == 0 || code_ok(code_prefix)) {
SAFECOPY(cfg.lib[i]->code_prefix, code_prefix);
} else {
uifc.helpbuf = invalid_code;
uifc.msg("Invalid Code Prefix");
uifc.msg(strInvalidCodePrefix);
}
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment