41 for (
int c = 0; content[c]; c++) free(content[c]);
59 const char *
get_entry(
const char *serverID)
const;
62 #if defined(DUMP_ATD_ACCESS)
71 for (c = 0; content[c]; c++) {
72 const char *
id = content[c];
74 if (strcmp(
id, serverID) == 0) {
75 result = strchr(
id, 0)+1;
83 #if defined(DUMP_ATD_ACCESS)
84 void ArbTcpDat::dump() {
85 fprintf(stderr,
"filename='%s'\n", filename);
86 fprintf(stderr,
"modtime='%lu'\n", modtime);
89 for (c = 0; content[c]; c++) {
90 char *data = content[c];
92 fprintf(stderr,
"Entry #%i:\n", c);
95 fprintf(stderr,
"- '%s'\n", tok);
96 tok = strchr(tok, 0)+1;
101 fprintf(stderr,
"No content\n");
104 #endif // DUMP_ATD_ACCESS
106 #define MAXLINELEN 512
109 GB_ERROR ArbTcpDat::read(
int *versionFound) {
112 FILE *in = fopen(filename,
"rt");
116 #if defined(DUMP_ATD_ACCESS)
117 fprintf(stderr,
"(re)reading %s\n", filename);
118 #endif // DUMP_ATD_ACCESS
129 char **tokens = ARB_alloc<char*>(
MAXTOKENS);
131 int entries_allocated = 30;
133 char **entry = ARB_alloc<char*>(entries_allocated);
135 if (!tokens || !entry) error =
"Out of memory";
147 while ((tok = strtok(lp,
" \t\n"))) {
148 if (tok[0] ==
'#')
break;
149 if (tokCount >=
MAXTOKENS) { error =
"Too many tokens";
break; }
156 if (!error && tokCount>0) {
157 if (strcmp(tokens[0],
"ARB_TCP_DAT_VERSION") == 0) {
158 if (tokCount>1) *versionFound = atoi(tokens[1]);
166 for (t = 0; t<tokCount; t++) {
167 size[t] = strlen(tokens[t])+1;
172 data = ARB_alloc<char>(allsize);
175 for (t = 0; t<tokCount; t++) {
176 memmove(d, tokens[t], size[t]);
183 if (entries == entries_allocated) {
184 entries_allocated = (
int)(entries_allocated*1.5);
188 entry[entries++] = data;
195 if (error) error =
GBS_global_string(
"%s (in line %i of '%s')", error, lineNumber, filename);
196 for (t = 0; t<tokCount; t++) freenull(tokens[t]);
202 content[entries] =
NULp;
203 serverCount = entries;
209 #if defined(DUMP_ATD_ACCESS)
211 #endif // DUMP_ATD_ACCESS
226 error =
"File $ARBHOME/lib/arb_tcp.dat missing or unreadable";
230 if (stat(filename, &st) == 0) {
232 if (modtime != mtime) {
234 error = read(&arb_tcp_version);
237 int expected_version = 2;
238 if (arb_tcp_version != expected_version) {
240 "Your '%s' has version %i\n"
241 "To solve the problem\n"
242 "- either reinstall ARB and do not select\n"
243 " 'Use information of already installed ARB'\n"
244 " (any changes to arb_tcp.dat will be lost)\n"
245 "- or backup your changed %s,\n"
246 " replace it by the contents from $ARBHOME/lib/arb_tcp_org.dat\n"
247 " and edit it to fit your needs.",
249 filename, arb_tcp_version,
253 modtime = error ? -1 : mtime;
263 #if defined(DUMP_ATD_ACCESS)
264 fprintf(stderr,
"error=%s\n", error);
265 #endif // DUMP_ATD_ACCESS
281 const char *exe = strchr(ipPort, 0)+1;
282 const char *param = strchr(exe, 0)+1;
283 size_t plen = strlen(param);
284 size_t wplen = strlen(wantedParam);
287 if (strncasecmp(param, wantedParam, wplen) == 0) {
288 result = param+wplen;
292 plen = strlen(param);
304 if (add_field && add_field[0]) {
309 return "ARB_NAME_SERVER";
313 #ifdef UNIT_TESTS // UT_DIFF
314 if (
id == TEST_SERVER_ID)
return "ARB_TEST_PT_SERVER";
315 if (
id == TEST_GENESERVER_ID)
return "ARB_TEST_PT_SERVER_GENE";
318 const int MAXIDSIZE = 30;
319 static char server_tag[MAXIDSIZE];
360 if (strchr(env,
':')) {
361 static char *resBuf =
NULp;
362 freedup(resBuf, env);
366 error = arb_tcp_dat.
update();
394 static const char **matchingEntries =
NULp;
395 static int matchingEntriesSize = 0;
401 if (matchingEntriesSize != count) {
402 freeset(matchingEntries, ARB_alloc<const char*>(count+1));
403 matchingEntriesSize = count;
407 for (
int c = 0; c<count; c++) {
410 if (!strchr(
id,
':')) {
412 matchingEntries[matched++] =
id;
416 matchingEntries[matched] =
NULp;
419 return error ?
NULp : matchingEntries;
435 time_t t = time(
NULp);
436 tm *tms = localtime(&t);
438 strftime(atime, 255,
"%Y/%m/%d %k:%M:%S", tms);
439 fprintf(log,
"%s %s\n", atime, entry);
458 const char *nameOnly = strrchr(file,
'/');
460 if (nameOnly) nameOnly++;
461 else nameOnly = file;
465 char *colon = strchr(remote,
':');
466 if (colon) *colon = 0;
468 if (strcmp(remote,
"localhost") == 0) {
469 result = nulldup(nameOnly);
481 if (stat(file, &st) == 0) {
482 time_t fileMod = st.st_mtime;
484 char *newResult =
NULp;
486 if (stat(serverDB, &st) == 0) {
487 if (st.st_mtime < fileMod) {
492 tm *tms = localtime(&st.st_mtime);
494 strftime(atime, 255,
"%Y/%m/%d %k:%M", tms);
500 if (stat(serverDB_duringBuild, &st) == 0) {
503 free(serverDB_duringBuild);
506 if (newResult) freeset(result, newResult);
521 void TEST_GBS_servertags() {
char * GB_arbtcpdat_path()
char * ARB_strdup(const char *str)
const char * GBS_global_string(const char *templat,...)
const char * GBS_ptserver_tag(int id)
char buffer[MESSAGE_BUFFERSIZE]
GB_ERROR GB_export_error(const char *error)
static ArbTcpDat arb_tcp_dat
GB_ERROR GB_await_error()
#define ASSERT_RESULT_PREDICATE(Pred, Expr)
const char * get_serverID(int idx) const
const char * get_filename() const
static void error(const char *msg)
#define RETURN_ONETIME_ALLOC(allocated)
#define RETURN_LOCAL_ALLOC(mallocation)
GB_CSTR GB_path_in_ARBLIB(const char *relative_path)
char * ARB_strupper(char *s)
char * GB_lib_file(bool warn_when_not_found, const char *libprefix, const char *filename)
GB_CSTR GB_getenvUSER(void)
int get_server_count() const
void ARB_realloc(TYPE *&tgt, size_t nelem)
const char * GBS_ptserver_logname()
const char * get_entry(const char *serverID) const
char * GBS_eval_env(GB_CSTR p)
const char *const * GBS_get_arb_tcp_entries(const char *matching)
void GBS_add_ptserver_logentry(const char *entry)
const char * GBS_read_arb_tcp(const char *env)
const char * GBS_nameserver_tag(const char *add_field)
char * GBS_ptserver_id_to_choice(int i, int showBuild)
bool GBS_string_matches(const char *str, const char *expr, GB_CASE case_sens)
#define TEST_EXPECT_EQUAL(expr, want)
char * GBS_global_string_copy(const char *templat,...)
const char * GBS_scan_arb_tcp_param(const char *ipPort, const char *wantedParam)