void locator_prepcache(enum locator_servicetype_t svc, int timeout) { if (!havecache[svc]) { locatorcache[svc] = xtreeNew(strcasecmp); havecache[svc] = 1; } else { locator_flushcache(svc, NULL); } cachetimeout[svc] = ((timeout>0) ? timeout : DEFAULT_CACHETIMEOUT); }
void locator_prepcache(enum locator_servicetype_t svc, int timeout) { if (!havecache[svc]) { locatorcache[svc] = rbtNew(name_compare); havecache[svc] = 1; } else { locator_flushcache(svc, NULL); } cachetimeout[svc] = ((timeout>0) ? timeout : DEFAULT_CACHETIMEOUT); }
int locator_serverforget(char *servername, enum locator_servicetype_t svctype) { char *buf; int bufsz; int res; bufsz = strlen(servername) + 100; buf = (char *)malloc(bufsz); sprintf(buf, "F|%s|%s", servername, servicetype_names[svctype]); res = call_locator(buf, bufsz); locator_flushcache(svctype, NULL); xfree(buf); return res; }
char *locator_query(char *hostname, enum locator_servicetype_t svctype, char **extras) { static char *buf = NULL; static int bufsz = 0; int res, bufneeded; bufneeded = strlen(hostname) + 100; if (extras) bufneeded += 1024; if (!buf) { bufsz = bufneeded; buf = (char *)malloc(bufsz); } else if (bufneeded > bufsz) { bufsz = bufneeded; buf = (char *)realloc(buf, bufsz); } if (havecache[svctype] && !extras) { char *cachedata = locator_querycache(svctype, hostname); if (cachedata) return cachedata; } sprintf(buf, "Q|%s|%s", servicetype_names[svctype], hostname); if (extras) buf[0] = 'X'; res = call_locator(buf, bufsz); if (res == -1) return NULL; switch (*buf) { case '!': /* This host is fixed on an available server */ case '*': /* Roaming host */ if (extras) { *extras = strchr(buf+2, '|'); if (**extras == '|') { **extras = '\0'; (*extras)++; } } if (havecache[svctype] && !extras) locator_updatecache(svctype, hostname, buf+2); return ((strlen(buf) > 2) ? buf+2 : NULL); case '?': /* No available server to handle the request */ locator_flushcache(svctype, hostname); return NULL; } return NULL; }