Skip to content

Commit

Permalink
Fix share.mod user file feature parser/checker
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelortmann committed Jun 22, 2024
1 parent 4c42116 commit 3e6d5f6
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/mod/share.mod/uf_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,29 +234,28 @@ static void uff_deltable(uff_table_t *ut)
*/
static void uf_features_parse(int idx, char *par)
{
char *buf, *s, *p;
char *buf, *feature, *brkt;
uff_list_t *ul;

uff_sbuf[0] = 0; /* Reset static buffer */
p = s = buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
strcpy(buf, par);

/* Clear all currently set features. */
dcc[idx].u.bot->uff_flags = 0;

/* Parse string */
while ((s = strchr(s, ' ')) != NULL) {
*s = '\0';

for (feature = strtok_r(buf, " $:", &brkt);
feature;
feature = strtok_r(NULL, " $:", &brkt)) {
/* Is the feature available and active? */
ul = uff_findentry_byname(p);
ul = uff_findentry_byname(feature);
if (ul && (ul->entry->ask_func == NULL || ul->entry->ask_func(idx))) {
dcc[idx].u.bot->uff_flags |= ul->entry->flag; /* Set flag */
if (uff_sbuf[0])
strncat(uff_sbuf, " ", sizeof uff_sbuf - strlen(uff_sbuf) - 1);
strncat(uff_sbuf, ul->entry->feature, sizeof uff_sbuf - strlen(uff_sbuf) - 1); /* Add feature to list */
}
p = ++s;
}
nfree(buf);

Expand All @@ -283,22 +282,22 @@ static char *uf_features_dump(int idx)

static int uf_features_check(int idx, char *par)
{
char *buf, *s, *p;
char *buf, *feature, *brkt;
uff_list_t *ul;

uff_sbuf[0] = 0; /* Reset static buffer */
p = s = buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
buf = nmalloc(strlen(par) + 1); /* Allocate temp buffer */
strcpy(buf, par);

/* Clear all currently set features. */
dcc[idx].u.bot->uff_flags = 0;

/* Parse string */
while ((s = strchr(s, ' ')) != NULL) {
*s = '\0';

for (feature = strtok_r(buf, " $:", &brkt);
feature;
feature = strtok_r(NULL, " $:", &brkt)) {
/* Is the feature available and active? */
ul = uff_findentry_byname(p);
ul = uff_findentry_byname(feature);
if (ul && (ul->entry->ask_func == NULL || ul->entry->ask_func(idx)))
dcc[idx].u.bot->uff_flags |= ul->entry->flag; /* Set flag */
else {
Expand All @@ -316,7 +315,6 @@ static int uf_features_check(int idx, char *par)
nfree(buf);
return 0;
}
p = ++s;
}
nfree(buf);
return 1;
Expand Down

0 comments on commit 3e6d5f6

Please sign in to comment.