Annotation of 43BSDReno/contrib/isode-beta/others/callback/initiator.c, revision 1.1

1.1     ! root        1: /* initiator.c -- initiator for callback demo */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/others/callback/RCS/initiator.c,v 7.0 89/11/23 21:58:11 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/others/callback/RCS/initiator.c,v 7.0 89/11/23 21:58:11 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       initiator.c,v $
        !            12:  * Revision 7.0  89/11/23  21:58:11  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: #include <stdio.h>
        !            29: #include "callback.h"
        !            30: 
        !            31: /*  */
        !            32: 
        !            33: static char *mycontext = "isode callback demo";
        !            34: 
        !            35: /*  */
        !            36: 
        !            37: /* ARGSUSED */
        !            38: 
        !            39: main (argc, argv, envp)
        !            40: int    argc;
        !            41: char  **argv,
        !            42:       **envp;
        !            43: {
        !            44:     int            vecp;
        !            45:     char   *taddr,
        !            46:           *vec[4];
        !            47:     struct TSAPaddr *ta;
        !            48:     struct TSAPdisconnect tds;
        !            49:     struct TSAPdisconnect *td = &tds;
        !            50:     register struct SSAPaddr *sz;
        !            51:     struct SSAPconnect scs;
        !            52:     register struct SSAPconnect *sc = &scs;
        !            53:     struct SSAPstart sss;
        !            54:     register struct SSAPstart *ss = &sss;
        !            55:     struct SSAPdata sxs;
        !            56:     register struct SSAPdata   *sx = &sxs;
        !            57:     struct SSAPrelease  srs;
        !            58:     register struct SSAPrelease *sr = &srs;
        !            59:     struct SSAPindication sis;
        !            60:     register struct SSAPindication *si = &sis;
        !            61:     register struct SSAPabort *sa = &si -> si_abort;
        !            62:     AEI            aei;
        !            63:     struct PSAPaddr *pa;
        !            64:     struct sblk incoming,
        !            65:                outgoing;
        !            66:     SB     sbi = &incoming,
        !            67:            sbo = &outgoing;
        !            68: 
        !            69:     reportailor (argv[0]);
        !            70: 
        !            71:     if (argc != 2)
        !            72:        adios (NULLCP, "usage: %s \"host\"", argv[0]);
        !            73: 
        !            74: /* really should postpone this until after the session connect so we
        !            75:    can bind to the same network address (in the case of a multi-homed ES) */
        !            76:     if ((aei = str2aei (PLocalHostName (), mycontext)) == NULLAEI)
        !            77:        adios (NULLCP, "%s-%s: unknown application-entity",
        !            78:               PLocalHostName (), mycontext);
        !            79:     if ((pa = aei2addr (aei)) == NULLPA)
        !            80:        adios (NULLCP, "address translation failed");
        !            81:     ta = &pa -> pa_addr.sa_addr;
        !            82:     if (TNetUnique (ta, td) == NOTOK) {
        !            83:        if (td -> td_cc > 0)
        !            84:            adios (NULLCP, "TNetUnique: [%s] %*.*s", TErrString (td -> td_reason),
        !            85:                    td -> td_cc, td -> td_cc, td -> td_data);
        !            86:        else
        !            87:            adios (NULLCP, "TNetUnique: [%s]", TErrString (td -> td_reason));
        !            88:     }
        !            89:     if ((taddr = taddr2str (ta)) == NULLCP)
        !            90:        adios (NULLCP, "taddr2str failed");
        !            91: 
        !            92:     if ((aei = str2aei (argv[1], mycontext)) == NULLAEI)
        !            93:        adios (NULLCP, "%s-%s: unknown application-entity",
        !            94:               argv[1], mycontext);
        !            95:     if ((pa = aei2addr (aei)) == NULLPA)
        !            96:        adios (NULLCP, "address translation failed");
        !            97:     sz = &pa -> pa_addr;
        !            98: 
        !            99:     bzero ((char *) sbo, sizeof *sbo);
        !           100:     sbo -> sb_requirements = SR_BASUBSET;
        !           101:     sbo -> sb_settings = 0;
        !           102: #define dotoken(requires,shift,bit,type) \
        !           103: { \
        !           104:     if (sbo -> sb_requirements & requires) \
        !           105:            sbo -> sb_settings |= ST_INIT_VALUE << shift; \
        !           106: }
        !           107:     dotokens ();
        !           108: #undef  dotoken
        !           109:     sbo -> sb_isn = SERIAL_NONE;
        !           110: 
        !           111:        /* we pass the transport address we are listening on in the initial
        !           112:           user data */
        !           113:     if (SConnRequest (&sbo -> sb_connect, NULLSA, sz, sbo -> sb_requirements,
        !           114:                      sbo -> sb_settings, sbo -> sb_isn, taddr, strlen (taddr),
        !           115:                      NULLQOS, sc, si) == NOTOK)
        !           116:        adios (NULLCP, "S-CONNECT.REQUEST: %s", SErrString (sa -> sa_reason));
        !           117:     if (sc -> sc_result != SC_ACCEPT)
        !           118:        adios (NULLCP, "connection rejected by peer: %s",
        !           119:                SErrString (sc -> sc_result));
        !           120:     advise (LLOG_NOTICE, NULLCP,
        !           121:            "S-CONNECT.RESPONSE: <%d, %s, %s, %s, %ld, %d>",
        !           122:            sc -> sc_sd, sprintref (&sc -> sc_connect),
        !           123:            saddr2str (&sc -> sc_responding),
        !           124:            sprintb (sc -> sc_requirements, RMASK), sc -> sc_isn,
        !           125:            sc -> sc_ssdusize);
        !           126: 
        !           127:     sbo -> sb_sd = sc -> sc_sd;
        !           128:     sbo -> sb_requirements = sc -> sc_requirements;
        !           129:     sbo -> sb_settings = sc -> sc_settings;
        !           130: #define dotoken(requires,shift,bit,type) \
        !           131: { \
        !           132:     if (sbo -> sb_requirements & requires) \
        !           133:        if ((sbo -> sb_settings & (ST_MASK << shift)) == ST_INIT_VALUE) \
        !           134:            sbo -> sb_owned |= bit; \
        !           135: }
        !           136:     dotokens ();
        !           137: #undef  dotoken
        !           138:     sbo -> sb_ssn = sbo -> sb_isn = sc -> sc_isn;
        !           139: 
        !           140:     SCFREE (sc);
        !           141: 
        !           142:        /* now wait for the other end to call us back */
        !           143:     for (;;) {
        !           144:        if (TNetAccept (&vecp, vec, 0, NULLFD, NULLFD, NULLFD, NOTOK, td)
        !           145:                == NOTOK) {
        !           146:            if (td -> td_cc > 0)
        !           147:                adios (NULLCP, "TNetAccept: [%s] %*.*s", TErrString (td -> td_reason),
        !           148:                        td -> td_cc, td -> td_cc, td -> td_data);
        !           149:            else
        !           150:                adios (NULLCP, "TNetAccept: [%s]", TErrString (td -> td_reason));
        !           151:        }
        !           152: 
        !           153:        if (vecp > 0)
        !           154:            break;
        !           155:     }
        !           156: 
        !           157:     if (SInit (vecp, vec, ss, si) == NOTOK)
        !           158:        adios (NULLCP, "S-CONNECT.INDICATION: %s",
        !           159:               SErrString (sa -> sa_reason));
        !           160:     advise (LLOG_NOTICE, NULLCP,
        !           161:            "S-CONNECT.INDICATION: <%d, %s, %s, %s, %s, %ld, %d>",
        !           162:            ss -> ss_sd, sprintref (&ss -> ss_connect),
        !           163:            saddr2str (&ss -> ss_calling), saddr2str (&ss -> ss_called),
        !           164:            sprintb (ss -> ss_requirements, RMASK), ss -> ss_isn,
        !           165:            ss -> ss_ssdusize);
        !           166: 
        !           167:        /* stop listening, we have what we want */
        !           168:     (void) TNetClose (NULLTA, td);
        !           169: 
        !           170:     bzero ((char *) sbi, sizeof *sbi);
        !           171:     sbi -> sb_sd = ss -> ss_sd;
        !           172:     sbi -> sb_connect = ss -> ss_connect;      /* struct copy */    
        !           173:     sbi -> sb_requirements = ss -> ss_requirements & SR_BASUBSET;
        !           174:     sbi -> sb_settings = ss -> ss_settings;
        !           175: #define dotoken(requires,shift,bit,type) \
        !           176: { \
        !           177:     if (sbi -> sb_requirements & requires) \
        !           178:        switch (sbi -> sb_settings & (ST_MASK << shift)) { \
        !           179:            case ST_CALL_VALUE << shift: \
        !           180:                sbi -> sb_settings &= ~(ST_MASK << shift); \
        !           181:                sbi -> sb_settings |= ST_INIT_VALUE << shift; \
        !           182:                break; \
        !           183:  \
        !           184:            case ST_INIT_VALUE: \
        !           185:                break; \
        !           186:  \
        !           187:            case ST_RESP_VALUE: \
        !           188:                sbi -> sb_owned |= bit; \
        !           189:                break; \
        !           190:  \
        !           191:            default: \
        !           192:                adios (NULLCP, "%s token: reserved", type); \
        !           193:                break; \
        !           194:        } \
        !           195: }
        !           196:     dotokens ();
        !           197: #undef dotoken
        !           198:     sbi -> sb_ssn = sbi -> sb_isn = ss -> ss_isn;
        !           199: 
        !           200:     SSFREE (ss);
        !           201: 
        !           202:     if (SConnResponse (sbi -> sb_sd, &sbi -> sb_connect, NULLSA, SC_ACCEPT,
        !           203:            sbi -> sb_requirements, sbi -> sb_settings, sbi -> sb_isn,
        !           204:            NULLCP, 0, si) == NOTOK)
        !           205:        adios (NULLCP, "S-CONNECT.RESPONSE: %s", SErrString (sa -> sa_reason));
        !           206: 
        !           207: /* do work here */
        !           208: 
        !           209:     if (SRelRequest (sbo -> sb_sd, NULLCP, 0, NOTOK, sr, si) == NOTOK)
        !           210:        adios (NULLCP, "S-RELEASE.REQUEST: %s", SErrString (sa -> sa_reason));
        !           211:     if (!sr -> sr_affirmative)
        !           212:        adios (NULLCP, "release rejected by peer");
        !           213: 
        !           214:     switch (SReadRequest (sbi -> sb_sd, sx, NOTOK, si)) {
        !           215:        case NOTOK:
        !           216:            adios (NULLCP, "S-READ.REQUEST: %s", SErrString (sa -> sa_reason));
        !           217: 
        !           218:        case OK:
        !           219:            adios (NULLCP, "not expecting DATA indication 0x%x", sx -> sx_type);
        !           220: 
        !           221:        case DONE:
        !           222:            if (si -> si_type != SI_FINISH)
        !           223:                adios (NULLCP, "not expecting indication 0x%x", si -> si_type);
        !           224:            if (SRelResponse (sbi -> sb_sd, SC_ACCEPT, NULLCP, 0, si) == NOTOK)
        !           225:                adios (NULLCP, "S-RELEASE.RESPONSE: %s", SErrString (sa -> sa_reason));
        !           226:            break;
        !           227:     }
        !           228: 
        !           229:     exit (0);
        !           230: }

unix.superglobalmegacorp.com

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