/*
* IR toolkit for tcl/tk
* (c) Index Data 1995
+ * Sebastian Hammer, Adam Dickmeiss
*
* $Log: ir-tcl.c,v $
- * Revision 1.10 1995-03-15 16:14:50 adam
+ * Revision 1.16 1995-03-21 08:26:06 adam
+ * New method, setName, to specify the result set name (other than Default).
+ * New method, responseStatus, which returns diagnostic info, if any, after
+ * present response / search response.
+ *
+ * Revision 1.15 1995/03/20 15:24:07 adam
+ * Diagnostic records saved on searchResponse.
+ *
+ * Revision 1.14 1995/03/20 08:53:22 adam
+ * Event loop in tclmain.c rewritten. New method searchStatus.
+ *
+ * Revision 1.13 1995/03/17 18:26:17 adam
+ * Non-blocking i/o used now. Database names popup as cascade items.
+ *
+ * Revision 1.12 1995/03/17 15:45:00 adam
+ * Improved target/database setup.
+ *
+ * Revision 1.11 1995/03/16 17:54:03 adam
+ * Minor changes really.
+ *
+ * Revision 1.10 1995/03/15 16:14:50 adam
* Blocking arg in cs_create changed.
*
* Revision 1.9 1995/03/15 13:59:24 adam
#include "ir-tcl.h"
+#define CS_BLOCK 0
+
typedef struct {
- COMSTACK cs_link;
+ COMSTACK cs_link;
- int preferredMessageSize;
- int maximumRecordSize;
+ int preferredMessageSize;
+ int maximumRecordSize;
Odr_bitmask options;
Odr_bitmask protocolVersion;
- char *idAuthentication;
- char *implementationName;
- char *implementationId;
+ char *idAuthentication;
+ char *implementationName;
+ char *implementationId;
- char *hostname;
+ char *hostname;
- char *buf_out;
- int len_out;
+ char *buf_out;
+ int len_out;
- char *buf_in;
- int len_in;
+ char *buf_in;
+ int len_in;
- ODR odr_in;
- ODR odr_out;
- ODR odr_pr;
+ char *sbuf;
+ int slen;
+
+ ODR odr_in;
+ ODR odr_out;
+ ODR odr_pr;
Tcl_Interp *interp;
- char *callback;
+ char *callback;
- int smallSetUpperBound;
- int largeSetLowerBound;
- int mediumSetPresentNumber;
- int replaceIndicator;
- char **databaseNames;
- int num_databaseNames;
- char *query_method;
+ int smallSetUpperBound;
+ int largeSetLowerBound;
+ int mediumSetPresentNumber;
+ int replaceIndicator;
+ char **databaseNames;
+ int num_databaseNames;
+ char *query_method;
- CCL_bibset bibset;
+ CCL_bibset bibset;
struct IRSetObj_ *child;
} IRObj;
} IRRecordList;
typedef struct IRSetObj_ {
- IRObj *parent;
- int resultCount;
- int start;
- int number;
- int numberOfRecordsReturned;
- Z_Records *z_records;
- int which;
- int condition;
- char *addinfo;
+ IRObj *parent;
+ int searchStatus;
+ int resultCount;
+ int start;
+ int number;
+ int numberOfRecordsReturned;
+ char *setName;
+ int recordFlag;
+ int which;
+ int condition;
+ char *addinfo;
IRRecordList *record_list;
} IRSetObj;
typedef struct {
int type;
char *name;
- int (*method) (void * obj, Tcl_Interp *interp, int argc, char **argv);
+ int (*method) (void *obj, Tcl_Interp *interp, int argc, char **argv);
} IRMethod;
static int do_disconnect (void *obj,Tcl_Interp *interp, int argc, char **argv);
Z_APDU apdu, *apdup;
IRObj *p = obj;
Z_InitRequest req;
- char *sbuf;
- int slen;
+ int r;
req.referenceId = 0;
req.options = &p->options;
odr_reset (p->odr_out);
return TCL_ERROR;
}
- sbuf = odr_getbuf (p->odr_out, &slen);
- if (cs_put (p->cs_link, sbuf, slen) < 0)
- {
+ p->sbuf = odr_getbuf (p->odr_out, &p->slen);
+ if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
+ {
interp->result = "cs_put failed in init";
return TCL_ERROR;
}
- printf("Sent initializeRequest (%d bytes).\n", slen);
+ else if (r == 1)
+ {
+ ir_select_add_write (cs_fileno(p->cs_link), p);
+ printf("Sent part of initializeRequest (%d bytes).\n", p->slen);
+ }
+ else
+ printf("Sent whole initializeRequest (%d bytes).\n", p->slen);
return TCL_OK;
}
if (cs_type (p->cs_link) == tcpip_type)
{
cs_close (p->cs_link);
- p->cs_link = cs_create (tcpip_type, 1);
+ p->cs_link = cs_create (tcpip_type, CS_BLOCK);
}
else if (cs_type (p->cs_link) == mosi_type)
{
cs_close (p->cs_link);
- p->cs_link = cs_create (mosi_type, 1);
+ p->cs_link = cs_create (mosi_type, CS_BLOCK);
}
else
{
char *cs_type = NULL;
if (argc == 3)
{
+ cs_close (((IRObj*) obj)->cs_link);
if (!strcmp (argv[2], "tcpip"))
- ((IRObj *)obj)->cs_link = cs_create (tcpip_type, 1);
+ ((IRObj *)obj)->cs_link = cs_create (tcpip_type, CS_BLOCK);
else if (!strcmp (argv[2], "mosi"))
- ((IRObj *)obj)->cs_link = cs_create (mosi_type, 1);
+ ((IRObj *)obj)->cs_link = cs_create (mosi_type, CS_BLOCK);
else
{
interp->result = "wrong comstack type";
if (argc < 3)
{
- interp->result = "wrong # args";
- return TCL_ERROR;
+ for (i=0; i<p->num_databaseNames; i++)
+ Tcl_AppendElement (interp, p->databaseNames[i]);
+ return TCL_OK;
}
if (p->databaseNames)
{
return TCL_OK;
}
+/*
+ * do_replaceIndicator: Set/get replace Set indicator
+ */
+static int do_replaceIndicator (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRObj *p = obj;
+ char buf[20];
+
+ if (argc == 3)
+ {
+ if (Tcl_GetInt (interp, argv[2],
+ &p->replaceIndicator)==TCL_ERROR)
+ return TCL_ERROR;
+ }
+ sprintf (buf, "%d", p->replaceIndicator);
+ Tcl_AppendResult (interp, buf, NULL);
+ return TCL_OK;
+}
+
/*
* ir_obj_method: IR Object methods
*/
{ 0, "protocolVersion", do_protocolVersion },
{ 0, "options", do_options },
{ 1, "preferredMessageSize", do_preferredMessageSize },
- { 1, "maximumRecordSize", do_maximumRecordSize },
+ { 1, "maximumRecordSize", do_maximumRecordSize },
{ 1, "implementationName", do_implementationName },
{ 1, "implementationId", do_implementationId },
{ 1, "idAuthentication", do_idAuthentication },
{ 0, "init", do_init_request },
{ 0, "disconnect", do_disconnect },
{ 0, "callback", do_callback },
- { 0, "databaseNames", do_databaseNames},
+ { 1, "databaseNames", do_databaseNames},
+ { 1, "replaceIndicator", do_replaceIndicator},
{ 1, "query", do_query },
{ 0, NULL, NULL}
};
}
if (!(obj = ir_malloc (interp, sizeof(*obj))))
return TCL_ERROR;
- obj->cs_link = cs_create (tcpip_type, 1);
+ obj->cs_link = cs_create (tcpip_type, CS_BLOCK);
obj->maximumRecordSize = 32768;
obj->preferredMessageSize = 4096;
Odr_oct ccl_query;
IRSetObj *obj = o;
IRObj *p = obj->parent;
- char *sbuf;
- int slen;
+ int r;
p->child = o;
if (argc != 3)
req.largeSetLowerBound = &p->largeSetLowerBound;
req.mediumSetPresentNumber = &p->mediumSetPresentNumber;
req.replaceIndicator = &p->replaceIndicator;
- req.resultSetName = "Default";
+ req.resultSetName = obj->setName ? obj->setName : "Default";
req.num_databaseNames = p->num_databaseNames;
req.databaseNames = p->databaseNames;
+ printf ("Search:");
+ for (r=0; r<p->num_databaseNames; r++)
+ {
+ printf (" %s", p->databaseNames[r]);
+ }
req.smallSetElementSetNames = 0;
req.mediumSetElementSetNames = 0;
req.preferredRecordSyntax = 0;
assert((RPNquery = ccl_rpn_query(rpn)));
RPNquery->attributeSetId = bib1;
query.u.type_1 = RPNquery;
+ printf ("- RPN\n");
}
else if (!strcmp (p->query_method, "ccl"))
{
query.u.type_2 = &ccl_query;
ccl_query.buf = argv[2];
ccl_query.len = strlen (argv[2]);
+ printf ("- CCL\n");
}
else
{
odr_reset (p->odr_out);
return TCL_ERROR;
}
- sbuf = odr_getbuf (p->odr_out, &slen);
- if (cs_put (p->cs_link, sbuf, slen) < 0)
+ p->sbuf = odr_getbuf (p->odr_out, &p->slen);
+ if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
{
interp->result = "cs_put failed in init";
return TCL_ERROR;
}
- printf ("Search request\n");
+ else if (r == 1)
+ {
+ ir_select_add_write (cs_fileno(p->cs_link), p);
+ printf("Sent part of searchRequest (%d bytes).\n", p->slen);
+ }
+ else
+ {
+ printf ("Whole search request\n");
+ }
return TCL_OK;
}
}
/*
+ * do_searchStatus: Get search status (after search response)
+ */
+static int do_searchStatus (void *o, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRSetObj *obj = o;
+
+ sprintf (interp->result, "%d", obj->searchStatus);
+ return TCL_OK;
+}
+
+/*
+ * do_setName: Set result Set name
+ */
+static int do_setName (void *o, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRSetObj *obj = o;
+
+ if (argc == 3)
+ {
+ free (obj->setName);
+ if (ir_strdup (interp, &obj->setName, argv[2])
+ == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ Tcl_AppendElement (interp, obj->setName);
+ return TCL_OK;
+}
+
+/*
* do_numberOfRecordsReturned: Get number of records returned
*/
static int do_numberOfRecordsReturned (void *o, Tcl_Interp *interp,
}
/*
- * do_presentStatus: Return present status (after present response)
+ * do_responseStatus: Return response status (present or search)
*/
-static int do_presentStatus (void *o, Tcl_Interp *interp,
+static int do_responseStatus (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
IRSetObj *obj = o;
const char *cp;
char buf[28];
+ if (!obj->recordFlag)
+ return TCL_OK;
switch (obj->which)
{
case Z_Records_DBOSD:
Z_PresentRequest req;
int start;
int number;
- char *sbuf;
- int slen;
+ int r;
if (argc >= 3)
{
odr_reset (p->odr_out);
return TCL_ERROR;
}
- sbuf = odr_getbuf (p->odr_out, &slen);
- if (cs_put (p->cs_link, sbuf, slen) < 0)
+ p->sbuf = odr_getbuf (p->odr_out, &p->slen);
+ if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
{
interp->result = "cs_put failed in init";
return TCL_ERROR;
}
- printf ("Present request, start=%d, num=%d\n", start, number);
+ else if (r == 1)
+ {
+ ir_select_add_write (cs_fileno(p->cs_link), p);
+ printf ("Part of present request, start=%d, num=%d (%d bytes)\n",
+ start, number, p->slen);
+ }
+ else
+ {
+ printf ("Whole present request, start=%d, num=%d (%d bytes)\n",
+ start, number, p->slen);
+ }
return TCL_OK;
}
{
static IRMethod tab[] = {
{ 0, "search", do_search },
+ { 0, "searchStatus", do_searchStatus },
+ { 0, "setName", do_setName },
{ 0, "resultCount", do_resultCount },
{ 0, "numberOfRecordsReturned", do_numberOfRecordsReturned },
{ 0, "present", do_present },
{ 0, "recordType", do_recordType },
{ 0, "recordMarc", do_recordMarc },
{ 0, "recordDiag", do_recordDiag },
- { 0, "presentStatus", do_presentStatus },
+ { 0, "responseStatus", do_responseStatus },
{ 0, "loadFile", do_loadFile },
{ 0, NULL, NULL}
};
return TCL_ERROR;
if (!(obj = ir_malloc (interp, sizeof(*obj))))
return TCL_ERROR;
- obj->z_records = NULL;
+ obj->setName = NULL;
obj->record_list = NULL;
obj->addinfo = NULL;
obj->parent = (IRObj *) parent_info.clientData;
/* ------------------------------------------------------- */
-static void ir_searchResponse (void *o, Z_SearchResponse *searchrs)
-{
- IRObj *p = o;
- IRSetObj *obj = p->child;
-
- if (obj)
- obj->resultCount = *searchrs->resultCount;
- if (searchrs->searchStatus)
- printf("Search was a success.\n");
- else
- printf("Search was a bloomin' failure.\n");
- printf("Number of hits: %d\n", *searchrs->resultCount);
-}
-
static void ir_initResponse (void *obj, Z_InitResponse *initrs)
{
if (!*initrs->result)
printf("Name : %s\n", initrs->implementationName);
if (initrs->implementationVersion)
printf("Version: %s\n", initrs->implementationVersion);
+ if (initrs->maximumRecordSize)
+ printf ("MaximumRecordSize=%d\n", *initrs->maximumRecordSize);
+ if (initrs->preferredMessageSize)
+ printf ("PreferredMessageSize=%d\n", *initrs->preferredMessageSize);
#if 0
if (initrs->userInformationField)
{
#endif
}
-static void ir_presentResponse (void *o, Z_PresentResponse *presrs)
+static void ir_handleRecords (void *o, Z_Records *zrs)
{
IRObj *p = o;
IRSetObj *setobj = p->child;
- Z_Records *zrs = presrs->records;
- setobj->z_records = presrs->records;
-
- printf ("Received presentResponse\n");
- if (zrs)
- {
- setobj->which = zrs->which;
- if (zrs->which == Z_Records_NSD)
- {
- const char *addinfo;
- printf ("They are diagnostic!!!\n");
-
- setobj->numberOfRecordsReturned = 0;
- setobj->condition = *zrs->u.nonSurrogateDiagnostic->condition;
- free (setobj->addinfo);
- setobj->addinfo = NULL;
- addinfo = zrs->u.nonSurrogateDiagnostic->addinfo;
- if (addinfo && (setobj->addinfo = malloc (strlen(addinfo) + 1)))
- strcpy (setobj->addinfo, addinfo);
- return;
- }
- else
+ setobj->which = zrs->which;
+ setobj->recordFlag = 1;
+ if (zrs->which == Z_Records_NSD)
+ {
+ const char *addinfo;
+
+ setobj->numberOfRecordsReturned = 0;
+ setobj->condition = *zrs->u.nonSurrogateDiagnostic->condition;
+ free (setobj->addinfo);
+ setobj->addinfo = NULL;
+ addinfo = zrs->u.nonSurrogateDiagnostic->addinfo;
+ if (addinfo && (setobj->addinfo = malloc (strlen(addinfo) + 1)))
+ strcpy (setobj->addinfo, addinfo);
+ printf ("Diagnostic response. %s (%d): %s\n",
+ diagbib1_str (setobj->condition),
+ setobj->condition,
+ setobj->addinfo ? setobj->addinfo : "");
+ }
+ else
+ {
+ int offset;
+ IRRecordList *rl;
+
+ setobj->numberOfRecordsReturned =
+ zrs->u.databaseOrSurDiagnostics->num_records;
+ printf ("Got %d records\n", setobj->numberOfRecordsReturned);
+ for (offset = 0; offset<setobj->numberOfRecordsReturned; offset++)
{
- int offset;
- IRRecordList *rl;
-
- setobj->numberOfRecordsReturned =
- zrs->u.databaseOrSurDiagnostics->num_records;
- printf ("Got %d records\n", setobj->numberOfRecordsReturned);
- for (offset = 0; offset<setobj->numberOfRecordsReturned; offset++)
+ rl = new_IR_record (setobj, setobj->start + offset,
+ zrs->u.databaseOrSurDiagnostics->
+ records[offset]->which);
+ if (rl->which == Z_NamePlusRecord_surrogateDiagnostic)
{
- rl = new_IR_record (setobj, setobj->start + offset,
- zrs->u.databaseOrSurDiagnostics->
- records[offset]->which);
- if (rl->which == Z_NamePlusRecord_surrogateDiagnostic)
+ Z_DiagRec *diagrec;
+
+ diagrec = zrs->u.databaseOrSurDiagnostics->
+ records[offset]->u.surrogateDiagnostic;
+
+ rl->u.diag.condition = *diagrec->condition;
+ if (diagrec->addinfo && (rl->u.diag.addinfo =
+ malloc (strlen (diagrec->addinfo)+1)))
+ strcpy (rl->u.diag.addinfo, diagrec->addinfo);
+ }
+ else
+ {
+ Z_DatabaseRecord *zr;
+ Odr_external *oe;
+
+ zr = zrs->u.databaseOrSurDiagnostics->records[offset]
+ ->u.databaseRecord;
+ oe = (Odr_external*) zr;
+ if (oe->which == ODR_EXTERNAL_octet
+ && zr->u.octet_aligned->len)
{
- Z_DiagRec *diagrec;
-
- diagrec = zrs->u.databaseOrSurDiagnostics->
- records[offset]->u.surrogateDiagnostic;
-
- rl->u.diag.condition = *diagrec->condition;
- if (diagrec->addinfo && (rl->u.diag.addinfo =
- malloc (strlen (diagrec->addinfo)+1)))
- strcpy (rl->u.diag.addinfo, diagrec->addinfo);
+ const char *buf = (char*) zr->u.octet_aligned->buf;
+ rl->u.marc.rec = iso2709_cvt (buf);
}
else
- {
- Z_DatabaseRecord *zr;
- Odr_external *oe;
-
- zr = zrs->u.databaseOrSurDiagnostics->records[offset]
- ->u.databaseRecord;
- oe = (Odr_external*) zr;
- if (oe->which == ODR_EXTERNAL_octet
- && zr->u.octet_aligned->len)
- {
- const char *buf = (char*) zr->u.octet_aligned->buf;
- rl->u.marc.rec = iso2709_cvt (buf);
- }
- else
- rl->u.marc.rec = NULL;
- }
+ rl->u.marc.rec = NULL;
}
}
}
+}
+
+static void ir_searchResponse (void *o, Z_SearchResponse *searchrs)
+{
+ IRObj *p = o;
+ IRSetObj *setobj = p->child;
+ Z_Records *zrs = searchrs->records;
+
+ if (setobj)
+ {
+ setobj->searchStatus = searchrs->searchStatus ? 1 : 0;
+ setobj->resultCount = *searchrs->resultCount;
+ printf ("Search response %d, %d hits\n",
+ setobj->searchStatus, setobj->resultCount);
+ if (zrs)
+ ir_handleRecords (o, zrs);
+ else
+ setobj->recordFlag = 0;
+ }
+ else
+ printf ("Search response, no object!\n");
+}
+
+
+static void ir_presentResponse (void *o, Z_PresentResponse *presrs)
+{
+ IRObj *p = o;
+ IRSetObj *setobj = p->child;
+ Z_Records *zrs = presrs->records;
+
+ printf ("Received presentResponse\n");
+ if (zrs)
+ ir_handleRecords (o, zrs);
else
{
+ setobj->recordFlag = 0;
printf ("No records!\n");
}
}
-void ir_select_proc (ClientData clientData)
+/*
+ * ir_select_read: handle incoming packages
+ */
+void ir_select_read (ClientData clientData)
{
IRObj *p = clientData;
Z_APDU *apdu;
ir_select_remove (cs_fileno (p->cs_link), p);
return;
}
+ if (r == 1)
+ return ;
odr_setbuf (p->odr_in, p->buf_in, r);
printf ("cs_get ok, got %d\n", r);
if (!z_APDU (p->odr_in, &apdu, 0))
} while (cs_more (p->cs_link));
}
+/*
+ * ir_select_write: handle outgoing packages - not yet written.
+ */
+void ir_select_write (ClientData clientData)
+{
+ IRObj *p = clientData;
+ int r;
+
+ printf ("In write handler.....\n");
+ if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
+ {
+ printf ("select write fail\n");
+ cs_close (p->cs_link);
+ }
+ else if (r == 0) /* remove select bit */
+ {
+ ir_select_remove_write (cs_fileno (p->cs_link), p);
+ }
+}
+
/* ------------------------------------------------------- */
/*
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}
+
+