Clean up menus.c.

In the course of removing calls to realloc(), change
the menu parsing and use logic to use ptr_vector's
directly.

This also fixes some detects menu issues in parsing
and avoids e.g. writing to a bad pointer (or should;
of course it needs testing...).

Finally, free menu state on return from the menu_system
function. There was a comment here to do that, but it
didn't appear to be done.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
Dan Cross 2018-10-15 14:37:49 +00:00 committed by Andrew Pamment
parent 69c7286ea7
commit 9f4269c74e

View File

@ -64,22 +64,116 @@ extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
extern int mynode; extern int mynode;
struct menu_command {
int command;
char *data;
};
struct menu_item { struct menu_item {
char hotkey; char hotkey;
int *command; struct ptr_vector commands;
char **data;
int command_count;
int seclevel; int seclevel;
}; };
struct key_value_map {
const char *key;
int value;
};
static const struct key_value_map commands[] = {
{ "SUBMENU", MENU_SUBMENU },
{ "LOGOFF", MENU_LOGOFF },
{ "PREVMENU", MENU_PREVMENU },
{ "AUTOMESSAGE", MENU_AUTOMESSAGE },
{ "TEXTFILES", MENU_TEXTFILES },
{ "CHATSYSTEM", MENU_CHATSYSTEM },
{ "BBSLIST", MENU_BBSLIST },
{ "LISTUSERS", MENU_LISTUSERS },
{ "BULLETINS", MENU_BULLETINS },
{ "LAST10CALLERS", MENU_LAST10 },
{ "SETTINGS", MENU_SETTINGS },
{ "RUNDOOR", MENU_DOOR },
{ "MAILSCAN", MENU_MAILSCAN },
{ "READMAIL", MENU_READMAIL },
{ "POSTMESSAGE", MENU_POSTMESSAGE },
{ "CHOOSEMAILCONF", MENU_CHOOSEMAILCONF },
{ "CHOOSEMAILAREA", MENU_CHOOSEMAILAREA },
{ "SENDEMAIL", MENU_SENDEMAIL },
{ "LISTEMAIL", MENU_LISTEMAIL },
{ "NEXTMAILCONF", MENU_NEXTMAILCONF },
{ "PREVMAILCONF", MENU_PREVMAILCONF },
{ "NEXTMAILAREA", MENU_NEXTMAILAREA },
{ "PREVMAILAREA", MENU_PREVMAILAREA },
{ "BLUEWAVEDOWNLOAD", MENU_BLUEWAVEDOWN },
{ "BLUEWAVEUPLOAD", MENU_BLUEWAVEUP },
{ "CHOOSEFILEDIR", MENU_CHOOSEFILEDIR },
{ "CHOOSEFILESUB", MENU_CHOOSEFILESUB },
{ "LISTFILES", MENU_LISTFILES },
{ "UPLOAD", MENU_UPLOAD },
{ "DOWNLOAD", MENU_DOWNLOAD },
{ "CLEARTAGGED", MENU_CLEARTAGGEDFILES },
{ "NEXTFILEDIR", MENU_NEXTFILEDIR },
{ "PREVFILEDIR", MENU_PREVFILEDIR },
{ "NEXTFILESUB", MENU_NEXTFILESUB },
{ "PREVFILESUB", MENU_PREVFILESUB },
{ "LISTMESSAGES", MENU_LISTMESSAGES },
{ "DOSCRIPT", MENU_DOSCRIPT },
{ "SENDNODEMSG", MENU_SENDNODEMSG },
{ "SUBUNSUBCONF", MENU_SUBUNSUBCONF },
{ "RESETMSGPTRS", MENU_RESETPOINTERS },
{ "RESETALLMSGPTRS", MENU_RESETALLPOINTERS },
{ "FILESCAN", MENU_FILESCAN },
{ "FULLMAILSCAN", MENU_FULLMAILSCAN },
{ "FILESEARCH", MENU_FILESEARCH },
{ "DISPLAYTXTFILE", MENU_DISPTXTFILE },
{ "DISPLAYTXTPAUSE", MENU_DISPTXTFILEPAUSE },
{ "GENWWWURLS", MENU_GENWWWURLS },
{ "NLBROWSER", MENU_NLBROWSER },
{ "SENDFEEDBACK", MENU_SENDFEEDBACK },
{ "BLOGDISPLAY", MENU_BLOGDISPLAY },
{ "BLOGWRITE", MENU_BLOGWRITE }
};
#define ARRAY_SIZE(A) (sizeof(A)/sizeof((A)[0]))
int cmd2cmd(const char *cmd) {
for (size_t i = 0; i < ARRAY_SIZE(commands); ++i)
if (strncmp(cmd, commands[i].key, strlen(commands[i].key)) == 0)
return commands[i].value;
return -1;
}
static int badmenu(const char *menufile) {
s_printf("Bad menu file! %s\r\n", menufile);
return 0;
}
static void free_menu(struct ptr_vector *menu) {
assert(menu != NULL);
for (size_t i = 0; i < ptr_vector_len(menu); ++i) {
struct menu_item *item = ptr_vector_get(menu, i);
assert(item != NULL);
for (size_t j = 0; j < ptr_vector_len(&item->commands); ++j) {
struct menu_command *cmd = ptr_vector_get(&item->commands, j);
assert(cmd != NULL);
free(cmd->data);
}
ptr_vector_apply(&item->commands, free);
destroy_ptr_vector(&item->commands);
}
ptr_vector_apply(menu, free);
destroy_ptr_vector(menu);
}
int menu_system(char *menufile) { int menu_system(char *menufile) {
FILE *fptr; FILE *fptr;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
int menu_items = 0; struct ptr_vector menu = EMPTY_PTR_VECTOR;
struct menu_item **menu; struct menu_item *this_menu = NULL;
char *lua_script; struct menu_command *this_command = NULL;
int do_lua_menu; char *lua_script = NULL;
char *ansi_file; int do_lua_menu = 0;
char *ansi_file = NULL;
int i; int i;
int j; int j;
int k; int k;
@ -103,169 +197,47 @@ int menu_system(char *menufile) {
snprintf(buffer, PATH_MAX, "%s/%s.mnu", conf.menu_path, menufile); snprintf(buffer, PATH_MAX, "%s/%s.mnu", conf.menu_path, menufile);
} }
fptr = fopen(buffer, "r"); fptr = fopen(buffer, "r");
if (!fptr)
return badmenu(menufile);
if (!fptr) { init_ptr_vector(&menu);
s_printf("Error opening menu file! %s\r\n", menufile); while (fgets(buffer, sizeof buffer, fptr) != NULL && !feof(fptr)) {
return 0;
}
lua_script = NULL;
ansi_file = NULL;
fgets(buffer, 256, fptr);
while (!feof(fptr)) {
chomp(buffer); chomp(buffer);
if (strncasecmp(buffer, "HOTKEY", 6) == 0) { if (strncasecmp(buffer, "HOTKEY", 6) == 0) {
menu_items++; this_menu = malloz(sizeof(struct menu_item));
if (menu_items == 1) { this_menu->hotkey = buffer[7];
menu = (struct menu_item **)malloz(sizeof(struct menu_item *)); init_ptr_vector(&this_menu->commands);
} else { this_menu->seclevel = 0;
menu = (struct menu_item **)realloc(menu, sizeof(struct menu_item *) * (menu_items)); ptr_vector_append(&menu, this_menu);
} } else if (strncasecmp(buffer, "COMMAND", 7) == 0) {
menu[menu_items - 1] = (struct menu_item *)malloz(sizeof(struct menu_item)); if (this_menu == NULL)
menu[menu_items - 1]->hotkey = buffer[7]; return badmenu(menufile);
menu[menu_items - 1]->command = NULL; int cmd = cmd2cmd(buffer + 8);
menu[menu_items - 1]->data = NULL; if (cmd < 0)
menu[menu_items - 1]->command_count = 0; continue;
menu[menu_items - 1]->seclevel = 0; this_command = malloz(sizeof(struct menu_command));
} else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) { this_command->command = cmd;
if (menu[menu_items - 1]->command_count == 0) { this_command->data = NULL;
menu[menu_items - 1]->command = (int *)malloz(sizeof(int)); ptr_vector_append(&this_menu->commands, this_command);
menu[menu_items - 1]->data = (char **)malloz(sizeof(char *));
} else {
menu[menu_items - 1]->command = (int *)realloc(menu[menu_items - 1]->command, sizeof(int) * (menu[menu_items - 1]->command_count + 1));
menu[menu_items - 1]->data = (char **)realloc(menu[menu_items - 1]->data, sizeof(char *) * (menu[menu_items - 1]->command_count + 1));
}
menu[menu_items - 1]->command_count++;
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = 0;
menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] = NULL;
if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SUBMENU;
} else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LOGOFF;
} else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMENU;
} else if (strncasecmp(&buffer[8], "AUTOMESSAGE", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_AUTOMESSAGE;
} else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_TEXTFILES;
} else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHATSYSTEM;
} else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BBSLIST;
} else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTUSERS;
} else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BULLETINS;
} else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LAST10;
} else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SETTINGS;
} else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOOR;
} else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_MAILSCAN;
} else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_READMAIL;
} else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_POSTMESSAGE;
} else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEMAILCONF;
} else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEMAILAREA;
} else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDEMAIL;
} else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTEMAIL;
} else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTMAILCONF;
} else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMAILCONF;
} else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTMAILAREA;
} else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVMAILAREA;
} else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLUEWAVEDOWN;
} else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLUEWAVEUP;
} else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEFILEDIR;
} else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CHOOSEFILESUB;
} else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTFILES;
} else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_UPLOAD;
} else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOWNLOAD;
} else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_CLEARTAGGEDFILES;
} else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTFILEDIR;
} else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVFILEDIR;
} else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NEXTFILESUB;
} else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_PREVFILESUB;
} else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_LISTMESSAGES;
} else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DOSCRIPT;
} else if (strncasecmp(&buffer[8], "SENDNODEMSG", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDNODEMSG;
} else if (strncasecmp(&buffer[8], "SUBUNSUBCONF", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SUBUNSUBCONF;
} else if (strncasecmp(&buffer[8], "RESETMSGPTRS", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_RESETPOINTERS;
} else if (strncasecmp(&buffer[8], "RESETALLMSGPTRS", 15) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_RESETALLPOINTERS;
} else if (strncasecmp(&buffer[8], "FILESCAN", 8) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_FILESCAN;
} else if (strncasecmp(&buffer[8], "FULLMAILSCAN", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_FULLMAILSCAN;
} else if (strncasecmp(&buffer[8], "FILESEARCH", 10) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_FILESEARCH;
} else if (strncasecmp(&buffer[8], "DISPLAYTXTFILE", 14) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DISPTXTFILE;
} else if (strncasecmp(&buffer[8], "DISPLAYTXTPAUSE", 15) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_DISPTXTFILEPAUSE;
} else if (strncasecmp(&buffer[8], "GENWWWURLS", 10) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_GENWWWURLS;
} else if (strncasecmp(&buffer[8], "NLBROWSER", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_NLBROWSER;
} else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_SENDFEEDBACK;
} else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLOGDISPLAY;
} else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) {
menu[menu_items - 1]->command[menu[menu_items - 1]->command_count - 1] = MENU_BLOGWRITE;
}
} else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) {
menu[menu_items - 1]->seclevel = atoi(&buffer[9]); if (this_menu == NULL)
return badmenu(menufile);
this_menu->seclevel = atoi(buffer + 9);
} else if (strncasecmp(buffer, "DATA", 4) == 0) { } else if (strncasecmp(buffer, "DATA", 4) == 0) {
if (menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] != NULL) { if (this_command == NULL)
free(menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1]); return badmenu(menufile);
} free(this_command->data);
menu[menu_items - 1]->data[menu[menu_items - 1]->command_count - 1] = strdup(&buffer[5]); this_command->data = strdup(buffer + 5);
} else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) { } else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) {
if (lua_script != NULL) {
free(lua_script); free(lua_script);
} lua_script = strdup(buffer + 10);
lua_script = strdup(&buffer[10]);
} else if (strncasecmp(buffer, "ANSIFILE", 8) == 0) { } else if (strncasecmp(buffer, "ANSIFILE", 8) == 0) {
if (ansi_file != NULL) {
free(ansi_file); free(ansi_file);
} ansi_file = strdup(buffer + 9);
ansi_file = strdup(&buffer[9]);
} else if (strncasecmp(buffer, "CLEARSCREEN", 11) == 0) { } else if (strncasecmp(buffer, "CLEARSCREEN", 11) == 0) {
clearscreen = 1; clearscreen = 1;
} }
fgets(buffer, 256, fptr);
} }
fclose(fptr); fclose(fptr);
@ -345,81 +317,38 @@ int menu_system(char *menufile) {
lua_pop(L, 1); lua_pop(L, 1);
} }
for (i = 0; i < menu_items; i++) { for (size_t i = 0; i < ptr_vector_len(&menu); i++) {
if (tolower(menu[i]->hotkey) == tolower(c)) { struct menu_item *item = ptr_vector_get(&menu, i);
if (menu[i]->seclevel <= gUser->sec_level) { if (tolower(item->hotkey) == tolower(c)) {
for (j = 0; j < menu[i]->command_count; j++) { if (item->seclevel <= gUser->sec_level) {
switch (menu[i]->command[j]) { for (size_t j = 0; j < ptr_vector_len(&item->commands); ++j) {
struct menu_command *cmd = ptr_vector_get(&item->commands, j);
switch (cmd->command) {
case MENU_SUBMENU: case MENU_SUBMENU:
doquit = menu_system(menu[i]->data[j]); doquit = menu_system(cmd->data);
if (doquit == 1) { if (doquit == 1) {
// free menus // free menus
if (do_lua_menu) { free_menu(&menu);
lua_close(L);
}
if (lua_script != NULL) {
free(lua_script);
}
if (ansi_file != NULL) {
free(ansi_file); free(ansi_file);
} if (do_lua_menu)
for (i = 0; i < menu_items; i++) { lua_close(L);
for (j = 0; j < menu[i]->command_count; j++) { free(lua_script);
if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]);
}
}
free(menu[i]->data);
free(menu[i]->command);
free(menu[i]);
}
free(menu);
return doquit; return doquit;
} }
break; break;
case MENU_LOGOFF: case MENU_LOGOFF:
if (do_lua_menu) {
lua_close(L);
}
if (lua_script != NULL) {
free(lua_script);
}
if (ansi_file != NULL) {
free(ansi_file); free(ansi_file);
} if (do_lua_menu)
for (i = 0; i < menu_items; i++) { lua_close(L);
for (j = 0; j < menu[i]->command_count; j++) { free(lua_script);
if (menu[i]->data[j] != NULL) { free_menu(&menu);
free(menu[i]->data[j]);
}
}
free(menu[i]->data);
free(menu[i]->command);
free(menu[i]);
}
free(menu);
return 1; return 1;
case MENU_PREVMENU: case MENU_PREVMENU:
if (do_lua_menu) { if (do_lua_menu)
lua_close(L); lua_close(L);
}
if (lua_script != NULL) {
free(lua_script); free(lua_script);
}
if (ansi_file != NULL) {
free(ansi_file); free(ansi_file);
} free_menu(&menu);
for (i = 0; i < menu_items; i++) {
for (j = 0; j < menu[i]->command_count; j++) {
if (menu[i]->data[j] != NULL) {
free(menu[i]->data[j]);
}
}
free(menu[i]->data);
free(menu[i]->command);
free(menu[i]);
}
free(menu);
return 0; return 0;
case MENU_AUTOMESSAGE: case MENU_AUTOMESSAGE:
broadcast("USER: %s; NODE:%d; STATUS: Viewing/Changing Automessage.", gUser->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Viewing/Changing Automessage.", gUser->loginname, mynode);
@ -454,7 +383,7 @@ int menu_system(char *menufile) {
break; break;
case MENU_DOOR: { case MENU_DOOR: {
for (m = 0; m < conf.door_count; m++) { for (m = 0; m < conf.door_count; m++) {
if (strcasecmp(menu[i]->data[j], conf.doors[m]->name) == 0) { if (strcasecmp(cmd->data, conf.doors[m]->name) == 0) {
dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode);
broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, conf.doors[m]->name); broadcast("USER: %s; NODE:%d; STATUS: Executing Door %s.", gUser->loginname, mynode, conf.doors[m]->name);
rundoor(gUser, conf.doors[m]->command, conf.doors[m]->stdio, conf.doors[m]->codepage); rundoor(gUser, conf.doors[m]->command, conf.doors[m]->stdio, conf.doors[m]->codepage);
@ -554,8 +483,8 @@ int menu_system(char *menufile) {
list_messages(gUser); list_messages(gUser);
break; break;
case MENU_DOSCRIPT: case MENU_DOSCRIPT:
broadcast("USER: %s; NODE:%d; STATUS: Executing a script %s.", gUser->loginname, mynode, menu[i]->data[j]); broadcast("USER: %s; NODE:%d; STATUS: Executing a script %s.", gUser->loginname, mynode, cmd->data);
do_lua_script(menu[i]->data[j]); do_lua_script(cmd->data);
break; break;
case MENU_SENDNODEMSG: case MENU_SENDNODEMSG:
broadcast("USER: %s; NODE:%d; STATUS: Sending a node Message.", gUser->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Sending a node Message.", gUser->loginname, mynode);
@ -602,8 +531,8 @@ int menu_system(char *menufile) {
file_scan(); file_scan();
break; break;
case MENU_FULLMAILSCAN: case MENU_FULLMAILSCAN:
if (menu[i]->data[j] != NULL) { if (cmd->data != NULL) {
if (strcasecmp(menu[i]->data[j], "PERSONAL") == 0) { if (strcasecmp(cmd->data, "PERSONAL") == 0) {
broadcast("USER: %s; NODE:%d; STATUS: Scanning for personal mail.", gUser->loginname, mynode); broadcast("USER: %s; NODE:%d; STATUS: Scanning for personal mail.", gUser->loginname, mynode);
full_mail_scan_personal(gUser); full_mail_scan_personal(gUser);
} else { } else {
@ -619,15 +548,15 @@ int menu_system(char *menufile) {
file_search(); file_search();
break; break;
case MENU_DISPTXTFILE: case MENU_DISPTXTFILE:
if (menu[i]->data[j] != NULL) { if (cmd->data != NULL) {
broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]); broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, cmd->data);
s_displayansi_pause(menu[i]->data[j], 0); s_displayansi_pause(cmd->data, 0);
} }
break; break;
case MENU_DISPTXTFILEPAUSE: case MENU_DISPTXTFILEPAUSE:
if (menu[i]->data[j] != NULL) { if (cmd->data != NULL) {
broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, menu[i]->data[j]); broadcast("USER: %s; NODE:%d; STATUS: Displaying Text File: %s.", gUser->loginname, mynode, cmd->data);
s_displayansi_pause(menu[i]->data[j], 1); s_displayansi_pause(cmd->data, 1);
} }
s_printf(get_string(6)); s_printf(get_string(6));
s_getc(); s_getc();
@ -668,6 +597,11 @@ int menu_system(char *menufile) {
} }
} }
// free menus; free(ansi_file);
if (do_lua_menu)
lua_close(L);
free(lua_script);
free_menu(&menu);
return doquit; return doquit;
} }