|
|
1.1 ! root 1: /* ftamattr.c - FPM: encode/decode attributes */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/ftam/RCS/ftamattr.c,v 7.1 90/03/23 10:53:58 mrose Exp $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/ftam/RCS/ftamattr.c,v 7.1 90/03/23 10:53:58 mrose Exp $ ! 9: * ! 10: * ! 11: * $Log: ftamattr.c,v $ ! 12: * Revision 7.1 90/03/23 10:53:58 mrose ! 13: * update ! 14: * ! 15: * Revision 7.0 89/11/23 21:53:23 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: /* LINTLIBRARY */ ! 32: ! 33: #include <stdio.h> ! 34: #include "fpkt.h" ! 35: ! 36: /* */ ! 37: ! 38: struct type_FTAM_Read__Attributes *attr2fpm (fsb, fa, fti) ! 39: register struct ftamblk *fsb; ! 40: register struct FTAMattributes *fa; ! 41: struct FTAMindication *fti; ! 42: { ! 43: register int i; ! 44: register char *cp, ! 45: **ap; ! 46: register struct type_FTAM_Read__Attributes *fpm; ! 47: ! 48: if ((fpm = (struct type_FTAM_Read__Attributes *) calloc (1, sizeof *fpm)) ! 49: == NULL) { ! 50: no_mem: ; ! 51: (void) ftamlose (fti, FS_GEN (fsb), 1, NULLCP, "out of memory"); ! 52: out: ; ! 53: if (fpm) ! 54: free_FTAM_Read__Attributes (fpm); ! 55: return NULL; ! 56: } ! 57: ! 58: if (fa -> fa_present & FA_FILENAME) { ! 59: register struct type_FTAM_Filename__Attribute *fn, ! 60: **fc; ! 61: ! 62: if (fa -> fa_novalue & FA_FILENAME) { ! 63: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 64: "filename not present"); ! 65: goto out; ! 66: } ! 67: ! 68: if (fa -> fa_nfile > NFFILE) { ! 69: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 70: "too many filenames"); ! 71: goto out; ! 72: } ! 73: ! 74: fc = &fpm -> filename; ! 75: for (ap = fa -> fa_files, i = fa -> fa_nfile - 1; i >= 0; ap++, i--) { ! 76: if (*ap == NULL) { ! 77: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 78: "empty filename at slot %d", ! 79: fa -> fa_nfile - i - 1); ! 80: goto out; ! 81: } ! 82: ! 83: if ((fn = (struct type_FTAM_Filename__Attribute *) ! 84: calloc (1, sizeof *fpm -> filename)) ! 85: == NULL) ! 86: goto no_mem; ! 87: *fc = fn; ! 88: ! 89: if ((fn -> GraphicString = str2qb (*ap, strlen (*ap), 1)) == NULL) ! 90: goto no_mem; ! 91: ! 92: fc = &((*fc) -> next); ! 93: } ! 94: } ! 95: ! 96: if (fa -> fa_present & FA_ACTIONS) { ! 97: if (fa -> fa_novalue & FA_ACTIONS) { ! 98: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 99: "permitted-actions not present"); ! 100: goto out; ! 101: } ! 102: ! 103: if ((fpm -> permitted__actions = bits2fpm (fsb, fpermitted_pairs, ! 104: fa -> fa_permitted, fti)) ! 105: == NULL) ! 106: goto out; ! 107: } ! 108: ! 109: if (fa -> fa_present & FA_CONTENTS) { ! 110: if (fa -> fa_novalue & FA_CONTENTS) { ! 111: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 112: "contents-type not present"); ! 113: goto out; ! 114: } ! 115: if (fa -> fa_contents == NULLOID) { ! 116: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 117: "missing contents-type"); ! 118: goto out; ! 119: } ! 120: if ((fpm -> contents__type = ! 121: (struct type_FTAM_Contents__Type__Attribute *) ! 122: calloc (1, sizeof *fpm -> contents__type)) == NULL ! 123: || (fpm -> contents__type -> document__type__name = ! 124: oid_cpy (fa -> fa_contents)) == NULL) ! 125: goto no_mem; ! 126: if (fpm -> contents__type -> parameter = fa -> fa_parameter) ! 127: fpm -> contents__type -> parameter -> pe_refcnt++; ! 128: } ! 129: ! 130: if (fa -> fa_present & FA_ACCOUNT) { ! 131: if (fa -> fa_account == NULL) { ! 132: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 133: "missing account"); ! 134: goto out; ! 135: } ! 136: if ((fpm -> storage__account = ! 137: (struct type_FTAM_Account__Attribute *) ! 138: calloc (1, sizeof *fpm -> storage__account)) ! 139: == NULL) ! 140: goto no_mem; ! 141: if (fa -> fa_novalue & FA_ACCOUNT) ! 142: fpm -> storage__account -> offset = ! 143: type_FTAM_Account__Attribute_no__value__available; ! 144: else { ! 145: fpm -> storage__account -> offset = ! 146: type_FTAM_Account__Attribute_actual__values; ! 147: if ((fpm -> storage__account -> un.actual__values = ! 148: str2qb (fa -> fa_account, strlen (fa -> fa_account), 1)) ! 149: == NULL) ! 150: goto no_mem; ! 151: } ! 152: } ! 153: ! 154: #define dodate(flag,field,tag) \ ! 155: if (fa -> fa_present & flag) { \ ! 156: if ((fpm -> tag = (struct type_FTAM_Date__and__Time__Attribute *) \ ! 157: calloc (1, sizeof *fpm -> tag)) == NULL) \ ! 158: goto no_mem; \ ! 159: if (fa -> fa_novalue & flag) \ ! 160: fpm -> tag -> offset = \ ! 161: type_FTAM_Date__and__Time__Attribute_no__value__available;\ ! 162: else { \ ! 163: fpm -> tag -> offset = \ ! 164: type_FTAM_Date__and__Time__Attribute_actual__values; \ ! 165: if ((cp = gent2str (field)) == NULL \ ! 166: || (fpm -> tag -> un.actual__values = \ ! 167: str2qb (cp, strlen (cp), 1)) == NULL) \ ! 168: goto no_mem; \ ! 169: } \ ! 170: } ! 171: dodate (FA_DATE_CREATE, &fa -> fa_date_create, ! 172: date__and__time__of__creation); ! 173: dodate (FA_DATE_MODIFY, &fa -> fa_date_modify, ! 174: date__and__time__of__last__modification); ! 175: dodate (FA_DATE_READ, &fa -> fa_date_read, ! 176: date__and__time__of__last__read__access); ! 177: dodate (FA_DATE_ATTR, &fa -> fa_date_attribute, ! 178: date__and__time__of__last__attribute__modification); ! 179: #undef dodate ! 180: ! 181: #define douser(flag,field,tag,name) \ ! 182: if (fa -> fa_present & flag) { \ ! 183: if ((fpm -> tag = (struct type_FTAM_User__Identity__Attribute *) \ ! 184: calloc (1, sizeof *fpm -> tag)) == NULL) \ ! 185: goto no_mem; \ ! 186: if (fa -> fa_novalue & flag) \ ! 187: fpm -> tag -> offset = \ ! 188: type_FTAM_User__Identity__Attribute_no__value__available; \ ! 189: else { \ ! 190: if (field == NULL) { \ ! 191: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, "missing %s", \ ! 192: name); \ ! 193: goto out; \ ! 194: } \ ! 195: fpm -> tag -> offset = \ ! 196: type_FTAM_User__Identity__Attribute_actual__values; \ ! 197: if ((fpm -> tag -> un.actual__values = str2qb (field, \ ! 198: strlen (field), 1)) \ ! 199: == NULL) \ ! 200: goto no_mem; \ ! 201: } \ ! 202: } ! 203: douser (FA_ID_CREATE, fa -> fa_id_create, ! 204: identity__of__creator, "identity-of-creator"); ! 205: douser (FA_ID_MODIFY, fa -> fa_id_modify, ! 206: identity__of__last__modifier, "identity-of-last-modifier"); ! 207: douser (FA_ID_READ, fa -> fa_id_read, ! 208: identity__of__last__reader, "identity-of-last-reader"); ! 209: douser (FA_ID_ATTR, fa -> fa_id_attribute, ! 210: identity__of__last__attribute__modifier, ! 211: "identity-of-last-attribute-modifier"); ! 212: #undef douser ! 213: ! 214: if (fa -> fa_present & FA_AVAILABILITY) { ! 215: if ((fpm -> file__availability = ! 216: (struct type_FTAM_File__Availability__Attribute *) ! 217: calloc (1, sizeof *fpm -> file__availability)) ! 218: == NULL) ! 219: goto no_mem; ! 220: if (fa -> fa_novalue & FA_AVAILABILITY) ! 221: fpm -> file__availability -> offset = ! 222: type_FTAM_File__Availability__Attribute_no__value__available; ! 223: else { ! 224: fpm -> file__availability -> offset = ! 225: type_FTAM_File__Availability__Attribute_actual__values; ! 226: switch (fa -> fa_availability) { ! 227: case FA_AVAIL_IMMED: ! 228: case FA_AVAIL_DEFER: ! 229: fpm -> file__availability -> un.actual__values = ! 230: fa -> fa_availability; ! 231: break; ! 232: ! 233: default: ! 234: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 235: "bad value for file-availability"); ! 236: goto out; ! 237: } ! 238: } ! 239: } ! 240: ! 241: #define dosize(flag,field,tag) \ ! 242: if (fa -> fa_present & flag) { \ ! 243: if ((fpm -> tag = (struct type_FTAM_Filesize__Attribute *) \ ! 244: calloc (1, sizeof *fpm -> tag)) == NULL) \ ! 245: goto no_mem; \ ! 246: if (fa -> fa_novalue & flag) \ ! 247: fpm -> tag -> offset = \ ! 248: type_FTAM_Filesize__Attribute_no__value__available; \ ! 249: else { \ ! 250: fpm -> tag -> offset = \ ! 251: type_FTAM_Filesize__Attribute_actual__values; \ ! 252: fpm -> tag -> un.actual__values = field; \ ! 253: } \ ! 254: } ! 255: dosize (FA_FILESIZE, fa -> fa_filesize, filesize); ! 256: dosize (FA_FUTURESIZE, fa -> fa_futuresize, future__filesize); ! 257: #undef dosize ! 258: ! 259: if (fa -> fa_present & FA_CONTROL) { ! 260: if ((fpm -> access__control = ! 261: (struct type_FTAM_Access__Control__Attribute *) ! 262: calloc (1, sizeof *fpm -> access__control)) ! 263: == NULL) ! 264: goto no_mem; ! 265: if (fa -> fa_novalue & FA_CONTROL) ! 266: fpm -> access__control -> offset = ! 267: type_FTAM_Access__Control__Attribute_no__value__available; ! 268: else { ! 269: fpm -> access__control -> offset = ! 270: type_FTAM_Access__Control__Attribute_actual__values; ! 271: if ((fpm -> access__control -> un.actual__values = ! 272: acl2fpm (fsb, fa -> fa_control, fti)) == NULL) ! 273: goto out; ! 274: } ! 275: } ! 276: ! 277: if (fa -> fa_present & FA_LEGAL) { ! 278: if ((fpm -> legal__qualification = ! 279: (struct type_FTAM_Legal__Qualification__Attribute *) ! 280: calloc (1, sizeof *fpm -> legal__qualification)) ! 281: == NULL) ! 282: goto no_mem; ! 283: if (fa -> fa_novalue & FA_LEGAL) ! 284: fpm -> legal__qualification -> offset = ! 285: type_FTAM_Legal__Qualification__Attribute_no__value__available; ! 286: else { ! 287: if (fa -> fa_legal == NULL) { ! 288: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 289: "missing legal-qualification"); ! 290: goto out; ! 291: } ! 292: fpm -> legal__qualification -> offset = ! 293: type_FTAM_Legal__Qualification__Attribute_actual__values; ! 294: if ((fpm -> legal__qualification -> un.actual__values = ! 295: str2qb (fa -> fa_legal, strlen (fa -> fa_legal), 1)) ! 296: == NULL) ! 297: goto no_mem; ! 298: } ! 299: } ! 300: ! 301: /* ! 302: * Added private use attribute functionality for Retix NBS9 interworking. ! 303: * No value should always be set because we don't support private use. ! 304: * pmk. ! 305: */ ! 306: if (fa -> fa_present & FA_PRIVATE) { ! 307: (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP, ! 308: "private-use attribute not supported"); ! 309: goto out; ! 310: } ! 311: ! 312: return fpm; ! 313: } ! 314: ! 315: /* */ ! 316: ! 317: int fpm2attr (fsb, fpm, fa, fti) ! 318: register struct ftamblk *fsb; ! 319: register struct type_FTAM_Read__Attributes *fpm; ! 320: register struct FTAMattributes *fa; ! 321: struct FTAMindication *fti; ! 322: { ! 323: register char *cp; ! 324: register UTC u; ! 325: ! 326: bzero ((char *) fa, sizeof *fa); ! 327: ! 328: if (fpm -> filename) { ! 329: register int n; ! 330: register char **ap; ! 331: register struct type_FTAM_Filename__Attribute *fn; ! 332: ! 333: fa -> fa_present |= FA_FILENAME; ! 334: ! 335: ap = fa -> fa_files, n = NFFILE; ! 336: for (fn = fpm -> filename; fn; fn = fn -> next) { ! 337: if (n-- <= 0) { ! 338: (void) ftamlose (fti, FS_GEN (fsb), 1, NULLCP, ! 339: "too many names in filename"); ! 340: out: ; ! 341: FAFREE (fa); ! 342: return NOTOK; ! 343: } ! 344: if ((*ap++ = qb2str (fn -> GraphicString)) == NULL) { ! 345: no_mem: ; ! 346: (void) ftamlose (fti, FS_GEN (fsb), 1, NULLCP, ! 347: "out of memory"); ! 348: goto out; ! 349: } ! 350: fa -> fa_nfile++; ! 351: } ! 352: } ! 353: ! 354: if (fpm -> permitted__actions) { ! 355: fa -> fa_present |= FA_ACTIONS; ! 356: ! 357: if (fpm2bits (fsb, fpermitted_pairs, fpm -> permitted__actions, ! 358: &fa -> fa_permitted, fti) == NOTOK) ! 359: goto out; ! 360: } ! 361: ! 362: if (fpm -> contents__type) { ! 363: fa -> fa_present |= FA_CONTENTS; ! 364: ! 365: fa -> fa_contents = fpm -> contents__type -> document__type__name; ! 366: fpm -> contents__type -> document__type__name = NULLOID; ! 367: if (fpm -> contents__type -> parameter ! 368: && (fa -> fa_parameter = ! 369: pe_cpy (fpm -> contents__type -> parameter)) ! 370: == NULLPE) ! 371: goto no_mem; ! 372: } ! 373: ! 374: if (fpm -> storage__account) { ! 375: fa -> fa_present |= FA_ACCOUNT; ! 376: ! 377: if (fpm -> storage__account -> offset ! 378: == type_FTAM_Account__Attribute_no__value__available) ! 379: fa -> fa_novalue |= FA_ACCOUNT; ! 380: else ! 381: if ((fa -> fa_account = ! 382: qb2str (fpm -> storage__account -> un.actual__values)) ! 383: == NULL) ! 384: goto no_mem; ! 385: } ! 386: ! 387: #define dodate(flag,field,tag) \ ! 388: if (fpm -> tag) { \ ! 389: fa -> fa_present |= flag; \ ! 390: \ ! 391: if (fpm -> tag -> offset \ ! 392: == type_FTAM_Date__and__Time__Attribute_no__value__available) \ ! 393: fa -> fa_novalue |= flag; \ ! 394: else { \ ! 395: if ((cp = qb2str (fpm -> tag -> un.actual__values)) == NULL) \ ! 396: goto no_mem; \ ! 397: u = str2gent (cp, strlen (cp)); \ ! 398: free (cp); \ ! 399: if (u == NULLUTC) \ ! 400: goto no_mem; \ ! 401: field = *u; \ ! 402: } \ ! 403: } ! 404: dodate (FA_DATE_CREATE, fa -> fa_date_create, ! 405: date__and__time__of__creation); ! 406: dodate (FA_DATE_MODIFY, fa -> fa_date_modify, ! 407: date__and__time__of__last__modification); ! 408: dodate (FA_DATE_READ, fa -> fa_date_read, ! 409: date__and__time__of__last__read__access); ! 410: dodate (FA_DATE_ATTR, fa -> fa_date_attribute, ! 411: date__and__time__of__last__attribute__modification); ! 412: #undef dodate ! 413: ! 414: #define douser(flag,field,tag,name) \ ! 415: if (fpm -> tag) { \ ! 416: fa -> fa_present |= flag; \ ! 417: \ ! 418: if (fpm -> tag -> offset \ ! 419: == type_FTAM_User__Identity__Attribute_no__value__available) \ ! 420: fa -> fa_novalue |= flag; \ ! 421: else \ ! 422: if ((field = qb2str (fpm -> tag -> un.actual__values)) == NULL) \ ! 423: goto no_mem; \ ! 424: } ! 425: douser (FA_ID_CREATE, fa -> fa_id_create, ! 426: identity__of__creator, "identity-of-creator"); ! 427: douser (FA_ID_MODIFY, fa -> fa_id_modify, ! 428: identity__of__last__modifier, "identity-of-last-modifier"); ! 429: douser (FA_ID_READ, fa -> fa_id_read, ! 430: identity__of__last__reader, "identity-of-last-reader"); ! 431: douser (FA_ID_ATTR, fa -> fa_id_attribute, ! 432: identity__of__last__attribute__modifier, ! 433: "identity-of-last-attribute-modifier"); ! 434: #undef douser ! 435: ! 436: if (fpm -> file__availability) { ! 437: fa -> fa_present |= FA_AVAILABILITY; ! 438: ! 439: if (fpm -> file__availability -> offset == ! 440: type_FTAM_File__Availability__Attribute_no__value__available) ! 441: fa -> fa_novalue |= FA_AVAILABILITY; ! 442: else ! 443: fa -> fa_availability = ! 444: fpm -> file__availability -> un.actual__values; ! 445: } ! 446: ! 447: #define dosize(flag,field,tag) \ ! 448: if (fpm -> tag) { \ ! 449: fa -> fa_present |= flag; \ ! 450: \ ! 451: if (fpm -> tag -> offset \ ! 452: == type_FTAM_Filesize__Attribute_no__value__available) \ ! 453: fa -> fa_novalue |= flag; \ ! 454: else \ ! 455: field = fpm -> tag -> un.actual__values; \ ! 456: } ! 457: dosize (FA_FILESIZE, fa -> fa_filesize, filesize); ! 458: dosize (FA_FUTURESIZE, fa -> fa_futuresize, future__filesize); ! 459: #undef dosize ! 460: ! 461: if (fpm -> access__control) { ! 462: fa -> fa_present |= FA_CONTROL; ! 463: ! 464: if (fpm -> access__control -> offset ! 465: == type_FTAM_Access__Control__Attribute_no__value__available) ! 466: fa -> fa_novalue |= FA_CONTROL; ! 467: else ! 468: if (fpm2acl (fsb, fpm -> access__control -> un.actual__values, ! 469: &fa -> fa_control, fti) == NOTOK) ! 470: goto out; ! 471: } ! 472: ! 473: if (fpm -> legal__qualification) { ! 474: fa -> fa_present |= FA_LEGAL; ! 475: ! 476: if (fpm -> legal__qualification -> offset == ! 477: type_FTAM_Legal__Qualification__Attribute_no__value__available) ! 478: fa -> fa_novalue |= FA_LEGAL; ! 479: else ! 480: if ((fa -> fa_legal = ! 481: qb2str (fpm -> legal__qualification -> un.actual__values)) ! 482: == NULL) ! 483: goto no_mem; ! 484: } ! 485: ! 486: /* Added private use functionality pmk */ ! 487: if (fpm -> private__use) { ! 488: fa -> fa_present |= FA_PRIVATE; ! 489: /* Set no value, regardless of what is there we don't support it */ ! 490: fa -> fa_novalue |= FA_PRIVATE; ! 491: } ! 492: ! 493: return OK; ! 494: } ! 495: ! 496: /* */ ! 497: ! 498: void FAFREE (fa) ! 499: register struct FTAMattributes *fa; ! 500: { ! 501: register int FAI; ! 502: ! 503: for (FAI = (fa) -> fa_nfile - 1; FAI >= 0; FAI--) ! 504: if ((fa) -> fa_files[FAI]) ! 505: free ((fa) -> fa_files[FAI]), (fa) -> fa_files[FAI] = NULL; ! 506: (fa) -> fa_nfile = 0; ! 507: if ((fa) -> fa_contents) ! 508: oid_free ((fa) -> fa_contents), (fa) -> fa_contents = NULLOID; ! 509: if ((fa) -> fa_parameter) ! 510: pe_free ((fa) -> fa_parameter), (fa) -> fa_parameter = NULLPE; ! 511: if ((fa) -> fa_account) ! 512: free ((fa) -> fa_account), (fa) -> fa_account = NULL; ! 513: if ((fa) -> fa_id_create) ! 514: free ((fa) -> fa_id_create), (fa) -> fa_id_create = NULL; ! 515: if ((fa) -> fa_id_modify) ! 516: free ((fa) -> fa_id_modify), (fa) -> fa_id_modify = NULL; ! 517: if ((fa) -> fa_id_read) ! 518: free ((fa) -> fa_id_read), (fa) -> fa_id_read = NULL; ! 519: if ((fa) -> fa_id_attribute) ! 520: free ((fa) -> fa_id_attribute), (fa) -> fa_id_attribute = NULL; ! 521: if (fa -> fa_control) { ! 522: FEFREE (fa -> fa_control); ! 523: fa -> fa_control = NULL; ! 524: } ! 525: if ((fa) -> fa_legal) ! 526: free ((fa) -> fa_legal), (fa) -> fa_legal = NULL; ! 527: if ((fa) -> fa_private) ! 528: free ((fa) -> fa_private), (fa) -> fa_private = NULL; ! 529: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.