X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=4262079837761f2a4ed61449ae897b9fc840cece;hb=30cfc59b71c25923e2e9cfb63c310c095bb3b6c1;hp=c979041d83f0a881e3f9dcecc662188626a7c0e3;hpb=2ae069a121b2105132a7e00702a1b8e439312981;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index c979041..4262079 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,26 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.84 1999-06-01 14:29:11 adam + * Revision 1.90 1999-11-30 13:47:11 adam + * Improved installation. Moved header files to include/yaz. + * + * Revision 1.89 1999/11/04 14:58:44 adam + * Added status elements for backend delete result set handler. + * Updated delete result result set command for client. + * + * Revision 1.88 1999/10/11 10:00:29 adam + * Modified printing of records. + * + * Revision 1.87 1999/08/27 09:40:32 adam + * Renamed logf function to yaz_log. Removed VC++ project files. + * + * Revision 1.86 1999/07/06 12:13:35 adam + * Added "schema" command. + * + * Revision 1.85 1999/06/16 11:55:24 adam + * Added APDU log to client. + * + * Revision 1.84 1999/06/01 14:29:11 adam * Work on Extended Services. * * Revision 1.83 1999/05/26 15:24:26 adam @@ -282,22 +301,21 @@ #include #include -#include +#include -#include -#include +#include #ifdef USE_XTIMOSI -#include +#include #endif -#include -#include -#include +#include +#include +#include -#include +#include #if CCL2RPN -#include +#include #endif #if HAVE_READLINE_READLINE_H @@ -310,6 +328,7 @@ #define C_PROMPT "Z> " static ODR out, in, print; /* encoding and decoding streams */ +static FILE *apdu_file = 0; static COMSTACK conn = 0; /* our z-association */ static Z_IdAuthentication *auth = 0; /* our current auth definition */ static char *databaseNames[128]; @@ -323,6 +342,7 @@ static Z_ElementSetNames *elementSetNames = 0; static int setno = 1; /* current set offset */ static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */ static enum oid_value recordsyntax = VAL_USMARC; +static enum oid_value schema = VAL_NONE; static int sent_close = 0; static NMEM session_mem = NULL; /* memory handle for init-response */ static Z_InitResponse *session = 0; /* session parameters */ @@ -353,6 +373,11 @@ static void send_apdu(Z_APDU *a) odr_perror(out, "Encoding APDU"); exit(1); } + if (apdu_file) + { + z_APDU(print, &a, 0, 0); + odr_reset(print); + } buf = odr_getbuf(out, &len, 0); if (cs_put(conn, buf, len) < 0) { @@ -403,6 +428,7 @@ static void send_initRequest() ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3); *req->maximumRecordSize = 1024*1024; + *req->preferredMessageSize = 1024*1024; req->idAuthentication = auth; @@ -647,6 +673,19 @@ static void display_grs1(Z_GenericRecord *r, int level) } } +static void print_record(const unsigned char *buf, size_t len) +{ + size_t i; + for (i = 0; i= 32) || strchr ("\n\r\t\f", buf[i])) + fputc (buf[i], stdout); + else + printf ("\\X%02X", buf[i]); + /* add newline if not already added ... */ + if (i <= 0 || buf[i-1] != '\n') + fputc ('\n', stdout); +} + static void display_record(Z_DatabaseRecord *p) { Z_External *r = (Z_External*) p; @@ -699,21 +738,13 @@ static void display_record(Z_DatabaseRecord *p) } } if (ent && ent->value == VAL_SOIF) - printf("%.*s", r->u.octet_aligned->len, r->u.octet_aligned->buf); + print_record(r->u.octet_aligned->buf, r->u.octet_aligned->len); else if (r->which == Z_External_octet && p->u.octet_aligned->len) { const char *octet_buf = (char*)p->u.octet_aligned->buf; if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML || ent->value == VAL_HTML) - { - int i; - for (i = 0; iu.octet_aligned->len; i++) - if (octet_buf[i] > 126 || octet_buf[i] < 7) - printf ("<%02X>", octet_buf[i]); - else - fputc (octet_buf[i], stdout); - printf ("\n"); - } + print_record(octet_buf, p->u.octet_aligned->len); else marc_display (octet_buf, NULL); if (marcdump) @@ -726,7 +757,7 @@ static void display_record(Z_DatabaseRecord *p) printf("Expecting single SUTRS type for SUTRS.\n"); return; } - printf("%.*s", r->u.sutrs->len, r->u.sutrs->buf); + print_record(r->u.sutrs->buf, r->u.sutrs->len); } else if (ent && ent->value == VAL_GRS1) { @@ -828,18 +859,35 @@ static void display_records(Z_Records *p) static int send_deleteResultSetRequest(char *arg) { + char names[8][32]; + int i; + Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest); Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest; req->referenceId = set_refid (out); - req->num_resultSetList = 1; - req->resultSetList = (char **) - odr_malloc (out, sizeof(*req->resultSetList)); - *req->resultSetList = arg; + req->num_resultSetList = + sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s", + names[0], names[1], names[2], names[3], + names[4], names[5], names[6], names[7]); + req->deleteFunction = (int *) odr_malloc (out, sizeof(*req->deleteFunction)); - *req->deleteFunction = Z_DeleteRequest_list; + if (req->num_resultSetList > 0) + { + *req->deleteFunction = Z_DeleteRequest_list; + req->resultSetList = (char **) + odr_malloc (out, sizeof(*req->resultSetList)* + req->num_resultSetList); + for (i = 0; inum_resultSetList; i++) + req->resultSetList[i] = names[i]; + } + else + { + *req->deleteFunction = Z_DeleteRequest_all; + req->resultSetList = 0; + } send_apdu(apdu); printf("Sent deleteResultSetRequest.\n"); @@ -1313,11 +1361,6 @@ static int cmd_find(char *arg) static int cmd_delete(char *arg) { - if (!*arg) - { - printf("Delete what?\n"); - return 0; - } if (!conn) { printf("Not connected yet\n"); @@ -1415,9 +1458,53 @@ static int send_presentRequest(char *arg) prefsyn.proto = protocol; prefsyn.oclass = CLASS_RECSYN; prefsyn.value = recordsyntax; - req->preferredRecordSyntax = oid_ent_to_oid(&prefsyn, oid); - - if (elementSetNames) + req->preferredRecordSyntax = + odr_oiddup (out, oid_ent_to_oid(&prefsyn, oid)); + + if (schema != VAL_NONE) + { + oident prefschema; + + prefschema.proto = protocol; + prefschema.oclass = CLASS_SCHEMA; + prefschema.value = schema; + + req->recordComposition = &compo; + compo.which = Z_RecordComp_complex; + compo.u.complex = (Z_CompSpec *) + odr_malloc(out, sizeof(*compo.u.complex)); + compo.u.complex->selectAlternativeSyntax = (bool_t *) + odr_malloc(out, sizeof(bool_t)); + *compo.u.complex->selectAlternativeSyntax = 0; + + compo.u.complex->generic = (Z_Specification *) + odr_malloc(out, sizeof(*compo.u.complex->generic)); + compo.u.complex->generic->schema = (Odr_oid *) + odr_oiddup(out, oid_ent_to_oid(&prefschema, oid)); + if (!compo.u.complex->generic->schema) + { + /* OID wasn't a schema! Try record syntax instead. */ + prefschema.oclass = CLASS_RECSYN; + compo.u.complex->generic->schema = (Odr_oid *) + odr_oiddup(out, oid_ent_to_oid(&prefschema, oid)); + } + if (!elementSetNames) + compo.u.complex->generic->elementSpec = 0; + else + { + compo.u.complex->generic->elementSpec = (Z_ElementSpec *) + odr_malloc(out, sizeof(Z_ElementSpec)); + compo.u.complex->generic->elementSpec->which = + Z_ElementSpec_elementSetName; + compo.u.complex->generic->elementSpec->u.elementSetName = + elementSetNames->u.generic; + } + compo.u.complex->num_dbSpecific = 0; + compo.u.complex->dbSpecific = 0; + compo.u.complex->num_recordSyntax = 0; + compo.u.complex->recordSyntax = 0; + } + else if (elementSetNames) { req->recordComposition = &compo; compo.which = Z_RecordComp_simple; @@ -1739,6 +1826,21 @@ void process_sortResponse(Z_SortResponse *res) #endif } +void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res) +{ + printf("Got deleteResultSetResponse status=%d\n", + *res->deleteOperationStatus); + if (res->deleteListStatuses) + { + int i; + for (i = 0; i < res->deleteListStatuses->num; i++) + { + printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id, + *res->deleteListStatuses->elements[i]->status); + } + } +} + int cmd_sort_generic(char *arg, int newset) { if (!conn) @@ -1793,6 +1895,22 @@ int cmd_scan(char *arg) return 2; } +int cmd_schema(char *arg) +{ + if (!arg || !*arg) + { + schema = VAL_NONE; + return 1; + } + schema = oid_getvalbyname (arg); + if (schema == VAL_NONE) + { + printf ("unknown schema\n"); + return 0; + } + return 1; +} + int cmd_format(char *arg) { if (!arg || !*arg) @@ -1816,8 +1934,8 @@ int cmd_elements(char *arg) if (!arg || !*arg) { - printf("Usage: elements \n"); - return 0; + elementSetNames = 0; + return 1; } strcpy(what, arg); esn.which = Z_ElementSetNames_generic; @@ -1848,7 +1966,7 @@ int cmd_querytype (char *arg) { if (!strcmp (arg, "ccl")) queryType = QueryType_CCL; - else if (!strcmp (arg, "prefix")) + else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn")) queryType = QueryType_Prefix; #if CCL2RPN else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn")) @@ -1909,6 +2027,8 @@ static void initialize(void) exit(1); } setvbuf(stdout, 0, _IONBF, 0); + if (apdu_file) + odr_setprint(print, apdu_file); #if CCL2RPN bibset = ccl_qual_mk (); @@ -1946,6 +2066,7 @@ static int client(int wait) {"setnames", cmd_setnames, ""}, {"cancel", cmd_cancel, ""}, {"format", cmd_format, ""}, + {"schema", cmd_schema, ""}, {"elements", cmd_elements, ""}, {"close", cmd_close, ""}, {"attributeset", cmd_attributeset, ""}, @@ -2061,14 +2182,12 @@ static int client(int wait) fprintf(stderr, "---------\n"); exit(1); } -#if 0 - if (!z_APDU(print, &apdu, 0)) + if (apdu_file && !z_APDU(print, &apdu, 0, 0)) { odr_perror(print, "Failed to print incoming APDU"); odr_reset(print); continue; } -#endif switch(apdu->which) { case Z_APDU_initResponse: @@ -2107,9 +2226,8 @@ static int client(int wait) (apdu->u.resourceControlRequest); break; case Z_APDU_deleteResultSetResponse: - printf("Got deleteResultSetResponse status=%d\n", - *apdu->u.deleteResultSetResponse-> - deleteOperationStatus); + process_deleteResultSetResponse(apdu->u. + deleteResultSetResponse); break; default: printf("Received unknown APDU type (%d).\n", @@ -2130,7 +2248,7 @@ int main(int argc, char **argv) int ret; int opened = 0; - while ((ret = options("m:v:", argv, argc, &arg)) != -2) + while ((ret = options("a:m:v:", argv, argc, &arg)) != -2) { switch (ret) { @@ -2149,11 +2267,18 @@ int main(int argc, char **argv) exit (1); } break; + case 'a': + if (!strcmp(arg, "-")) + apdu_file=stderr; + else + apdu_file=fopen(arg, "a"); + break; case 'v': log_init (log_mask_str(arg), "", NULL); break; default: - fprintf (stderr, "Usage: %s [-m ] []\n", + fprintf (stderr, "Usage: %s [-m ] [ -m ] " + "[]\n", prog); exit (1); }