-// This function will most likely vanish when a proper target profile mechanism is
-// introduced.
-void load_simpletargets(const char *fn)
-{
- FILE *f = fopen(fn, "r");
- char line[256];
-
- if (!f)
- {
- yaz_log(YLOG_WARN|YLOG_ERRNO, "open %s", fn);
- exit(1);
- }
-
- while (fgets(line, 255, f))
- {
- char *url, *db;
- struct host *host;
- struct database *database;
-
- if (strncmp(line, "target ", 7))
- continue;
- url = line + 7;
- url[strlen(url) - 1] = '\0';
- yaz_log(YLOG_DEBUG, "Target: %s", url);
- if ((db = strchr(url, '/')))
- *(db++) = '\0';
- else
- db = "Default";
-
- for (host = hosts; host; host = host->next)
- if (!strcmp(url, host->hostport))
- break;
- if (!host)
- {
- struct addrinfo *addrinfo, hints;
- char *port;
- char ipport[128];
- unsigned char addrbuf[4];
- int res;
-
- host = xmalloc(sizeof(struct host));
- host->hostport = xstrdup(url);
- host->connections = 0;
-
- if ((port = strchr(url, ':')))
- *(port++) = '\0';
- else
- port = "210";
-
- hints.ai_flags = 0;
- hints.ai_family = PF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- hints.ai_addrlen = 0;
- hints.ai_addr = 0;
- hints.ai_canonname = 0;
- hints.ai_next = 0;
- // This is not robust code. It assumes that getaddrinfo returns AF_INET
- // address.
- if ((res = getaddrinfo(url, port, &hints, &addrinfo)))
- {
- yaz_log(YLOG_WARN, "Failed to resolve %s: %s", url, gai_strerror(res));
- xfree(host->hostport);
- xfree(host);
- continue;
- }
- assert(addrinfo->ai_family == PF_INET);
- memcpy(addrbuf, &((struct sockaddr_in*)addrinfo->ai_addr)->sin_addr.s_addr, 4);
- sprintf(ipport, "%hhd.%hhd.%hhd.%hhd:%s",
- addrbuf[0], addrbuf[1], addrbuf[2], addrbuf[3], port);
- host->ipport = xstrdup(ipport);
- freeaddrinfo(addrinfo);
- host->next = hosts;
- hosts = host;
- }
- database = xmalloc(sizeof(struct database));
- database->host = host;
- database->url = xmalloc(strlen(url) + strlen(db) + 2);
- strcpy(database->url, url);
- strcat(database->url, "/");
- strcat(database->url, db);
-
- database->databases = xmalloc(2 * sizeof(char *));
- database->databases[0] = xstrdup(db);
- database->databases[1] = 0;
- database->errors = 0;
- database->qprofile = 0;
- database->rprofile = database_retrieval_profile(database);
- database->next = databases;
- databases = database;
-
- }
- fclose(f);
-}
-
-static void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num)
-{
- switch (n->kind)
- {
- case CCL_RPN_AND:
- case CCL_RPN_OR:
- case CCL_RPN_NOT:
- case CCL_RPN_PROX:
- pull_terms(nmem, n->u.p[0], termlist, num);
- pull_terms(nmem, n->u.p[1], termlist, num);
- break;
- case CCL_RPN_TERM:
- termlist[(*num)++] = nmem_strdup(nmem, n->u.t.term);
- break;
- default: // NOOP
- break;
- }
-}
-
-// Extract terms from query into null-terminated termlist
-static int extract_terms(NMEM nmem, char *query, char **termlist)
-{
- int error, pos;
- struct ccl_rpn_node *n;
- int num = 0;
-
- n = ccl_find_str(global_parameters.ccl_filter, query, &error, &pos);
- if (!n)
- return -1;
- pull_terms(nmem, n, termlist, &num);
- termlist[num] = 0;
- ccl_rpn_delete(n);
- return 0;
-}
-