+};
+
+struct connection;
+
+// Represents a host (irrespective of databases)
+struct host {
+ char *hostport;
+ char *ipport;
+ struct connection *connections; // All connections to this
+ struct host *next;
+};
+
+// Represents a (virtual) database on a host
+struct database {
+ struct host *host;
+ char *url;
+ char databases[MAX_DATABASES][128];
+ int errors;
+ struct database *next;
+};
+
+struct client;
+
+// Represents a physical, reusable connection to a remote Z39.50 host
+struct connection {
+ IOCHAN iochan;
+ COMSTACK link;
+ struct host *host;
+ struct client *client;
+ char *ibuf;
+ int ibufsize;
+ enum {
+ Conn_Connecting,
+ Conn_Open,
+ Conn_Waiting,
+ } state;
+ struct connection *next;
+};
+
+// Represents client state for a connection to one search target
+struct client {
+ struct database *database;
+ struct connection *connection;
+ struct session *session;
+ int hits;
+ int records;
+ int setno;
+ int requestid; // ID of current outstanding request
+ int diagnostic;
+ enum client_state
+ {
+ Client_Connecting,
+ Client_Connected,
+ Client_Idle,
+ Client_Initializing,
+ Client_Searching,
+ Client_Presenting,
+ Client_Error,
+ Client_Failed,
+ Client_Disconnected,
+ Client_Stopped
+ } state;
+ struct client *next;
+};
+
+// End-user session
+struct session {
+ struct client *clients;
+ int requestid;
+ char query[1024];
+ NMEM nmem; // Nmem for each operation (i.e. search)
+ WRBUF wrbuf; // Wrbuf for scratch(i.e. search)
+ struct termlist *termlist;
+ struct relevance *relevance;
+ struct reclist *reclist;
+ int total_hits;
+ int total_records;