|
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 q
Length: 10382 (0x288e) Types: TextFile Names: »qstub.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Src/qmgr/qstub.c«
/* qstub.c: stub Qmgr for debugging etc. */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Src/qmgr/RCS/qstub.c,v 5.0 90/09/20 16:21:34 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Src/qmgr/RCS/qstub.c,v 5.0 90/09/20 16:21:34 pp Exp Locker: pp $ * * $Log: qstub.c,v $ * Revision 5.0 90/09/20 16:21:34 pp * rcsforce : 5.0 public release * */ #include <stdio.h> #include <isode/rosy.h> #include "qmgr.h" #include <isode/logger.h> #include <varargs.h> char *myname; char *chan_context = "pp qmgr channel"; char *chan_pci = "pp qmgr channel pci"; extern char *pptsapd_addr; void ros_adios (), ros_advise (), acs_adios (), acs_advise (), adios (), advise (); struct type_Qmgr_UserList *read_users (); main (argc, argv) int argc; char **argv; { extern char *optarg; extern int optind; int opt; char *channel; int sd, i; myname = argv[0]; while((opt = getopt(argc, argv, "")) != EOF) switch (opt) { default: fprintf (stderr, "Usage: %s", myname); break; } argc -= optind; argv += optind; if (argc <= 0) adios (NULLCP, "Usage: %s channel [message-id's]", myname); channel = *argv; argv ++; argc --; sd = start_assoc ("localhost", channel, chan_context, chan_pci); doinit (sd, channel); for (i = 0; i < argc; i++) domessage(sd, channel, argv[i]); (void) assoc_release (sd); exit (0); } static int start_assoc (myhost, myservice, mycontext, mypci) char *myhost, *myservice, *mycontext, *mypci; { int fd; AEI aei; struct PSAPctxlist pcs; register struct PSAPctxlist *pc = &pcs; struct SSAPref sfs; register struct SSAPref *sf; register struct PSAPaddr *pa; struct SSAPaddr *sa; struct TSAPaddr *ta; OID ctx, pci; struct AcSAPconnect accs; register struct AcSAPconnect *acc = &accs; struct AcSAPindication acis; register struct AcSAPindication *aci = &acis; register struct AcSAPabort *aca = &aci -> aci_abort; struct RoSAPindication rois; register struct RoSAPindication *roi = &rois; register struct RoSAPpreject *rop = &roi -> roi_preject; pa = str2paddr (pptsapd_addr); sa = &pa -> pa_addr; ta = &sa -> sa_addr; ta -> ta_selectlen = str2sel (myservice, 1, ta -> ta_selector, TSSIZE); if ((ctx = ode2oid (mycontext)) == NULLOID) adios (NULLCP, "%s: unknown ISO object descriptor", mycontext); if ((ctx = oid_cpy (ctx)) == NULLOID) adios (NULLCP, "out of memory"); if ((pci = ode2oid (mypci)) == NULLOID) adios (NULLCP, "%s: unknown ISO object descriptor", mypci); if ((pci = oid_cpy (pci)) == NULLOID) adios (NULLCP, "out of memory"); 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); } if (AcAssocRequest (ctx, NULLAEI, NULLAEI, NULLPA, pa, pc, NULLOID, 0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, NULLPEP, 0, NULLQOS, acc, aci) == NOTOK) acs_adios (aca, "A-ASSOCIATE.REQUEST"); if (acc -> acc_result != ACS_ACCEPT) adios (NULLCP, "Association rejected: [%s]", AcErrString (acc -> acc_result)); fd = acc -> acc_sd; ACCFREE (acc); if (RoSetService (fd, RoPService, roi) == NOTOK) ros_adios (rop, "set RO/PS fails"); advise (NULLCP, "Association established to %s", myhost); return fd; } domessage (sd, channel, qid) int sd; char *qid; char *channel; { struct type_Qmgr_ProcMsg *pm; int result; int proc_results (), proc_error (); struct RoSAPindication rois; register struct RoSAPindication *roi = &rois; register struct RoSAPpreject *rop = &roi -> roi_preject; pm = (struct type_Qmgr_ProcMsg *) malloc (sizeof *pm); if (pm == NULL) adios ("memory", "out of"); pm -> qid = str2qb (qid, strlen (qid), 1); pm -> channel = str2qb (channel, strlen (channel), 1); pm -> users = read_users (); switch (result = RyStub (sd, table_Qmgr_Operations, operation_Qmgr_processmessage, RyGenID (sd), NULLIP, (caddr_t)pm, proc_results, proc_error, ROS_SYNC, roi)) { case NOTOK: ros_adios (rop, "STUB"); case OK: /* got a result/error response */ break; case DONE: /* got RO-END? */ adios (NULLCP, "got RO-END.INDICATION"); default: adios (NULLCP, "unknown return from RyStub=%d", result); /* NOTREACHED */ } free_Qmgr_ProcMsg (pm); } doinit (sd, chan) int sd; char *chan; { struct type_Qmgr_Channel *cp; int result; int proc_null (), proc_error (); struct RoSAPindication rois; register struct RoSAPindication *roi = &rois; register struct RoSAPpreject *rop = &roi -> roi_preject; cp = str2qb (chan, strlen(chan), 1); switch (result = RyStub (sd, table_Qmgr_Operations, operation_Qmgr_channelInitialise, RyGenID (sd), NULLIP, (caddr_t)cp, proc_null, proc_error, ROS_SYNC, roi)) { case NOTOK: ros_adios (rop, "STUB"); case OK: /* got a result/error response */ break; case DONE: /* got RO-END? */ adios (NULLCP, "got RO-END.INDICATION"); default: adios (NULLCP, "unknown return from RyStub=%d", result); /* NOTREACHED */ } free_Qmgr_Channel (cp); } int assoc_release (sd) int sd; { struct AcSAPrelease acrs; register struct AcSAPrelease *acr = &acrs; struct AcSAPindication acis; register struct AcSAPindication *aci = &acis; register struct AcSAPabort *aca = &aci -> aci_abort; if (AcRelRequest (sd, ACF_NORMAL, NULLPEP, 0, acr, aci) == NOTOK) acs_adios (aca, "A-RELEASE.REQUEST"); if (!acr -> acr_affirmative) { (void) AcUAbortRequest (sd, NULLPEP, 0, aci); advise (NULLCP, "Release rejected by peer: %d", acr -> acr_reason); } ACRFREE (acr); advise (NULLCP, "Association released"); return DONE; } static struct type_Qmgr_UserList *read_users () { struct type_Qmgr_UserList *ul = NULL, *ul1; do { if (ul == NULL) ul1 = ul = (struct type_Qmgr_UserList *) malloc (sizeof *ul); else { ul -> next = (struct type_Qmgr_UserList *) malloc (sizeof *ul); ul = ul -> next; } ul -> next = 0; ul -> RecipientId = (struct type_Qmgr_RecipientId *) malloc (sizeof *ul->RecipientId); ul -> RecipientId -> parm = getint ("recipient number"); } while (another()); return ul1; } static char *getline (prompt) char *prompt; { static char buffer[BUFSIZ]; char *p; printf ("%s : ", prompt); fflush (stdout); if (fgets (buffer, sizeof buffer, stdin) == NULL) return NULL; if (buffer[0] == '\n') return NULL; if (p = index (buffer, '\n')) *p = '\0'; return buffer; } static another () { char *s; s = getline ("Another user? "); if (s == NULL) return 0; if (*s == 'y' || *s == 'Y') return 1; return 0; } static int getint (prompt) char *prompt; { char *s = getline (prompt); return atoi (s); } /* ARGSUSED */ static proc_results (sd, id, error, arg, roi) int sd, id, error; struct type_Qmgr_DeliveryStatus *arg; struct RoSAPindication *roi; { struct type_Qmgr_DeliveryStatus *ds; for (ds = arg; ds; ds = ds -> next) { printf ("Recipient number %d", ds -> IndividualDeliveryStatus -> recipient -> parm); switch (ds -> IndividualDeliveryStatus -> status) { case int_Qmgr_status_success: printf ("success\n"); break; case int_Qmgr_status_permanentFailure: printf ("permanentFailure\n"); break; case int_Qmgr_status_messageFailure: printf ("messageFailure\n"); break; case int_Qmgr_status_mtaFailure: printf ("mtaFailure\n"); break; case int_Qmgr_status_mtaAndMessageFailure: printf ("mtaAndMessageFailure\n"); break; default: printf ("Unknown response %d\n", arg -> IndividualDeliveryStatus -> status); break; } } return OK; } /* ARGSUSED */ static proc_null (sd, id, error, arg, roi) int sd, id, error; struct type_Qmgr_DeliveryStatus *arg; struct RoSAPindication *roi; { return OK; } /* ARGSUSED */ proc_error (sd, id, error, parameter, roi) int sd, id, error; caddr_t parameter; struct RoSAPindication *roi; { register struct RyError *rye; if (error == RY_REJECT) { advise (NULLCP, "%s", RoErrString ((int) parameter)); return OK; } if (rye = finderrbyerr (table_Qmgr_Errors, error)) advise (NULLCP, "%s", rye -> rye_name); else advise (NULLCP, "Error %d", error); return OK; } /* \f */ void ros_adios (rop, event) register struct RoSAPpreject *rop; char *event; { ros_advise (rop, event); _exit (1); } void ros_advise (rop, event) register struct RoSAPpreject *rop; char *event; { char buffer[BUFSIZ]; if (rop -> rop_cc > 0) (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason), rop -> rop_cc, rop -> rop_cc, rop -> rop_data); else (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason)); advise (NULLCP, "%s: %s", event, buffer); } /* \f */ void acs_adios (aca, event) register struct AcSAPabort *aca; char *event; { acs_advise (aca, event); _exit (1); } void acs_advise (aca, event) register struct AcSAPabort *aca; char *event; { char buffer[BUFSIZ]; if (aca -> aca_cc > 0) (void) sprintf (buffer, "[%s] %*.*s", AcErrString (aca -> aca_reason), aca -> aca_cc, aca -> aca_cc, aca -> aca_data); else (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason)); advise (NULLCP, "%s: %s (source %d)", event, buffer, aca -> aca_source); } /* \f */ #ifndef lint void _advise (); void adios (va_alist) va_dcl { va_list ap; va_start (ap); _advise (ap); va_end (ap); _exit (1); } #else /* VARARGS */ void adios (what, fmt) char *what, *fmt; { adios (what, fmt); } #endif #ifndef lint void advise (va_alist) va_dcl { va_list ap; va_start (ap); _advise (ap); va_end (ap); } static void _advise (ap) va_list ap; { char buffer[BUFSIZ]; asprintf (buffer, ap); (void) fflush (stdout); fprintf (stderr, "%s: ", myname); (void) fputs (buffer, stderr); (void) fputc ('\n', stderr); (void) fflush (stderr); } #else /* VARARGS */ void advise (what, fmt) char *what, *fmt; { advise (what, fmt); } #endif #ifndef lint void ryr_advise (va_alist) va_dcl { char *what; va_list ap; va_start (ap); _advise (ap); va_end (ap); } #else /* VARARGS */ void ryr_advise (what, fmt) char *what, *fmt; { ryr_advise (what, fmt); } #endif