|
|
1.1 ! root 1: /* ssaptoken.c - SPM: tokens */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/ssap/RCS/ssaptoken.c,v 7.0 89/11/23 22:25:50 mrose Rel $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/ssap/RCS/ssaptoken.c,v 7.0 89/11/23 22:25:50 mrose Rel $ ! 9: * ! 10: * ! 11: * $Log: ssaptoken.c,v $ ! 12: * Revision 7.0 89/11/23 22:25:50 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: /* LINTLIBRARY */ ! 29: ! 30: #include <stdio.h> ! 31: #include <signal.h> ! 32: #include "spkt.h" ! 33: ! 34: /* S-TOKEN-GIVE.REQUEST */ ! 35: ! 36: #define dotoken(requires,shift,bit,type) \ ! 37: { \ ! 38: if (tokens & bit) { \ ! 39: if (!(sb -> sb_requirements & requires)) \ ! 40: return ssaplose (si, SC_OPERATION, NULLCP, \ ! 41: "%s token unavailable", type); \ ! 42: if (!(sb -> sb_owned & bit)) \ ! 43: return ssaplose (si, SC_OPERATION, NULLCP, \ ! 44: "%s token not owned by you", type); \ ! 45: settings |= bit; \ ! 46: } \ ! 47: } ! 48: ! 49: /* */ ! 50: ! 51: int SGTokenRequest (sd, tokens, si) ! 52: int sd; ! 53: int tokens; ! 54: struct SSAPindication *si; ! 55: { ! 56: SBV smask; ! 57: int result; ! 58: register struct ssapblk *sb; ! 59: ! 60: missingP (si); ! 61: ! 62: smask = sigioblock (); ! 63: ! 64: ssapXsig (sb, sd); ! 65: ! 66: result = SGTokenRequestAux (sb, tokens, si); ! 67: ! 68: (void) sigiomask (smask); ! 69: ! 70: return result; ! 71: } ! 72: ! 73: /* */ ! 74: ! 75: static int SGTokenRequestAux (sb, tokens, si) ! 76: register struct ssapblk *sb; ! 77: int tokens; ! 78: struct SSAPindication *si; ! 79: { ! 80: int result, ! 81: settings; ! 82: register struct ssapkt *s; ! 83: ! 84: settings = 0; ! 85: dotokens (); ! 86: if (settings == 0) ! 87: return ssaplose (si, SC_PARAMETER, NULLCP, "no tokens to give"); ! 88: ! 89: if (sb -> sb_flags & SB_GTC) ! 90: return ssaplose (si, SC_OPERATION, NULLCP, ! 91: "give control request in progress"); ! 92: ! 93: if (settings & ST_DAT_TOKEN) ! 94: sb -> sb_flags &= ~(SB_EDACK | SB_ERACK); ! 95: else ! 96: if (sb -> sb_flags & (SB_EDACK | SB_ERACK)) ! 97: return ssaplose (si, SC_OPERATION, "exception in progress"); ! 98: ! 99: if ((s = newspkt (SPDU_GT)) == NULL) ! 100: return ssaplose (si, SC_CONGEST, NULLCP, "out of memory"); ! 101: s -> s_mask |= SMASK_SPDU_GT; ! 102: ! 103: s -> s_mask |= SMASK_GT_TOKEN; ! 104: s -> s_gt_token = settings & 0xff; ! 105: ! 106: if ((result = spkt2sd (s, sb -> sb_fd, 0, si)) == NOTOK) ! 107: freesblk (sb); ! 108: else ! 109: sb -> sb_owned &= ~s -> s_gt_token; ! 110: ! 111: freespkt (s); ! 112: ! 113: return result; ! 114: } ! 115: ! 116: #undef dotoken ! 117: ! 118: /* S-TOKEN-PLEASE.REQUEST */ ! 119: ! 120: #define dotoken(requires,shift,bit,type) \ ! 121: { \ ! 122: if (tokens & bit) { \ ! 123: if (!(sb -> sb_requirements & requires)) \ ! 124: return ssaplose (si, SC_OPERATION, NULLCP, \ ! 125: "%s token unavailable", type); \ ! 126: if (sb -> sb_owned & bit) \ ! 127: return ssaplose (si, SC_OPERATION, NULLCP, \ ! 128: "%s token owned by you", type); \ ! 129: settings |= bit; \ ! 130: } \ ! 131: } ! 132: ! 133: /* */ ! 134: ! 135: int SPTokenRequest (sd, tokens, data, cc, si) ! 136: int sd; ! 137: int tokens, ! 138: cc; ! 139: char *data; ! 140: struct SSAPindication *si; ! 141: { ! 142: SBV smask; ! 143: int result; ! 144: register struct ssapblk *sb; ! 145: ! 146: missingP (si); ! 147: ! 148: smask = sigioblock (); ! 149: ! 150: ssapPsig (sb, sd); ! 151: toomuchP (sb, data, cc, ST_SIZE, "token"); ! 152: ! 153: result = SPTokenRequestAux (sb, tokens, data, cc, si); ! 154: ! 155: (void) sigiomask (smask); ! 156: ! 157: return result; ! 158: } ! 159: ! 160: /* */ ! 161: ! 162: static int SPTokenRequestAux (sb, tokens, data, cc, si) ! 163: register struct ssapblk *sb; ! 164: int tokens, ! 165: cc; ! 166: char *data; ! 167: struct SSAPindication *si; ! 168: { ! 169: int result, ! 170: settings; ! 171: register struct ssapkt *s; ! 172: ! 173: settings = 0; ! 174: dotokens (); ! 175: if (settings == 0) ! 176: return ssaplose (si, SC_PARAMETER, NULLCP, "no tokens to ask for"); ! 177: ! 178: if (sb -> sb_flags & SB_GTC) ! 179: return ssaplose (si, SC_OPERATION, NULLCP, ! 180: "give control request in progress"); ! 181: ! 182: if ((s = newspkt (SPDU_PT)) == NULL) ! 183: return ssaplose (si, SC_CONGEST, NULLCP, "out of memory"); ! 184: ! 185: s -> s_mask |= SMASK_PT_TOKEN; ! 186: s -> s_pt_token = settings & 0xff; ! 187: ! 188: if (cc > 0) { ! 189: s -> s_mask |= SMASK_UDATA_PGI; ! 190: s -> s_udata = data, s -> s_ulen = cc; ! 191: } ! 192: else ! 193: s -> s_udata = NULL, s -> s_ulen = 0; ! 194: if ((result = spkt2sd (s, sb -> sb_fd, 0, si)) == NOTOK) ! 195: freesblk (sb); ! 196: s -> s_mask &= ~SMASK_UDATA_PGI; ! 197: s -> s_udata = NULL, s -> s_ulen = 0; ! 198: ! 199: freespkt (s); ! 200: ! 201: return result; ! 202: } ! 203: ! 204: #undef dotoken
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.