| 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or |
| 3 | * modify it under the terms of the GNU General Public License |
| 4 | * as published by the Free Software Foundation; either version 2 |
| 5 | * of the License, or (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 15 | */ |
| 16 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 17 | #define COMMAND_GROUPS_INTERNAL_ACCESScxx . . $ `src/bnetd/command_groups.cpp:17:9`! |
| 18 | #include "command_groups.h"cxx . . $ `<file>/src/bnetd/command_groups.h`/ |
| 19 | |
| 20 | #include <cstdio> |
| 21 | #include <cerrno> |
| 22 | #include <cstring> |
| 23 | |
| 24 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 25 | #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 26 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 27 | #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/ |
| 28 | |
| 29 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 30 | |
| 31 | //#define COMMANDGROUPSDEBUG 1 |
| 32 | |
| 33 | namespace pvpgncxx . . $ pvpgn/ |
| 34 | { |
| 35 | |
| 36 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 37 | { |
| 38 | |
| 39 | static t_listcxx . . $ pvpgn/t_list# * command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 40 | static stdcxx . . $ std/::FILEcxx . . $ std/FILE# * fpcxx . . $ pvpgn/bnetd/fp. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 41 | |
| 42 | extern int command_groups_loadcxx . . $ pvpgn/bnetd/command_groups_load(5c4306d8553b3696).(char const * filename) |
| 43 | { |
| 44 | unsigned int line; |
| 45 | unsigned int pos; |
| 46 | char * buff; |
| 47 | char * temp; |
| 48 | char const * command; |
| 49 | unsigned int group; |
| 50 | t_command_groupscxx . . $ pvpgn/bnetd/t_command_groups# * entry; |
| 51 | |
| 52 | if (!filename) { |
| 53 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL filename"); |
| 54 | return -1; |
| 55 | } |
| 56 | if (!(fpcxx . . $ pvpgn/bnetd/fp. = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(filename, "r"))) { |
| 57 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not open file \"{}\" for reading (std::fopen: {})", filename, stdcxx . . $ std/::strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head. = list_createcxx . . $ pvpgn/list_create(7a6cb11de248e2c9).(); |
| 62 | |
| 63 | for (line = 1; (buff = file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(fpcxx . . $ pvpgn/bnetd/fp.)); line++) { |
| 64 | for (pos = 0; buff[pos] == '\t' || buff[pos] == ' '; pos++); |
| 65 | if (buff[pos] == '\0' || buff[pos] == '#') { |
| 66 | continue; |
| 67 | } |
| 68 | if ((temp = stdcxx . . $ std/::strrchr(buff, '#'))) { |
| 69 | unsigned int len; |
| 70 | unsigned int endpos; |
| 71 | |
| 72 | *temp = '\0'; |
| 73 | len = stdcxx . . $ std/::strlen(buff) + 1; |
| 74 | for (endpos = len - 1; buff[endpos] == '\t' || buff[endpos] == ' '; endpos--); |
| 75 | buff[endpos + 1] = '\0'; |
| 76 | } |
| 77 | if (!(temp = stdcxx . . $ std/::strtok(buff, " \t"))) { /* std::strtok modifies the string it is passed */ |
| 78 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "missing group on line {} of file \"{}\"", line, filename); |
| 79 | continue; |
| 80 | } |
| 81 | if (str_to_uintcxx . . $ pvpgn/str_to_uint(6974107818eeb505).(temp, &group)<0) { |
| 82 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "group '{}' not a valid group (1-8)", temp); |
| 83 | continue; |
| 84 | } |
| 85 | if (group == 0 || group > 8) { |
| 86 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "group '{}' not within groups limits (1-8)", group); |
| 87 | continue; |
| 88 | } |
| 89 | while ((command = stdcxx . . $ std/::strtok(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!, " \t"))) { |
| 90 | entry = (t_command_groupscxx . . $ pvpgn/bnetd/t_command_groups#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_command_groups)); |
| 91 | entry->groupcxx . . $ pvpgn/bnetd/$anonymous_type_d5d1bab303a2360e_0#group. = 1 << (group - 1); |
| 92 | entry->commandcxx . . $ pvpgn/bnetd/$anonymous_type_d5d1bab303a2360e_0#command. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(command); |
| 93 | list_append_datacxx . . $ pvpgn/list_append_data(4e1348bd294d996f).(command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head., entry); |
| 94 | #ifdef COMMANDGROUPSDEBUG |
| 95 | eventlog(eventlog_level_info, __FUNCTION__, "Added command: {} - with group {}", entry->command, entry->group); |
| 96 | #endif |
| 97 | } |
| 98 | } |
| 99 | file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!); // clear file_get_line buffer |
| 100 | stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fpcxx . . $ pvpgn/bnetd/fp.); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | extern int command_groups_unloadcxx . . $ pvpgn/bnetd/command_groups_unload(b126dc7c1de90089).(void) |
| 105 | { |
| 106 | t_elemcxx . . $ pvpgn/t_elem# * curr; |
| 107 | t_command_groupscxx . . $ pvpgn/bnetd/t_command_groups# * entry; |
| 108 | |
| 109 | if (command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head.) { |
| 110 | LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(command_groups_head, curr) { |
| 111 | if (!(entry = (t_command_groupscxx . . $ pvpgn/bnetd/t_command_groups#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr))) |
| 112 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "found NULL entry in list"); |
| 113 | else { |
| 114 | xfreecxx . . $ `src/common/xalloc.h:51:9`!(entry->command); |
| 115 | xfreecxx . . $ `src/common/xalloc.h:51:9`!(entry); |
| 116 | } |
| 117 | list_remove_elemcxx . . $ pvpgn/list_remove_elem(17f7246ce0d3563b).(command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head., &curr); |
| 118 | } |
| 119 | list_destroycxx . . $ pvpgn/list_destroy(20db0232078327de).(command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head.); |
| 120 | command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 121 | } |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | extern unsigned int command_get_groupcxx . . $ pvpgn/bnetd/command_get_group(c61c63047ce273de).(char const * command) |
| 126 | { |
| 127 | t_elemcxx . . $ pvpgn/t_elem# const * curr; |
| 128 | t_command_groupscxx . . $ pvpgn/bnetd/t_command_groups# * entry; |
| 129 | |
| 130 | if (command_groups_headcxx . . $ pvpgn/bnetd/command_groups_head.) { |
| 131 | LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(command_groups_head, curr) { |
| 132 | if (!(entry = (t_command_groupscxx . . $ pvpgn/bnetd/t_command_groups#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr))) |
| 133 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "found NULL entry in list"); |
| 134 | else if (!(stdcxx . . $ std/::strcmp(entry->commandcxx . . $ pvpgn/bnetd/$anonymous_type_d5d1bab303a2360e_0#command., command))) |
| 135 | return entry->groupcxx . . $ pvpgn/bnetd/$anonymous_type_d5d1bab303a2360e_0#group.; |
| 136 | } |
| 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | extern int command_groups_reloadcxx . . $ pvpgn/bnetd/command_groups_reload(5c4306d8553b3696).(char const * filename) |
| 142 | { |
| 143 | command_groups_unloadcxx . . $ pvpgn/bnetd/command_groups_unload(b126dc7c1de90089).(); |
| 144 | return command_groups_loadcxx . . $ pvpgn/bnetd/command_groups_load(5c4306d8553b3696).(filename); |
| 145 | } |
| 146 | |
| 147 | } |
| 148 | |
| 149 | } |