X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fconnection.c;h=487f511ddd5a50d43c13f9de33959b9324953f91;hb=d4bec7aba21f3f7adbbb139685993b0cd50f04ec;hp=77bd8e77d00c1df6a9b3250d63842c1d7ad89f8b;hpb=2c3ba8ff22f015f6832180401bd46b4ea54967d7;p=pazpar2-moved-to-github.git diff --git a/src/connection.c b/src/connection.c index 77bd8e7..487f511 100644 --- a/src/connection.c +++ b/src/connection.c @@ -71,7 +71,6 @@ struct connection { struct client *client; char *ibuf; int ibufsize; - char *authentication; // Empty string or authentication string if set char *zproxy; enum { Conn_Resolving, @@ -83,15 +82,16 @@ struct connection { static struct connection *connection_freelist = 0; +static int connection_connect(struct connection *con); + static int connection_is_idle(struct connection *co) { ZOOM_connection link = co->link; - int event = ZOOM_connection_peek_event(link); + int event; - if (co->state != Conn_Open) + if (co->state != Conn_Open || !link) return 0; - link = co->link; event = ZOOM_connection_peek_event(link); if (event == ZOOM_EVENT_NONE || event == ZOOM_EVENT_END) @@ -135,10 +135,8 @@ static void remove_connection_from_host(struct connection *con) void connection_continue(struct connection *co) { -#if 1 yaz_log(YLOG_LOG, "connection_continue"); iochan_setevent(co->iochan, EVENT_OUTPUT); -#endif } // Close connection and recycle structure @@ -167,7 +165,7 @@ void connection_destroy(struct connection *co) // Creates a new connection for client, associated with the host of // client's database -struct connection *connection_create(struct client *cl) +static struct connection *connection_create(struct client *cl) { struct connection *new; struct host *host = client_get_host(cl); @@ -184,7 +182,6 @@ struct connection *connection_create(struct client *cl) new->next = new->host->connections; new->host->connections = new; new->client = cl; - new->authentication = ""; new->zproxy = 0; client_set_connection(cl, new); new->link = 0; @@ -320,7 +317,7 @@ void connect_resolver_host(struct host *host) } } -struct host *connection_get_host(struct connection *con) +static struct host *connection_get_host(struct connection *con) { return con->host; } @@ -347,12 +344,15 @@ static int maskfun(IOCHAN c) return ZOOM_connection_get_mask(co->link); } -int connection_connect(struct connection *con) +static int connection_connect(struct connection *con) { ZOOM_connection link = 0; struct host *host = connection_get_host(con); ZOOM_options zoptions = ZOOM_options_create(); - char *auth; + const char *auth; + const char *sru; + const char *sru_version = 0; + char ipport[512] = ""; struct session_database *sdb = client_get_database(con->client); const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY); @@ -374,8 +374,13 @@ int connection_connect(struct connection *con) if (apdulog && *apdulog) ZOOM_options_set(zoptions, "apdulog", apdulog); - if ((auth = (char*) session_setting_oneval(sdb, PZ_AUTHENTICATION))) + if ((auth = session_setting_oneval(sdb, PZ_AUTHENTICATION))) ZOOM_options_set(zoptions, "user", auth); + if ((sru = session_setting_oneval(sdb, PZ_SRU)) && *sru) + ZOOM_options_set(zoptions, "sru", sru); + if ((sru_version = session_setting_oneval(sdb, PZ_SRU_VERSION)) + && *sru_version) + ZOOM_options_set(zoptions, "sru_version", sru_version); if (!(link = ZOOM_connection_create(zoptions))) { @@ -383,7 +388,21 @@ int connection_connect(struct connection *con) ZOOM_options_destroy(zoptions); return -1; } - ZOOM_connection_connect(link, host->ipport, 0); + + if (sru && *sru) + strcpy(ipport, "http://"); + strcat(ipport, host->ipport); + /* deal with SRU path here because databaseName option is not read in + ZOOM in SRU mode */ + if (sru && *sru) + { + if (*sdb->database->databases[0]) + { + strcat(ipport, "/"); + strcat(ipport, sdb->database->databases[0]); + } + } + ZOOM_connection_connect(link, ipport, 0); con->link = link; con->iochan = iochan_create(0, connection_handler, 0); @@ -407,11 +426,6 @@ const char *connection_get_url(struct connection *co) return client_get_url(co->client); } -void connection_set_authentication(struct connection *co, char *auth) -{ - co->authentication = auth; -} - // Ensure that client has a connection associated int client_prep_connection(struct client *cl) { @@ -435,9 +449,9 @@ int client_prep_connection(struct client *cl) for (co = host->connections; co; co = co->next) if (connection_is_idle(co) && (!co->client || client_get_session(co->client) != se) && - !strcmp(co->authentication, - session_setting_oneval(client_get_database(cl), - PZ_AUTHENTICATION))) + !strcmp(ZOOM_connection_option_get(co->link, "user"), + session_setting_oneval(client_get_database(cl), + PZ_AUTHENTICATION))) { if (zproxy == 0 && co->zproxy == 0) break; @@ -460,13 +474,6 @@ int client_prep_connection(struct client *cl) return 0; } -// DELETEME - - -int connection_send_apdu(struct connection *co, Z_APDU *a){return 10;} - - - /* * Local variables: * c-basic-offset: 4