📄 client.c
字号:
*cp1 = ' '; num_databaseNames++; if (!*cp) break; arg = cp+1; } if (num_databaseNames == 0) { num_databaseNames = 1; databaseNames[0] = xstrdup(""); } return 1;}static int cmd_base(const char *arg){ if (!*arg) { printf("Usage: base <database> <database> ...\n"); return 0; } return set_base(arg);}void cmd_open_remember_last_open_command(const char* arg, char* new_open_command){ if(last_open_command != arg) { if(last_open_command) xfree(last_open_command); last_open_command = xstrdup(new_open_command); }}int session_connect(const char *arg){ void *add; char type_and_host[101]; const char *basep = 0; if (conn) { cs_close (conn); conn = NULL; if (session_mem) { nmem_destroy (session_mem); session_mem = NULL; } } cs_get_host_args(arg, &basep); strncpy(type_and_host, arg, sizeof(type_and_host)-1); type_and_host[sizeof(type_and_host)-1] = '\0'; cmd_open_remember_last_open_command(arg,type_and_host); if (yazProxy) conn = cs_create_host(yazProxy, 1, &add); else conn = cs_create_host(arg, 1, &add); if (!conn) { printf ("Couldn't create comstack\n"); return 0; }#if HAVE_XML2#else if (conn->protocol == PROTO_HTTP) { printf ("SRW/HTTP not enabled in this YAZ\n"); cs_close(conn); conn = 0; return 0; }#endif protocol = conn->protocol; if (conn->protocol == PROTO_HTTP) set_base(""); else set_base("Default"); printf("Connecting..."); fflush(stdout); if (cs_connect(conn, add) < 0) { printf ("error = %s\n", cs_strerror(conn)); if (conn->cerrno == CSYSERR) { char msg[256]; yaz_strerror(msg, sizeof(msg)); printf ("%s\n", msg); } cs_close(conn); conn = 0; return 0; } printf("OK.\n"); if (basep && *basep) set_base (basep); if (protocol == PROTO_Z3950) { send_initRequest(type_and_host); return 2; } return 0;}int cmd_open(const char *arg){ static char cur_host[200]; if (arg) { strncpy (cur_host, arg, sizeof(cur_host)-1); cur_host[sizeof(cur_host)-1] = 0; } return session_connect(cur_host);}void try_reconnect() { char* open_command; if(!( auto_reconnect && last_open_command) ) return ; open_command = (char *) xmalloc (strlen(last_open_command)+6); strcpy (open_command, "open "); strcat (open_command, last_open_command); process_cmd_line(open_command); xfree(open_command); }int cmd_authentication(const char *arg){ static Z_IdAuthentication au; static char user[40], group[40], pass[40]; static Z_IdPass idPass; int r; if (!*arg) { printf("Auth field set to null\n"); auth = 0; return 1; } r = sscanf (arg, "%39s %39s %39s", user, group, pass); if (r == 0) { printf("Authentication set to null\n"); auth = 0; } if (r == 1) { auth = &au; if (!strcmp(user, "-")) { au.which = Z_IdAuthentication_anonymous; printf("Authentication set to Anonymous\n"); } else { au.which = Z_IdAuthentication_open; au.u.open = user; printf("Authentication set to Open (%s)\n", user); } } if (r == 2) { auth = &au; au.which = Z_IdAuthentication_idPass; au.u.idPass = &idPass; idPass.groupId = NULL; idPass.userId = user; idPass.password = group; printf("Authentication set to User (%s), Pass (%s)\n", user, group); } if (r == 3) { auth = &au; au.which = Z_IdAuthentication_idPass; au.u.idPass = &idPass; idPass.groupId = group; idPass.userId = user; idPass.password = pass; printf("Authentication set to User (%s), Group (%s), Pass (%s)\n", user, group, pass); } return 1;}/* SEARCH SERVICE ------------------------------ */static void display_record(Z_External *r);static void print_record(const unsigned char *buf, size_t len){ size_t i = len; print_stringn (buf, len); /* add newline if not already added ... */ if (i <= 0 || buf[i-1] != '\n') printf ("\n");}static void display_record(Z_External *r){ oident *ent = oid_getentbyoid(r->direct_reference); record_last = r; /* * Tell the user what we got. */ if (r->direct_reference) { printf("Record type: "); if (ent) printf("%s\n", ent->desc); else if (!odr_oid(print, &r->direct_reference, 0, 0)) { odr_perror(print, "print oid"); odr_reset(print); } } /* Check if this is a known, ASN.1 type tucked away in an octet string */ if (ent && r->which == Z_External_octet) { Z_ext_typeent *type = z_ext_getentbyref(ent->value); void *rr; if (type) { /* * Call the given decoder to process the record. */ odr_setbuf(in, (char*)r->u.octet_aligned->buf, r->u.octet_aligned->len, 0); if (!(*type->fun)(in, (char **)&rr, 0, 0)) { odr_perror(in, "Decoding constructed record."); fprintf(stdout, "[Near %d]\n", odr_offset(in)); fprintf(stdout, "Packet dump:\n---------\n"); odr_dumpBER(stdout, (char*)r->u.octet_aligned->buf, r->u.octet_aligned->len); fprintf(stdout, "---------\n"); /* note just ignores the error ant print the bytes form the octet_aligned later */ } else { /* * Note: we throw away the original, BER-encoded record here. * Do something else with it if you want to keep it. */ r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */ r->which = type->what; } } } if (ent && ent->oclass != CLASS_RECSYN) return; if (ent && ent->value == VAL_SOIF) print_record((const unsigned char *) r->u.octet_aligned->buf, r->u.octet_aligned->len); else if (r->which == Z_External_octet) { const char *octet_buf = (char*)r->u.octet_aligned->buf; if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML || ent->value == VAL_HTML) { print_record((const unsigned char *) octet_buf, r->u.octet_aligned->len); } else if (ent->value == VAL_POSTSCRIPT) { int size = r->u.octet_aligned->len; if (size > 100) size = 100; print_record((const unsigned char *) octet_buf, size); } else { if ( #if AVOID_MARC_DECODE /* primitive check for a marc OID 5.1-29 except 16 */ ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 && ent->oidsuffix[1] != 16#else 1#endif ) { char *result; int rlen; yaz_iconv_t cd = 0; yaz_marc_t mt = yaz_marc_create(); if (yaz_marc_decode_buf(mt, octet_buf,r->u.octet_aligned->len, &result, &rlen)> 0) { char *from = 0; if (marcCharset && !strcmp(marcCharset, "auto")) { if (ent->value == VAL_USMARC) { if (octet_buf[9] == 'a') from = "UTF-8"; else from = "MARC-8"; } else from = "ISO-8859-1"; } else if (marcCharset) from = marcCharset; if (outputCharset && from) { cd = yaz_iconv_open(outputCharset, from); printf ("convert from %s to %s", from, outputCharset); if (!cd) printf (" unsupported\n"); else printf ("\n"); } if (!cd) fwrite (result, 1, rlen, stdout); else { char outbuf[6]; size_t inbytesleft = rlen; const char *inp = result; while (inbytesleft) { size_t outbytesleft = sizeof(outbuf); char *outp = outbuf; size_t r; r = yaz_iconv (cd, (char**) &inp, &inbytesleft, &outp, &outbytesleft); if (r == (size_t) (-1)) { int e = yaz_iconv_error(cd); if (e != YAZ_ICONV_E2BIG) break; } fwrite (outbuf, outp - outbuf, 1, stdout); } } } else { printf ("bad MARC. Dumping as it is:\n"); print_record((const unsigned char*) octet_buf, r->u.octet_aligned->len); } yaz_marc_destroy(mt); if (cd) yaz_iconv_close(cd); } else { print_record((const unsigned char*) octet_buf, r->u.octet_aligned->len); } } if (marc_file) fwrite (octet_buf, 1, r->u.octet_aligned->len, marc_file); } else if (ent && ent->value == VAL_SUTRS) { if (r->which != Z_External_sutrs) { printf("Expecting single SUTRS type for SUTRS.\n"); return; } print_record(r->u.sutrs->buf, r->u.sutrs->len); } else if (ent && ent->value == VAL_GRS1) { WRBUF w; if (r->which != Z_External_grs1) { printf("Expecting single GRS type for GRS.\n"); return; } w = wrbuf_alloc(); yaz_display_grs1(w, r->u.grs1, 0); puts (wrbuf_buf(w)); wrbuf_free(w, 1); } else if ( /* OPAC display not complete yet .. */ ent && ent->value == VAL_OPAC) { int i; if (r->u.opac->bibliographicRecord) display_record(r->u.opac->bibliographicRecord); for (i = 0; i<r->u.opac->num_holdingsData; i++) { Z_HoldingsRecord *h = r->u.opac->holdingsData[i]; if (h->which == Z_HoldingsRecord_marcHoldingsRecord) { printf ("MARC holdings %d\n", i); display_record(h->u.marcHoldingsRecord); } else if (h->which == Z_HoldingsRecord_holdingsAndCirc) { int j; Z_HoldingsAndCircData *data = h->u.holdingsAndCirc; printf ("Data holdings %d\n", i); if (data->typeOfRecord) printf ("typeOfRecord: %s\n", data->typeOfRecord); if (data->encodingLevel) printf ("encodingLevel: %s\n", data->encodingLevel); if (data->receiptAcqStatus) printf ("receiptAcqStatus: %s\n", data->receiptAcqStatus); if (data->generalRetention) printf ("generalRetention: %s\n", data->generalRetention); if (data->completeness) printf ("completeness: %s\n", data->completeness); if (data->dateOfReport) printf ("dateOfReport: %s\n", data->dateOfReport); if (data->nucCode) printf ("nucCode: %s\n", data->nucCode); if (data->localLocation) printf ("localLocation: %s\n", data->localLocation); if (data->shelvingLocation) printf ("shelvingLocation: %s\n", data->shelvingLocation); if (data->callNumber) printf ("callNumber: %s\n", data->callNumber); if (data->copyNumber) printf ("copyNumber: %s\n", data->copyNumber); if (data->publicNote) printf ("publicNote: %s\n", data->publicNote); if (data->reproductionNote) printf ("reproductionNote: %s\n", data->reproductionNote); if (data->termsUseRepro) printf ("termsUseRepro: %s\n", data->termsUseRepro); if (data->enumAndChron) printf ("enumAndChron: %s\n", data->enumAndChron); for (j = 0; j<data->num_volumes; j++) { printf ("volume %d\n", j); if (data->volumes[j]->enumeration) printf (" enumeration: %s\n", data->volumes[j]->enumeration); if (data->volumes[j]->chronology) printf (" chronology: %s\n", data->volumes[j]->chronology);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -