Annotation of 43BSDReno/contrib/isode-beta/imisc/ryresponder.c, revision 1.1.1.1

1.1       root        1: /* ryresponder.c - generic idempotent responder */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/imisc/RCS/ryresponder.c,v 7.1 90/07/09 14:38:54 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/imisc/RCS/ryresponder.c,v 7.1 90/07/09 14:38:54 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       ryresponder.c,v $
                     12:  * Revision 7.1  90/07/09  14:38:54  mrose
                     13:  * sync
                     14:  * 
                     15:  * Revision 7.0  89/11/23  21:57:44  mrose
                     16:  * Release 6.0
                     17:  * 
                     18:  */
                     19: 
                     20: /*
                     21:  *                               NOTICE
                     22:  *
                     23:  *    Acquisition, use, and distribution of this module and related
                     24:  *    materials are subject to the restrictions of a license agreement.
                     25:  *    Consult the Preface in the User's Manual for the full terms of
                     26:  *    this agreement.
                     27:  *
                     28:  */
                     29: 
                     30: 
                     31: #include <stdio.h>
                     32: #include <setjmp.h>
                     33: #include <varargs.h>
                     34: #include "ryresponder.h"
                     35: #include "tsap.h"              /* for listening */
                     36: #include "tailor.h"
                     37: 
                     38: /*    DATA */
                     39: 
                     40: int    debug = 0;
                     41: 
                     42: static LLog _pgm_log = {
                     43:     "responder.log", NULLCP, NULLCP,
                     44:     LLOG_FATAL | LLOG_EXCEPTIONS | LLOG_NOTICE, LLOG_FATAL, -1,
                     45:     LLOGCLS | LLOGCRT | LLOGZER, NOTOK
                     46: };
                     47: LLog *pgm_log = &_pgm_log;
                     48: 
                     49: static char *myname = "ryresponder";
                     50: 
                     51: 
                     52: static jmp_buf toplevel;
                     53: 
                     54: 
                     55: static IFP     startfnx;
                     56: static IFP     stopfnx;
                     57: 
                     58: int    ros_init (), ros_work (), ros_indication (), ros_lose ();
                     59: 
                     60: 
                     61: extern int  errno;
                     62: 
                     63: /*    RESPONDER */
                     64: 
                     65: ryresponder (argc, argv, host, myservice, mycontext, dispatches, ops,
                     66:             start, stop)
                     67: int    argc;
                     68: char  **argv,
                     69:        *host,
                     70:        *myservice,
                     71:        *mycontext;
                     72: struct dispatch *dispatches;
                     73: struct RyOperation *ops;
                     74: IFP    start,
                     75:        stop;
                     76: {
                     77:     register struct dispatch   *ds;
                     78:     AEI            aei;
                     79:     struct TSAPdisconnect   tds;
                     80:     struct TSAPdisconnect  *td = &tds;
                     81:     struct RoSAPindication  rois;
                     82:     register struct RoSAPindication *roi = &rois;
                     83:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
                     84: 
                     85:     if (myname = rindex (argv[0], '/'))
                     86:        myname++;
                     87:     if (myname == NULL || *myname == NULL)
                     88:        myname = argv[0];
                     89: 
                     90:     isodetailor (myname, 0);
                     91:     if (debug = isatty (fileno (stderr)))
                     92:        ll_dbinit (pgm_log, myname);
                     93:     else {
                     94:        static char  myfile[BUFSIZ];
                     95: 
                     96:        (void) sprintf (myfile, "%s.log",
                     97:                        (strncmp (myname, "ros.", 4)                    
                     98:                                    && strncmp (myname, "lpp.", 4))
                     99:                                || myname[4] == NULL
                    100:                            ? myname : myname + 4);
                    101:        pgm_log -> ll_file = myfile;
                    102:        ll_hdinit (pgm_log, myname);
                    103:     }
                    104: 
                    105:     advise (LLOG_NOTICE, NULLCP, "starting");
                    106: 
                    107:     if ((aei = _str2aei (host, myservice, mycontext, 0)) == NULLAEI)
                    108:        adios (NULLCP, "unable to resolve service: %s", PY_pepy);
                    109: 
                    110:     for (ds = dispatches; ds -> ds_name; ds++)
                    111:        if (RyDispatch (NOTOK, ops, ds -> ds_operation, ds -> ds_vector, roi)
                    112:                == NOTOK)
                    113:            ros_adios (rop, ds -> ds_name);
                    114: 
                    115:     startfnx = start;
                    116:     stopfnx = stop;
                    117: 
                    118:     if (isodeserver (argc, argv, aei, ros_init, ros_work, ros_lose, td)
                    119:            == NOTOK) {
                    120:        if (td -> td_cc > 0)
                    121:            adios (NULLCP, "isodeserver: [%s] %*.*s",
                    122:                    TErrString (td -> td_reason),
                    123:                    td -> td_cc, td -> td_cc, td -> td_data);
                    124:        else
                    125:            adios (NULLCP, "isodeserver: [%s]",
                    126:                    TErrString (td -> td_reason));
                    127:     }
                    128: 
                    129:     exit (0);
                    130: }
                    131: 
                    132: /*  */
                    133: 
                    134: static int  ros_init (vecp, vec)
                    135: int    vecp;
                    136: char  **vec;
                    137: {
                    138:     int            reply,
                    139:            result,
                    140:            sd;
                    141:     struct AcSAPstart   acss;
                    142:     register struct AcSAPstart *acs = &acss;
                    143:     struct AcSAPindication  acis;
                    144:     register struct AcSAPindication *aci = &acis;
                    145:     register struct AcSAPabort   *aca = &aci -> aci_abort;
                    146:     register struct PSAPstart *ps = &acs -> acs_start;
                    147:     struct RoSAPindication  rois;
                    148:     register struct RoSAPindication *roi = &rois;
                    149:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
                    150: 
                    151:     if (AcInit (vecp, vec, acs, aci) == NOTOK) {
                    152:        acs_advise (aca, "initialization fails");
                    153:        return NOTOK;
                    154:     }
                    155:     advise (LLOG_NOTICE, NULLCP,
                    156:                "A-ASSOCIATE.INDICATION: <%d, %s, %s, %s, %d>",
                    157:                acs -> acs_sd, oid2ode (acs -> acs_context),
                    158:                sprintaei (&acs -> acs_callingtitle),
                    159:                sprintaei (&acs -> acs_calledtitle), acs -> acs_ninfo);
                    160: 
                    161:     sd = acs -> acs_sd;
                    162: 
                    163:     for (vec++; *vec; vec++)
                    164:        advise (LLOG_EXCEPTIONS, NULLCP, "unknown argument \"%s\"", *vec);
                    165: 
                    166:     reply = startfnx ? (*startfnx) (sd, acs) : ACS_ACCEPT;
                    167: 
                    168:     result = AcAssocResponse (sd, reply,
                    169:                reply != ACS_ACCEPT ? ACS_USER_NOREASON : ACS_USER_NULL,
                    170:                NULLOID, NULLAEI, NULLPA, NULLPC, ps -> ps_defctxresult,
                    171:                ps -> ps_prequirements, ps -> ps_srequirements, SERIAL_NONE,
                    172:                ps -> ps_settings, &ps -> ps_connect, NULLPEP, 0, aci);
                    173: 
                    174:     ACSFREE (acs);
                    175: 
                    176:     if (result == NOTOK) {
                    177:        acs_advise (aca, "A-ASSOCIATE.RESPONSE");
                    178:        return NOTOK;
                    179:     }
                    180:     if (reply != ACS_ACCEPT)
                    181:        return NOTOK;
                    182: 
                    183:     if (RoSetService (sd, RoPService, roi) == NOTOK)
                    184:        ros_adios (rop, "set RO/PS fails");
                    185: 
                    186:     return sd;
                    187: }
                    188: 
                    189: /*  */
                    190: 
                    191: static int  ros_work (fd)
                    192: int    fd;
                    193: {
                    194:     int            result;
                    195:     caddr_t out;
                    196:     struct AcSAPindication  acis;
                    197:     struct RoSAPindication  rois;
                    198:     register struct RoSAPindication *roi = &rois;
                    199:     register struct RoSAPpreject   *rop = &roi -> roi_preject;
                    200: 
                    201:     switch (setjmp (toplevel)) {
                    202:        case OK: 
                    203:            break;
                    204: 
                    205:        default: 
                    206:            if (stopfnx)
                    207:                (*stopfnx) (fd, (struct AcSAPfinish *) 0);
                    208:        case DONE:
                    209:            (void) AcUAbortRequest (fd, NULLPEP, 0, &acis);
                    210:            (void) RyLose (fd, roi);
                    211:            return NOTOK;
                    212:     }
                    213: 
                    214:     switch (result = RyWait (fd, NULLIP, &out, OK, roi)) {
                    215:        case NOTOK: 
                    216:            if (rop -> rop_reason == ROS_TIMER)
                    217:                break;
                    218:        case OK: 
                    219:        case DONE: 
                    220:            ros_indication (fd, roi);
                    221:            break;
                    222: 
                    223:        default: 
                    224:            adios (NULLCP, "unknown return from RoWaitRequest=%d", result);
                    225:     }
                    226: 
                    227:     return OK;
                    228: }
                    229: 
                    230: /*  */
                    231: 
                    232: static int ros_indication (sd, roi)
                    233: int    sd;
                    234: register struct RoSAPindication *roi;
                    235: {
                    236:     int            reply,
                    237:            result;
                    238: 
                    239:     switch (roi -> roi_type) {
                    240:        case ROI_INVOKE: 
                    241:        case ROI_RESULT: 
                    242:        case ROI_ERROR: 
                    243:            adios (NULLCP, "unexpected indication type=%d", roi -> roi_type);
                    244:            break;
                    245: 
                    246:        case ROI_UREJECT: 
                    247:            {
                    248:                register struct RoSAPureject   *rou = &roi -> roi_ureject;
                    249: 
                    250:                if (rou -> rou_noid)
                    251:                    advise (LLOG_EXCEPTIONS, NULLCP,
                    252:                            "RO-REJECT-U.INDICATION/%d: %s",
                    253:                            sd, RoErrString (rou -> rou_reason));
                    254:                else
                    255:                    advise (LLOG_EXCEPTIONS, NULLCP,
                    256:                            "RO-REJECT-U.INDICATION/%d: %s (id=%d)",
                    257:                            sd, RoErrString (rou -> rou_reason),
                    258:                            rou -> rou_id);
                    259:            }
                    260:            break;
                    261: 
                    262:        case ROI_PREJECT: 
                    263:            {
                    264:                register struct RoSAPpreject   *rop = &roi -> roi_preject;
                    265: 
                    266:                if (ROS_FATAL (rop -> rop_reason))
                    267:                    ros_adios (rop, "RO-REJECT-P.INDICATION");
                    268:                ros_advise (rop, "RO-REJECT-P.INDICATION");
                    269:            }
                    270:            break;
                    271: 
                    272:        case ROI_FINISH: 
                    273:            {
                    274:                register struct AcSAPfinish *acf = &roi -> roi_finish;
                    275:                struct AcSAPindication  acis;
                    276:                register struct AcSAPabort *aca = &acis.aci_abort;
                    277: 
                    278:                advise (LLOG_NOTICE, NULLCP, "A-RELEASE.INDICATION/%d: %d",
                    279:                        sd, acf -> acf_reason);
                    280: 
                    281:                reply = stopfnx ? (*stopfnx) (sd, acf) : ACS_ACCEPT;
                    282: 
                    283:                result = AcRelResponse (sd, reply, ACR_NORMAL, NULLPEP, 0,
                    284:                            &acis);
                    285: 
                    286:                ACFFREE (acf);
                    287: 
                    288:                if (result == NOTOK)
                    289:                    acs_advise (aca, "A-RELEASE.RESPONSE");
                    290:                else
                    291:                    if (reply != ACS_ACCEPT)
                    292:                        break;
                    293:                longjmp (toplevel, DONE);
                    294:            }
                    295:        /* NOTREACHED */
                    296: 
                    297:        default: 
                    298:            adios (NULLCP, "unknown indication type=%d", roi -> roi_type);
                    299:     }
                    300: }
                    301: 
                    302: /*  */
                    303: 
                    304: static int  ros_lose (td)
                    305: struct TSAPdisconnect *td;
                    306: {
                    307:     if (td -> td_cc > 0)
                    308:        adios (NULLCP, "TNetAccept: [%s] %*.*s",
                    309:                TErrString (td -> td_reason), td -> td_cc, td -> td_cc,
                    310:                td -> td_data);
                    311:     else
                    312:        adios (NULLCP, "TNetAccept: [%s]", TErrString (td -> td_reason));
                    313: }
                    314: 
                    315: /*    ERRORS */
                    316: 
                    317: void   ros_adios (rop, event)
                    318: register struct RoSAPpreject *rop;
                    319: char   *event;
                    320: {
                    321:     ros_advise (rop, event);
                    322: 
                    323:     longjmp (toplevel, NOTOK);
                    324: }
                    325: 
                    326: 
                    327: void   ros_advise (rop, event)
                    328: register struct RoSAPpreject *rop;
                    329: char   *event;
                    330: {
                    331:     char    buffer[BUFSIZ];
                    332: 
                    333:     if (rop -> rop_cc > 0)
                    334:        (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason),
                    335:                rop -> rop_cc, rop -> rop_cc, rop -> rop_data);
                    336:     else
                    337:        (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason));
                    338: 
                    339:     advise (LLOG_EXCEPTIONS, NULLCP, "%s: %s", event, buffer);
                    340: }
                    341: 
                    342: /*  */
                    343: 
                    344: void   acs_advise (aca, event)
                    345: register struct AcSAPabort *aca;
                    346: char   *event;
                    347: {
                    348:     char    buffer[BUFSIZ];
                    349: 
                    350:     if (aca -> aca_cc > 0)
                    351:        (void) sprintf (buffer, "[%s] %*.*s",
                    352:                AcErrString (aca -> aca_reason),
                    353:                aca -> aca_cc, aca -> aca_cc, aca -> aca_data);
                    354:     else
                    355:        (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason));
                    356: 
                    357:     advise (LLOG_EXCEPTIONS, NULLCP, "%s: %s (source %d)", event, buffer,
                    358:                aca -> aca_source);
                    359: }
                    360: 
                    361: /*  */
                    362: 
                    363: #ifndef        lint
                    364: void   adios (va_alist)
                    365: va_dcl
                    366: {
                    367:     va_list ap;
                    368: 
                    369:     va_start (ap);
                    370:     
                    371:     _ll_log (pgm_log, LLOG_FATAL, ap);
                    372: 
                    373:     va_end (ap);
                    374: 
                    375:     _exit (1);
                    376: }
                    377: #else
                    378: /* VARARGS2 */
                    379: 
                    380: void   adios (what, fmt)
                    381: char   *what,
                    382:        *fmt;
                    383: {
                    384:     adios (what, fmt);
                    385: }
                    386: #endif
                    387: 
                    388: 
                    389: #ifndef        lint
                    390: void   advise (va_alist)
                    391: va_dcl
                    392: {
                    393:     int            code;
                    394:     va_list ap;
                    395: 
                    396:     va_start (ap);
                    397:     
                    398:     code = va_arg (ap, int);
                    399: 
                    400:     _ll_log (pgm_log, code, ap);
                    401: 
                    402:     va_end (ap);
                    403: }
                    404: #else
                    405: /* VARARGS3 */
                    406: 
                    407: void   advise (code, what, fmt)
                    408: char   *what,
                    409:        *fmt;
                    410: int    code;
                    411: {
                    412:     advise (code, what, fmt);
                    413: }
                    414: #endif
                    415: 
                    416: 
                    417: #ifndef        lint
                    418: void   ryr_advise (va_alist)
                    419: va_dcl
                    420: {
                    421:     va_list ap;
                    422: 
                    423:     va_start (ap);
                    424:     
                    425:     _ll_log (pgm_log, LLOG_NOTICE, ap);
                    426: 
                    427:     va_end (ap);
                    428: }
                    429: #else
                    430: /* VARARGS2 */
                    431: 
                    432: void   ryr_advise (what, fmt)
                    433: char   *what,
                    434:        *fmt;
                    435: {
                    436:     ryr_advise (what, fmt);
                    437: }
                    438: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.