* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ir-tcl.c,v $
- * Revision 1.28 1995-05-23 15:34:48 adam
+ * Revision 1.30 1995-05-26 08:54:11 adam
+ * New MARC utilities. Uses prefix query.
+ *
+ * Revision 1.29 1995/05/24 14:10:22 adam
+ * Work on idAuthentication, protocolVersion and options.
+ *
+ * Revision 1.28 1995/05/23 15:34:48 adam
* Many new settings, userInformationField, smallSetUpperBound, etc.
* A number of settings are inherited when ir-set is executed.
* This version is incompatible with the graphical test client (client.tcl).
switch (rl->which)
{
case Z_NamePlusRecord_databaseRecord:
- iso2709_rm (rl->u.marc.rec);
+ free (rl->u.dbrec.buf);
+ rl->u.dbrec.buf = NULL;
break;
case Z_NamePlusRecord_surrogateDiagnostic:
free (rl->u.diag.addinfo);
}
/*
+ * ir_named_bits: get/set named bits
+ */
+int ir_named_bits (struct ir_named_entry *tab, Odr_bitmask *ob,
+ Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ struct ir_named_entry *ti;
+ if (argc > 0)
+ {
+ int no;
+ ODR_MASK_ZERO (ob);
+ for (no = 0; no < argc; no++)
+ {
+ for (ti = tab; ti->name; ti++)
+ if (!strcmp (argv[no], ti->name))
+ {
+ ODR_MASK_SET (ob, ti->pos);
+ break;
+ }
+ if (!ti->name)
+ {
+ Tcl_AppendResult (interp, "Bad bit mask: ", argv[no], NULL);
+ return TCL_ERROR;
+ }
+ }
+ return TCL_OK;
+ }
+ for (ti = tab; ti->name; ti++)
+ if (ODR_MASK_GET (ob, ti->pos))
+ Tcl_AppendElement (interp, ti->name);
+ return TCL_OK;
+}
+
+/*
* ir_strdup: Duplicate string
*/
int ir_strdup (Tcl_Interp *interp, char** p, const char *s)
req.preferredMessageSize = &p->preferredMessageSize;
req.maximumRecordSize = &p->maximumRecordSize;
- req.idAuthentication = p->idAuthentication;
+ if (p->idAuthenticationGroupId)
+ {
+ Z_IdPass *pass = odr_malloc (p->odr_out, sizeof(*pass));
+ Z_IdAuthentication *auth = odr_malloc (p->odr_out, sizeof(*auth));
+
+ auth->which = Z_IdAuthentication_idPass;
+ auth->u.idPass = pass;
+ if (p->idAuthenticationGroupId && *p->idAuthenticationGroupId)
+ {
+ printf ("i");
+ pass->groupId = p->idAuthenticationGroupId;
+ }
+ else
+ pass->groupId = NULL;
+ if (p->idAuthenticationUserId && *p->idAuthenticationUserId)
+ {
+ printf ("u");
+ pass->userId = p->idAuthenticationUserId;
+ }
+ else
+ pass->userId = NULL;
+ if (p->idAuthenticationPassword && *p->idAuthenticationPassword)
+ {
+ printf ("p");
+ pass->password = p->idAuthenticationPassword;
+ }
+ else
+ pass->password = NULL;
+ req.idAuthentication = auth;
+ }
+ else if (!p->idAuthenticationOpen || !*p->idAuthenticationOpen)
+ req.idAuthentication = NULL;
+ else
+ {
+ Z_IdAuthentication *auth = odr_malloc (p->odr_out, sizeof(*auth));
+
+ auth->which = Z_IdAuthentication_open;
+ auth->u.open = p->idAuthenticationOpen;
+ req.idAuthentication = auth;
+ }
req.implementationId = p->implementationId;
req.implementationName = p->implementationName;
req.implementationVersion = "0.1";
static int do_protocolVersion (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- if (argc == 3)
- ir_asc2bitmask (argv[2], &((IRObj *) obj)->protocolVersion);
- return TCL_OK;
+ static struct ir_named_entry version_tab[] = {
+ { "1", 0 },
+ { "2", 1 },
+ { "3", 2 },
+ { "4", 3 },
+ { NULL,0}
+ };
+ IRObj *p = obj;
+
+ return ir_named_bits (version_tab, &p->protocolVersion,
+ interp, argc-2, argv+2);
}
/*
static int do_options (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- if (argc == 3)
- ir_asc2bitmask (argv[2], &((IRObj *) obj)->options);
- return TCL_OK;
+ static struct ir_named_entry options_tab[] = {
+ { "search", 0 },
+ { "present", 1 },
+ { "delSet", 2 },
+ { "resourceReport", 3 },
+ { "triggerResourceCtrl", 4},
+ { "resourceCtrl", 5},
+ { "accessCtrl", 6},
+ { "scan", 7},
+ { "sort", 8},
+ { "extentedServices", 10},
+ { "level-1Segmentation", 11},
+ { "level-2Segmentation", 12},
+ { "concurrentOperations", 13},
+ { "namedResultSets", 14},
+ { NULL, 0}
+ };
+ IRObj *p = obj;
+
+ return ir_named_bits (options_tab, &p->options, interp, argc-2, argv+2);
}
/*
/*
* do_initResult: Get init result
*/
-static int do_initResult (void *o, Tcl_Interp *interp,
+static int do_initResult (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *obj = o;
+ IRObj *p = obj;
- return get_set_int (&obj->initResult, interp, argc, argv);
+ return get_set_int (&p->initResult, interp, argc, argv);
}
static int do_idAuthentication (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- if (argc == 3)
+ IRObj *p = obj;
+
+ if (argc >= 3)
{
- free (((IRObj*)obj)->idAuthentication);
- if (ir_strdup (interp, &((IRObj*) obj)->idAuthentication, argv[2])
- == TCL_ERROR)
- return TCL_ERROR;
+ free (p->idAuthenticationOpen);
+ free (p->idAuthenticationGroupId);
+ free (p->idAuthenticationUserId);
+ free (p->idAuthenticationPassword);
+ p->idAuthenticationOpen = NULL;
+ p->idAuthenticationGroupId = NULL;
+ p->idAuthenticationUserId = NULL;
+ p->idAuthenticationPassword = NULL;
+
+ if (argc == 3)
+ {
+ if (ir_strdup (interp, &p->idAuthenticationOpen, argv[2])
+ == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ else if (argc == 5)
+ {
+ if (ir_strdup (interp, &p->idAuthenticationGroupId, argv[2])
+ == TCL_ERROR)
+ return TCL_ERROR;
+ if (ir_strdup (interp, &p->idAuthenticationUserId, argv[3])
+ == TCL_ERROR)
+ return TCL_ERROR;
+ if (ir_strdup (interp, &p->idAuthenticationPassword, argv[4])
+ == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ }
+ if (p->idAuthenticationOpen)
+ Tcl_AppendElement (interp, p->idAuthenticationOpen);
+ else
+ {
+ Tcl_AppendElement (interp, p->idAuthenticationGroupId ?
+ p->idAuthenticationGroupId : "");
+ Tcl_AppendElement (interp, p->idAuthenticationUserId ?
+ p->idAuthenticationUserId : "");
+ Tcl_AppendElement (interp, p->idAuthenticationPassword ?
+ p->idAuthenticationPassword : "");
}
- Tcl_AppendResult (interp, ((IRObj*)obj)->idAuthentication,
- (char*) NULL);
return TCL_OK;
}
int argc, char **argv)
{
IRObj *obj;
+#if CCL2RPN
FILE *inf;
+#endif
if (argc != 2)
{
obj->preferredMessageSize = 4096;
obj->connectFlag = 0;
- obj->idAuthentication = NULL;
+ obj->idAuthenticationOpen = NULL;
+ obj->idAuthenticationGroupId = NULL;
+ obj->idAuthenticationUserId = NULL;
+ obj->idAuthenticationPassword = NULL;
if (ir_strdup (interp, &obj->implementationName, "TCL/TK on YAZ")
== TCL_ERROR)
obj->hostname = NULL;
+#if CCL2RPN
obj->bibset = ccl_qual_mk ();
if ((inf = fopen ("default.bib", "r")))
{
ccl_qual_file (obj->bibset, inf);
fclose (inf);
}
+#endif
ODR_MASK_ZERO (&obj->protocolVersion);
ODR_MASK_SET (&obj->protocolVersion, 0);
ODR_MASK_SET (&obj->protocolVersion, 1);
ODR_MASK_ZERO (&obj->options);
ODR_MASK_SET (&obj->options, 0);
+ ODR_MASK_SET (&obj->options, 1);
+ ODR_MASK_SET (&obj->options, 7);
+ ODR_MASK_SET (&obj->options, 14);
obj->odr_in = odr_createmem (ODR_DECODE);
obj->odr_out = odr_createmem (ODR_ENCODE);
req.databaseNames = p->set_inher.databaseNames;
printf ("Search:");
for (r=0; r < p->set_inher.num_databaseNames; r++)
- {
printf (" %s", p->set_inher.databaseNames[r]);
- }
req.smallSetElementSetNames = 0;
req.mediumSetElementSetNames = 0;
req.preferredRecordSyntax = 0;
if (!strcmp (p->set_inher.queryType, "rpn"))
{
+ Z_RPNQuery *RPNquery;
+
+ RPNquery = p_query_rpn (p->odr_out, argv[2]);
+ if (!RPNquery)
+ {
+ Tcl_AppendResult (interp, "Syntax error in query", NULL);
+ return TCL_ERROR;
+ }
+ RPNquery->attributeSetId = oid_getoidbyent (&p->bib1);
+ query.which = Z_Query_type_1;
+ query.u.type_1 = RPNquery;
+ printf ("- RPN\n");
+ }
+#if CCL2RPN
+ else if (!strcmp (p->set_inher.queryType, "cclrpn"))
+ {
int error;
int pos;
struct ccl_rpn_node *rpn;
}
ccl_pr_tree (rpn, stderr);
fprintf (stderr, "\n");
- query.which = Z_Query_type_1;
assert((RPNquery = ccl_rpn_query(rpn)));
RPNquery->attributeSetId = oid_getoidbyent (&p->bib1);
+ query.which = Z_Query_type_1;
query.u.type_1 = RPNquery;
- printf ("- RPN\n");
+ printf ("- CCLRPN\n");
}
+#endif
else if (!strcmp (p->set_inher.queryType, "ccl"))
{
query.which = Z_Query_type_2;
return get_set_int (&obj->numberOfRecordsReturned, interp, argc, argv);
}
+#if 0
static int get_marc_fields(Tcl_Interp *interp, Iso2709Rec rec,
int argc, char **argv)
{
iso2709_a_rm (a);
return TCL_OK;
}
+#endif
+#if 0
static int get_marc_lines(Tcl_Interp *interp, Iso2709Rec rec,
int argc, char **argv)
{
iso2709_a_rm (a);
return TCL_OK;
}
+#endif
/*
* do_recordType: Return record type (if any) at position.
}
/*
- * do_recordMarc: Get ISO2709 Record lines/fields
+ * do_getMarc: Get ISO2709 Record lines/fields
*/
-static int do_recordMarc (void *o, Tcl_Interp *interp, int argc, char **argv)
+static int do_getMarc (void *o, Tcl_Interp *interp, int argc, char **argv)
{
IRSetObj *obj = o;
int offset;
Tcl_AppendResult (interp, "No MARC record at #", argv[2], NULL);
return TCL_ERROR;
}
- if (!strcmp (argv[3], "field"))
- return get_marc_fields (interp, rl->u.marc.rec, argc, argv);
- else if (!strcmp (argv[3], "line"))
- return get_marc_lines (interp, rl->u.marc.rec, argc, argv);
- else
- {
- Tcl_AppendResult (interp, "field/line expected", NULL);
- return TCL_ERROR;
- }
+ return ir_tcl_get_marc (interp, rl->u.dbrec.buf, argc, argv);
}
{
IRSetObj *setobj = o;
FILE *inf;
+ size_t size;
int no = 1;
- const char *buf;
+ char *buf;
if (argc < 3)
{
Tcl_AppendResult (interp, "Cannot open ", argv[2], NULL);
return TCL_ERROR;
}
- while ((buf = iso2709_read (inf)))
+ while ((buf = ir_tcl_fread_marc (inf, &size)))
{
IRRecordList *rl;
- Iso2709Rec rec;
- rec = iso2709_cvt (buf);
- if (!rec)
- break;
rl = new_IR_record (setobj, no, Z_NamePlusRecord_databaseRecord);
- rl->u.marc.rec = rec;
+ rl->u.dbrec.buf = buf;
+ rl->u.dbrec.size = size;
no++;
}
setobj->numberOfRecordsReturned = no-1;
{ 0, "numberOfRecordsReturned", do_numberOfRecordsReturned },
{ 0, "present", do_present },
{ 0, "recordType", do_recordType },
- { 0, "recordMarc", do_recordMarc },
+ { 0, "getMarc", do_getMarc },
{ 0, "recordDiag", do_recordDiag },
{ 0, "responseStatus", do_responseStatus },
{ 0, "loadFile", do_loadFile },
Z_APDU apdu, *apdup = &apdu;
IRScanObj *obj = o;
IRObj *p = obj->parent;
- int r, pos;
+ int r;
+#if CCL2RPN
struct ccl_rpn_node *rpn;
+ int pos;
+#endif
p->scan_child = o;
if (argc != 3)
req.databaseNames = p->set_inher.databaseNames;
req.attributeSet = oid_getoidbyent (&p->bib1);
-#if 0
- if (!(req.termListAndStartPoint =
- ir_malloc (interp, sizeof(*req.termListAndStartPoint))))
- return TCL_ERROR;
- req.termListAndStartPoint->num_attributes = 0;
- req.termListAndStartPoint->attributeList = NULL;
- if (!(req.termListAndStartPoint->term = ir_malloc (interp,
- sizeof(Z_Term))))
- return TCL_ERROR;
- req.termListAndStartPoint->term->which = Z_Term_general;
- if (!(req.termListAndStartPoint->term->u.general =
- ir_malloc (interp, sizeof(*req.termListAndStartPoint->
- term->u.general))))
- return TCL_ERROR;
- if (ir_strdup (interp, &req.termListAndStartPoint->term->u.general->buf,
- argv[2]) == TCL_ERROR)
- return TCL_ERROR;
- req.termListAndStartPoint->term->u.general->len =
- req.termListAndStartPoint->term->u.general->size = strlen(argv[2]);
+#if !CCL2RPN
+ if (!(req.termListAndStartPoint = p_query_scan (p->odr_out, argv[2])))
+ {
+ Tcl_AppendResult (interp, "Syntax error in query", NULL);
+ return TCL_ERROR;
+ }
#else
rpn = ccl_find_str(p->bibset, argv[2], &r, &pos);
if (r)
p->maximumRecordSize = *initrs->maximumRecordSize;
p->preferredMessageSize = *initrs->preferredMessageSize;
-
+
+ memcpy (&p->options, initrs->options, sizeof(initrs->options));
+ memcpy (&p->protocolVersion, initrs->protocolVersion,
+ sizeof(initrs->protocolVersion));
free (p->userInformationField);
p->userInformationField = NULL;
if (initrs->userInformationField)
zr = zrs->u.databaseOrSurDiagnostics->records[offset]
->u.databaseRecord;
oe = (Odr_external*) zr;
- if (oe->which == ODR_EXTERNAL_octet
- && zr->u.octet_aligned->len)
+ rl->u.dbrec.size = zr->u.octet_aligned->len;
+ if (oe->which == ODR_EXTERNAL_octet && rl->u.dbrec.size > 0)
{
const char *buf = (char*) zr->u.octet_aligned->buf;
- rl->u.marc.rec = iso2709_cvt (buf);
+ if ((rl->u.dbrec.buf = malloc (rl->u.dbrec.size)))
+ memcpy (rl->u.dbrec.buf, buf, rl->u.dbrec.size);
}
else
- rl->u.marc.rec = NULL;
+ rl->u.dbrec.buf = NULL;
}
}
}