| 1 |
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
| 2 |
/*
|
| 3 |
* bbs_cmd
|
| 4 |
* - manager of menu command handler
|
| 5 |
*
|
| 6 |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com>
|
| 7 |
*/
|
| 8 |
|
| 9 |
#ifdef HAVE_CONFIG_H
|
| 10 |
#include "config.h"
|
| 11 |
#endif
|
| 12 |
|
| 13 |
#include "bbs_cmd.h"
|
| 14 |
#include "data_file_mgr.h"
|
| 15 |
#include "menu_proc.h"
|
| 16 |
#include "trie_dict.h"
|
| 17 |
#include <string.h>
|
| 18 |
|
| 19 |
static const BBS_CMD bbs_cmd_list[] = {
|
| 20 |
{"LIST_SECTION", list_section},
|
| 21 |
{"RunMBEM", exec_mbem},
|
| 22 |
{"EXITBBS", exit_bbs},
|
| 23 |
{"EULA", eula},
|
| 24 |
{"LICENSE", license},
|
| 25 |
{"COPYRIGHT", copyright},
|
| 26 |
{"VERSION", version},
|
| 27 |
{"RELOADCONF", reload_bbs_conf},
|
| 28 |
{"DATAMGR", data_file_mgr},
|
| 29 |
{"SHUTDOWN", shutdown_bbs},
|
| 30 |
{"M_FAVOR_SECTION", favor_section_filter},
|
| 31 |
{"VIEW_EX_ARTICLE", view_ex_article},
|
| 32 |
{"LIST_EX_SECTION", list_ex_section},
|
| 33 |
{"TOP10", show_top10_menu},
|
| 34 |
{"LOCATE_ARTICLE", locate_article},
|
| 35 |
{"FAVOR_TOPIC", favor_topic},
|
| 36 |
{"LIST_USER", list_user},
|
| 37 |
{"LIST_ONLINE_USER", list_online_user},
|
| 38 |
{"EDIT_INTRO", edit_intro},
|
| 39 |
{"EDIT_SIGN", edit_sign},
|
| 40 |
};
|
| 41 |
|
| 42 |
static const int bbs_cmd_count = sizeof(bbs_cmd_list) / sizeof(BBS_CMD);
|
| 43 |
|
| 44 |
static TRIE_NODE *p_bbs_cmd_dict;
|
| 45 |
|
| 46 |
int load_cmd()
|
| 47 |
{
|
| 48 |
if (p_bbs_cmd_dict != NULL)
|
| 49 |
{
|
| 50 |
return -1;
|
| 51 |
}
|
| 52 |
|
| 53 |
p_bbs_cmd_dict = trie_dict_create();
|
| 54 |
|
| 55 |
if (p_bbs_cmd_dict == NULL)
|
| 56 |
{
|
| 57 |
return -2;
|
| 58 |
}
|
| 59 |
|
| 60 |
for (int i = 0; i < bbs_cmd_count; i++)
|
| 61 |
{
|
| 62 |
if (trie_dict_set(p_bbs_cmd_dict, bbs_cmd_list[i].cmd, (int64_t)i) != 1)
|
| 63 |
{
|
| 64 |
return -3;
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
| 68 |
return 0;
|
| 69 |
}
|
| 70 |
|
| 71 |
void unload_cmd()
|
| 72 |
{
|
| 73 |
trie_dict_destroy(p_bbs_cmd_dict);
|
| 74 |
p_bbs_cmd_dict = NULL;
|
| 75 |
}
|
| 76 |
|
| 77 |
bbs_cmd_handler get_cmd_handler(const char *cmd)
|
| 78 |
{
|
| 79 |
int64_t i;
|
| 80 |
|
| 81 |
if (p_bbs_cmd_dict == NULL)
|
| 82 |
{
|
| 83 |
return NULL;
|
| 84 |
}
|
| 85 |
|
| 86 |
if (trie_dict_get(p_bbs_cmd_dict, cmd, &i) != 1)
|
| 87 |
{
|
| 88 |
return NULL;
|
| 89 |
}
|
| 90 |
|
| 91 |
return (bbs_cmd_list[i].handler);
|
| 92 |
}
|