| 1 | /* |
| 2 | * Copyright (C) 2002,2003 Dizzy |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 20 | #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/ |
| 21 | #include <cstring> |
| 22 | #include <cstdlib> |
| 23 | |
| 24 | #include "storage.h"cxx . . $ `<file>/src/bnetd/storage.h`/ |
| 25 | #include "storage_file.h"cxx . . $ `<file>/src/bnetd/storage_file.h`/ |
| 26 | #ifdef WITH_SQL |
| 27 | #include "storage_sql.h" |
| 28 | #endif |
| 29 | |
| 30 | #include "compat/strdup.h"cxx . . $ `<file>/src/compat/strdup.h`/ |
| 31 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 32 | #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/ |
| 33 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 34 | |
| 35 | namespace pvpgncxx . . $ pvpgn/ |
| 36 | { |
| 37 | |
| 38 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 39 | { |
| 40 | |
| 41 | t_storagecxx . . $ pvpgn/bnetd/t_storage# *storagecxx . . $ pvpgn/bnetd/storage. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 42 | |
| 43 | extern int storage_initcxx . . $ pvpgn/bnetd/storage_init(5c4306d8553b3696).(const char *spath) |
| 44 | { |
| 45 | char *p; |
| 46 | int res; |
| 47 | char dstr[256]; |
| 48 | |
| 49 | if (spath == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 50 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL spath"); |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | if ((p = stdcxx . . $ std/::strchr((char *)spath, ':')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 55 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "malformed storage_path , driver not found"); |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | stdcxx . . $ std/::strcpy(dstr, "file"); |
| 60 | #ifdef WITH_SQL |
| 61 | std::strcat(dstr, ", sql"); |
| 62 | #endif |
| 63 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "initializing storage layer (available drivers: {})", dstr); |
| 64 | |
| 65 | *p = '\0'; |
| 66 | if (strcasecmp(spath, "file") == 0) { |
| 67 | storagecxx . . $ pvpgn/bnetd/storage. = &storage_filecxx . . $ pvpgn/bnetd/storage_file.; |
| 68 | res = storagecxx . . $ pvpgn/bnetd/storage.->initcxx . . $ pvpgn/bnetd/$anonymous_type_c7c18ce0294b47dd_0#init.(p + 1); |
| 69 | if (!res) |
| 70 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "using file storage driver"); |
| 71 | } |
| 72 | #ifdef WITH_SQL |
| 73 | else if (strcasecmp(spath, "sql") == 0) { |
| 74 | storage = &storage_sql; |
| 75 | res = storage->init(p + 1); |
| 76 | if (!res) |
| 77 | eventlog(eventlog_level_info, __FUNCTION__, "using sql storage driver"); |
| 78 | } |
| 79 | #endif |
| 80 | else { |
| 81 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_fatalcxx . . $ pvpgn/eventlog_level_fatal., __FUNCTION__, "no known driver specified ({})", spath); |
| 82 | res = -1; |
| 83 | } |
| 84 | |
| 85 | return res; |
| 86 | } |
| 87 | |
| 88 | extern void storage_closecxx . . $ pvpgn/bnetd/storage_close(49f6e7a06ebc5aa8).(void) |
| 89 | { |
| 90 | storagecxx . . $ pvpgn/bnetd/storage.->closecxx . . $ pvpgn/bnetd/$anonymous_type_c7c18ce0294b47dd_0#close.(); |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | |
| 95 | } |