Annotation of 43BSDReno/contrib/isode-beta/ftam2/ftamd-trans.c, revision 1.1.1.1

1.1       root        1: /* ftamd-trans.c - FTAM responder -- transfer */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/ftam2/RCS/ftamd-trans.c,v 7.2 90/07/01 21:03:28 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/ftam2/RCS/ftamd-trans.c,v 7.2 90/07/01 21:03:28 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       ftamd-trans.c,v $
                     12:  * Revision 7.2  90/07/01  21:03:28  mrose
                     13:  * pepsy
                     14:  * 
                     15:  * Revision 7.1  90/01/16  20:43:01  mrose
                     16:  * last check-out
                     17:  * 
                     18:  * Revision 7.0  89/11/23  21:54:33  mrose
                     19:  * Release 6.0
                     20:  * 
                     21:  */
                     22: 
                     23: /*
                     24:  *                               NOTICE
                     25:  *
                     26:  *    Acquisition, use, and distribution of this module and related
                     27:  *    materials are subject to the restrictions of a license agreement.
                     28:  *    Consult the Preface in the User's Manual for the full terms of
                     29:  *    this agreement.
                     30:  *
                     31:  */
                     32: 
                     33: #include <stdio.h>
                     34: #include "FTAM-types.h"
                     35: #include "ftamsystem.h"
                     36: #if    defined(SYS5) && !defined(HPUX)
                     37: #include <sys/times.h>
                     38: #define        TMS
                     39: #endif
                     40: 
                     41: /*    DATA */
                     42: 
                     43: static int  nbytes;
                     44: 
                     45: long   lseek ();
                     46: 
                     47: 
                     48: /*    TRANSFER */
                     49: 
                     50: int    ftam_bulkbeginindication (ftg)
                     51: struct FTAMgroup *ftg;
                     52: {
                     53:     int            state;
                     54:     struct FTAMgroup    ftms;
                     55:     struct FTAMgroup   *ftm = &ftms;
                     56:     struct FTAMindication   ftis;
                     57:     register struct FTAMindication *fti = &ftis;
                     58: 
                     59:     ftam_selection (ftg, ftm);
                     60: 
                     61:     if (ftm -> ftg_flags & FTG_SELECT)
                     62:        state = ftm -> ftg_select.ftse_state;
                     63:     else
                     64:        state = ftm -> ftg_create.ftce_state;
                     65:     if ((state != FSTATE_SUCCESS
                     66:                || ((ftm -> ftg_flags & FTG_OPEN)
                     67:                        && ftm -> ftg_open.ftop_state != FSTATE_SUCCESS))
                     68:            && myfd != NOTOK) {
                     69: #ifndef        BRIDGE
                     70:        unlock ();
                     71: #endif
                     72:        (void) close (myfd);
                     73:        myfd = NOTOK;
                     74:     }
                     75: 
                     76:     if (FBulkBeginResponse (ftamfd, ftm, fti) == NOTOK)
                     77:        ftam_adios (&fti -> fti_abort, "F-BULK-BEGIN.RESPONSE");
                     78: 
                     79:     FTGFREE (ftg);
                     80: }
                     81: 
                     82: /*  */
                     83: 
                     84: /* we really pay the price here for not keeping more constraint set
                     85:    information in the vfs structure...
                     86: 
                     87:    regular files have the unstructured constraint set
                     88:        access context US
                     89: 
                     90:    directory files have the sequential flat constraint set
                     91:        access context UA (is forced)
                     92: 
                     93:    Hence, when FADUs are transmitted, only data elements of type
                     94: 
                     95:        File-Contents-Data-Element
                     96: 
                     97:    are sent.
                     98: */
                     99: 
                    100: 
                    101: int    ftam_readwriteindication (ftrw)
                    102: struct FTAMreadwrite *ftrw;
                    103: {
                    104:     int            result;
                    105:     register struct FADUidentity *fa = &ftrw -> ftrw_identity;
                    106:     struct FTAMdiagnostic   diags[NFDIAG];
                    107:     struct FTAMdiagnostic *dp = diags;
                    108:     struct FTAMindication   ftis;
                    109:     register struct FTAMindication *fti = &ftis;
                    110: 
                    111:     mylocation = *fa;          /* struct copy */
                    112:     mylevel = ftrw -> ftrw_level;
                    113:     
                    114: #ifdef BRIDGE
                    115:     myoperation = ftrw -> ftrw_operation; 
                    116:     if (ftp_type (myvf - vfs) == NOTOK
                    117:            && myoperation == FA_OPS_READ
                    118:            && (mycontext = ftrw -> ftrw_context) != myvf -> vf_context) {
                    119: #else
                    120:     if ((myoperation = ftrw -> ftrw_operation) == FA_OPS_READ
                    121:            && (mycontext = ftrw -> ftrw_context) != myvf -> vf_context) {
                    122: #endif
                    123:        dp -> ftd_type = DIAG_PERM;
                    124:        dp -> ftd_identifier = FS_ACC_CTXSUPRT;
                    125:        dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    126:        dp -> ftd_delay = DIAG_NODELAY;
                    127:        dp -> ftd_cc = 0;
                    128:        dp++;
                    129: 
                    130:        goto do_cancel;
                    131:     }
                    132: 
                    133:     switch (myvf - vfs) {
                    134:        case VFS_UBF: 
                    135:        case VFS_UTF: 
                    136:        default: 
                    137:            if (fa -> fa_type != FA_FIRSTLAST
                    138:                    || fa -> fa_firstlast != FA_FIRST) {
                    139:                dp -> ftd_type = DIAG_PERM;
                    140:                dp -> ftd_identifier = FS_ACC_FADULOC;
                    141:                dp -> ftd_observer = EREF_RFSU, dp -> ftd_source = EREF_IFSU;
                    142:                dp -> ftd_delay = DIAG_NODELAY;
                    143:                dp -> ftd_cc = 0;
                    144:                dp++;
                    145: 
                    146:                goto do_cancel;
                    147:            }
                    148:            break;
                    149:     }
                    150: 
                    151:     switch (myoperation) {
                    152:        case FA_OPS_READ:
                    153:        default:
                    154:            advise (LLOG_NOTICE, NULLCP, "read %s", myfile);
                    155:            break;
                    156: 
                    157:        case FA_OPS_INSERT:     /* not valid on an FDF */
                    158:            dp -> ftd_type = DIAG_PERM;
                    159:            dp -> ftd_identifier = FS_ACC_INSERT;
                    160:            dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    161:            dp -> ftd_delay = DIAG_NODELAY;
                    162:            dp -> ftd_cc = 0;
                    163:            dp++;
                    164:            goto do_cancel;
                    165: 
                    166:        case FA_OPS_REPLACE:
                    167: #ifdef BRIDGE
                    168:            if ((myfd = ftp_write (myfile)) == NOTOK) {
                    169: #else
                    170:            if (statok && myst.st_size == 0)
                    171:                goto replace;
                    172: #ifdef SUNOS4
                    173:            if (ftruncate (myfd, (off_t) 0) == NOTOK) {
                    174: #else
                    175:            if (ftruncate (myfd, 0) == NOTOK) {
                    176: #endif
                    177: #endif
                    178: bad_operation: ;
                    179:                dp -> ftd_type = DIAG_PERM;
                    180:                dp -> ftd_identifier = myoperation == FA_OPS_REPLACE
                    181:                                            ? FS_ACC_REPLACE : FS_ACC_INSERT;
                    182:                dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    183:                dp -> ftd_delay = DIAG_NODELAY;
                    184: #ifdef BRIDGE
                    185:                (void) strcpy (dp -> ftd_data, ftp_error);
                    186: #else
                    187:                (void) strcpy (dp -> ftd_data, sys_errname (errno));
                    188: #endif
                    189:                dp -> ftd_cc = strlen (dp -> ftd_data);
                    190:                dp++;
                    191:                goto do_cancel;
                    192:            }
                    193: #ifndef        BRIDGE
                    194: replace: ;
                    195: #endif
                    196:            advise (LLOG_NOTICE, NULLCP, "replace %s", myfile);
                    197:            break;
                    198: 
                    199:        case FA_OPS_EXTEND:
                    200: #ifdef BRIDGE
                    201:            if ((myfd = ftp_append (myfile)) == NOTOK)
                    202: #else
                    203:            if (lseek (myfd, 0L, L_XTND) == (long) NOTOK)
                    204: #endif
                    205:                goto bad_operation;
                    206:            advise (LLOG_NOTICE, NULLCP, "extend %s", myfile);
                    207:            break;
                    208:     }
                    209: 
                    210:     FTRWFREE (ftrw);
                    211: 
                    212:     timer (nbytes = 0, NULLCP);
                    213:     if (myoperation != FA_OPS_READ)
                    214:        return;
                    215: 
                    216:     switch (myvf - vfs) {
                    217:        case VFS_UTF:
                    218:        case VFS_UBF:
                    219:        default:
                    220:            result = uxfget (&dp);
                    221:            break;
                    222: 
                    223:        case VFS_FDF:
                    224:            result = fdfget (&dp);
                    225:            break;
                    226:     }
                    227: 
                    228:     if (result != NOTOK)
                    229:        return;
                    230: 
                    231: do_cancel: ;
                    232:     FTRWFREE (ftrw);
                    233: 
                    234:     if (FCancelRequest (ftamfd, FACTION_PERM, NULLPE, diags, dp - diags, fti)
                    235:            == NOTOK)
                    236:        ftam_adios (&fti -> fti_abort, "F-CANCEL-REQUEST");
                    237: 
                    238:     if (fti -> fti_type == FTI_CANCEL) {
                    239:        register struct FTAMcancel *ftcn = &fti -> fti_cancel;
                    240: 
                    241:        advise (LLOG_NOTICE, NULLCP, "F-CANCEL.RESPONSE: %d",
                    242:                    ftcn -> ftcn_action);
                    243:        ftam_diag (ftcn -> ftcn_diags, ftcn -> ftcn_ndiag);
                    244:        FTCNFREE (ftcn);
                    245:     }
                    246: }
                    247: 
                    248: /*  */
                    249: 
                    250: static uxfget (diags)
                    251: register struct FTAMdiagnostic **diags;
                    252: {
                    253:     register int    n;
                    254:     int            bsize,
                    255:            effector,
                    256:            gd,
                    257:            magic,
                    258:            nc,
                    259:            size;
                    260:     PE     pe,
                    261:            de;
                    262:     register struct FTAMdiagnostic *dp = *diags;
                    263:     struct FTAMindication   ftis;
                    264:     register struct FTAMindication *fti = &ftis;
                    265:     register struct FTAMabort *fta = &fti -> fti_abort;
                    266:     register struct type_DOCS_FTAM__1__Parameters *p1;
                    267:     register struct type_DOCS_FTAM__3__Parameters *p3;
                    268:     FILE   *fp;
                    269: #ifdef BRIDGE
                    270:     char line[BUFSIZ];
                    271: #endif
                    272: 
                    273: #ifdef BRIDGE
                    274:     /* try opening file for ftp read */
                    275:     if ((myfd = ftp_read (myfile)) == NOTOK){
                    276:        dp -> ftd_type = DIAG_PERM;
                    277:        dp -> ftd_identifier = FS_ACC_LCL;
                    278:        dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    279:        dp -> ftd_delay = DIAG_NODELAY;
                    280:        (void) strcpy (dp -> ftd_data, "failed file access on remote host");
                    281:        dp -> ftd_cc = strlen (dp -> ftd_data);
                    282:        dp++;
                    283: 
                    284:        *diags = dp;
                    285:        return NOTOK;
                    286:     }
                    287: #endif
                    288: 
                    289:     effector = 1;
                    290:     switch (myvf - vfs) {
                    291:        case VFS_UTF: 
                    292:            p1 = (struct type_DOCS_FTAM__1__Parameters *) myparam;
                    293:            if ((gd = dup (myfd)) == NOTOK
                    294:                    || (fp = fdopen (gd, "r")) == NULL) {
                    295:                if (gd != NOTOK)
                    296:                    (void) close (gd);
                    297:                if (myfd != NOTOK){
                    298: #ifdef BRIDGE
                    299:                        (void) close (myfd);
                    300:                        myfd = NOTOK;
                    301:                        (void) ftp_reply ();
                    302: #endif
                    303:                }
                    304:                goto no_mem;
                    305:            }
                    306: 
                    307:            {
                    308:                PElementID    id;
                    309: 
                    310:                if (p1 -> optionals
                    311:                        & opt_DOCS_FTAM__1__Parameters_universal__class__number)
                    312:                    id = (PElementID) p1 -> universal__class__number;
                    313:                else
                    314:                    id = PE_DEFN_GFXS;
                    315: 
                    316:                pe = pe_alloc (PE_CLASS_UNIV, PE_FORM_PRIM, id);
                    317: 
                    318:                switch (pe -> pe_id) {
                    319:                    case PE_DEFN_GFXS:
                    320:                        if (getenv ("HP-FTAM")) {
                    321:                            effector = 1;
                    322:                            break;
                    323:                        }       /* else fall... */
                    324:                    case PE_DEFN_PRTS:
                    325:                    case PE_DEFN_VISS:
                    326:                        effector = 0;
                    327:                        break;
                    328: 
                    329:                    case PE_DEFN_T61S:
                    330:                    case PE_DEFN_VTXS:
                    331:                    case PE_DEFN_IA5S:
                    332:                    case PE_DEFN_GENS:
                    333:                        effector = 1;
                    334:                        break;
                    335: 
                    336:                    default:
                    337:                        break;
                    338:                }
                    339:            }
                    340:            if ((magic = fadusize - MAGIC_OCTET1) < 0)
                    341:                magic = 0;
                    342:            break;
                    343: 
                    344:        case VFS_UBF:
                    345:            p3 = (struct type_DOCS_FTAM__3__Parameters *) myparam;
                    346:            /* and fall */
                    347:        default:
                    348:            fp = NULL;
                    349: 
                    350:            pe = pe_alloc (PE_CLASS_UNIV, PE_FORM_PRIM, PE_PRIM_OCTS);
                    351:            if ((magic = fadusize - MAGIC_SINGLE) < 0)
                    352:                magic = 0;
                    353:            break;
                    354:     }
                    355:     if (pe == NULLPE)
                    356:        goto no_mem;
                    357:     pe -> pe_context = myvf -> vf_id;
                    358: 
                    359: #ifdef BRIDGE
                    360:     bsize = BUFSIZ << 2;
                    361:     size = magic >= bsize ? magic : bsize;
                    362:     if (size > bsize)
                    363:        size -= size % bsize;
                    364: #else
                    365: #ifndef        MAXBSIZE
                    366:     bsize = BUFSIZ;
                    367: #else
                    368:     bsize = myst.st_blksize > 0 ? myst.st_blksize : BUFSIZ;
                    369: #endif
                    370:     size = (1024 <= magic && magic < bsize) ? magic : bsize;
                    371: #endif
                    372:     switch (myvf - vfs) {
                    373:        case VFS_UTF:
                    374:            if ((p1 -> optionals
                    375:                        & opt_DOCS_FTAM__1__Parameters_maximum__string__length)
                    376:                    && p1 -> maximum__string__length > 0)                   
                    377:                size = p1 -> maximum__string__length;
                    378:            break;
                    379: 
                    380:        case VFS_UBF:
                    381:            if ((p3 -> optionals
                    382:                        & opt_DOCS_FTAM__3__Parameters_maximum__string__length)
                    383:                    && p3 -> maximum__string__length > 0)                   
                    384:                size = p3 -> maximum__string__length;
                    385:            /* and fall */
                    386:        default:
                    387:            break;
                    388:     }
                    389: 
                    390:     if (debug)
                    391:        advise (LLOG_DEBUG, NULLCP, "effector=%d id=0x%x size=%d",
                    392:                effector, pe -> pe_id, size);
                    393: 
                    394:     if ((pe -> pe_prim = PEDalloc (pe -> pe_len = size)) == NULLPED) {
                    395: no_mem: ;
                    396:        dp -> ftd_type = DIAG_PERM;
                    397:        dp -> ftd_identifier = FS_ACC_LCL;
                    398:        dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    399:        dp -> ftd_delay = DIAG_NODELAY;
                    400:        (void) strcpy (dp -> ftd_data, "out of memory");
                    401:        dp -> ftd_cc = strlen (dp -> ftd_data);
                    402:        dp++;
                    403: 
                    404: error_return: ;
                    405:        (void) de2fadu (NULLPE, 0);
                    406:        if (pe)
                    407:            pe_free (pe);
                    408:        if (fp)
                    409:            (void) fclose (fp);
                    410:        *diags = dp;
                    411:        return NOTOK;
                    412:     }
                    413: 
                    414:     for (;;) {
                    415:        register char  *bp,
                    416:                       *ep;
                    417: 
                    418:        for (ep = (bp = (char *) pe -> pe_prim) + size - (fp ? 2 : 0), nc = 0;
                    419:                bp < ep; ) {
                    420:            if (fp) {
                    421:                register char *cp;
                    422: 
                    423: #ifdef BRIDGE
                    424:                if (strlen (line) || fgets (line, BUFSIZ, fp)) {
                    425:                    if ((strlen (line) + 1) < (ep - bp + 1)) {
                    426:                        (void) strcpy (bp, line);
                    427:                        line[0] = NULL;
                    428:                    }
                    429:                    else
                    430:                        break;
                    431:                }
                    432:                else {
                    433:                    n = (ferror (fp) && !feof (fp)) ? NOTOK : OK;
                    434:                    break;
                    435:                }
                    436: #else
                    437:                if (fgets (bp, ep - bp + 1, fp) == NULL) {
                    438:                    n = (ferror (fp) && !feof (fp)) ? NOTOK : OK;
                    439:                    break;
                    440:                }
                    441: #endif
                    442:                cp = bp + strlen (bp) - 1;
                    443:                if (!effector) {
                    444:                    if (*cp == '\n') {
                    445: #ifndef        BRIDGE
                    446:                        *cp = NULL;
                    447: #else
                    448:                        if (cp > bp) {
                    449:                            if (*--cp == '\r')
                    450:                                *cp = NULL;
                    451:                            else
                    452:                                *++cp = NULL;
                    453:                        }
                    454:                        else
                    455:                            *cp = NULL;
                    456: #endif
                    457:                        n = cp - bp;
                    458:                        bp = cp;
                    459:                    }
                    460:                    else {                      /* XXX: losing! */
                    461:                        n = cp - bp + 1;
                    462:                        bp = cp + 1;
                    463:                    }
                    464:                }
                    465:                else {
                    466:                    if (*cp == '\n') {
                    467: #ifndef        BRIDGE
                    468:                        *cp++ = '\r';
                    469: #endif
                    470:                        *cp++ = '\n';
                    471:                        n = cp - bp;
                    472:                        bp = cp;
                    473:                        nc++;
                    474:                        continue;
                    475:                    }
                    476: 
                    477:                    n = cp - bp + 1;
                    478:                    bp = cp + 1;
                    479:                }
                    480:            }
                    481:            else {
                    482:                switch (n = read (myfd, bp, ep - bp)) {
                    483:                    case NOTOK: 
                    484:                    case OK: 
                    485:                        break;
                    486: 
                    487:                    default: 
                    488:                        bp += n;
                    489:                        continue;
                    490:                }
                    491:            }
                    492:            break;
                    493:        }
                    494:        if (n == NOTOK || (n = bp - (char *) pe -> pe_prim) == 0)
                    495:            break;
                    496:        pe -> pe_len = n;
                    497: 
                    498:        if (fp && !effector) {
                    499:            if ((de = pe_cpy (pe)) == NULLPE)
                    500:                goto no_mem;
                    501:        }
                    502:        else
                    503:            de = pe;
                    504: 
                    505:        if (debug)
                    506:            if (fp) {
                    507:                WATCHP (DOCS_FTAM__1__Datatype1, de, 0);
                    508:            }
                    509:            else
                    510:                WATCHP (DOCS_FTAM__3__Datatype1, de, 0);
                    511: 
                    512: 
                    513:        switch (de2fadu (de, pe != de ? 1 : 0)) {
                    514:            case NOTOK:
                    515:                dp -> ftd_type = DIAG_PERM;
                    516:                dp -> ftd_identifier = FS_ACC_LCL;
                    517:                dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    518:                dp -> ftd_delay = DIAG_NODELAY;
                    519:                dp -> ftd_cc = 0;
                    520:                dp++;
                    521:                goto error_return;
                    522: 
                    523:            case OK:
                    524:            default:
                    525:                nbytes += (n - nc), nc = 0;
                    526:                continue;
                    527: 
                    528:            case DONE:
                    529:                break;
                    530:        }
                    531:        break;
                    532:     }
                    533: 
                    534:     pe_free (pe);
                    535: 
                    536:     if (fp)
                    537:        (void) fclose (fp);
                    538: 
                    539:     if (n == DONE)
                    540:        return DONE;
                    541: 
                    542:     if (n == NOTOK) {
                    543:        dp -> ftd_type = DIAG_PERM;
                    544:        dp -> ftd_identifier = FS_ACC_LCLDEV;
                    545:        dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    546:        dp -> ftd_delay = DIAG_NODELAY;
                    547:        (void) strcpy (dp -> ftd_data, sys_errname (errno));
                    548:        dp -> ftd_cc = strlen (dp -> ftd_data);
                    549:        dp++;
                    550: 
                    551:        *diags = dp;
                    552: 
                    553:        (void) de2fadu (NULLPE, 0);
                    554:        return NOTOK;
                    555:     }
                    556: 
                    557:     n = de2fadu (NULLPE, 1);
                    558: 
                    559:     if (n != DONE) {
                    560:        timer (nbytes, "sent");
                    561: 
                    562:        if (FDataEndRequest (ftamfd, FACTION_SUCCESS,
                    563:                             (struct FTAMdiagnostic *) 0, 0, fti) == NOTOK)
                    564:            ftam_adios (fta, "F-DATA-END.REQUEST");
                    565:     }
                    566: 
                    567:     return n;
                    568: }
                    569: 
                    570: /*  */
                    571: 
                    572: static fdfget (diags)
                    573: register struct FTAMdiagnostic **diags;
                    574: {
                    575:     int            names,
                    576:            len,
                    577:            n;
                    578:     char   *pp,
                    579:            path[MAXPATHLEN];
                    580:     PE     pe;
                    581: #ifdef BRIDGE
                    582:     int            dd;
                    583:     FILE   *df;
                    584:     char   *ptr,
                    585:            line[BUFSIZ];
                    586: #else
                    587:     register struct dirent *d;
                    588:     register DIR *dd;
                    589: #endif
                    590:     struct stat st;
                    591:     register struct FTAMdiagnostic *dp = *diags;
                    592:     struct FTAMindication   ftis;
                    593:     register struct FTAMindication *fti = &ftis;
                    594:     register struct FTAMabort *fta = &fti -> fti_abort;
                    595:     register struct type_DOCS_NBS__9__Parameters *p9;
                    596:     struct type_DOCS_NBS__9__Datatype1 *d9;
                    597: 
                    598:     if (strcmp (myfile, ".") == 0) {
                    599:        pp = path;
                    600:        *pp = NULL;
                    601:        len = 0;
                    602:     }
                    603:     else 
                    604: #ifdef apollo
                    605:         if (strcmp (myfile, "/") == 0 || strcmp (myfile, "//") == 0) {
                    606:             (void) sprintf (pp = path, "%s", myfile);
                    607:             pp += (len = strlen (pp));
                    608:         }
                    609:         else
                    610: #endif                
                    611:     {
                    612:        (void) sprintf (pp = path, "%s/", myfile);
                    613:        pp += (len = strlen (pp));
                    614:     }
                    615: 
                    616:     pe = NULLPE;
                    617: 
                    618: #ifdef BRIDGE
                    619:     if ((dd = ftp_ls (myfile)) == NOTOK || (df = fdopen (dd,"r")) == NULL) {
                    620: #else
                    621:     if ((dd = opendir (myfile)) == NULL) {
                    622: #endif
                    623: no_mem: ;
                    624:        dp -> ftd_type = DIAG_PERM;
                    625:        dp -> ftd_identifier = FS_ACC_LCL;
                    626:        dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    627:        dp -> ftd_delay = DIAG_NODELAY;
                    628:        (void) strcpy (dp -> ftd_data, "out of memory");
                    629:        dp -> ftd_cc = strlen (dp -> ftd_data);
                    630:        dp++;
                    631: 
                    632: error_return: ;
                    633:        (void) de2fadu (NULLPE, 0);
                    634:        if (pe)
                    635:            pe_free (pe);
                    636: #ifdef BRIDGE
                    637:        if (dd) {
                    638:            (void) close (dd);
                    639:            (void) ftp_reply ();
                    640:         }
                    641: #else
                    642:        if (dd)
                    643:            (void) closedir (dd);
                    644: #endif
                    645:        *diags = dp;
                    646:        return NOTOK;
                    647:     }
                    648: 
                    649: 
                    650:     p9 = (struct type_DOCS_NBS__9__Parameters *) myparam;
                    651:     if (fdf_p2names (ftamfd, p9, &names, fti) == NOTOK) {
                    652:        register struct FTAMdiagnostic *d2 = fti -> fti_abort.fta_diags;
                    653: 
                    654:        dp = d2;        /* struct copy */
                    655:        dp++;
                    656:        goto error_return;
                    657:     }
                    658: 
                    659:     n = OK;
                    660: #ifdef BRIDGE
                    661:     while (fgets(line, BUFSIZ, df)) {
                    662: #else
                    663:     for (errno = 0; d = readdir (dd); errno = 0) {
                    664: #endif
                    665:        struct FTAMattributes fas;
                    666:        register struct FTAMattributes *fa = &fas;
                    667: #ifndef        BRIDGE
                    668:        register struct vfsmap *vf;
                    669: #endif
                    670: 
                    671: #ifdef BRIDGE
                    672:        if (ptr = rindex(line,'\r'))
                    673:            *ptr = '\0';
                    674: #endif
                    675: 
                    676:        if (debug)
                    677: #ifdef BRIDGE
                    678:            advise (LLOG_DEBUG, NULLCP, "len=%d name=\"%s\"",
                    679:                        strlen(line), line);
                    680: #else
                    681:            advise (LLOG_DEBUG, NULLCP, "ino=%ld len=%d name=\"%s\"",
                    682:                    d -> d_ino, strlen (d -> d_name), d -> d_name);
                    683: #endif
                    684: 
                    685: #ifndef        BRIDGE
                    686:        if (!d -> d_ino)
                    687:            continue;
                    688: #endif
                    689: 
                    690: #ifdef BRIDGE
                    691:        if (len + strlen (line) >= MAXPATHLEN)
                    692: #else
                    693:        if (len + strlen (d -> d_name) >= MAXPATHLEN)
                    694: #endif
                    695:            continue;
                    696: 
                    697: #ifdef BRIDGE
                    698:        (void) strcpy (pp, line);
                    699: #else
                    700:        (void) strcpy (pp, d -> d_name);
                    701: #endif
                    702: 
                    703: #ifndef        BRIDGE
                    704:        if (stat (path, &st) == NOTOK
                    705:                || (vf = st2vfs (NOTOK, path, &st, NULLOID, ftamfd)) == NULL)
                    706:            continue;
                    707: #endif
                    708: 
                    709:        bzero ((char *) fa, sizeof *fa);
                    710:        *diags = dp;
                    711: #ifdef BRIDGE
                    712:        (void) readattrs (names, fa, vfs[VFS_UTF].vf_oid, NULLPE, path, &st,
                    713:                          diags);
                    714: #else
                    715:        (void) readattrs (names, fa, vf -> vf_oid, NULLPE, path, &st, diags);
                    716: #endif
                    717:        dp = *diags;
                    718: 
                    719:        if (fdf_attrs2d (ftamfd, fa, &d9, fti) == NOTOK) {
                    720:            register struct FTAMdiagnostic *d2 = fti -> fti_abort.fta_diags;
                    721: 
                    722:            dp = d2;    /* struct copy */
                    723:            dp++;
                    724:            goto error_return;
                    725:        }
                    726: 
                    727:        if (encode_DOCS_NBS__9__Datatype1 (&pe, 1, 0, NULLCP, d9) == NOTOK) {
                    728:            dp -> ftd_type = DIAG_PERM;
                    729:            dp -> ftd_identifier = FS_ACC_LCL;
                    730:            dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    731:            dp -> ftd_delay = DIAG_NODELAY;
                    732:            (void) sprintf (dp -> ftd_data, "error encoding Datatype1: %s",
                    733:                            PY_pepy);
                    734:            dp -> ftd_cc = strlen (dp -> ftd_data);
                    735:            dp++;
                    736: 
                    737:            free_DOCS_NBS__9__Datatype1 (d9);
                    738:            goto error_return;
                    739:        }
                    740:        pe -> pe_context = myvf -> vf_id;
                    741: 
                    742:        if (debug)
                    743:            WATCHP (DOCS_NBS__9__Datatype1, pe, 0);
                    744: 
                    745:        n = de2fadu (pe, 1), pe = NULLPE;
                    746:        switch (n) {
                    747:            case NOTOK:
                    748:                goto no_mem;
                    749: 
                    750:            case OK:
                    751:            default:
                    752:                continue;
                    753: 
                    754:            case DONE:
                    755:                break;
                    756:        }
                    757:        break;
                    758:     }
                    759: 
                    760: #ifdef BRIDGE
                    761:     (void) fclose (df);
                    762:     (void) close (dd);
                    763:     (void) ftp_reply ();
                    764: #else
                    765:     if (errno != 0) {
                    766:        dp -> ftd_type = DIAG_PERM;
                    767:        dp -> ftd_identifier = FS_ACC_LCL;
                    768:        dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    769:        dp -> ftd_delay = DIAG_NODELAY;
                    770:        (void) sprintf (dp -> ftd_data, "%s: %s", myfile, sys_errname (errno));
                    771:        dp -> ftd_cc = strlen (dp -> ftd_data);
                    772:        dp++;
                    773: 
                    774:        goto error_return;
                    775:        
                    776:     }
                    777:     (void) closedir (dd);
                    778: #endif
                    779: 
                    780:     if (n == OK)
                    781:        n = de2fadu (NULLPE, 1);
                    782: 
                    783:     switch (n) {
                    784:        case DONE:
                    785:            return DONE;
                    786: 
                    787:        case OK:
                    788:        default:
                    789:            if (FDataEndRequest (ftamfd, FACTION_SUCCESS,
                    790:                        (struct FTAMdiagnostic *) 0, 0, fti) == NOTOK)
                    791:                ftam_adios (fta, "F-DATA-END.REQUEST");
                    792:            return OK;
                    793:     }
                    794: }
                    795: 
                    796: /*  */
                    797: 
                    798: static int  de2fadu (pe, concat)
                    799: PE     pe;
                    800: int    concat;
                    801: {
                    802:     struct FTAMindication   ftis;
                    803:     register struct FTAMindication *fti = &ftis;
                    804:     register struct FTAMabort  *fta = &fti -> fti_abort;
                    805:     static int ninfo = 0;
                    806:     static int size = 0;
                    807:     static PE info[NPDATA];
                    808: 
                    809:     if (pe == NULLPE) {
                    810:        if (concat
                    811:                && ninfo > 0
                    812:                && FDataRequest (ftamfd, info, ninfo, fti) == NOTOK)
                    813:            ftam_adios (fta, "F-DATA.REQUEST");
                    814: 
                    815:        while (ninfo > 0)
                    816:            pe_free (info[--ninfo]);
                    817:        size = 0;
                    818: 
                    819:        return OK;
                    820:     }
                    821: 
                    822:     if (concat) {
                    823:        int     flush,
                    824:                n;
                    825: 
                    826:        if (size + (n = ps_get_abs (pe) + MAGIC_OCTET2) >= fadusize
                    827:                && ninfo > 0) {
                    828:            if (debug)
                    829:                advise (LLOG_DEBUG, NULLCP,
                    830:                        "de2fadu flushing on %d FADUs, estimated size %d/%d",
                    831:                        ninfo, size, fadusize);
                    832: 
                    833:            (void) de2fadu (NULLPE, 1);
                    834:            flush = 1;
                    835:        }
                    836:        else
                    837:            flush = 0;
                    838:        
                    839:        info[ninfo++] = pe;
                    840:        size += n;
                    841: 
                    842:        if (ninfo < NPDATA && size < fadusize) {
                    843:            if (!flush)
                    844:                return OK;
                    845:        }
                    846:        else {
                    847:            if (FDataRequest (ftamfd, info, ninfo, fti) == NOTOK)
                    848:                ftam_adios (fta, "F-DATA.REQUEST");
                    849: 
                    850:            while (ninfo > 0)
                    851:                pe_free (info[--ninfo]);
                    852:            size = 0;
                    853:        }
                    854:     }
                    855:     else
                    856:        if (FDataRequest (ftamfd, &pe, 1, fti) == NOTOK)
                    857:            ftam_adios (fta, "F-DATA.REQUEST");
                    858: 
                    859:     if (FWaitRequest (ftamfd, OK, fti) == NOTOK) {
                    860:        if (fta -> fta_peer
                    861:                || fta -> fta_action != FACTION_TRANS
                    862:                || fta -> fta_ndiag < 1
                    863:                || fta -> fta_diags[0].ftd_type != DIAG_TRANS
                    864:                || fta -> fta_diags[0].ftd_identifier != FS_PRO_TIMEOUT)
                    865:            ftam_adios (fta, "F-WAIT.REQUEST");
                    866: 
                    867:        return OK;
                    868:     }
                    869: 
                    870:     if (fti -> fti_type == FTI_CANCEL) {
                    871:        register struct FTAMcancel *ftcn = &fti -> fti_cancel;
                    872: 
                    873:        advise (LLOG_NOTICE, NULLCP, "F-CANCEL.INDICATION: %d",
                    874:                ftcn -> ftcn_action);
                    875:        ftam_diag (ftcn -> ftcn_diags, ftcn -> ftcn_ndiag);
                    876:        FTCNFREE (ftcn);
                    877: 
                    878:        if (FCancelResponse (ftamfd, FACTION_SUCCESS, NULLPE, 
                    879:                    (struct FTAMdiagnostic *) 0, 0, fti) == NOTOK)
                    880:            ftam_adios (fta, "F-CANCEL.RESPONSE");
                    881:     }
                    882: 
                    883:     return DONE;
                    884: }
                    885: 
                    886: /*  */
                    887: 
                    888: int    ftam_dataindication (px)
                    889: register struct PSAPdata *px;
                    890: {
                    891:     register int    i;
                    892:     int            effector,
                    893:            n;
                    894:     register PE     pe,
                    895:                   *pep;
                    896:     struct FTAMdiagnostic   diags[NFDIAG];
                    897:     register struct FTAMdiagnostic *dp = diags;
                    898:     struct FTAMindication   ftis;
                    899:     register struct FTAMindication *fti = &ftis;
                    900: 
                    901:     effector = 1;
                    902:     switch (myvf - vfs) {
                    903:        case VFS_UBF:
                    904:        default:
                    905:            break;
                    906: 
                    907:        case VFS_UTF:
                    908:            {
                    909:                PElementID    id;
                    910:                register struct type_DOCS_FTAM__1__Parameters *p1 =
                    911:                            (struct type_DOCS_FTAM__1__Parameters *) myparam;
                    912: 
                    913:                if (p1 -> optionals
                    914:                        & opt_DOCS_FTAM__1__Parameters_universal__class__number)
                    915:                    id = (PElementID) p1 -> universal__class__number;
                    916:                else
                    917:                    id = PE_DEFN_GFXS;
                    918:                switch (id) {
                    919:                    case PE_DEFN_GFXS:
                    920:                        if (getenv ("HP-FTAM")) {
                    921:                            effector = 1;
                    922:                            break;
                    923:                        }       /* else fall... */
                    924:                    case PE_DEFN_PRTS:
                    925:                    case PE_DEFN_VISS:
                    926:                        effector = 0;
                    927:                        break;
                    928: 
                    929:                    case PE_DEFN_T61S:
                    930:                    case PE_DEFN_VTXS:
                    931:                    case PE_DEFN_IA5S:
                    932:                    case PE_DEFN_GENS:
                    933:                        effector = 1;
                    934:                        break;
                    935: 
                    936:                    default:
                    937:                        break;
                    938:                }
                    939:            }
                    940:            break;
                    941:     }
                    942: 
                    943:     for (pep = px -> px_info, i = px -> px_ninfo - 1; i >= 0; pep++, i--) {
                    944:        if ((pe = *pep) == NULLPE)
                    945:            continue;
                    946: 
                    947:        switch (myvf - vfs) {
                    948:            case VFS_UBF:
                    949:            default:
                    950:                if (debug)
                    951:                    WATCHP (DOCS_FTAM__3__Datatype1, pe, 1);
                    952:                n = de2fd (myfd, pe, 0, 0);
                    953:                break;
                    954: 
                    955:            case VFS_UTF:
                    956:                if (debug)
                    957:                    WATCHP (DOCS_FTAM__1__Datatype1, pe, 1);
                    958:                n = de2fd (myfd, pe, 1, effector);
                    959:                break;
                    960:        }
                    961: 
                    962:        if (n != NOTOK) {
                    963:            nbytes += n;
                    964:            continue;
                    965:        }
                    966: 
                    967:        dp -> ftd_type = DIAG_PERM;
                    968:        switch (errno) {
                    969:            case ENOSPC: 
                    970:                dp -> ftd_identifier = FS_ACC_LCLSPACE;
                    971:                dp -> ftd_cc = 0;
                    972:                break;
                    973: 
                    974:            case EIO: 
                    975:            case ENXIO: 
                    976:                dp -> ftd_identifier = FS_ACC_LCLDEV;
                    977:                dp -> ftd_cc = 0;
                    978:                break;
                    979: 
                    980:            default: 
                    981:                dp -> ftd_identifier = FS_ACC_WRITE;
                    982:                (void) strcpy (dp -> ftd_data, sys_errname (errno));
                    983:                dp -> ftd_cc = strlen (dp -> ftd_data);
                    984:                break;
                    985:        }
                    986:        dp -> ftd_observer = dp -> ftd_source = EREF_RFSU;
                    987:        dp -> ftd_delay = DIAG_NODELAY;
                    988:        dp++;
                    989: 
                    990:        if (FCancelRequest (ftamfd, FACTION_PERM, NULLPE, diags, dp - diags,
                    991:                            fti) == NOTOK)
                    992:            ftam_adios (&fti -> fti_abort, "F-CANCEL-REQUEST");
                    993: 
                    994:        if (fti -> fti_type == FTI_CANCEL) {
                    995:            register struct FTAMcancel *ftcn = &fti -> fti_cancel;
                    996: 
                    997:            advise (LLOG_NOTICE, NULLCP, "F-CANCEL.RESPONSE: %d",
                    998:                    ftcn -> ftcn_action);
                    999:            ftam_diag (ftcn -> ftcn_diags, ftcn -> ftcn_ndiag);
                   1000:            FTCNFREE (ftcn);
                   1001:        }
                   1002:        break;
                   1003:     }
                   1004: 
                   1005:     PXFREE (px);
                   1006: }
                   1007: 
                   1008: /*  */
                   1009: 
                   1010: /* ARGSUSED */
                   1011: 
                   1012: int    ftam_dataendindication (ftda)
                   1013: struct FTAMdataend *ftda;
                   1014: {
                   1015:     timer (nbytes, "received");
                   1016: 
                   1017: #ifndef        SYS5
                   1018:     if (ftda -> ftda_action == FACTION_SUCCESS)
                   1019:        (void) fsync (myfd);
                   1020: #endif
                   1021: }
                   1022: 
                   1023: /*  */
                   1024: 
                   1025: int    ftam_cancelindication (ftcn)
                   1026: register struct FTAMcancel *ftcn;
                   1027: {
                   1028:     struct FTAMindication   ftis;
                   1029:     register struct FTAMindication *fti = &ftis;
                   1030: 
                   1031:     advise (LLOG_NOTICE, NULLCP, "F-CANCEL.INDICATION: %d",
                   1032:            ftcn -> ftcn_action);
                   1033:     ftam_diag (ftcn -> ftcn_diags, ftcn -> ftcn_ndiag);
                   1034:     FTCNFREE (ftcn);
                   1035: 
                   1036:     if (FCancelResponse (ftamfd, FACTION_SUCCESS, NULLPE,
                   1037:                (struct FTAMdiagnostic *) 0, 0, fti) == NOTOK)
                   1038:        ftam_adios (&fti -> fti_abort, "F-CANCEL.RESPONSE");
                   1039: }
                   1040: 
                   1041: /*  */
                   1042: 
                   1043: /* ARGSUSED */
                   1044: 
                   1045: int    ftam_transendindication (ftre)
                   1046: struct FTAMtransend *ftre;
                   1047: {
                   1048:     struct FTAMindication   ftis;
                   1049:     register struct FTAMindication *fti = &ftis;
                   1050: 
                   1051:     if (FTransEndResponse (ftamfd, FACTION_SUCCESS, NULLPE, 
                   1052:                (struct FTAMdiagnostic *) 0, 0, fti) == NOTOK)
                   1053:        ftam_adios (&fti -> fti_abort, "F-TRANSFER-END.RESPONSE");
                   1054: }
                   1055: 
                   1056: /*  */
                   1057: 
                   1058: int    ftam_bulkendindication (ftg)
                   1059: struct FTAMgroup *ftg;
                   1060: {
                   1061:     struct FTAMgroup    ftms;
                   1062:     struct FTAMgroup   *ftm = &ftms;
                   1063:     struct FTAMindication   ftis;
                   1064:     register struct FTAMindication *fti = &ftis;
                   1065: 
                   1066:     ftam_selection (ftg, ftm);
                   1067: 
                   1068:     if (myfd != NOTOK) {
                   1069: #ifdef BRIDGE
                   1070:        (void) close (myfd);
                   1071:        (void) ftp_reply ();
                   1072: #else
                   1073:        unlock ();
                   1074:        (void) close (myfd);
                   1075: #endif
                   1076:        myfd = NOTOK;
                   1077:     }
                   1078: 
                   1079:     if (FBulkEndResponse (ftamfd, ftm, fti) == NOTOK)
                   1080:        ftam_adios (&fti -> fti_abort, "F-BULK-END.RESPONSE");
                   1081: 
                   1082:     FTGFREE (ftg);
                   1083: }
                   1084: 
                   1085: /*  */
                   1086: 
                   1087: #ifndef        NBBY
                   1088: #define        NBBY    8
                   1089: #endif
                   1090: 
                   1091: 
                   1092: #ifndef        TMS
                   1093: timer (cc, action)
                   1094: int     cc;
                   1095: char   *action;
                   1096: {
                   1097:     long    ms;
                   1098:     float   bs;
                   1099:     struct timeval  stop,
                   1100:                     td;
                   1101:     static struct timeval   start;
                   1102: 
                   1103:     if (cc == 0) {
                   1104:        (void) gettimeofday (&start, (struct timezone *) 0);
                   1105:        return;
                   1106:     }
                   1107:     else
                   1108:        (void) gettimeofday (&stop, (struct timezone  *) 0);
                   1109: 
                   1110:     tvsub (&td, &stop, &start);
                   1111:     ms = (td.tv_sec * 1000) + (td.tv_usec / 1000);
                   1112:     bs = (((float) cc * NBBY * 1000) / (float) (ms ? ms : 1)) / NBBY;
                   1113: 
                   1114:     advise (LLOG_NOTICE, NULLCP,
                   1115:            "%d bytes %s in %d.%02d seconds (%.2f Kbytes/s)",
                   1116:            cc, action, td.tv_sec, td.tv_usec / 10000, bs / 1024);
                   1117: }
                   1118: 
                   1119: 
                   1120: static  tvsub (tdiff, t1, t0)
                   1121: register struct timeval *tdiff,
                   1122:                        *t1,
                   1123:                        *t0;
                   1124: {
                   1125: 
                   1126:     tdiff -> tv_sec = t1 -> tv_sec - t0 -> tv_sec;
                   1127:     tdiff -> tv_usec = t1 -> tv_usec - t0 -> tv_usec;
                   1128:     if (tdiff -> tv_usec < 0)
                   1129:        tdiff -> tv_sec--, tdiff -> tv_usec += 1000000;
                   1130: }
                   1131: 
                   1132: #else
                   1133: #ifndef        HZ
                   1134: #define        HZ      60
                   1135: #endif
                   1136: 
                   1137: 
                   1138: long   times ();
                   1139: 
                   1140: 
                   1141: static timer (cc, action)
                   1142: int    cc;
                   1143: char   *action;
                   1144: {
                   1145:     long    ms;
                   1146:     float   bs;
                   1147:     long    stop,
                   1148:            td,
                   1149:            secs,
                   1150:            msecs;
                   1151:     struct tms tm;
                   1152:     static long start;
                   1153: 
                   1154:     if (cc == 0) {
                   1155:        start = times (&tm);
                   1156:        return;
                   1157:     }
                   1158:     else
                   1159:        stop = times (&tm);
                   1160: 
                   1161:     td = stop - start;
                   1162:     secs = td / HZ, msecs = (td % HZ) * 1000 / HZ;
                   1163:     ms = (secs * 1000) +  msecs;
                   1164:     bs = (((float) cc * NBBY * 1000) / (float) (ms ? ms : 1)) / NBBY;
                   1165:     
                   1166:     advise (LLOG_NOTICE, NULLCP,
                   1167:            "%d bytes %s in %d.%02d seconds (%.2f Kbytes/s)",
                   1168:            cc, action, secs, msecs / 10, bs / 1024);
                   1169: }
                   1170: #endif

unix.superglobalmegacorp.com

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