Debian Codegraph @

src/bnetd/autoupdate.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2000 Rob Crittenden ([email protected])
3 * Copyright (C) 2002 Gianluigi Tiesi ([email protected])
4 * Copyright (C) 2004 CreepLord ([email protected])
5 * Copyright (C) 2008 Pelish ([email protected])
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
22 #define AUTOUPDATE_INTERNAL_ACCESScxx . . $ `src/bnetd/autoupdate.cpp:22:9`!
23 #include "autoupdate.h"cxx . . $ `<file>/src/bnetd/autoupdate.h`/
24
25 #include <cerrno>
26 #include <cstring>
27
28 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
29 #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/
30 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
31 #include "common/proginfo.h"cxx . . $ `<file>/src/common/proginfo.h`/
32 #include "common/tag.h"cxx . . $ `<file>/src/common/tag.h`/
33 #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/
34 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
35
36 namespace pvpgncxx . . $ pvpgn/
37 {
38
39 namespace bnetdcxx . . $ pvpgn/bnetd/
40 {
41
42 static t_listcxx . . $ pvpgn/t_list# * autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
43 static stdcxx . . $ std/::FILEcxx . . $ std/FILE# * fpcxx . . $ pvpgn/bnetd/fp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
44
45
46 /*
47 * Open the autoupdate configuration file, create a linked list of the
48 * clienttag and the update file for it. The format of the file is:
49 * archtag<tab>clienttag<tab>versiontag<tab>update file
50 *
51 * Comments begin with # and are ignored.
52 *
53 * The server assumes that the update file is in the "files" directory
54 * so do not include "/" in the filename - it won't be sent
55 * (because it is a security risk).
56 */
57
58 extern int autoupdate_loadcxx . . $ pvpgn/bnetd/autoupdate_load(5c4306d8553b3696).(char const * filename)
59 {
60 unsigned int line;
61 unsigned int pos;
62 char * buff;
63 char * temp;
64 char const * archtag;
65 char const * clienttag;
66 char const * updatefile;
67 char const * versiontag;
68 char const * path;
69 t_autoupdatecxx . . $ pvpgn/bnetd/t_autoupdate# * entry;
70
71 if (!filename) {
72 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL filename");
73 return -1;
74 }
75
76 if (!(fpcxx . . $ pvpgn/bnetd/fp. = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(filename, "r"))) {
77 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`!));
78 return -1;
79 }
80
81 autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head. = list_createcxx . . $ pvpgn/list_create(7a6cb11de248e2c9).();
82
83 for (line = 1; (buff = file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(fpcxx . . $ pvpgn/bnetd/fp.)); line++) {
84 for (pos = 0; buff[pos] == '\t' || buff[pos] == ' '; pos++);
85
86 if (buff[pos] == '\0' || buff[pos] == '#') {
87 continue;
88 }
89
90 if ((temp = stdcxx . . $ std/::strrchr(buff, '#'))) {
91 unsigned int len;
92 unsigned int endpos;
93
94 *temp = '\0';
95 len = stdcxx . . $ std/::strlen(buff) + 1;
96 for (endpos = len - 1; buff[endpos] == '\t' || buff[endpos] == ' '; endpos--);
97 buff[endpos + 1] = '\0';
98 }
99
100 /* FIXME: use next_token instead of std::strtok */
101 if (!(archtag = stdcxx . . $ std/::strtok(buff, " \t"))) { /* std::strtok modifies the string it is passed */
102 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "missing archtag on line {} of file \"{}\"", line, filename);
103 continue;
104 }
105 if (!(clienttag = stdcxx . . $ std/::strtok(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, " \t"))) {
106 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "missing clienttag on line {} of file \"{}\"", line, filename);
107 continue;
108 }
109 if (!(versiontag = stdcxx . . $ std/::strtok(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, " \t"))) {
110 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "missing versiontag on line {} of file \"{}\"", line, filename);
111 continue;
112 }
113 if (!(updatefile = stdcxx . . $ std/::strtok(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, " \t"))) {
114 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "missing updatefile on line {} of file \"{}\"", line, filename);
115 continue;
116 }
117 if ((!(path = stdcxx . . $ std/::strtok(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, " \t"))) && tag_check_wolv1cxx . . $ pvpgn/tag_check_wolv1(4c679297bf94b9eb).(tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(clienttag)) && tag_check_wolv2cxx . . $ pvpgn/tag_check_wolv2(4c679297bf94b9eb).(tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(clienttag))) { /* Only in WOL is needed to have path */
118 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "missing path on line {} of file \"{}\"", line, filename);
119 }
120
121 entry = (t_autoupdatecxx . . $ pvpgn/bnetd/t_autoupdate#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_autoupdate));
122
123 if (!tag_check_archcxx . . $ pvpgn/tag_check_arch(4c679297bf94b9eb).((entry->archtagcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#archtag. = tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(archtag)))) {
124 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got unknown archtag");
125 xfreecxx . . $ `src/common/xalloc.h:51:9`!(entry);
126 continue;
127 }
128 if (!tag_check_clientcxx . . $ pvpgn/tag_check_client(4c679297bf94b9eb).((entry->clienttagcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#clienttag. = tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(clienttag)))) {
129 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got unknown clienttag");
130 xfreecxx . . $ `src/common/xalloc.h:51:9`!(entry);
131 continue;
132 }
133 entry->versiontagcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#versiontag. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(versiontag);
134 entry->updatefilecxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#updatefile. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(updatefile);
135 if (path)
136 entry->pathcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#path. = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(path);
137 else
138 entry->pathcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#path. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
139
140 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_debugcxx . . $ pvpgn/eventlog_level_debug., __FUNCTION__, "update '{}' version '{}' with file {}", clienttag, versiontag, updatefile);
141
142 list_append_datacxx . . $ pvpgn/list_append_data(4e1348bd294d996f).(autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head., entry);
143 }
144 file_get_linecxx . . $ pvpgn/file_get_line(e31226b218f63160).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); // clear file_get_line buffer
145 stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fpcxx . . $ pvpgn/bnetd/fp.);
146 return 0;
147 }
148
149 /*
150 * Free up all of the elements in the linked list
151 */
152
153 extern int autoupdate_unloadcxx . . $ pvpgn/bnetd/autoupdate_unload(b126dc7c1de90089).(void)
154 {
155 if (autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head.) {
156 t_elemcxx . . $ pvpgn/t_elem# * curr;
157 t_autoupdatecxx . . $ pvpgn/bnetd/t_autoupdate# * entry;
158 LIST_TRAVERSEcxx . . $ `src/common/list.h:94:9`!(autoupdate_head, curr)
159 {
160 if (!(entry = (t_autoupdatecxx . . $ pvpgn/bnetd/t_autoupdate#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr)))
161 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "found NULL entry in list");
162 else {
163 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)entry->versiontag); /* avoid warning */
164 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)entry->updatefile); /* avoid warning */
165 if (entry->pathcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#path.)
166 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)entry->path); /* avoid warning */
167 xfreecxx . . $ `src/common/xalloc.h:51:9`!(entry);
168 }
169 list_remove_elemcxx . . $ pvpgn/list_remove_elem(17f7246ce0d3563b).(autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head., &curr);
170 }
171
172 if (list_destroycxx . . $ pvpgn/list_destroy(20db0232078327de).(autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head.) < 0) return -1;
173 autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
174 }
175 return 0;
176 }
177
178 /*
179 * Check to see if an update exists for the clients version
180 * return file name if there is one
181 * retrun NULL if no update exists
182 */
183
184 extern char * autoupdate_checkcxx . . $ pvpgn/bnetd/autoupdate_check(89dc5b73db77f621).(t_tagcxx . . $ pvpgn/t_tag# archtag, t_tagcxx . . $ pvpgn/t_tag# clienttag, t_tagcxx . . $ pvpgn/t_tag# gamelang, char const * versiontag, char const * sku)
185 {
186 if (autoupdate_headcxx . . $ pvpgn/bnetd/autoupdate_head.) {
187 t_elemcxx . . $ pvpgn/t_elem# const * curr;
188 t_autoupdatecxx . . $ pvpgn/bnetd/t_autoupdate# * entry;
189 char * temp;
190
191 LIST_TRAVERSE_CONSTcxx . . $ `src/common/list.h:95:9`!(autoupdate_head, curr)
192 {
193 if (!(entry = (t_autoupdatecxx . . $ pvpgn/bnetd/t_autoupdate#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr))) {
194 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "found NULL entry in list");
195 continue;
196 }
197
198 if (entry->archtagcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#archtag. != archtag)
199 continue;
200 if (entry->clienttagcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#clienttag. != clienttag)
201 continue;
202 if (stdcxx . . $ std/::strcmp(entry->versiontagcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#versiontag., versiontag) != 0)
203 continue;
204
205 /* if we have a gamelang or SKU then add it to the update file name */
206 // so far only WAR3 uses gamelang specific MPQs!
207 if (((gamelang) && ((clienttag == CLIENTTAG_WARCRAFT3_UINTcxx . . $ `src/common/tag.h:111:9`!) || (clienttag == CLIENTTAG_WAR3XP_UINTcxx . . $ `src/common/tag.h:113:9`!)))
208 || ((sku) && (tag_check_wolv2cxx . . $ pvpgn/tag_check_wolv2(4c679297bf94b9eb).(clienttag)))) {
209 char gltag[5];
210 char * tempmpq;
211 char * extention;
212 char const * path = entry->pathcxx . . $ pvpgn/bnetd/$anonymous_type_f6cccf9ade0682e5_0#path.;
213
214 tempmpq = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(entry->updatefile);
215
216 extention = stdcxx . . $ std/::strrchr(tempmpq, '.');
217 *extention = '\0';
218 extention++;
219
220 if ((clienttag == CLIENTTAG_WARCRAFT3_UINTcxx . . $ `src/common/tag.h:111:9`!) || (clienttag == CLIENTTAG_WAR3XP_UINTcxx . . $ `src/common/tag.h:113:9`!)) {
221 tag_uint_to_strcxx . . $ pvpgn/tag_uint_to_str(d172961b102a89a5).(gltag, gamelang);
222
223 temp = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(entry->updatefile) + 6);
224 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(temp, "%s_%s.%s", tempmpq, gltag, extention);
225 }
226 else {
227 temp = (char*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(std::strlen(path) + std::strlen(entry->updatefile) + std::strlen(sku) + 3);
228 stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).(temp, "%s %s_%s.%s", path, tempmpq, sku, extention);
229 }
230
231 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)tempmpq);
232 return temp;
233 }
234 temp = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(entry->updatefile);
235 return temp;
236 }
237 }
238 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
239 }
240
241 }
242
243 }