home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / ckmail / ryinitiator.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  6.5 KB  |  331 lines

  1. /* ryinitiator.c - generic interactive initiator */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Tools/ckmail/RCS/ryinitiator.c,v 6.0 1991/12/18 20:29:15 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Tools/ckmail/RCS/ryinitiator.c,v 6.0 1991/12/18 20:29:15 jpo Rel $
  9.  *
  10.  * $Log: ryinitiator.c,v $
  11.  * Revision 6.0  1991/12/18  20:29:15  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <varargs.h>
  20. #include "util.h"
  21. #include "qmgr.h"
  22. #include "ryinitiator.h"
  23.  
  24.  
  25. /*
  26.  *                  NOTICE
  27.  *
  28.  *    Acquisition, use, and distribution of this module and related
  29.  *    materials are subject to the restrictions of a license agreement.
  30.  *    Consult the Preface in the User's Manual for the full terms of
  31.  *    this agreement.
  32.  *
  33.  */
  34.  
  35.  
  36.  
  37. static int     invoke();
  38. /*     DATA */
  39.  
  40. static char *myname = "ckmail";
  41.  
  42.  
  43. extern char *isodeversion;
  44. extern int    verbose;
  45.  
  46. /*     INITIATOR */
  47.  
  48. ryinitiator (name, host, argc, argv, myservice, ops, dispatches, quit)
  49. char    *name,
  50.     *host;
  51. int    argc;
  52. char  **argv,
  53.        *myservice;
  54. struct RyOperation ops[];
  55. struct client_dispatch *dispatches;
  56. IFP    quit;
  57. {
  58.     int        sd;
  59.     register struct client_dispatch   *ds;
  60.     struct SSAPref sfs;
  61.     register struct SSAPref *sf;
  62.     register struct PSAPaddr *pa;
  63.     struct AcSAPconnect accs;
  64.     register struct AcSAPconnect   *acc = &accs;
  65.     struct AcSAPindication  acis;
  66.     register struct AcSAPindication *aci = &acis;
  67.     register struct AcSAPabort *aca = &aci -> aci_abort;
  68.     AEI        aei;
  69.     OID        ctx,
  70.         pci;
  71.     struct PSAPctxlist pcs;
  72.     register struct PSAPctxlist *pc = &pcs;
  73.     struct RoSAPindication rois;
  74.     register struct RoSAPindication *roi = &rois;
  75.     register struct RoSAPpreject *rop = &roi -> roi_preject;
  76.     
  77.     if (name != NULLCP)
  78.         myname = strdup(name);
  79.     if ((aei = _str2aei (host, myservice, QMGR_CTX_OID, 
  80.              0, dap_user, dap_passwd)) == NULLAEI)
  81.     adios (NULLCP, "%s-%s: unknown application-entity",
  82.         host, myservice);
  83.     if ((pa = aei2addr (aei)) == NULLPA)
  84.     adios (NULLCP, "address translation failed");
  85.  
  86.     if ((ctx = oid_cpy (QMGR_AC)) == NULLOID)
  87.     adios (NULLCP, "out of memory");
  88.     if ((pci = oid_cpy (QMGR_PCI)) == NULLOID)
  89.     adios (NULLCP, "out of memory");
  90.     pc -> pc_nctx = 1;
  91.     pc -> pc_ctx[0].pc_id = 1;
  92.     pc -> pc_ctx[0].pc_asn = pci;
  93.     pc -> pc_ctx[0].pc_atn = NULLOID;
  94.  
  95.     if ((sf = addr2ref (host)) == NULL) {
  96.     sf = &sfs;
  97.     (void) bzero ((char *) sf, sizeof *sf);
  98.     }
  99.  
  100.     for (ds = dispatches; ds -> ds_name; ds++)
  101.         if (strcmp (ds -> ds_name, "readmsginfo") == 0)
  102.             break;
  103.     if (ds -> ds_name == NULL)
  104.         adios (NULLCP, "unknown operation \"%s\"", "newmessage");
  105.  
  106.     if (AcAssocRequest (ctx, NULLAEI, aei, NULLPA, pa, pc, NULLOID,
  107.         0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, NULLPEP, 0, NULLQOS,
  108.         acc, aci)
  109.         == NOTOK)
  110.     acs_adios (aca, "A-ASSOCIATE.REQUEST");
  111.  
  112.     if (acc -> acc_result != ACS_ACCEPT) {
  113.         adios (NULLCP, "Association rejected: [%s]",
  114.            AcErrString (acc -> acc_result));
  115.     }
  116.     sd = acc -> acc_sd;
  117.     ACCFREE (acc);
  118.  
  119.     if (RoSetService (sd, RoPService, roi) == NOTOK)
  120.     ros_adios (rop, "set RO/PS fails");
  121.     if (verbose == TRUE) {
  122.         printf("connected\n");
  123.         fflush(stdout);
  124.     }
  125.     invoke (sd, ops, ds, argv);
  126.  
  127.     (*quit) (sd, (struct client_dispatch *) NULL, (char **) NULL, (caddr_t *) NULL);
  128. }
  129.  
  130. /*   */
  131.  
  132. static    invoke (sd, ops, ds, args)
  133. int    sd;
  134. struct RyOperation ops[];
  135. register struct client_dispatch *ds;
  136. char  **args;
  137. {
  138.     int        result;
  139.     caddr_t in;
  140.     struct RoSAPindication  rois;
  141.     register struct RoSAPindication *roi = &rois;
  142.     register struct RoSAPpreject   *rop = &roi -> roi_preject;
  143.  
  144.     in = NULL;
  145.  
  146.     if (ds -> ds_argument && (*ds -> ds_argument) (sd, ds, args, &in) != OK) {
  147.         printf("Failed in attempting %s\n",*args);
  148.     }
  149.  
  150.     switch (result = RyStub (sd, ops, ds -> ds_operation, RyGenID (sd),
  151.                  NULLIP, in, ds -> ds_result, 
  152.                  ds -> ds_error, ROS_SYNC, roi)) {
  153.     case NOTOK:        /* failure */
  154.         if (ROS_FATAL (rop -> rop_reason))
  155.             ros_adios (rop, "STUB");
  156.         ros_advise (rop, "STUB");
  157.         break;
  158.  
  159.     case OK:        /* got a result/error response */
  160.         break;
  161.         
  162.     case DONE:        /* got RO-END? */
  163.         adios (NULLCP, "got RO-END.INDICATION");
  164.         /* NOTREACHED */
  165.  
  166.     default:
  167.         adios (NULLCP, "unknown return from RyStub=%d", result);
  168.         /* NOTREACHED */
  169.     }
  170.     
  171. #ifdef PEPSY_VERSION
  172.     if (ds -> ds_fr_mod && in)
  173.     fre_obj (in, ds -> ds_fr_mod -> md_dtab[ds -> ds_fr_index],
  174.          ds -> ds_fr_mod);
  175. #else
  176.     if (ds -> ds_free && in)
  177.     (*ds -> ds_free)(in);
  178. #endif
  179. }
  180.  
  181. /*   */
  182.  
  183. void    ros_adios (rop, event)
  184. register struct RoSAPpreject *rop;
  185. char   *event;
  186. {
  187.     ros_advise (rop, event);
  188.  
  189.     _exit (1);
  190. }
  191.  
  192.  
  193. void    ros_advise (rop, event)
  194. register struct RoSAPpreject *rop;
  195. char   *event;
  196. {
  197.     char    buffer[BUFSIZ];
  198.  
  199.     if (rop -> rop_cc > 0)
  200.     (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason),
  201.         rop -> rop_cc, rop -> rop_cc, rop -> rop_data);
  202.     else
  203.     (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason));
  204.  
  205.     advise (NULLCP, "%s: %s", event, buffer);
  206. }
  207.  
  208. /*   */
  209.  
  210. void    acs_adios (aca, event)
  211. register struct AcSAPabort *aca;
  212. char   *event;
  213. {
  214.     acs_advise (aca, event);
  215.  
  216.     _exit (1);
  217. }
  218.  
  219.  
  220. void    acs_advise (aca, event)
  221. register struct AcSAPabort *aca;
  222. char   *event;
  223. {
  224.     char    buffer[BUFSIZ];
  225.  
  226.     if (aca -> aca_cc > 0)
  227.     (void) sprintf (buffer, "[%s] %*.*s",
  228.         AcErrString (aca -> aca_reason),
  229.         aca -> aca_cc, aca -> aca_cc, aca -> aca_data);
  230.     else
  231.     (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason));
  232.  
  233.     advise (NULLCP, "%s: %s (source %d)", event, buffer,
  234.         aca -> aca_source);
  235. }
  236.  
  237. /*   */
  238.  
  239. #ifndef    lint
  240. static void    _advise ();
  241.  
  242.  
  243. void    adios (va_alist)
  244. va_dcl
  245. {
  246.     va_list ap;
  247.  
  248.     va_start (ap);
  249.  
  250.     _advise (ap);
  251.  
  252.     va_end (ap);
  253.  
  254.     _exit (1);
  255. }
  256. #else
  257. /* VARARGS */
  258.  
  259. void    adios (what, fmt)
  260. char   *what,
  261.        *fmt;
  262. {
  263.     adios (what, fmt);
  264. }
  265. #endif
  266.  
  267.  
  268. #ifndef    lint
  269. void    advise (va_alist)
  270. va_dcl
  271. {
  272.     va_list ap;
  273.  
  274.     va_start (ap);
  275.  
  276.     _advise (ap);
  277.  
  278.     va_end (ap);
  279. }
  280.  
  281.  
  282. static void  _advise (ap)
  283. va_list    ap;
  284. {
  285.     char    buffer[BUFSIZ];
  286.  
  287.     asprintf (buffer, ap);
  288.  
  289.     (void) fflush (stdout);
  290.  
  291.     fprintf (stderr, "%s: ", myname);
  292.     (void) fputs (buffer, stderr);
  293.     (void) fputc ('\n', stderr);
  294.  
  295.     (void) fflush (stderr);
  296. }
  297. #else
  298. /* VARARGS */
  299.  
  300. void    advise (what, fmt)
  301. char   *what,
  302.        *fmt;
  303. {
  304.     advise (what, fmt);
  305. }
  306. #endif
  307.  
  308.  
  309. #ifndef    lint
  310. void    ryr_advise (va_alist)
  311. va_dcl
  312. {
  313.     va_list ap;
  314.  
  315.     va_start (ap);
  316.  
  317.     _advise (ap);
  318.  
  319.     va_end (ap);
  320. }
  321. #else
  322. /* VARARGS */
  323.  
  324. void    ryr_advise (what, fmt)
  325. char   *what,
  326.        *fmt;
  327. {
  328.     ryr_advise (what, fmt);
  329. }
  330. #endif
  331.