|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T r
Length: 7266 (0x1c62)
Types: TextFile
Names: »rdbm.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z«
└─⟦de7628f85⟧
└─⟦this⟧ »isode-6.0/others/rdbm/rdbm.c«
/* rdbm.c - remote opeatations dbm library */
#ifndef lint
static char *rcsid = "$Header: /f/osi/others/rdbm/RCS/rdbm.c,v 7.0 89/11/23 22:10:30 mrose Rel $";
#endif lint
#include <errno.h>
#include <stdio.h>
#include <varargs.h>
#include "RDBM-types.h"
#include "RDBM-ops.h"
/* \f
DATA */
static char *myservice = "dbmstore";
static char *mycontext = "isode dbm demo";
static char *mypci = "isode dbm demo pci";
typedef struct {
char *dptr;
int dsize;
} datum;
static int mysd;
static int resval;
static datum empty = { NULL, 0 };
static datum full1 = { NULL, 0 };
static datum full2 = { NULL, 0 };
static datum *full = &full1;
extern int errno;
void advise ();
/* \f
OPERATIONS */
static int invoke (op, arg, afx, rfx)
int op;
caddr_t arg;
IFP afx,
rfx;
{
int id;
struct RoSAPindication rois;
register struct RoSAPindication *roi = &rois;
register struct RoSAPpreject *rop = &roi -> roi_preject;
if (afx && !arg) {
errno = ENOMEM;
return NOTOK;
}
switch (RyStub (mysd, table_RDBM_Operations, op, id = RyGenID (mysd),
NULLIP, arg, rfx, rfx, ROS_SYNC, roi)) {
case NOTOK: /* failure */
(*rfx) (mysd, id, RY_REJECT, rop -> rop_reason, roi);
break;
case OK:
break;
case DONE:
(*rfx) (mysd, id, RY_REJECT, ROS_DONE, roi);
break;
default:
(*rfx) (mysd, id, RY_REJECT, ROS_OPERATION, roi);
break;
}
if (arg && afx)
(*afx) (arg);
return resval;
}
/* \f
*/
/* ARGSUSED */
static int status_result (sd, id, error, result, roi)
int sd,
id,
error;
register struct type_RDBM_Status *result;
struct RoSAPindication *roi;
{
if (error == RY_RESULT) {
if ((resval = result -> parm) == NOTOK)
errno = EIO;
}
else {
resval = NOTOK;
errno = EIO;
advise (NULLCP, "%s", RoErrString ((int) result));
}
return OK;
}
/* ARGSUSED */
static int datum_result (sd, id, error, result, roi)
int sd,
id,
error;
register struct type_RDBM_Datum *result;
struct RoSAPindication *roi;
{
if (error == RY_RESULT) {
resval = OK;
if (full -> dptr)
free ((char *) full -> dptr);
full -> dptr = qb2str (result), full -> dsize = result -> qb_len;
}
else {
resval = NOTOK;
errno = EIO;
advise (NULLCP, "%s", RoErrString ((int) result));
}
return OK;
}
/* \f
*/
int dbminit (fname)
char *fname;
{
register char *sp;
register struct type_UNIV_PrintableString *arg;
if (sp = index (fname, ':'))
*sp++ = NULL;
else
sp = fname, fname = PLocalHostName ();
if (ryinitiator (fname, myservice, mycontext, mypci) == NOTOK)
return NOTOK;
arg = str2qb (sp, strlen (sp) + 1, 1);
return invoke (operation_RDBM_dbminit, (caddr_t) arg,
free_UNIV_PrintableString, status_result);
}
/* \f
*/
datum fetch (key)
datum key;
{
register struct type_RDBM_Datum *arg = str2qb (key.dptr, key.dsize, 1);
full = &full1;
if (invoke (operation_RDBM_fetch, (caddr_t) arg, free_RDBM_Datum,
datum_result) == NOTOK)
return empty;
else
return full1;
}
/* \f
*/
int store (key, content)
datum key,
content;
{
register struct type_RDBM_Pair *arg;
if ((arg = (struct type_RDBM_Pair *) malloc (sizeof *arg)) == NULL) {
errno = ENOMEM;
return NOTOK;
}
arg -> key = str2qb (key.dptr, key.dsize, 1);
arg -> content = str2qb (content.dptr, content.dsize, 1);
return invoke (operation_RDBM_store, (caddr_t) arg, free_RDBM_Pair,
status_result);
}
/* \f
*/
int delete (key)
datum key;
{
register struct type_RDBM_Datum *arg = str2qb (key.dptr, key.dsize, 1);
return invoke (operation_RDBM_delete, (caddr_t) arg, free_RDBM_Datum,
status_result);
}
/* \f
*/
datum firstkey ()
{
full = &full2;
if (invoke (operation_RDBM_firstkey, (caddr_t) NULL, NULLIFP, datum_result)
== NOTOK)
return empty;
else
return full2;
}
/* \f
*/
datum nextkey (key)
datum key;
{
register struct type_RDBM_Datum *arg = str2qb (key.dptr, key.dsize, 1);
full = &full2;
if (invoke (operation_RDBM_nextkey, (caddr_t) arg, free_RDBM_Datum,
datum_result) == NOTOK)
return empty;
else
return full2;
}
/* \f
BINDING */
static int ryinitiator (host, service, context, pcid)
char *host,
*service,
*context,
*pcid;
{
int result;
struct SSAPref sfs;
register struct SSAPref *sf;
register struct PSAPaddr *pa;
struct AcSAPconnect accs;
register struct AcSAPconnect *acc = &accs;
struct AcSAPindication acis;
register struct AcSAPindication *aci = &acis;
register struct AcSAPabort *aca = &aci -> aci_abort;
AEI aei;
OID ctx,
pci;
struct PSAPctxlist pcs;
register struct PSAPctxlist *pc = &pcs;
struct RoSAPindication rois;
register struct RoSAPindication *roi = &rois;
register struct RoSAPpreject *rop = &roi -> roi_preject;
if ((aei = str2aei (host, service)) == NULLAEI) {
advise (NULLCP, "%s-%s: unknown application-entity",
host, service);
goto out;
}
if ((pa = aei2addr (aei)) == NULLPA) {
advise (NULLCP, "address translation failed");
goto out;
}
if ((ctx = ode2oid (context)) == NULLOID) {
advise (NULLCP, "%s: unknown object descriptor", context);
goto out;
}
if ((ctx = oid_cpy (ctx)) == NULLOID) {
errno = ENOMEM;
return NOTOK;
}
if ((pci = ode2oid (pcid)) == NULLOID) {
advise (NULLCP, "%s: unknown object descriptor", pcid);
oid_free (ctx);
goto out;
}
if ((pci = oid_cpy (pci)) == NULLOID) {
oid_free (ctx);
errno = ENOMEM;
return NOTOK;
}
pc -> pc_nctx = 1;
pc -> pc_ctx[0].pc_id = 1;
pc -> pc_ctx[0].pc_asn = pci;
pc -> pc_ctx[0].pc_atn = NULLOID;
if ((sf = addr2ref (PLocalHostName ())) == NULL) {
sf = &sfs;
(void) bzero ((char *) sf, sizeof *sf);
}
result = AcAssocRequest (ctx, NULLAEI, aei, NULLPA, pa, pc, NULLOID, 0,
ROS_MYREQUIRE, SERIAL_NONE, 0, sf, NULLPEP, 0,
NULLQOS, acc, aci);
oid_free (ctx);
oid_free (pci);
if (result == NOTOK) {
advise (NULLCP, "association failed: [%s]",
AcErrString (aca -> aca_reason));
goto out;
}
if (acc -> acc_result != ACS_ACCEPT) {
advise (NULLCP, "association rejected: [%s]",
AcErrString (acc -> acc_result));
goto out;
}
mysd = acc -> acc_sd;
ACCFREE (acc);
if (RoSetService (mysd, RoPService, roi) == NOTOK) {
advise (NULLCP, "set RO/PS fails: [%s]",
RoErrString (rop -> rop_reason));
(void) AcUAbortRequest (mysd, NULLPEP, 0, aci);
goto out;
}
return OK;
out: ;
errno = EIO;
return NOTOK;
}
/* \f
*/
#ifdef AETDBM
/* ARGSUSED */
static AEI str2aei (host, service)
char *host,
*service;
{
advise (NULLCP, "sorry, you can't use this library recursively...");
return NULLAEI;
}
#endif
/* \f
ADVISE */
#ifndef lint
static void _advise (ap)
va_list ap;
{
char buffer[BUFSIZ];
asprintf (buffer, ap);
(void) fputs (buffer, stdout);
(void) fputc ('\n', stdout);
(void) fflush (stdout);
}
void advise (va_alist)
va_dcl
{
va_list ap;
va_start (ap);
_advise (ap);
va_end (ap);
}
#else
/* VARARGS */
void advise (what, fmt)
char *what,
*fmt;
{
advise (what, fmt);
}
#endif