From 5c0b5b368867a9b8fe6c3ffe7887890584ee9643 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Sat, 6 Jan 2007 04:54:58 +0000 Subject: [PATCH] Removed command.c (telnet-style interface) Beginning of structures to configure metadata handling (incomplete) --- src/Makefile.dist | 14 +- src/command.c | 394 ---------------------------------------------------- src/command.h | 6 - src/config.h | 28 ++++ src/http.c | 3 +- src/http_command.c | 3 +- src/pazpar2.c | 12 +- src/pazpar2.h | 16 ++- 8 files changed, 54 insertions(+), 422 deletions(-) delete mode 100644 src/command.c delete mode 100644 src/command.h diff --git a/src/Makefile.dist b/src/Makefile.dist index 7d6e41d..c736ba2 100644 --- a/src/Makefile.dist +++ b/src/Makefile.dist @@ -1,6 +1,6 @@ # ParaZ. Copyright (C) 2000-2004, Index Data ApS # All rights reserved. -# $Id: Makefile.dist,v 1.1 2007-01-04 21:08:26 quinn Exp $ +# $Id: Makefile.dist,v 1.2 2007-01-06 04:54:58 quinn Exp $ SHELL=/bin/sh @@ -11,7 +11,7 @@ YAZLIBS=`$(YAZCONF) --libs` YAZCFLAGS=`$(YAZCONF) --cflags` PROG=pazpar2 -PROGO=pazpar2.o eventl.o util.o command.o http.o http_command.o termlists.o \ +PROGO=pazpar2.o eventl.o util.o http.o http_command.o termlists.o \ reclists.o relevance.o config.o all: $(PROG) @@ -29,16 +29,14 @@ clean: ## Dependencies go below -command.o: command.c command.h util.h eventl.h pazpar2.h termlists.h \ - relevance.h reclists.h config.h config.o: config.c config.h eventl.o: eventl.c eventl.h -http.o: http.c command.h util.h eventl.h pazpar2.h termlists.h \ +http.o: http.c util.h eventl.h pazpar2.h termlists.h relevance.h \ + reclists.h config.h http.h http_command.h +http_command.o: http_command.c util.h eventl.h pazpar2.h termlists.h \ relevance.h reclists.h config.h http.h http_command.h -http_command.o: http_command.c command.h util.h eventl.h pazpar2.h \ - termlists.h relevance.h reclists.h config.h http.h http_command.h pazpar2.o: pazpar2.c pazpar2.h termlists.h relevance.h reclists.h \ - eventl.h config.h command.h http.h + eventl.h config.h http.h reclists.o: reclists.c pazpar2.h termlists.h relevance.h reclists.h \ eventl.h config.h relevance.o: relevance.c relevance.h pazpar2.h termlists.h eventl.h \ diff --git a/src/command.c b/src/command.c deleted file mode 100644 index c400585..0000000 --- a/src/command.c +++ /dev/null @@ -1,394 +0,0 @@ -/* $Id: command.c,v 1.2 2006-12-20 22:19:35 adam Exp $ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "command.h" -#include "util.h" -#include "eventl.h" -#include "pazpar2.h" - -extern IOCHAN channel_list; - -struct command_session { - IOCHAN channel; - char *outbuf; - - int outbuflen; - int outbufwrit; - - struct session *psession; -}; - -void command_destroy(struct command_session *s); -void command_prompt(struct command_session *s); -void command_puts(struct command_session *s, const char *buf); - -static int cmd_quit(struct command_session *s, char **argv, int argc) -{ - IOCHAN i = s->channel; - close(iochan_getfd(i)); - iochan_destroy(i); - command_destroy(s); - return 0; -} - -#ifdef GAGA -static int cmd_load(struct command_session *s, char **argv, int argc) -{ - if (argc != 2) { - command_puts(s, "Usage: load filename\n"); - } - if (load_targets(s->psession, argv[1]) < 0) - command_puts(s, "Failed to open file\n"); - return 1; -} -#endif - -static int cmd_search(struct command_session *s, char **argv, int argc) -{ - if (argc != 2) - { - command_puts(s, "Usage: search word\n"); - return 1; - } - search(s->psession, argv[1]); - return 1; -} - -static int cmd_hitsbytarget(struct command_session *s, char **argv, int argc) -{ - int count; - int i; - - struct hitsbytarget *ht = hitsbytarget(s->psession, &count); - for (i = 0; i < count; i++) - { - char buf[1024]; - - sprintf(buf, "%s: %d (%d records, diag=%d, state=%s conn=%d)\n", ht[i].id, ht[i].hits, - ht[i].records, ht[i].diagnostic, ht[i].state, ht[i].connected); - command_puts(s, buf); - } - return 1; -} - -static int cmd_show(struct command_session *s, char **argv, int argc) -{ - struct record **recs; - int num = 10; - int merged, total; - int i; - NMEM nmem_show = nmem_create(); - - if (argc == 2) - num = atoi(argv[1]); - - recs = show(s->psession, 0, &num, &merged, &total, nmem_show); - - for (i = 0; i < num; i++) - { - int rc; - struct record *cnode; - struct record *r = recs[i]; - - command_puts(s, r->merge_key); - for (rc = 1, cnode = r->next_cluster; cnode; cnode = cnode->next_cluster, rc++) - ; - if (rc > 1) - { - char buf[256]; - sprintf(buf, " (%d records)", rc); - command_puts(s, buf); - } - command_puts(s, "\n"); - } - nmem_destroy(nmem_show); - return 1; -} - -static int cmd_stat(struct command_session *s, char **argv, int argc) -{ - char buf[1024]; - struct statistics stat; - - statistics(s->psession, &stat); - sprintf(buf, "Number of connections: %d\n", stat.num_clients); - command_puts(s, buf); - if (stat.num_no_connection) - { - sprintf(buf, "#No_connection: %d\n", stat.num_no_connection); - command_puts(s, buf); - } - if (stat.num_connecting) - { - sprintf(buf, "#Connecting: %d\n", stat.num_connecting); - command_puts(s, buf); - } - if (stat.num_initializing) - { - sprintf(buf, "#Initializing: %d\n", stat.num_initializing); - command_puts(s, buf); - } - if (stat.num_searching) - { - sprintf(buf, "#Searching: %d\n", stat.num_searching); - command_puts(s, buf); - } - if (stat.num_presenting) - { - sprintf(buf, "#Ppresenting: %d\n", stat.num_presenting); - command_puts(s, buf); - } - if (stat.num_idle) - { - sprintf(buf, "#Idle: %d\n", stat.num_idle); - command_puts(s, buf); - } - if (stat.num_failed) - { - sprintf(buf, "#Failed: %d\n", stat.num_failed); - command_puts(s, buf); - } - if (stat.num_error) - { - sprintf(buf, "#Error: %d\n", stat.num_error); - command_puts(s, buf); - } - return 1; -} - -static struct { - char *cmd; - int (*fun)(struct command_session *s, char *argv[], int argc); -} cmd_array[] = { - {"quit", cmd_quit}, -#ifdef GAGA - {"load", cmd_load}, -#endif - {"find", cmd_search}, - {"ht", cmd_hitsbytarget}, - {"stat", cmd_stat}, - {"show", cmd_show}, - {0,0} -}; - -void command_command(struct command_session *s, char *command) -{ - char *p; - char *argv[20]; - int argc = 0; - int i; - int res = -1; - - p = command; - while (*p) - { - while (isspace(*p)) - p++; - if (!*p) - break; - argv[argc++] = p; - while (*p && !isspace(*p)) - p++; - if (!*p) - break; - *(p++) = '\0'; - } - if (argc) { - for (i = 0; cmd_array[i].cmd; i++) - { - if (!strcmp(cmd_array[i].cmd, argv[0])) { - res = (cmd_array[i].fun)(s, argv, argc); - - break; - } - } - if (res < 0) { - command_puts(s, "Unknown command.\n"); - command_prompt(s); - } - else if (res == 1) { - command_prompt(s); - } - } - else - command_prompt(s); - -} - - -static void command_io(IOCHAN i, int event) -{ - int res; - char buf[1024]; - struct command_session *s; - - s = iochan_getdata(i); - - - switch (event) - { - case EVENT_INPUT: - res = read(iochan_getfd(i), buf, 1024); - if (res <= 0) - { - yaz_log(YLOG_WARN|YLOG_ERRNO, "read command"); - close(iochan_getfd(i)); - iochan_destroy(i); - command_destroy(s); - return; - } - if (!index(buf, '\n')) { - yaz_log(YLOG_WARN|YLOG_ERRNO, "Did not receive complete command"); - close(iochan_getfd(i)); - iochan_destroy(i); - command_destroy(s); - return; - } - buf[res] = '\0'; - command_command(s, buf); - break; - case EVENT_OUTPUT: - if (!s->outbuflen || s->outbufwrit < 0) - { - yaz_log(YLOG_WARN, "Called with outevent but no data"); - iochan_clearflag(i, EVENT_OUTPUT); - } - else - { - res = write(iochan_getfd(i), s->outbuf + s->outbufwrit, s->outbuflen - - s->outbufwrit); - if (res < 0) { - yaz_log(YLOG_WARN|YLOG_ERRNO, "write command"); - close(iochan_getfd(i)); - iochan_destroy(i); - command_destroy(s); - } - else - { - s->outbufwrit += res; - if (s->outbufwrit >= s->outbuflen) - { - s->outbuflen = s->outbufwrit = 0; - iochan_clearflag(i, EVENT_OUTPUT); - } - } - } - break; - default: - yaz_log(YLOG_WARN, "Bad voodoo on socket"); - } -} - -void command_puts(struct command_session *s, const char *buf) -{ - int len = strlen(buf); - memcpy(s->outbuf + s->outbuflen, buf, len); - s->outbuflen += len; - iochan_setflag(s->channel, EVENT_OUTPUT); -} - -void command_prompt(struct command_session *s) -{ - command_puts(s, "Pazpar2> "); -} - - -/* Accept a new command connection */ -static void command_accept(IOCHAN i, int event) -{ - struct sockaddr_in addr; - int fd = iochan_getfd(i); - socklen_t len; - int s; - IOCHAN c; - struct command_session *ses; - int flags; - - len = sizeof addr; - if ((s = accept(fd, (struct sockaddr *) &addr, &len)) < 0) - { - yaz_log(YLOG_WARN|YLOG_ERRNO, "accept"); - return; - } - if ((flags = fcntl(s, F_GETFL, 0)) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl"); - if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2"); - - yaz_log(YLOG_LOG, "New command connection"); - c = iochan_create(s, command_io, EVENT_INPUT | EVENT_EXCEPT); - - ses = xmalloc(sizeof(*ses)); - ses->outbuf = xmalloc(50000); - ses->outbuflen = 0; - ses->outbufwrit = 0; - ses->channel = c; - ses->psession = new_session(); - iochan_setdata(c, ses); - - command_puts(ses, "Welcome to pazpar2\n\n"); - command_prompt(ses); - - c->next = channel_list; - channel_list = c; -} - -void command_destroy(struct command_session *s) { - xfree(s->outbuf); - xfree(s); -} - -/* Create a command-channel listener */ -void command_init(int port) -{ - IOCHAN c; - int l; - struct protoent *p; - struct sockaddr_in myaddr; - int one = 1; - - yaz_log(YLOG_LOG, "Command port is %d", port); - if (!(p = getprotobyname("tcp"))) { - abort(); - } - if ((l = socket(PF_INET, SOCK_STREAM, p->p_proto)) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "socket"); - if (setsockopt(l, SOL_SOCKET, SO_REUSEADDR, (char*) - &one, sizeof(one)) < 0) - abort(); - - bzero(&myaddr, sizeof myaddr); - myaddr.sin_family = AF_INET; - myaddr.sin_addr.s_addr = INADDR_ANY; - myaddr.sin_port = htons(port); - if (bind(l, (struct sockaddr *) &myaddr, sizeof myaddr) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "bind"); - if (listen(l, SOMAXCONN) < 0) - yaz_log(YLOG_FATAL|YLOG_ERRNO, "listen"); - - c = iochan_create(l, command_accept, EVENT_INPUT | EVENT_EXCEPT); - //iochan_setdata(c, &l); - c->next = channel_list; - channel_list = c; -} - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ diff --git a/src/command.h b/src/command.h deleted file mode 100644 index 25e5b99..0000000 --- a/src/command.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef COMMAND_H -#define COMMAND_H - -void command_init(int port); - -#endif diff --git a/src/config.h b/src/config.h index 53c1de6..e3dda3d 100644 --- a/src/config.h +++ b/src/config.h @@ -11,9 +11,37 @@ struct conf_termlist struct conf_termlist *next; }; +// Describes known metadata elements and how they are to be manipulated +struct conf_metadata +{ + char *name; // The name of this element. Output by normalization stylesheet + int brief; // Is this element to be returned in the brief format? + enum + { + Metadata_type_generic, // Generic text field + Metadata_type_integer, // Integer type + Metadata_type_year // A year + } type; + enum + { + Metadata_sortkey_no, // This is not to be used as a sortkey + Metadata_sortkey_numeric, // Standard numerical sorting + Metadata_sortkey_range, // Range sorting (pick lowest or highest) + Metadata_sortkey_skiparticle // Skip leading article when sorting + } sortkey; + enum + { + Metadata_merge_no, // Don't merge + Metadata_merge_unique, // Include unique elements in merged block + Metadata_merge_longest, // Include the longest (strlen) value + Metadata_merge_range // Store value as a range of lowest-highest + } merge; +}; + struct conf_service { struct conf_termlist *termlists; + struct conf_metadata *metadata; }; struct conf_server diff --git a/src/http.c b/src/http.c index 5430f6e..db811b2 100644 --- a/src/http.c +++ b/src/http.c @@ -1,5 +1,5 @@ /* - * $Id: http.c,v 1.4 2006-12-21 04:27:17 quinn Exp $ + * $Id: http.c,v 1.5 2007-01-06 04:54:58 quinn Exp $ */ #include @@ -19,7 +19,6 @@ #include #include -#include "command.h" #include "util.h" #include "eventl.h" #include "pazpar2.h" diff --git a/src/http_command.c b/src/http_command.c index 25871a0..9a14705 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.6 2007-01-04 20:00:58 quinn Exp $ + * $Id: http_command.c,v 1.7 2007-01-06 04:54:58 quinn Exp $ */ #include @@ -13,7 +13,6 @@ #include -#include "command.h" #include "util.h" #include "eventl.h" #include "pazpar2.h" diff --git a/src/pazpar2.c b/src/pazpar2.c index fa2d51f..ea3af8a 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.16 2007-01-06 03:02:47 quinn Exp $ */; +/* $Id: pazpar2.c,v 1.17 2007-01-06 04:54:58 quinn Exp $ */; #include #include @@ -27,7 +27,6 @@ #include "pazpar2.h" #include "eventl.h" -#include "command.h" #include "http.h" #include "termlists.h" #include "reclists.h" @@ -1275,17 +1274,13 @@ int main(int argc, char **argv) yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0); - while ((ret = options("f:x:c:h:p:C:s:d", argv, argc, &arg)) != -2) + while ((ret = options("f:x:h:p:C:s:d", argv, argc, &arg)) != -2) { switch (ret) { case 'f': if (!read_config(arg)) exit(1); break; - case 'c': - command_init(atoi(arg)); - setport++; - break; case 'h': http_init(arg); setport++; @@ -1306,7 +1301,6 @@ int main(int argc, char **argv) fprintf(stderr, "Usage: pazpar2\n" " -f configfile\n" " -h [host:]port (REST protocol listener)\n" - " -c cmdport (telnet-style)\n" " -C cclconfig\n" " -s simpletargetfile\n" " -p hostname[:portno] (HTTP proxy)\n"); @@ -1316,7 +1310,7 @@ int main(int argc, char **argv) if (!setport) { - fprintf(stderr, "Set command port with -h or -c\n"); + fprintf(stderr, "Set command port with -h\n"); exit(1); } diff --git a/src/pazpar2.h b/src/pazpar2.h index 6bb709a..4ee4c0f 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -20,11 +20,25 @@ struct record; struct client; +struct record_metadata +{ + union + { + char *text; + struct { + int first; + int last; + } year_range; + int year; + } interpretation; +}; + struct record { struct client *client; + char *title; int target_offset; char *merge_key; - char *title; + struct record_metadata *md; int relevance; int *term_frequency_vec; struct record *next_cluster; -- 1.7.10.4