Annotation of 43BSDTahoe/new/xns/examples/filing_common/filingd.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *rcsid = "$Header: filingd.c,v 1.6 87/05/14 11:33:26 ed Exp $";
                      3: #endif lint
                      4: 
                      5: /*
                      6:  * Copyright (c) 1986, 1987 Xerox Corporation.
                      7:  */
                      8: 
                      9: /* $Log:       filingd.c,v $
                     10:  * Revision 1.6  87/05/14  11:33:26  ed
                     11:  * Open: don't set cur_dir_handle unless directory is opened.
                     12:  * 
                     13:  * Revision 1.5  87/05/05  14:46:31  ed
                     14:  * Don't close connection in continuance_expiration if BDT in progress.
                     15:  * 
                     16:  * Revision 1.4  87/04/16  15:30:29  ed
                     17:  * Fixed lingering Subset bugs.
                     18:  * 
                     19:  * Revision 1.3  87/03/31  14:22:53  ed
                     20:  * Initialize got_matches in get_filter.
                     21:  * 
                     22:  * Revision 1.2  87/03/31  09:05:15  ed
                     23:  * New procedures: Create, ChangeAttributes(name only), Copy, Move,
                     24:  *             Replace, Serialize, Deserialize.
                     25:  * Added conditional disabling of root logins.
                     26:  * Support for GetAttributes (allAttributeTypes).
                     27:  * Support for filter of type all.
                     28:  * 
                     29:  * Revision 1.1  87/01/14  11:25:59  ed
                     30:  * Initial revision
                     31:  * 
                     32:  */
                     33: 
                     34: #include <stdio.h>
                     35: #include <sys/types.h>
                     36: #include <netns/ns.h>
                     37: #include <netns/sp.h>
                     38: #ifdef FILING4
                     39: #include "filingV4.h"
                     40: #include "clearinghouseV2.h"
                     41: #include "authenticationV2.h"
                     42: #endif FILING4
                     43: #ifdef FILING5
                     44: #include "filingV5.h"
                     45: #include "clearinghouseV2.h"
                     46: #include "authenticationV2.h"
                     47: #endif FILING5
                     48: #ifdef FILING6
                     49: #include "filingV6.h"
                     50: #include "clearinghouseV3.h"
                     51: #include "authenticationV3.h"
                     52: #endif FILING6
                     53: #ifdef FILINGSUBSET1
                     54: #include "filingsubsetV1.h"
                     55: #include "clearinghouseV3.h"
                     56: #include "authenticationV3.h"
                     57: #endif FILINGSUBSET1
                     58: #include <xnscourier/filing_server.h>
                     59: #include <xnscourier/CH.h>
                     60: #include <xnscourier/filetypes.h>
                     61: 
                     62: #define SERVICE_ROOT   "/"                     /* root directory for service */
                     63: 
                     64: #ifdef DEBUG
                     65: FILE *msgs= 0;
                     66: #endif DEBUG
                     67: 
                     68: session_handle SessionHandle= 0;
                     69: file_handle RootHandle= { FILE_OPEN, SERVICE_ROOT, 0, 0, 0, TRUE, 0, 0, NULL };
                     70: extern CourierConnection *_serverConnection;   /* current connection */
                     71: 
                     72:        /*
                     73:         * The continuance value is slightly lower than the 90 second
                     74:         * value in lookahead.c. This should insure that the client will
                     75:         * send a Continue before this service stops looking for the next
                     76:         * procedure call.
                     77:         */
                     78: Cardinal continuance= 80;                      /* continuance value in seconds */
                     79: 
                     80: Boolean BDTabort_expected= FALSE;              /* should BDT attn be sent */
                     81: 
                     82: #ifdef FILETOOLCOMPATIBILITY
                     83: file_handle *cur_dir_handle= &RootHandle;
                     84: #endif FILETOOLCOMPATIBILITY
                     85: 
                     86: 
                     87: FILING_LogonResults
                     88: FILING_Logon(ServerConnection, BDTProc, service_name, user_credentials, user_verifier)
                     89: CourierConnection *ServerConnection;
                     90: int (*BDTProc)();
                     91: CLEARINGHOUSE_ObjectName service_name;
                     92: FILING_Credentials user_credentials;
                     93: FILING_Verifier user_verifier;
                     94: {
                     95:        FILING_LogonResults result;
                     96:        AUTHENTICATION_ThreePartName chs_name;
                     97:        session_handle *session_ptr;
                     98:        Unspecified *bp, buffer[SPPMAXDATA];
                     99:        char user[40];
                    100:        char pass[40];
                    101:        Cardinal credentials_type;
                    102:        Cardinal len;
                    103:        char *lowercase();
                    104: #if FILING4 | FILING5
                    105:        char *rindex();
                    106:        char *ptr;
                    107: #endif FILING4 | FILING5
                    108: 
                    109:        BDTabort_expected= FALSE;
                    110: 
                    111: #ifdef DEBUG
                    112:        if (msgs == 0) {
                    113:                char logfile[50];
                    114:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                    115:                msgs= fopen(logfile,"w");
                    116:        }
                    117:        fprintf(msgs,"Logon\n");
                    118: #endif DEBUG
                    119: 
                    120: #if FILING4 | FILING5
                    121:        if (user_credentials.type != AUTHENTICATION_simpleCredentials) {
                    122:                ReturnAuthenticationError(AUTHENTICATION_inappropriateCredentials);
                    123:                /* NOT REACHED */
                    124:        } else {
                    125:                CLEARINGHOUSE_externalize_Item(&user_credentials.value, buffer);
                    126:                bp= buffer;
                    127:                bp += internalize_Cardinal(&len, bp);
                    128:                AUTHENTICATION_internalize_SimpleCredentials(&chs_name, bp);
                    129: #ifdef DEBUG
                    130:                fprintf(msgs,"chs_name= %s:%s:%s\n",chs_name.object,chs_name.domain,chs_name.organization);
                    131: #endif DEBUG
                    132:        }
                    133: 
                    134: #ifdef ROOTNOTALLOWED
                    135:        /*
                    136:         * We don't allow root access from the file server
                    137:         */
                    138: 
                    139:        if ( strcmp(lowercase(chs_name.object), "root") == 0 ) {
                    140:                ReturnAuthenticationError(AUTHENTICATION_credentialsInvalid);
                    141:                /* NOT REACHED */
                    142:        }
                    143: #endif ROOTNOTALLOWED
                    144: 
                    145:        /*
                    146:         * Assumption (for Filing4/Filing5 implementation):
                    147:         * may receive fully specified Clearinghouse name, so we should try
                    148:         * to strip off last name (look for last space) assuming there is a
                    149:         * similary named account on this service. If the user credentials
                    150:         * pass network authentiction, then we will not check passwords on
                    151:         * this service (in fact, we can't since the verifier is hashed).
                    152:         * It is assumed that the name will be found in /etc/passwd and 
                    153:         * everything will work regardless of password checking.
                    154:         */
                    155: 
                    156:        if ( (ptr= rindex(chs_name.object, ' ')) == 0 ) {
                    157:                strcpy(user, chs_name.object);
                    158:        } else {
                    159:                ptr++;
                    160:                strcpy(user, ptr);
                    161:        }
                    162: 
                    163:        if ( !Auth_CredCheck(user_credentials, user_verifier) ) {
                    164:                ReturnAuthenticationError(AUTHENTICATION_credentialsInvalid);
                    165:                /* NOT REACHED */
                    166:        }
                    167: #else FILING4 | FILING5
                    168:        /*
                    169:         * assumption (for FILING6 and FILINGSUBSET1):
                    170:         * no primary credentials are ok
                    171:         * simple primary credentials will be validated with Authentication
                    172:         * strong credentials will be ignored
                    173:         *
                    174:         * secondary credentials must contain userName and userPassword
                    175:         * which are assumed to be Unix name and password
                    176:         */
                    177: 
                    178:        if (user_credentials.primary.type == AUTHENTICATION_simpleCredentials) {
                    179:                if ( !Auth_CredCheck(user_credentials.primary, user_verifier) ) {
                    180:                        ReturnAuthenticationError(FILING_primaryCredentialsInvalid);
                    181:                        /* NOT REACHED */
                    182:                }
                    183:        }
                    184: 
                    185:        if ( get_name_and_pwd(&user_credentials.secondary, user, pass) != -1 ) {
                    186:                ReturnAuthenticationError(FILING_secondaryCredentialsRequired);
                    187:                /* NOT REACHED */
                    188:        }
                    189: 
                    190: #ifdef ROOTNOTALLOWED
                    191:        /*
                    192:         * We don't allow root access from the file server
                    193:         */
                    194: 
                    195:        if ( strcmp(lowercase(user), "root") == 0 ) {
                    196:                ReturnAuthenticationError(AUTHENTICATION_credentialsInvalid);
                    197:                /* NOT REACHED */
                    198:        }
                    199: #endif ROOTNOTALLOWED
                    200: 
                    201: #endif FILING4 | FILING5
                    202: 
                    203: #ifdef DEBUG
                    204:        fprintf(msgs, "user= %s\n", user);
                    205: #endif DEBUG
                    206: 
                    207:        if ( verifyandposition_user(user, pass) != -1 ) {
                    208:                /* NOT REACHED */
                    209:        }
                    210: 
                    211:        session_ptr= &SessionHandle;
                    212:        SessionHandle.state= SESSION_OPEN;
                    213:        SessionHandle.verifier= user_verifier.sequence[0];
                    214: 
                    215: #ifdef DEBUG
                    216: /*     fprintf(msgs,"handle= %x, ver= %x\n",session_ptr,session_ptr->verifier);
                    217: */
                    218: #endif DEBUG
                    219: 
                    220:        copyhandle(result.session.token, &session_ptr);
                    221:        result.session.verifier.length= sizeof(AUTHENTICATION_SimpleVerifier) / sizeof(Cardinal);
                    222:        result.session.verifier.sequence= Allocate(sizeof(AUTHENTICATION_SimpleVerifier));
                    223:        result.session.verifier.sequence[0]= user_verifier.sequence[0];
                    224: 
                    225:        set_continuance_timer();
                    226: #ifdef DEBUG
                    227:        fprintf(msgs, "out of logon\n");
                    228: #endif DEBUG
                    229:        return(result);
                    230: 
                    231: }
                    232: 
                    233: copyhandle(dest, src)
                    234: Unspecified *dest, *src;
                    235: {
                    236:        if ( dest == (Unspecified *)0 ) {
                    237: #ifdef DEBUG
                    238:                fprintf(msgs, "Oops, dest is null in copyhandle\n");
                    239: #else DEBUG
                    240:                fprintf(stderr, "Oops, dest is null in copyhandle\n");
                    241: #endif DEBUG
                    242:                exit(1);
                    243:        }
                    244: 
                    245:        dest[0]= src[0];
                    246:        dest[1]= src[1];
                    247: }
                    248: 
                    249: 
                    250: void FILING_Logoff(ServerConnection, BDTProc, session)
                    251: CourierConnection *ServerConnection;
                    252: int (*BDTProc)();
                    253: FILING_Session session;
                    254: {
                    255:        session_handle *session_ptr;
                    256: 
                    257:        BDTabort_expected= FALSE;
                    258: 
                    259:        if ( verify_session(session) != -1 ) {
                    260:                /* NOT REACHED */
                    261:        }
                    262: 
                    263:        copyhandle(&session_ptr,session.token);
                    264: 
                    265: #ifdef SOMEDAY
                    266:        if ( session_ptr->state == SESSION_IN_USE ) {
                    267:                ReturnServiceError(FILING_sessionInUse);
                    268:        } 
                    269: #endif SOMEDAY
                    270: 
                    271:        session_ptr->state= SESSION_CLOSED;
                    272:        reset_continuance_timer();
                    273: 
                    274:        return;
                    275: }
                    276: 
                    277: 
                    278: FILING_OpenResults FILING_Open(ServerConnection, BDTProc, attributes,  directory, controls, session)
                    279: CourierConnection *ServerConnection;
                    280: int ( *BDTProc)();
                    281: FILING_AttributeSequence attributes;
                    282: FILING_Handle directory;
                    283: FILING_ControlSequence controls;
                    284: FILING_Session session;
                    285: {
                    286:        FILING_OpenResults results;
                    287:        file_handle *handle;
                    288: 
                    289: #ifdef FILETOOLCOMPATIBILITY
                    290:        file_handle *dir_handle;
                    291: #endif FILETOOLCOMPATIBILITY
                    292: 
                    293:        BDTabort_expected= FALSE;
                    294: 
                    295: #ifdef DEBUG
                    296:        if (msgs == 0) {
                    297:                char logfile[50];
                    298:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                    299:                msgs= fopen(logfile,"w");
                    300:        }
                    301:        fprintf(msgs,"Open\n");
                    302:        fflush(msgs);
                    303: #endif DEBUG
                    304: 
                    305:        if ( verify_session(session) != -1 ) {
                    306:                /* NOT REACHED */
                    307:        }
                    308: 
                    309: #ifndef FILETOOLCOMPATIBILITY
                    310:        if ( is_nullControls(controls) != -1 ) {
                    311:                ReturnControlTypeError(FILING_disallowed,0);
                    312:                /* NOT REACHED */
                    313:        }
                    314: 
                    315:        if ( is_nullHandle(directory) != -1 ) {
                    316:                ReturnHandleError(FILING_invalid);
                    317:                /* NOT REACHED */
                    318:        }
                    319: #endif FILETOOLCOMPATIBILITY
                    320:  
                    321:        if ( (handle= (file_handle *)malloc(sizeof(file_handle))) == NULL ) {
                    322:                ReturnUndefinedError(0);
                    323:                /* NOT REACHED */       
                    324:        }
                    325: 
                    326: #ifdef DEBUG
                    327:        fprintf(msgs,"Open-- file handle= %x\n",handle);
                    328:        fflush(msgs);
                    329: #endif DEBUG
                    330: 
                    331:        if ( (handle->pathname= (char *)malloc(MAX_FILE_NAME_LENGTH)) == NULL ) {
                    332:                ReturnUndefinedError(0);
                    333:                /* NOT REACHED */       
                    334:        }
                    335: 
                    336: #ifdef FILETOOLCOMPATIBILITY
                    337:        copyhandle(&dir_handle,directory);
                    338: 
                    339:        if ( dir_handle != 0 ) {
                    340:                if ( dir_handle->state != FILE_OPEN ) {
                    341:                        ReturnHandleError(FILING_invalid);
                    342:                        /* NOT REACHED */
                    343:                }
                    344: 
                    345:                if ( dir_handle->isdirectory != TRUE ) {
                    346:                        ReturnHandleError(FILING_directoryRequired);
                    347:                        /* NOT REACHED */
                    348:                }
                    349: 
                    350:                if ( access_file(dir_handle) != -1 ) {
                    351:                        /* NOT REACHED */
                    352:                }
                    353: 
                    354:                strcpy(handle->pathname,dir_handle->pathname);
                    355:                if ( strcmp(handle->pathname, "/") != 0 )
                    356:                        strcat(handle->pathname,"/");
                    357:        } else {
                    358:                strcpy(handle->pathname, SERVICE_ROOT);
                    359:        }
                    360: #else FILETOOLCOMPATIBILITY
                    361:        strcpy(handle->pathname, SERVICE_ROOT);
                    362: #endif FILETOOLCOMPATIBILITY
                    363: 
                    364:        if ( verify_open_attributes(attributes, handle) != -1 ) {
                    365:                /* NOT REACHED */
                    366:        }
                    367: 
                    368:        if ( stat_file(handle) != -1 ) {
                    369:                /* NOT REACHED */
                    370:        }
                    371: 
                    372:        handle->state= FILE_OPEN;
                    373:        handle->file_desc= NULL;
                    374:        handle->createdon= handle->modifiedon= 0;
                    375: 
                    376:        copyhandle(results.file,&handle);
                    377: 
                    378: #ifdef FILETOOLCOMPATIBILITY
                    379:        if ( handle->isdirectory == TRUE )
                    380:                cur_dir_handle= handle;
                    381: #endif FILETOOLCOMPATIBILITY
                    382: 
                    383:        reset_continuance_timer();
                    384: 
                    385:        return(results);
                    386: }
                    387: 
                    388: verify_session(session)
                    389: FILING_Session session;
                    390: {
                    391:        session_handle *session_ptr;
                    392: 
                    393:        copyhandle(&session_ptr, session.token);
                    394: 
                    395:        if ( session_ptr == 0  ||
                    396:                        (session_ptr->state != SESSION_OPEN) ) {
                    397:                ReturnSessionError(FILING_tokenInvalid);
                    398:                /* NOT REACHED */
                    399:        }
                    400: 
                    401:        if ( session_ptr->verifier != *(session.verifier.sequence) ) {
                    402:                ReturnAuthenticationError(AUTHENTICATION_verifierInvalid);
                    403:                /* NOT REACHED */
                    404:        }
                    405: 
                    406:        return(-1);
                    407: 
                    408: }
                    409: 
                    410: is_nullControls(controls)
                    411: FILING_ControlSequence controls;
                    412: {
                    413: 
                    414:        if ( controls.length != 0 && controls.sequence != 0 ) {
                    415:                return(0);
                    416:        }
                    417: 
                    418:        return(-1);
                    419: }
                    420: 
                    421: is_nullHandle(handle)
                    422: FILING_Handle handle;
                    423: {
                    424:        if ( handle[0] != 0 && handle[1] != 0 ) {
                    425:                return(0);
                    426:        }
                    427: 
                    428:        return(-1);
                    429: }
                    430: 
                    431: verify_open_attributes(attr, handle)
                    432: FILING_AttributeSequence attr;
                    433: file_handle *handle;
                    434: {
                    435:        int i;
                    436:        FILING_AttributeType t;
                    437:        int got_parentID, got_pathname, got_type, got_version;
                    438:        char *pathname;
                    439:        Unspecified *parentid;
                    440:        FILING_Version version;
                    441:        char *AttrToString();
                    442:        Unspecified *AttrToFileID();
                    443:        LongCardinal AttrToLongCardinal();
                    444: 
                    445: #ifdef FILETOOLCOMPATIBILITY
                    446:        int got_name, got_fileID;
                    447:        char *name;
                    448:        Unspecified *fileid;
                    449: #endif FILETOOLCOMPATIBILITY
                    450: 
                    451: #ifdef DEBUG
                    452:        fprintf(msgs,"verify_open_attribute %d attributes       ",attr.length);
                    453: #endif DEBUG
                    454: 
                    455:        got_parentID= got_pathname= got_type= got_version= 0;
                    456: 
                    457: #ifdef FILETOOLCOMPATIBILITY
                    458:        got_name= got_fileID= 0;
                    459: #endif FILETOOLCOMPATIBILITY
                    460: 
                    461: #ifdef FILETOOLCOMPATIBILITY
                    462:        if ( attr.length == 0 ) {
                    463:                return;
                    464:        }
                    465: #endif FILETOOLCOMPATIBILITY
                    466: 
                    467:        for ( i= 0 ; i < attr.length ; i++ ) {
                    468:                t= attr.sequence[i].type;
                    469: 
                    470:                if ( t == FILING_parentID ) {
                    471: #ifdef DEBUG
                    472:                        fprintf(msgs,"parentID  ");
                    473: #endif DEBUG
                    474:                        if ( got_parentID ) {
                    475:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    476:                                /* NOT REACHED */
                    477:                        }
                    478:                        got_parentID++;
                    479: 
                    480:                        parentid= AttrToFileID(&attr.sequence[i]);
                    481:                        if ( !is_nullID(parentid) ) {
                    482:                                ReturnAttributeValueError(FILING_unimplemented, t);
                    483:                                /* NOT REACHED */
                    484:                        }
                    485:                        continue;
                    486:                } 
                    487:                if ( t == FILING_pathname ) {
                    488: #ifdef DEBUG
                    489:                        fprintf(msgs,"pathname  ");
                    490: #endif DEBUG
                    491:                        if ( got_pathname ) {
                    492:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    493:                                /* NOT REACHED */
                    494:                        }
                    495:                        got_pathname++;
                    496: 
                    497:                        pathname= AttrToString(&attr.sequence[i]);
                    498:                        if ( check_pathname(pathname) != -1 ) {
                    499:                                /* NOT REACHED */
                    500:                        }
                    501:                        continue;
                    502:                }                       
                    503:                if ( t == FILING_type ) {
                    504: #ifdef DEBUG
                    505:                        fprintf(msgs,"type  ");
                    506: #endif DEBUG
                    507:                        if ( got_type ) {
                    508:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    509:                                /* NOT REACHED */
                    510:                        }
                    511:                        got_type++;
                    512: 
                    513:                        handle->type= AttrToLongCardinal(&attr.sequence[i]);
                    514: #ifndef EXTENSIONS
                    515:                        if ( (handle->type != FILING_tText) &&
                    516:                                        (handle->type != FILING_tUnspecified) ) {
                    517:                                ReturnAttributeValueError(FILING_unimplemented, t);
                    518:                                /* NOT REACHED */
                    519:                        }
                    520: #endif EXTENSIONS
                    521:                        continue;
                    522:                }
                    523:                if ( t == FILING_version ) {
                    524: #ifdef DEBUG
                    525:                        fprintf(msgs,"version  ");
                    526: #endif DEBUG
                    527:                        if ( got_version ) {
                    528:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    529:                                /* NOT REACHED */
                    530:                        }
                    531:                        got_version++;
                    532: 
                    533:                        version= AttrToCardinal(&attr.sequence[i]);
                    534:                        if ( version != FILING_highestVersion && version != FILING_lowestVersion ) {
                    535:                                        ReturnAttributeValueError(FILING_unimplemented, t);
                    536:                                        /* NOT REACHED */
                    537: 
                    538:                        }
                    539:                        continue;
                    540:                }
                    541: 
                    542: #ifdef FILETOOLCOMPATIBILITY
                    543:                if ( t == FILING_name ) {
                    544: #ifdef DEBUG
                    545:                        fprintf(msgs, "name  ");
                    546: #endif DEBUG
                    547:                        if ( got_name ) {
                    548:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    549:                                /* NOT REACHED */
                    550:                        }
                    551:                        got_name++;
                    552: 
                    553:                        name= AttrToString(&attr.sequence[i]);
                    554:                        continue;
                    555:                }
                    556: 
                    557:                if ( t == FILING_fileID ) {
                    558: #ifdef DEBUG
                    559:                        fprintf(msgs, "fileID  ");
                    560: #endif DEBUG
                    561:                        if ( got_fileID ) {
                    562:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    563:                                /* NOT REACHED */
                    564:                        }
                    565:                        got_fileID++;
                    566: 
                    567:                        fileid= AttrToFileID(&attr.sequence[i]);
                    568:                        if ( is_nullID(fileid) == -1 ) {
                    569:                                ReturnAttributeValueError(FILING_disallowed, t);
                    570:                                /* NOT REACHED */
                    571:                        }
                    572:                        strcpy(handle->pathname, cur_dir_handle->pathname);
                    573:                        if ( get_name_from_fileID(handle, fileid) != -1 ) {
                    574:                                /* NOT REACHED */
                    575:                        }
                    576:                        continue;
                    577:                }
                    578: #else FILETOOLCOMPATIBILITY
                    579:                if ( t == FILING_fileID ) {
                    580:                        ReturnAttributeTypeError(FILING_unimplemented, t);
                    581:                        /* NOT REACHED */
                    582:                }
                    583: 
                    584:                if ( t == FILING_name ) {
                    585:                        ReturnAttributeTypeError(FILING_unimplemented, t);
                    586:                        /* NOT REACHED */
                    587:                }
                    588: #endif FILETOOLCOMPATIBILITY
                    589: 
                    590:                if ( ( t < 0 ) || (t > FILING_subtreeSizeLimit) ) {
                    591:                        ReturnAttributeTypeError(FILING_illegal, t);
                    592:                        /* NOT REACHED */
                    593:                }
                    594: 
                    595:                ReturnAttributeTypeError(FILING_disallowed, t);
                    596:        }
                    597: 
                    598: #ifdef FILETOOLCOMPATIBILITY
                    599:        if ( !got_pathname && !got_name) {
                    600:                if ( !got_fileID ) {
                    601:                        handle->pathname= SERVICE_ROOT;
                    602:                }
                    603:        } else  if ( !got_pathname )  {
                    604:                strcat(handle->pathname,name);
                    605:        } else {
                    606:                if ( *pathname == '/' )
                    607:                        strcat(handle->pathname, pathname+1);
                    608:                else
                    609:                        strcat(handle->pathname,pathname);
                    610:                Deallocate(&pathname);
                    611:        }
                    612: 
                    613: #else FILETOOLCOMPATIBILITY
                    614:        if ( !got_pathname ) {
                    615:                handle->pathname= SERVICE_ROOT;
                    616:        } else {
                    617:                if ( *pathname == '/' )
                    618:                        strcat(handle->pathname, pathname+1);
                    619:                else
                    620:                        strcat(handle->pathname, pathname);
                    621:                Deallocate(&pathname);
                    622:        }
                    623: #endif FILETOOLCOMPATIBILITY
                    624: 
                    625:        if ( !got_type )
                    626:                handle->type= -1;
                    627: 
                    628:        return(-1);
                    629: }
                    630: 
                    631: is_nullID(fileid)
                    632: Unspecified *fileid;
                    633: {
                    634:        int i;
                    635: 
                    636:        for ( i= 0 ; i < 6 ; i++ ) {
                    637:                if ( fileid[i] != 0 )
                    638:                        return(0);
                    639:        }
                    640: 
                    641:        return(-1);
                    642: }
                    643: 
                    644: 
                    645: void FILING_Close(ServerConnection, BDTProc, file, session)
                    646: CourierConnection *ServerConnection;
                    647: int ( *BDTProc)();
                    648: FILING_Handle file;
                    649: FILING_Session session;
                    650: {
                    651:        file_handle *handle;
                    652: 
                    653:        BDTabort_expected= FALSE;
                    654: 
                    655: #ifdef DEBUG
                    656:        if (msgs == 0) {
                    657:                char logfile[50];
                    658:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                    659:                msgs= fopen(logfile,"w");
                    660:        }
                    661:        fprintf(msgs, "Close\n");
                    662: #endif DEBUG
                    663: 
                    664:        if ( verify_session(session) != -1 ) {
                    665:                /* NOT REACHED */
                    666:        }
                    667: 
                    668:        if ( is_nullHandle(file) == -1 ) {
                    669:                ReturnHandleError(FILING_nullDisallowed);
                    670:                /* NOT REACHED */
                    671:        }
                    672: 
                    673:        copyhandle(&handle,file);
                    674: #ifdef DEBUG
                    675:        fprintf(msgs, "closing %x\n",handle);
                    676: #endif DEBUG
                    677: 
                    678:        if ( handle->state != FILE_OPEN ) {
                    679:                ReturnHandleError(FILING_invalid);
                    680:                /* NOT REACHED */
                    681:        }
                    682: 
                    683:        if ( access_file(handle) != -1 ) {
                    684:                /* NOT REACHED */
                    685:        }
                    686: 
                    687:        close_file(handle);                             /* do it now */
                    688: 
                    689:        if ( handle->createdon != 0 )                   /* set date if needed */
                    690:                set_create_time(handle);
                    691: 
                    692:        handle->state= FILE_CLOSED;
                    693:        handle->pathname= (char *)0;
                    694: 
                    695: #ifdef FILETOOLCOMPATIBILITY
                    696:        if ( handle == cur_dir_handle )
                    697:                cur_dir_handle= &RootHandle;
                    698: #endif FILETOOLCOMPATIBILITY
                    699: 
                    700:        free(handle);
                    701:        reset_continuance_timer();
                    702: 
                    703:        return;
                    704: }
                    705: 
                    706: 
                    707: FILING_CreateResults FILING_Create(ServerConnection, BDTProc, directory, attributes, controls, session)
                    708: CourierConnection *ServerConnection;
                    709: int ( *BDTProc)();
                    710: FILING_Handle directory;
                    711: FILING_AttributeSequence attributes;
                    712: FILING_ControlSequence controls;
                    713: FILING_Session session;
                    714: {
                    715: #ifdef EXTENSIONS
                    716:        FILING_CreateResults results;
                    717:        file_handle *handle, *dir_handle;
                    718: 
                    719: #ifdef DEBUG
                    720:        if (msgs == 0) {
                    721:                char logfile[50];
                    722:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                    723:                msgs= fopen(logfile,"w");
                    724:        }
                    725:        fprintf(msgs, "Create  ");
                    726: #endif DEBUG
                    727: 
                    728:        BDTabort_expected= TRUE;
                    729: 
                    730:        if ( verify_session(session) != -1 ) {
                    731:                /* NOT REACHED */
                    732:        }
                    733: 
                    734: #ifndef FILETOOLCOMPATIBILITY
                    735:        if ( is_nullControls(controls) != -1) {
                    736:                ReturnControlTypeError(FILING_disallowed, 0);
                    737:                /* NOT REACHED */
                    738:        }
                    739: #endif FILETOOLCOMPATIBILITY
                    740: 
                    741:        if ( (handle= (file_handle *)malloc(sizeof(file_handle))) == NULL ) {
                    742:                ReturnUndefinedError(0);
                    743:                /* NOT REACHED */
                    744:        }
                    745: 
                    746:        if ( (handle->pathname= (char *)malloc(MAX_FILE_NAME_LENGTH)) == NULL ) {
                    747:                ReturnUndefinedError(0);
                    748:                /* NOT REACHED */
                    749:        }
                    750: 
                    751: #ifdef DEBUG
                    752:        fprintf(msgs, "create handle= %x\n",handle);
                    753: #endif DEBUG
                    754: 
                    755: #ifdef FILETOOLCOMPATIBILITY
                    756:        copyhandle(&dir_handle,directory);
                    757: 
                    758:        if ( dir_handle == 0 ) {
                    759:                dir_handle= &RootHandle;
                    760:                strcpy(handle->pathname, SERVICE_ROOT);
                    761:        } else {
                    762:                if ( dir_handle->state != FILE_OPEN ) {
                    763:                        ReturnHandleError(FILING_invalid);
                    764:                        /* NOT REACHED */
                    765:                }
                    766: 
                    767:                if ( access_file(dir_handle) != -1 ) {
                    768:                        /* NOT REACHED */
                    769:                }
                    770: 
                    771:                if ( dir_handle->isdirectory != TRUE ) {
                    772:                        ReturnHandleError(FILING_directoryRequired);
                    773:                        /* NOT REACHED */
                    774:                }
                    775: 
                    776:                strcpy(handle->pathname,dir_handle->pathname);
                    777:                if ( strcmp(handle->pathname, "/") != 0 )
                    778:                        strcat(handle->pathname,"/");
                    779:        } 
                    780: #else FILETOOLCOMPATIBILITY
                    781:        strcpy(handle->pathname, SERVICE_ROOT);
                    782: #endif FILETOOLCOMPATIBILITY
                    783: 
                    784:        if ( verify_create_attributes(attributes, handle) != -1 ) {
                    785:                /* NOT REACHED */
                    786:        }
                    787: 
                    788: #ifdef DEBUG
                    789:        fprintf(msgs, "creating '%s'\n", handle->pathname);
                    790: #endif DEBUG
                    791: 
                    792:        if ( handle->isdirectory == TRUE ) {
                    793:                if ( create_directory(handle) != -1 ) {
                    794:                        /* NOT REACHED */
                    795:                }
                    796:        } else {
                    797:                if ( create_file(handle) != -1 ) {
                    798:                        /* NOT REACHED */
                    799:                }
                    800:        }
                    801: 
                    802:        close_file(handle);
                    803: 
                    804:        handle->state= FILE_OPEN;
                    805:        handle->file_desc= NULL;
                    806: 
                    807:        copyhandle(results.file, &handle);
                    808:        reset_continuance_timer();
                    809: 
                    810:        return(results);
                    811: #else EXTENSIONS
                    812:        NoSuchProcedureValue("Filing", 4);
                    813: #endif EXTENSIONS
                    814: }
                    815: 
                    816: #ifdef EXTENSIONS
                    817: verify_create_attributes(attr, handle)
                    818: FILING_AttributeSequence attr;
                    819: file_handle *handle;
                    820: {
                    821:        int i;
                    822:        FILING_AttributeType t;
                    823:        int got_accesslist, got_childrenuniquelynamed, got_createdon, got_datasize;
                    824:        int got_defaultaccesslist, got_isdirectory, got_istemporary, got_ordering;
                    825:        int got_pathname, got_subtreesizelimit, got_type, got_version;
                    826:        char *pathname;
                    827:        FILING_Version version;
                    828:        Boolean childrenuniquelynamed, istemporary;
                    829:        Cardinal ordering;              
                    830:        Cardinal subtreesizelimit;
                    831:        char *AttrToString();
                    832:        Unspecified *AttrToFileID();
                    833:        LongCardinal AttrToLongCardinal();
                    834: 
                    835: #ifdef FILETOOLCOMPATIBILITY
                    836:        int got_name;
                    837:        char *name;
                    838: #endif FILETOOLCOMPATIBILITY
                    839: 
                    840: #ifdef DEBUG
                    841:        fprintf(msgs,"%d create attributes      ",attr.length);
                    842: #endif DEBUG
                    843: 
                    844:        if ( attr.length <= 0 ) {
                    845:                ReturnAttributeTypeError(FILING_illegal, 0);
                    846:                /* NOT REACHED */
                    847:        }
                    848: 
                    849:        got_accesslist= got_childrenuniquelynamed= got_createdon= 0;
                    850:        got_datasize= got_defaultaccesslist= got_isdirectory= 0;
                    851:        got_istemporary= got_ordering= got_pathname= 0;
                    852:        got_subtreesizelimit= got_type= got_version= 0;
                    853: 
                    854: #ifdef FILETOOLCOMPATIBILITY
                    855:        got_name= 0;
                    856: #endif FILETOOLCOMPATIBILITY
                    857: 
                    858: 
                    859:        for ( i= 0 ; i < attr.length ; i++ ) {
                    860:                t= attr.sequence[i].type;
                    861: #ifdef DEBUG
                    862:                fprintf(msgs, "%d ",t);
                    863: #endif DEBUG
                    864:                if ( t == FILING_createdOn ) {
                    865: #ifdef DEBUG
                    866:                        fprintf(msgs,"createdOn  ");
                    867: #endif DEBUG
                    868:                        if ( got_createdon ) {
                    869:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    870:                                /* NOT REACHED */
                    871:                        }
                    872:                        got_createdon++;
                    873: 
                    874:                        handle->createdon= AttrToLongCardinal(&attr.sequence[i]);
                    875:                        continue;
                    876:                }
                    877: 
                    878:                if ( t == FILING_dataSize ) {
                    879: #ifdef DEBUG
                    880:                        fprintf(msgs,"dataSize  ");
                    881: #endif DEBUG
                    882:                        if ( got_datasize ) {
                    883:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    884:                                /* NOT REACHED */
                    885:                        }
                    886:                        got_datasize++;
                    887: 
                    888:                        handle->datasize= AttrToLongCardinal(&attr.sequence[i]);
                    889:                        continue;
                    890:                }
                    891: 
                    892:                if ( t == FILING_isDirectory ) {
                    893: #ifdef DEBUG
                    894:                        fprintf(msgs,"isDirectory  ");
                    895: #endif DEBUG
                    896:                        if ( got_isdirectory ) {
                    897:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    898:                                /* NOT REACHED */
                    899:                        }
                    900: 
                    901:                        got_isdirectory++;
                    902: 
                    903:                        handle->isdirectory= AttrToBoolean(&attr.sequence[i]);
                    904:                        continue;
                    905:                }
                    906: 
                    907:                if ( t == FILING_pathname ) {
                    908: #ifdef DEBUG
                    909:                        fprintf(msgs,"pathname  ");
                    910: #endif DEBUG
                    911:                        if ( got_pathname ) {
                    912:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    913:                                /* NOT REACHED */
                    914:                        }
                    915:                        got_pathname++;
                    916: 
                    917:                        pathname= AttrToString(&attr.sequence[i]);
                    918:                        if ( check_pathname(pathname) != -1 ) {
                    919:                                /* NOT REACHED */
                    920:                        }
                    921:                        continue;
                    922:                }                       
                    923:                if ( t == FILING_type ) {
                    924: #ifdef DEBUG
                    925:                        fprintf(msgs,"type  ");
                    926: #endif DEBUG
                    927:                        if ( got_type ) {
                    928:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    929:                                /* NOT REACHED */
                    930:                        }
                    931:                        got_type++;
                    932: 
                    933:                        handle->type= AttrToLongCardinal(&attr.sequence[i]);
                    934:                        continue;
                    935:                }
                    936:                if ( t == FILING_version ) {
                    937: #ifdef DEBUG
                    938:                        fprintf(msgs,"version  ");
                    939: #endif DEBUG
                    940:                        if ( got_version ) {
                    941:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    942:                                /* NOT REACHED */
                    943:                        }
                    944:                        got_version++;
                    945: 
                    946:                        version= AttrToCardinal(&attr.sequence[i]);
                    947:                        if ( version != FILING_highestVersion ) {
                    948:                                        ReturnAttributeValueError(FILING_unimplemented, t);
                    949:                                        /* NOT REACHED */
                    950: 
                    951:                        }
                    952:                        continue;
                    953:                }
                    954: 
                    955: #ifdef FILETOOLCOMPATIBILITY
                    956:                if ( t == FILING_name ) {
                    957: #ifdef DEBUG
                    958:                        fprintf(msgs, "name  ");
                    959: #endif DEBUG
                    960:                        if ( got_name ) {
                    961:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    962:                                /* NOT REACHED */
                    963:                        }
                    964:                        got_name++;
                    965: 
                    966:                        name= AttrToString(&attr.sequence[i]);
                    967:                        continue;
                    968:                }
                    969: #endif FILETOOLCOMPATIBILITY
                    970: 
                    971: #ifdef SOMEDAY
                    972:                if ( t == FILING_accessList ) {
                    973:                        if ( got_accesslist ) {
                    974:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    975:                                /* NOT REACHED */
                    976:                        }
                    977: 
                    978:                        got_accesslist++;
                    979: 
                    980:                        if ( FALSE ) {
                    981:                                ReturnAttributeValueError(FILING_unimplemented, t);
                    982:                                /* NOT REACHED */
                    983:                        }
                    984: 
                    985:                        continue;
                    986:                }
                    987: #endif SOMEDAY
                    988: 
                    989:                if ( t == FILING_childrenUniquelyNamed ) {
                    990:                        if ( got_childrenuniquelynamed ) {
                    991:                                ReturnAttributeTypeError(FILING_duplicated, t);
                    992:                                /* NOT REACHED */
                    993:                        }
                    994: 
                    995:                        got_childrenuniquelynamed++;
                    996: 
                    997:                        childrenuniquelynamed= AttrToBoolean(&attr.sequence[i]);
                    998:                        if ( childrenuniquelynamed != TRUE ) {
                    999:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1000:                                /* NOT REACHED */
                   1001:                        }
                   1002: 
                   1003:                        continue;
                   1004:                }
                   1005: 
                   1006: 
                   1007: #ifdef SOMEDAY
                   1008:                if ( t == FILING_defaultAccessList ) {
                   1009:                        if ( got_defaultaccesslist ) {
                   1010:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1011:                                /* NOT REACHED */
                   1012:                        }
                   1013: 
                   1014:                        got_defaultaccesslist++;
                   1015: 
                   1016:                        if ( FALSE ) {
                   1017:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1018:                                /* NOT REACHED */
                   1019:                        }
                   1020: 
                   1021:                        continue;
                   1022:                }
                   1023: #endif SOMEDAY
                   1024: 
                   1025:                if ( t == FILING_isTemporary ) {
                   1026:                        if ( got_istemporary ) {
                   1027:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1028:                                /* NOT REACHED */
                   1029:                        }
                   1030: 
                   1031:                        got_istemporary++;
                   1032: 
                   1033:                        istemporary= AttrToBoolean(&attr.sequence[i]);
                   1034:                        if ( istemporary != FALSE ) {
                   1035:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1036:                                /* NOT REACHED */
                   1037:                        }
                   1038: 
                   1039:                        continue;
                   1040:                }
                   1041: 
                   1042:                if ( t == FILING_ordering ) {
                   1043:                        if ( got_ordering ) {
                   1044:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1045:                                /* NOT REACHED */
                   1046:                        }
                   1047: 
                   1048:                        got_ordering++;
                   1049: 
                   1050:                        if ( FALSE ) {
                   1051:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1052:                                /* NOT REACHED */
                   1053:                        }
                   1054: 
                   1055:                        continue;
                   1056:                }
                   1057: 
                   1058:                if ( t == FILING_subtreeSizeLimit ) {
                   1059:                        if ( got_subtreesizelimit ) {
                   1060:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1061:                                /* NOT REACHED */
                   1062:                        }
                   1063: 
                   1064:                        got_subtreesizelimit++;
                   1065: 
                   1066:                        subtreesizelimit= AttrToCardinal(&attr.sequence[i]);
                   1067:                        if ( subtreesizelimit != FILING_nullSubtreeSizeLimit ) {
                   1068:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1069:                                /* NOT REACHED */
                   1070:                        }
                   1071: 
                   1072:                        continue;
                   1073:                }
                   1074: 
                   1075:                if ( (t == FILING_fileID) || (t == FILING_modifiedBy) ||
                   1076:                                (t == FILING_modifiedOn) || 
                   1077:                                (t == FILING_numberOfChildren) || (t == FILING_parentID) ||
                   1078:                                (t == FILING_readBy) || (t == FILING_readOn) ||
                   1079:                                (t == FILING_storedSize) || (t == FILING_subtreeSize) ) {
                   1080:                        ReturnAttributeTypeError(FILING_disallowed, t);
                   1081:                }
                   1082: 
                   1083:                if ( t < 0 ) {
                   1084:                        ReturnAttributeTypeError(FILING_illegal, t);
                   1085:                        /* NOT REACHED */
                   1086:                }
                   1087: 
                   1088:                if ( handle->type != TYPE_VP ) {
                   1089:                        if ( (t == FILING_checksum) || (t == FILING_createdBy) ||
                   1090:                                                (t == FILING_position) )
                   1091:                                ReturnAttributeTypeError(FILING_unimplemented, t);
                   1092:                        else
                   1093:                                ReturnAttributeTypeError(FILING_disallowed, t);
                   1094:                }
                   1095:        }
                   1096: 
                   1097: #ifdef DEBUG
                   1098:        fprintf(msgs, "\n");
                   1099: #endif DEBUG
                   1100: 
                   1101: #ifdef FILETOOLCOMPATIBILITY
                   1102:        if ( !got_pathname && !got_name) {
                   1103:                handle->pathname= SERVICE_ROOT;
                   1104:        } else  if ( !got_pathname )  {
                   1105:                strcat(handle->pathname,name);
                   1106:        } else {
                   1107:                if ( *pathname == '/' )
                   1108:                        strcat(handle->pathname, pathname+1);
                   1109:                else
                   1110:                        strcat(handle->pathname,pathname);
                   1111:                Deallocate(&pathname);
                   1112:        }
                   1113: 
                   1114: #else FILETOOLCOMPATIBILITY
                   1115:        if ( !got_pathname ) {
                   1116:                ReturnAttributeTypeError(FILING_missing, t);
                   1117:                /* NOT REACHED */
                   1118:        } else {
                   1119:                if ( *pathname == '/' )
                   1120:                        strcat(handle->pathname, pathname+1);
                   1121:                else
                   1122:                        strcat(handle->pathname, pathname);
                   1123:                Deallocate(&pathname);
                   1124:        }
                   1125: #endif FILETOOLCOMPATIBILITY
                   1126: 
                   1127:        if ( !got_type )
                   1128:                handle->type= FILING_tUnspecified;
                   1129: 
                   1130:        if ( !got_createdon )
                   1131:                handle->createdon= 0;
                   1132: 
                   1133:        if ( !got_isdirectory ) {
                   1134:                if ( handle->type == FILING_tDirectory )
                   1135:                        handle->isdirectory= TRUE;
                   1136:                else
                   1137:                        handle->isdirectory= FALSE;
                   1138:        } else {
                   1139:                if ( ((handle->isdirectory == TRUE) && (handle->type != FILING_tDirectory)) ||
                   1140:                                ((handle->isdirectory == FALSE) && (handle->type == FILING_tDirectory)) ) {
                   1141:                        ReturnAttributeTypeError(FILING_unreasonable, FILING_isDirectory);
                   1142:                        /* NOT REACHED */
                   1143:                }
                   1144:        }
                   1145: 
                   1146:        return(-1);
                   1147: }
                   1148: #endif EXTENSIONS
                   1149: 
                   1150: 
                   1151: void FILING_Delete(ServerConnection, BDTProc, file, session)
                   1152: CourierConnection *ServerConnection;
                   1153: int ( *BDTProc)();
                   1154: FILING_Handle file;
                   1155: FILING_Session session;
                   1156: {
                   1157:        file_handle *handle;
                   1158: 
                   1159:        BDTabort_expected= FALSE;
                   1160: #ifdef DEBUG
                   1161:        if (msgs == 0) {
                   1162:                char logfile[50];
                   1163:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   1164:                msgs= fopen(logfile,"w");
                   1165:        }
                   1166:        fprintf(msgs, "Delete\n");
                   1167: #endif DEBUG
                   1168: 
                   1169:        if ( verify_session(session) != -1 ) {
                   1170:                /* NOT REACHED */
                   1171:        }
                   1172: 
                   1173:        if ( is_nullHandle(file) == -1 ) {
                   1174:                ReturnHandleError(FILING_nullDisallowed);
                   1175:                /* NOT REACHED */
                   1176:        }
                   1177: 
                   1178:        copyhandle(&handle,file);
                   1179: 
                   1180:        if ( handle->state != FILE_OPEN ) {
                   1181:                ReturnHandleError(FILING_invalid);
                   1182:                /* NOT REACHED */
                   1183:        }
                   1184: 
                   1185:        if ( access_file(handle) != -1 ) {
                   1186:                /* NOT REACHED */
                   1187:        }
                   1188: 
                   1189:        close_file(handle);                             /* do it now */
                   1190: 
                   1191:        if ( delete_file(handle) != -1 ) {
                   1192:                /* NOT REACHED */
                   1193:        }
                   1194: 
                   1195:        handle->state= FILE_CLOSED;
                   1196:        handle->pathname= (char *)0;
                   1197: 
                   1198:        free(handle);
                   1199:        reset_continuance_timer();
                   1200: 
                   1201:        return;
                   1202: }
                   1203: 
                   1204: 
                   1205: FILING_GetControlsResults FILING_GetControls(ServerConnection, BDTProc, file, types, session)
                   1206: CourierConnection *ServerConnection;
                   1207: int ( *BDTProc)();
                   1208: FILING_Handle file;
                   1209: FILING_ControlTypeSequence types;
                   1210: FILING_Session session;
                   1211: {
                   1212:        NoSuchProcedureValue("Filing", 6);
                   1213: }
                   1214: 
                   1215: 
                   1216: void FILING_ChangeControls(ServerConnection, BDTProc, file, controls, session)
                   1217: CourierConnection *ServerConnection;
                   1218: int ( *BDTProc)();
                   1219: FILING_Handle file;
                   1220: FILING_ControlSequence controls;
                   1221: FILING_Session session;
                   1222: {
                   1223:        NoSuchProcedureValue("Filing", 7);
                   1224: }
                   1225: 
                   1226: 
                   1227: FILING_GetAttributesResults FILING_GetAttributes(ServerConnection, BDTProc, file, types, session)
                   1228: CourierConnection *ServerConnection;
                   1229: int ( *BDTProc)();
                   1230: FILING_Handle file;
                   1231: FILING_AttributeTypeSequence types;
                   1232: FILING_Session session;
                   1233: {
                   1234: #ifdef EXTENSIONS
                   1235:        file_handle *handle;
                   1236:        FILING_GetAttributesResults results;
                   1237: 
                   1238: #ifdef DEBUG
                   1239:        if (msgs == 0) {
                   1240:                char logfile[50];
                   1241:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   1242:                msgs= fopen(logfile,"w");
                   1243:        }
                   1244:        fprintf(msgs, "Getattributes\n");
                   1245: #endif DEBUG
                   1246: 
                   1247:        BDTabort_expected= FALSE;
                   1248: 
                   1249:        if ( verify_session(session) != -1 ) {
                   1250:                /* NOT REACHED */
                   1251:        }
                   1252: 
                   1253:        if ( is_nullHandle(file) == -1 ) {
                   1254:                ReturnHandleError(FILING_nullDisallowed);
                   1255:                /* NOT REACHED */
                   1256:        }
                   1257: 
                   1258:        copyhandle(&handle,file);
                   1259: 
                   1260:        if ( handle->state != FILE_OPEN ) {
                   1261:                ReturnHandleError(FILING_invalid);
                   1262:                /* NOT REACHED */
                   1263:        }
                   1264: 
                   1265:        if ( access_file(handle) != -1 ) {
                   1266:                /* NOT REACHED */
                   1267:        }
                   1268: 
                   1269:        close_file(handle);                             /* do it now */
                   1270: 
                   1271:        if ( get_types(types,&results.attributes) != -1 ) {
                   1272:                /* NOT REACHED */
                   1273:        }
                   1274: 
                   1275:        make_attribute_sequence(handle->pathname,&results.attributes);
                   1276: 
                   1277:        return(results);
                   1278: #else EXTENSIONS
                   1279:        NoSuchProcedureValue("Filing", 8);
                   1280: #endif EXTENSIONS
                   1281: }
                   1282: 
                   1283: get_types(types, attrseq)
                   1284: FILING_AttributeTypeSequence types;
                   1285: FILING_AttributeSequence *attrseq;
                   1286: {
                   1287:        int i;
                   1288:        LongCardinal t;
                   1289: 
                   1290:        if ( types.length <= 0 ) {
                   1291:                ReturnAttributeTypeError(FILING_illegal, 0);
                   1292:                /* NOT REACHED */
                   1293:        }
                   1294: 
                   1295: #ifdef EXTENSIONS
                   1296:        if ( *(types.sequence) == 037777777777 ) {
                   1297: #ifdef DEBUG
                   1298:                fprintf(msgs, "get_types: asking for all\n");
                   1299: #endif DEBUG
                   1300:                attrseq->length= -1;
                   1301:                attrseq->sequence= (FILING_Attribute *)
                   1302:                                Allocate((SUPPORTEDATTRIBUTES + OPTIONALATTRIBUTES) * sizeof(FILING_Attribute)/sizeof(Unspecified));
                   1303:        } else {
                   1304: #endif EXTENSIONS
                   1305:                attrseq->length= types.length;
                   1306:                attrseq->sequence= (FILING_Attribute *)
                   1307:                                Allocate(types.length * sizeof(FILING_Attribute)/sizeof(Unspecified));
                   1308: 
                   1309: #ifdef DEBUG
                   1310:                fprintf(msgs, "get_types: asking for ");
                   1311: #endif DEBUG
                   1312: 
                   1313:                for ( i = 0; i < types.length ; i ++ ) {
                   1314:                        t= types.sequence[i];
                   1315: 
                   1316: #ifdef DEBUG
                   1317:                        fprintf(msgs, "%d  ",t);
                   1318: #endif DEBUG
                   1319: 
                   1320:                        
                   1321:                        if ( (t < 0) || ( t > FILING_subtreeSizeLimit) ) {
                   1322: #ifdef FILETOOLCOMPATIBILITY
                   1323:                                if ( t != 4938 ) {
                   1324:                                        ReturnAttributeTypeError(FILING_illegal, t);
                   1325:                                        /* NOT REACHED */
                   1326:                                }
                   1327: #else FILETOOLCOMPATIBILITY
                   1328:                                ReturnAttributeTypeError(FILING_illegal, t);
                   1329:                                /* NOT REACHED */
                   1330: #endif FILETOOLCOMPATIBILITY
                   1331:                        }
                   1332: 
                   1333:                        if ( (t != FILING_createdOn) && (t != FILING_modifiedOn) &&
                   1334:                                        (t != FILING_isDirectory) && (t != FILING_isTemporary) &&
                   1335:                                        (t != FILING_name) && (t != FILING_pathname) &&
                   1336: #ifndef FILETOOLCOMPATIBILITY
                   1337:                                        (t != FILING_dataSize) && (t != FILING_type) &&
                   1338:                                        (t != FILING_version) ) {
                   1339: #else FILETOOLCOMPATIBILITY
                   1340:                                        (t != FILING_dataSize) && (t != FILING_type) &&
                   1341:                                        (t != FILING_createdBy) && (t != FILING_readOn) &&
                   1342:                                        (t != FILING_version) && (t != FILING_fileID)  &&
                   1343:                                        (t != 4938) ) {
                   1344: #endif FILETOOLCOMPATIBILITY
                   1345:                                ReturnAttributeTypeError(FILING_disallowed, t);
                   1346:                                /* NOT REACHED */
                   1347:                        }
                   1348:                        attrseq->sequence[i].type= t;
                   1349:                }
                   1350: #ifdef EXTENSIONS
                   1351:        }
                   1352: #endif EXTENSIONS
                   1353: #ifdef DEBUG
                   1354:        fprintf(msgs, "\n");
                   1355: #endif DEBUG
                   1356: }
                   1357: 
                   1358: #ifdef EXTENSIONS
                   1359: make_supported_attributes(attrseq)
                   1360: FILING_AttributeSequence *attrseq;
                   1361: 
                   1362: {
                   1363:        attrseq->length= SUPPORTEDATTRIBUTES;
                   1364:        attrseq->sequence[0].type= FILING_createdOn;
                   1365:        attrseq->sequence[1].type= FILING_isDirectory;
                   1366:        attrseq->sequence[2].type= FILING_modifiedOn;
                   1367:        attrseq->sequence[3].type= FILING_name;
                   1368:        attrseq->sequence[4].type= FILING_dataSize;
                   1369:        attrseq->sequence[5].type= FILING_type;
                   1370:        attrseq->sequence[6].type= FILING_version;
                   1371:        attrseq->sequence[7].type= FILING_pathname;
                   1372: }
                   1373: 
                   1374: make_required_attributes(attrseq)
                   1375: FILING_AttributeSequence *attrseq;
                   1376: 
                   1377: {
                   1378:        attrseq->length= REQUIREDATTRIBUTES;
                   1379:        attrseq->sequence[0].type= FILING_createdOn;
                   1380:        attrseq->sequence[1].type= FILING_modifiedOn;
                   1381:        attrseq->sequence[2].type= FILING_name;
                   1382:        attrseq->sequence[3].type= FILING_dataSize;
                   1383:        attrseq->sequence[4].type= FILING_version;
                   1384:        attrseq->sequence[5].type= FILING_pathname;
                   1385: }
                   1386: #endif EXTENSIONS
                   1387: 
                   1388: void FILING_ChangeAttributes(ServerConnection, BDTProc, file, attributes, session)
                   1389: CourierConnection *ServerConnection;
                   1390: int ( *BDTProc)();
                   1391: FILING_Handle file;
                   1392: FILING_AttributeSequence attributes;
                   1393: FILING_Session session;
                   1394: {
                   1395: #ifdef EXTENSIONS
                   1396:        file_handle *handle;
                   1397:        char oldname[MAX_FILE_NAME_LENGTH];
                   1398: 
                   1399: #ifdef DEBUG
                   1400:        if (msgs == 0) {
                   1401:                char logfile[50];
                   1402:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   1403:                msgs= fopen(logfile,"w");
                   1404:        }
                   1405:        fprintf(msgs, "ChangeAttributes\n");
                   1406: #endif DEBUG
                   1407: 
                   1408:        if ( verify_session(session) != -1 ) {
                   1409:                /* NOT REACHED */
                   1410:        }
                   1411: 
                   1412:        if ( is_nullHandle(file) == -1 ) {
                   1413:                ReturnHandleError(FILING_nullDisallowed);
                   1414:                /* NOT REACHED */
                   1415:        }
                   1416: 
                   1417:        copyhandle(&handle,file);
                   1418: 
                   1419:        if ( handle->state != FILE_OPEN ) {
                   1420:                ReturnHandleError(FILING_invalid);
                   1421:                /* NOT REACHED */
                   1422:        }
                   1423: 
                   1424:        if ( access_file(handle) != -1 ) {
                   1425:                /* NOT REACHED */
                   1426:        }
                   1427: 
                   1428:        close_file(handle);                             /* do it now */
                   1429: 
                   1430:        strcpy(oldname, handle->pathname);
                   1431: 
                   1432:        if ( verify_change_attributes(attributes, handle) != -1 ) {
                   1433:                /* NOT REACHED */
                   1434:        }
                   1435: 
                   1436:        if ( strcmp(oldname, handle->pathname) != 0 ) {
                   1437:                rename_file(oldname, handle);
                   1438:        }
                   1439: 
                   1440:        set_create_time(handle);
                   1441: 
                   1442:        return;
                   1443: #else EXTENSIONS
                   1444:        NoSuchProcedureValue("Filing", 9);
                   1445: #endif EXTENSIONS
                   1446: }
                   1447: #ifdef EXTENSIONS
                   1448: verify_change_attributes(attr, handle)
                   1449: FILING_AttributeSequence attr;
                   1450: file_handle *handle;
                   1451: {
                   1452:        int i;
                   1453:        FILING_AttributeType t;
                   1454:        int got_accesslist, got_childrenuniquelynamed, got_createdon, got_datasize;
                   1455:        int got_defaultaccesslist, got_ordering;
                   1456:        int got_subtreesizelimit, got_type, got_version;
                   1457:        FILING_Version version;
                   1458:        Boolean childrenuniquelynamed;
                   1459:        Cardinal ordering;              
                   1460:        Cardinal subtreesizelimit;
                   1461:        char *AttrToString();
                   1462:        LongCardinal AttrToLongCardinal();
                   1463: 
                   1464:        int got_name;
                   1465:        char *name;
                   1466: 
                   1467: #ifdef DEBUG
                   1468:        fprintf(msgs,"%d change attributes      ",attr.length);
                   1469: #endif DEBUG
                   1470: 
                   1471:        if ( attr.length < 0 ) {
                   1472:                ReturnAttributeTypeError(FILING_illegal, 0);
                   1473:                /* NOT REACHED */
                   1474:        }
                   1475: 
                   1476:        got_accesslist= got_childrenuniquelynamed= got_createdon= 0;
                   1477:        got_datasize= got_defaultaccesslist= 0;
                   1478:        got_ordering= got_subtreesizelimit= got_type= got_version= 0;
                   1479:        got_name= 0;
                   1480: 
                   1481:        for ( i= 0 ; i < attr.length ; i++ ) {
                   1482:                t= attr.sequence[i].type;
                   1483: #ifdef DEBUG
                   1484:                fprintf(msgs, "%d ",t);
                   1485: #endif DEBUG
                   1486:                if ( t == FILING_createdOn ) {
                   1487: #ifdef DEBUG
                   1488:                        fprintf(msgs,"createdOn  ");
                   1489: #endif DEBUG
                   1490:                        if ( got_createdon ) {
                   1491:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1492:                                /* NOT REACHED */
                   1493:                        }
                   1494:                        got_createdon++;
                   1495: 
                   1496:                        handle->createdon= AttrToLongCardinal(&attr.sequence[i]);
                   1497:                        continue;
                   1498:                }
                   1499: 
                   1500:                if ( t == FILING_dataSize ) {
                   1501: #ifdef DEBUG
                   1502:                        fprintf(msgs,"dataSize  ");
                   1503: #endif DEBUG
                   1504:                        if ( got_datasize ) {
                   1505:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1506:                                /* NOT REACHED */
                   1507:                        }
                   1508:                        got_datasize++;
                   1509: 
                   1510:                        handle->datasize= AttrToLongCardinal(&attr.sequence[i]);
                   1511:                        continue;
                   1512:                }
                   1513: 
                   1514:                if ( t == FILING_type ) {
                   1515: #ifdef DEBUG
                   1516:                        fprintf(msgs,"type  ");
                   1517: #endif DEBUG
                   1518:                        if ( got_type ) {
                   1519:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1520:                                /* NOT REACHED */
                   1521:                        }
                   1522:                        got_type++;
                   1523: 
                   1524:                        handle->type= AttrToLongCardinal(&attr.sequence[i]);
                   1525:                        continue;
                   1526:                }
                   1527:                if ( t == FILING_version ) {
                   1528: #ifdef DEBUG
                   1529:                        fprintf(msgs,"version  ");
                   1530: #endif DEBUG
                   1531:                        if ( got_version ) {
                   1532:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1533:                                /* NOT REACHED */
                   1534:                        }
                   1535:                        got_version++;
                   1536: 
                   1537:                        version= AttrToCardinal(&attr.sequence[i]);
                   1538:                        if ( version != FILING_highestVersion ) {
                   1539:                                        ReturnAttributeValueError(FILING_unimplemented, t);
                   1540:                                        /* NOT REACHED */
                   1541: 
                   1542:                        }
                   1543:                        continue;
                   1544:                }
                   1545: 
                   1546:                if ( t == FILING_name ) {
                   1547: #ifdef DEBUG
                   1548:                        fprintf(msgs, "name  ");
                   1549: #endif DEBUG
                   1550:                        if ( got_name ) {
                   1551:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1552:                                /* NOT REACHED */
                   1553:                        }
                   1554:                        got_name++;
                   1555: 
                   1556:                        name= AttrToString(&attr.sequence[i]);
                   1557:                        continue;
                   1558:                }
                   1559: 
                   1560: #ifdef SOMEDAY
                   1561:                if ( t == FILING_accessList ) {
                   1562:                        if ( got_accesslist ) {
                   1563:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1564:                                /* NOT REACHED */
                   1565:                        }
                   1566: 
                   1567:                        got_accesslist++;
                   1568: 
                   1569:                        if ( FALSE ) {
                   1570:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1571:                                /* NOT REACHED */
                   1572:                        }
                   1573: 
                   1574:                        continue;
                   1575:                }
                   1576: #endif SOMEDAY
                   1577: 
                   1578:                if ( t == FILING_childrenUniquelyNamed ) {
                   1579:                        if ( got_childrenuniquelynamed ) {
                   1580:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1581:                                /* NOT REACHED */
                   1582:                        }
                   1583: 
                   1584:                        got_childrenuniquelynamed++;
                   1585: 
                   1586:                        childrenuniquelynamed= AttrToBoolean(&attr.sequence[i]);
                   1587:                        if ( childrenuniquelynamed != TRUE ) {
                   1588:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1589:                                /* NOT REACHED */
                   1590:                        }
                   1591: 
                   1592:                        continue;
                   1593:                }
                   1594: 
                   1595: 
                   1596: #ifdef SOMEDAY
                   1597:                if ( t == FILING_defaultAccessList ) {
                   1598:                        if ( got_defaultaccesslist ) {
                   1599:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1600:                                /* NOT REACHED */
                   1601:                        }
                   1602: 
                   1603:                        got_defaultaccesslist++;
                   1604: 
                   1605:                        if ( FALSE ) {
                   1606:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1607:                                /* NOT REACHED */
                   1608:                        }
                   1609: 
                   1610:                        continue;
                   1611:                }
                   1612: #endif SOMEDAY
                   1613: 
                   1614:                if ( t == FILING_ordering ) {
                   1615:                        if ( got_ordering ) {
                   1616:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1617:                                /* NOT REACHED */
                   1618:                        }
                   1619: 
                   1620:                        got_ordering++;
                   1621: 
                   1622:                        if ( FALSE ) {
                   1623:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1624:                                /* NOT REACHED */
                   1625:                        }
                   1626: 
                   1627:                        continue;
                   1628:                }
                   1629: 
                   1630:                if ( t == FILING_subtreeSizeLimit ) {
                   1631:                        if ( got_subtreesizelimit ) {
                   1632:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1633:                                /* NOT REACHED */
                   1634:                        }
                   1635: 
                   1636:                        got_subtreesizelimit++;
                   1637: 
                   1638:                        subtreesizelimit= AttrToCardinal(&attr.sequence[i]);
                   1639:                        if ( subtreesizelimit != FILING_nullSubtreeSizeLimit ) {
                   1640:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1641:                                /* NOT REACHED */
                   1642:                        }
                   1643: 
                   1644:                        continue;
                   1645:                }
                   1646: 
                   1647:                if ( (t == FILING_fileID) || (t == FILING_isDirectory) ||
                   1648:                                (t == FILING_isTemporary) || (t == FILING_modifiedBy) ||
                   1649:                                (t == FILING_modifiedOn) || (t == FILING_numberOfChildren) ||
                   1650:                                (t == FILING_parentID) || (t == FILING_pathname) ||
                   1651:                                (t == FILING_readBy) || (t == FILING_readOn) ||
                   1652:                                (t == FILING_storedSize) || (t == FILING_subtreeSize) ) {
                   1653:                        ReturnAttributeTypeError(FILING_disallowed, t);
                   1654:                }
                   1655: 
                   1656:                if ( t < 0 ) {
                   1657:                        ReturnAttributeTypeError(FILING_illegal, t);
                   1658:                        /* NOT REACHED */
                   1659:                }
                   1660: 
                   1661:                if ( (t == FILING_checksum) || (t == FILING_createdBy) ||
                   1662:                                        (t == FILING_position) )
                   1663:                        ReturnAttributeTypeError(FILING_unimplemented, t);
                   1664:                else
                   1665:                        ReturnAttributeTypeError(FILING_disallowed, t);
                   1666: 
                   1667:        }
                   1668: 
                   1669: #ifdef DEBUG
                   1670:        fprintf(msgs, "\n");
                   1671: #endif DEBUG
                   1672: 
                   1673:        if ( got_name ) {
                   1674:                char *ptr, *rindex();
                   1675:                if ( (ptr= rindex(handle->pathname, '/')) == 0 ) {
                   1676:                        ptr= handle->pathname;
                   1677:                } else {
                   1678:                        ptr++;
                   1679:                        *ptr= '\0';
                   1680:                }
                   1681:                strcat(handle->pathname, name);
                   1682:        }
                   1683: 
                   1684:        return(-1);
                   1685: }
                   1686: #endif EXTENSIONS
                   1687: 
                   1688: 
                   1689: FILING_CopyResults FILING_Copy(ServerConnection, BDTProc, file, destdir, attributes, controls,  session)
                   1690: CourierConnection *ServerConnection;
                   1691: int ( *BDTProc)();
                   1692: FILING_Handle file;
                   1693: FILING_Handle destdir;
                   1694: FILING_AttributeSequence attributes;
                   1695: FILING_ControlSequence controls;
                   1696: FILING_Session session;
                   1697: {
                   1698: #ifdef EXTENSIONS
                   1699:        FILING_CopyResults results;
                   1700:        file_handle *handle;
                   1701:        file_handle *dir_handle;
                   1702:        file_handle *new_handle;
                   1703: 
                   1704: #ifdef DEBUG
                   1705:        if (msgs == 0) {
                   1706:                char logfile[50];
                   1707:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   1708:                msgs= fopen(logfile,"w");
                   1709:        }
                   1710:        fprintf(msgs, "Copy\n");
                   1711: #endif DEBUG
                   1712: 
                   1713:        BDTabort_expected= FALSE;
                   1714: 
                   1715:        if ( verify_session(session) != -1 ) {
                   1716:                /* NOT REACHED */
                   1717:        }
                   1718: 
                   1719:        copyhandle(&handle, file);
                   1720: 
                   1721:        if ( handle->state != FILE_OPEN ) {
                   1722:                ReturnHandleError(FILING_invalid);
                   1723:                /* NOT REACHED */
                   1724:        }
                   1725: 
                   1726:        if ( access_file(handle) != -1 ) {
                   1727:                /* NOT REACHED */
                   1728:        }
                   1729: 
                   1730:        if ( (new_handle= (file_handle *)malloc(sizeof(file_handle))) == NULL ) {
                   1731:                ReturnUndefinedError(0);
                   1732:                /* NOT REACHED */
                   1733:        }
                   1734: 
                   1735:        if ( (new_handle->pathname= (char *)malloc(MAX_FILE_NAME_LENGTH)) == NULL ) {
                   1736:                ReturnUndefinedError(0);
                   1737:                /* NOT REACHED */
                   1738:        }
                   1739: 
                   1740: #ifdef DEBUG
                   1741:        fprintf(msgs, "copy handle= %x\n",new_handle);
                   1742: #endif DEBUG
                   1743: 
                   1744:        copyhandle(&dir_handle,destdir);
                   1745: 
                   1746:        if ( dir_handle == 0 ) {
                   1747:                dir_handle= &RootHandle;
                   1748:                strcpy(new_handle->pathname, SERVICE_ROOT);
                   1749:        } else {
                   1750:                if ( dir_handle->state != FILE_OPEN ) {
                   1751:                        ReturnHandleError(FILING_invalid);
                   1752:                        /* NOT REACHED */
                   1753:                }
                   1754: 
                   1755:                if ( access_file(dir_handle) != -1 ) {
                   1756:                        /* NOT REACHED */
                   1757:                }
                   1758: 
                   1759:                if ( dir_handle->isdirectory != TRUE ) {
                   1760:                        ReturnHandleError(FILING_directoryRequired);
                   1761:                        /* NOT REACHED */
                   1762:                }
                   1763: 
                   1764:                strcpy(new_handle->pathname,dir_handle->pathname);
                   1765:                if ( strcmp(new_handle->pathname, "/") != 0 )
                   1766:                        strcat(new_handle->pathname,"/");
                   1767:        } 
                   1768: 
                   1769:        if ( verify_copy_attributes(attributes,new_handle,handle) != -1 ) {
                   1770:                /* NOT REACHED */
                   1771:        }
                   1772: 
                   1773:        close_file(handle);
                   1774: 
                   1775: #ifdef DEBUG
                   1776:        fprintf(msgs, "copying %s to %s\n", handle->pathname, new_handle->pathname);
                   1777:        fflush(msgs);
                   1778: #endif DEBUG
                   1779: 
                   1780:        if ( copy_file(handle, new_handle) != -1 ) {
                   1781:                /* NOT REACHED */
                   1782:        }
                   1783: 
                   1784:        new_handle->state= FILE_OPEN;
                   1785:        new_handle->file_desc= NULL;
                   1786: 
                   1787:        copyhandle(results.newFile, &new_handle);
                   1788:        reset_continuance_timer();
                   1789:        return(results);
                   1790: 
                   1791: #else EXTENSIONS
                   1792:        NoSuchProcedureValue("Filing", 10);
                   1793: #endif EXTENSIONS
                   1794: }
                   1795: #ifdef EXTENSIONS
                   1796: verify_copy_attributes(attr, tohandle, fromhandle)
                   1797: FILING_AttributeSequence attr;
                   1798: file_handle *tohandle;
                   1799: file_handle *fromhandle;
                   1800: {
                   1801:        int i;
                   1802:        FILING_AttributeType t;
                   1803:        int got_accesslist, got_defaultaccesslist, got_istemporary;
                   1804:        int got_name, got_pathname, got_subtreesizelimit, got_version;
                   1805:        char *pathname;
                   1806:        char *name;
                   1807:        FILING_Version version;
                   1808:        Boolean istemporary;
                   1809:        Cardinal subtreesizelimit;
                   1810:        char *AttrToString();
                   1811:        LongCardinal AttrToLongCardinal();
                   1812: 
                   1813: #ifdef DEBUG
                   1814:        fprintf(msgs,"%d copy attributes        ",attr.length);
                   1815: #endif DEBUG
                   1816: 
                   1817:        if ( attr.length < 0 ) {
                   1818:                ReturnAttributeTypeError(FILING_illegal, 0);
                   1819:                /* NOT REACHED */
                   1820:        }
                   1821: 
                   1822:        got_accesslist= got_defaultaccesslist= got_istemporary= 0;
                   1823:        got_name= got_pathname= got_subtreesizelimit= got_version= 0;
                   1824: 
                   1825:        for ( i= 0 ; i < attr.length ; i++ ) {
                   1826:                t= attr.sequence[i].type;
                   1827: #ifdef DEBUG
                   1828:                fprintf(msgs, "%d ",t);
                   1829: #endif DEBUG
                   1830: 
                   1831:                if ( t == FILING_pathname ) {
                   1832: #ifdef DEBUG
                   1833:                        fprintf(msgs,"pathname  ");
                   1834: #endif DEBUG
                   1835:                        if ( got_pathname ) {
                   1836:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1837:                                /* NOT REACHED */
                   1838:                        }
                   1839:                        got_pathname++;
                   1840: 
                   1841:                        pathname= AttrToString(&attr.sequence[i]);
                   1842:                        if ( check_pathname(pathname) != -1 ) {
                   1843:                                /* NOT REACHED */
                   1844:                        }
                   1845:                        continue;
                   1846:                }                       
                   1847: 
                   1848:                if ( t == FILING_version ) {
                   1849: #ifdef DEBUG
                   1850:                        fprintf(msgs,"version  ");
                   1851: #endif DEBUG
                   1852:                        if ( got_version ) {
                   1853:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1854:                                /* NOT REACHED */
                   1855:                        }
                   1856:                        got_version++;
                   1857: 
                   1858:                        version= AttrToCardinal(&attr.sequence[i]);
                   1859:                        if ( version != FILING_highestVersion ) {
                   1860:                                        ReturnAttributeValueError(FILING_unimplemented, t);
                   1861:                                        /* NOT REACHED */
                   1862: 
                   1863:                        }
                   1864:                        continue;
                   1865:                }
                   1866: 
                   1867: 
                   1868:                if ( t == FILING_name ) {
                   1869: #ifdef DEBUG
                   1870:                        fprintf(msgs, "name  ");
                   1871: #endif DEBUG
                   1872:                        if ( got_name ) {
                   1873:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1874:                                /* NOT REACHED */
                   1875:                        }
                   1876:                        got_name++;
                   1877: 
                   1878:                        name= AttrToString(&attr.sequence[i]);
                   1879:                        continue;
                   1880:                }
                   1881: 
                   1882: #ifdef SOMEDAY
                   1883:                if ( t == FILING_accessList ) {
                   1884:                        if ( got_accesslist ) {
                   1885:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1886:                                /* NOT REACHED */
                   1887:                        }
                   1888: 
                   1889:                        got_accesslist++;
                   1890: 
                   1891:                        if ( FALSE ) {
                   1892:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1893:                                /* NOT REACHED */
                   1894:                        }
                   1895: 
                   1896:                        continue;
                   1897:                }
                   1898: 
                   1899:                if ( t == FILING_defaultAccessList ) {
                   1900:                        if ( got_defaultaccesslist ) {
                   1901:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1902:                                /* NOT REACHED */
                   1903:                        }
                   1904: 
                   1905:                        got_defaultaccesslist++;
                   1906: 
                   1907:                        if ( FALSE ) {
                   1908:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1909:                                /* NOT REACHED */
                   1910:                        }
                   1911: 
                   1912:                        continue;
                   1913:                }
                   1914: #endif SOMEDAY
                   1915: 
                   1916:                if ( t == FILING_isTemporary ) {
                   1917:                        if ( got_istemporary ) {
                   1918:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1919:                                /* NOT REACHED */
                   1920:                        }
                   1921: 
                   1922:                        got_istemporary++;
                   1923: 
                   1924:                        istemporary= AttrToBoolean(&attr.sequence[i]);
                   1925:                        if ( istemporary != FALSE ) {
                   1926:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1927:                                /* NOT REACHED */
                   1928:                        }
                   1929: 
                   1930:                        continue;
                   1931:                }
                   1932: 
                   1933:                if ( t == FILING_subtreeSizeLimit ) {
                   1934:                        if ( got_subtreesizelimit ) {
                   1935:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   1936:                                /* NOT REACHED */
                   1937:                        }
                   1938: 
                   1939:                        got_subtreesizelimit++;
                   1940: 
                   1941:                        subtreesizelimit= AttrToCardinal(&attr.sequence[i]);
                   1942:                        if ( subtreesizelimit != FILING_nullSubtreeSizeLimit ) {
                   1943:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   1944:                                /* NOT REACHED */
                   1945:                        }
                   1946: 
                   1947:                        continue;
                   1948:                }
                   1949: 
                   1950:                if ( t == FILING_position ) {
                   1951:                        ReturnAttributeTypeError(FILING_unimplemented, t);
                   1952:                        /* NOT REACHED */
                   1953:                }
                   1954: 
                   1955:                if ( ( t < 0 ) || (t > FILING_subtreeSizeLimit) ) {
                   1956:                        ReturnAttributeTypeError(FILING_illegal, t);
                   1957:                        /* NOT REACHED */
                   1958:                }
                   1959: 
                   1960:                ReturnAttributeTypeError(FILING_disallowed, t);
                   1961:        }
                   1962: 
                   1963: #ifdef DEBUG
                   1964:        fprintf(msgs, "\n");
                   1965: #endif DEBUG
                   1966: 
                   1967: #ifdef FILETOOLCOMPATIBILITY
                   1968:        if ( !got_pathname && !got_name) {
                   1969:                char *ptr, *rindex();
                   1970:                if ( (ptr= rindex(fromhandle->pathname,'/')) == 0 ) 
                   1971:                        ptr= fromhandle->pathname;
                   1972:                else
                   1973:                        ptr++;
                   1974:                strcat(tohandle->pathname, ptr);
                   1975:        } else  if ( !got_pathname )  {
                   1976:                strcat(tohandle->pathname,name);
                   1977:        } else {
                   1978:                if ( *pathname == '/' )
                   1979:                        strcat(tohandle->pathname, pathname+1);
                   1980:                else
                   1981:                        strcat(tohandle->pathname,pathname);
                   1982:                Deallocate(&pathname);
                   1983:        }
                   1984: 
                   1985: #else FILETOOLCOMPATIBILITY
                   1986:        if ( !got_pathname ) {
                   1987:                ReturnAttributeTypeError(FILING_missing, t);
                   1988:                /* NOT REACHED */
                   1989:        } else {
                   1990:                if ( *pathname == '/' )
                   1991:                        strcat(tohandle->pathname, pathname+1);
                   1992:                else
                   1993:                        strcat(tohandle->pathname, pathname);
                   1994:                Deallocate(&pathname);
                   1995:        }
                   1996: #endif FILETOOLCOMPATIBILITY
                   1997: 
                   1998:        return(-1);
                   1999: }
                   2000: #endif EXTENSIONS
                   2001: 
                   2002: 
                   2003: void FILING_Move(ServerConnection, BDTProc, file, destdir, attributes, session)
                   2004: CourierConnection *ServerConnection;
                   2005: int ( *BDTProc)();
                   2006: FILING_Handle file;
                   2007: FILING_Handle destdir;
                   2008: FILING_AttributeSequence attributes;
                   2009: FILING_Session session;
                   2010: {
                   2011: #ifdef EXTENSIONS
                   2012:        file_handle *handle;
                   2013:        file_handle *dir_handle;
                   2014:        char oldname[MAX_FILE_NAME_LENGTH];
                   2015: 
                   2016: #ifdef DEBUG
                   2017:        if (msgs == 0) {
                   2018:                char logfile[50];
                   2019:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   2020:                msgs= fopen(logfile,"w");
                   2021:        }
                   2022:        fprintf(msgs, "Move\n");
                   2023: #endif DEBUG
                   2024: 
                   2025:        BDTabort_expected= FALSE;
                   2026: 
                   2027:        if ( verify_session(session) != -1 ) {
                   2028:                /* NOT REACHED */
                   2029:        }
                   2030: 
                   2031:        copyhandle(&handle, file);
                   2032: 
                   2033:        if ( handle->state != FILE_OPEN ) {
                   2034:                ReturnHandleError(FILING_invalid);
                   2035:                /* NOT REACHED */
                   2036:        }
                   2037: 
                   2038:        if ( access_file(handle) != -1 ) {
                   2039:                /* NOT REACHED */
                   2040:        }
                   2041: 
                   2042:        strcpy(oldname, handle->pathname);
                   2043: 
                   2044:        copyhandle(&dir_handle,destdir);
                   2045: 
                   2046:        if ( dir_handle == 0 ) {
                   2047:                dir_handle= &RootHandle;
                   2048:                strcpy(handle->pathname, SERVICE_ROOT);
                   2049:        } else {
                   2050:                if ( dir_handle->state != FILE_OPEN ) {
                   2051:                        ReturnHandleError(FILING_invalid);
                   2052:                        /* NOT REACHED */
                   2053:                }
                   2054: 
                   2055:                if ( access_file(dir_handle) != -1 ) {
                   2056:                        /* NOT REACHED */
                   2057:                }
                   2058: 
                   2059:                if ( dir_handle->isdirectory != TRUE ) {
                   2060:                        ReturnHandleError(FILING_directoryRequired);
                   2061:                        /* NOT REACHED */
                   2062:                }
                   2063: 
                   2064:                strcpy(handle->pathname,dir_handle->pathname);
                   2065:                if ( strcmp(handle->pathname, "/") != 0 )
                   2066:                        strcat(handle->pathname,"/");
                   2067:        } 
                   2068: 
                   2069: 
                   2070:        if ( verify_move_attributes(attributes,handle,oldname) != -1 ) {
                   2071:                /* NOT REACHED */
                   2072:        }
                   2073: 
                   2074:        close_file(handle);
                   2075: 
                   2076: #ifdef DEBUG
                   2077:        fprintf(msgs, "moving %s to %s\n", oldname, handle->pathname);
                   2078: #endif DEBUG
                   2079: 
                   2080:        if ( rename_file(oldname, handle) != -1 ) {
                   2081:                /* NOT REACHED */
                   2082:        }
                   2083: 
                   2084:        reset_continuance_timer();
                   2085:        return;
                   2086: 
                   2087: #else EXTENSIONS
                   2088:        NoSuchProcedureValue("Filing", 11);
                   2089: #endif EXTENSIONS
                   2090: }
                   2091: #ifdef EXTENSIONS
                   2092: verify_move_attributes(attr, tohandle, fromname)
                   2093: FILING_AttributeSequence attr;
                   2094: file_handle *tohandle;
                   2095: char *fromname;
                   2096: {
                   2097:        int i;
                   2098:        FILING_AttributeType t;
                   2099:        int got_accesslist, got_defaultaccesslist, got_istemporary;
                   2100:        int got_name, got_subtreesizelimit, got_version;
                   2101:        char *name;
                   2102:        FILING_Version version;
                   2103:        Boolean istemporary;
                   2104:        Cardinal subtreesizelimit;
                   2105:        char *AttrToString();
                   2106:        LongCardinal AttrToLongCardinal();
                   2107: 
                   2108: #ifdef DEBUG
                   2109:        fprintf(msgs,"%d move attributes        ",attr.length);
                   2110: #endif DEBUG
                   2111: 
                   2112:        if ( attr.length < 0 ) {
                   2113:                ReturnAttributeTypeError(FILING_illegal, 0);
                   2114:                /* NOT REACHED */
                   2115:        }
                   2116: 
                   2117:        got_accesslist= got_defaultaccesslist= got_istemporary= 0;
                   2118:        got_name= got_subtreesizelimit= got_version= 0;
                   2119: 
                   2120:        for ( i= 0 ; i < attr.length ; i++ ) {
                   2121:                t= attr.sequence[i].type;
                   2122: #ifdef DEBUG
                   2123:                fprintf(msgs, "%d ",t);
                   2124: #endif DEBUG
                   2125: 
                   2126:                if ( t == FILING_version ) {
                   2127: #ifdef DEBUG
                   2128:                        fprintf(msgs,"version  ");
                   2129: #endif DEBUG
                   2130:                        if ( got_version ) {
                   2131:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2132:                                /* NOT REACHED */
                   2133:                        }
                   2134:                        got_version++;
                   2135: 
                   2136:                        version= AttrToCardinal(&attr.sequence[i]);
                   2137:                        if ( version != FILING_highestVersion ) {
                   2138:                                        ReturnAttributeValueError(FILING_unimplemented, t);
                   2139:                                        /* NOT REACHED */
                   2140: 
                   2141:                        }
                   2142:                        continue;
                   2143:                }
                   2144: 
                   2145: 
                   2146:                if ( t == FILING_name ) {
                   2147: #ifdef DEBUG
                   2148:                        fprintf(msgs, "name  ");
                   2149: #endif DEBUG
                   2150:                        if ( got_name ) {
                   2151:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2152:                                /* NOT REACHED */
                   2153:                        }
                   2154:                        got_name++;
                   2155: 
                   2156:                        name= AttrToString(&attr.sequence[i]);
                   2157:                        continue;
                   2158:                }
                   2159: 
                   2160: #ifdef SOMEDAY
                   2161:                if ( t == FILING_accessList ) {
                   2162:                        if ( got_accesslist ) {
                   2163:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2164:                                /* NOT REACHED */
                   2165:                        }
                   2166: 
                   2167:                        got_accesslist++;
                   2168: 
                   2169:                        if ( FALSE ) {
                   2170:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2171:                                /* NOT REACHED */
                   2172:                        }
                   2173: 
                   2174:                        continue;
                   2175:                }
                   2176: 
                   2177:                if ( t == FILING_defaultAccessList ) {
                   2178:                        if ( got_defaultaccesslist ) {
                   2179:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2180:                                /* NOT REACHED */
                   2181:                        }
                   2182: 
                   2183:                        got_defaultaccesslist++;
                   2184: 
                   2185:                        if ( FALSE ) {
                   2186:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2187:                                /* NOT REACHED */
                   2188:                        }
                   2189: 
                   2190:                        continue;
                   2191:                }
                   2192: #endif SOMEDAY
                   2193: 
                   2194:                if ( t == FILING_isTemporary ) {
                   2195:                        if ( got_istemporary ) {
                   2196:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2197:                                /* NOT REACHED */
                   2198:                        }
                   2199: 
                   2200:                        got_istemporary++;
                   2201: 
                   2202:                        istemporary= AttrToBoolean(&attr.sequence[i]);
                   2203:                        if ( istemporary != FALSE ) {
                   2204:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2205:                                /* NOT REACHED */
                   2206:                        }
                   2207: 
                   2208:                        continue;
                   2209:                }
                   2210: 
                   2211:                if ( t == FILING_subtreeSizeLimit ) {
                   2212:                        if ( got_subtreesizelimit ) {
                   2213:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2214:                                /* NOT REACHED */
                   2215:                        }
                   2216: 
                   2217:                        got_subtreesizelimit++;
                   2218: 
                   2219:                        subtreesizelimit= AttrToCardinal(&attr.sequence[i]);
                   2220:                        if ( subtreesizelimit != FILING_nullSubtreeSizeLimit ) {
                   2221:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2222:                                /* NOT REACHED */
                   2223:                        }
                   2224: 
                   2225:                        continue;
                   2226:                }
                   2227: 
                   2228:                if ( t == FILING_position ) {
                   2229:                        ReturnAttributeTypeError(FILING_unimplemented, t);
                   2230:                        /* NOT REACHED */
                   2231:                }
                   2232: 
                   2233:                if ( ( t < 0 ) || (t > FILING_subtreeSizeLimit) ) {
                   2234:                        ReturnAttributeTypeError(FILING_illegal, t);
                   2235:                        /* NOT REACHED */
                   2236:                }
                   2237: 
                   2238:                ReturnAttributeTypeError(FILING_disallowed, t);
                   2239:        }
                   2240: 
                   2241: #ifdef DEBUG
                   2242:        fprintf(msgs, "\n");
                   2243: #endif DEBUG
                   2244: 
                   2245:        if ( !got_name) {
                   2246:                char *ptr, *rindex();
                   2247:                if ( (ptr= rindex(fromname,'/')) == 0 ) 
                   2248:                        ptr= fromname;
                   2249:                else
                   2250:                        ptr++;
                   2251:                strcat(tohandle->pathname, ptr);
                   2252:        } else {
                   2253:                strcat(tohandle->pathname,name);
                   2254:        } 
                   2255: 
                   2256:        return(-1);
                   2257: }
                   2258: #endif EXTENSIONS
                   2259: 
                   2260: 
                   2261: FILING_StoreResults FILING_Store(ServerConnection, BDTProc, directory, attributes, controls, content, session)
                   2262: CourierConnection *ServerConnection;
                   2263: int ( *BDTProc)();
                   2264: FILING_Handle directory;
                   2265: FILING_AttributeSequence attributes;
                   2266: FILING_ControlSequence controls;
                   2267: BulkData1_Descriptor content;
                   2268: FILING_Session session;
                   2269: {
                   2270:        FILING_StoreResults results;
                   2271:        file_handle *handle, *dir_handle;
                   2272: 
                   2273: #ifdef DEBUG
                   2274:        if (msgs == 0) {
                   2275:                char logfile[50];
                   2276:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   2277:                msgs= fopen(logfile,"w");
                   2278:        }
                   2279:        fprintf(msgs, "Store  ");
                   2280: #endif DEBUG
                   2281: 
                   2282:        BDTabort_expected= TRUE;
                   2283: 
                   2284:        if ( verify_session(session) != -1 ) {
                   2285:                /* NOT REACHED */
                   2286:        }
                   2287: 
                   2288: #ifndef FILETOOLCOMPATIBILITY
                   2289:        if ( is_nullControls(controls) != -1) {
                   2290:                ReturnControlTypeError(FILING_disallowed, 0);
                   2291:                /* NOT REACHED */
                   2292:        }
                   2293: 
                   2294:        if ( is_nullHandle(directory) != -1 ) {
                   2295:                ReturnHandleError(FILING_invalid);
                   2296:                /* NOT REACHED */
                   2297:        }
                   2298: #endif FILETOOLCOMPATIBILITY
                   2299: 
                   2300:        if ( content.designator == BulkData1_null ) {
                   2301:                return;
                   2302:        } else  if ( content.designator != BulkData1_immediate ) {
                   2303:                ReturnTransferError(FILING_aborted);
                   2304:                /* NOT REACHED */
                   2305:        }
                   2306: 
                   2307:        if ( (handle= (file_handle *)malloc(sizeof(file_handle))) == NULL ) {
                   2308:                ReturnUndefinedError(0);
                   2309:                /* NOT REACHED */
                   2310:        }
                   2311: 
                   2312:        if ( (handle->pathname= (char *)malloc(MAX_FILE_NAME_LENGTH)) == NULL ) {
                   2313:                ReturnUndefinedError(0);
                   2314:                /* NOT REACHED */
                   2315:        }
                   2316: 
                   2317: #ifdef DEBUG
                   2318:        fprintf(msgs, "store handle= %x\n",handle);
                   2319: #endif DEBUG
                   2320: 
                   2321: #ifdef FILETOOLCOMPATIBILITY
                   2322:        copyhandle(&dir_handle,directory);
                   2323: 
                   2324:        if ( dir_handle == 0 ) {
                   2325:                dir_handle= &RootHandle;
                   2326:                strcpy(handle->pathname, SERVICE_ROOT);
                   2327:        } else {
                   2328:                if ( dir_handle->state != FILE_OPEN ) {
                   2329:                        ReturnHandleError(FILING_invalid);
                   2330:                        /* NOT REACHED */
                   2331:                }
                   2332: 
                   2333:                if ( access_file(dir_handle) != -1 ) {
                   2334:                        /* NOT REACHED */
                   2335:                }
                   2336: 
                   2337:                if ( dir_handle->isdirectory != TRUE ) {
                   2338:                        ReturnHandleError(FILING_directoryRequired);
                   2339:                        /* NOT REACHED */
                   2340:                }
                   2341: 
                   2342:                strcpy(handle->pathname,dir_handle->pathname);
                   2343:                if ( strcmp(handle->pathname, "/") != 0 )
                   2344:                        strcat(handle->pathname,"/");
                   2345:        } 
                   2346: #else FILETOOLCOMPATIBILITY
                   2347:        strcpy(handle->pathname, SERVICE_ROOT);
                   2348: #endif FILETOOLCOMPATIBILITY
                   2349: 
                   2350:        if ( verify_store_attributes(attributes, handle) != -1 ) {
                   2351:                /* NOT REACHED */
                   2352:        }
                   2353: 
                   2354: #ifdef DEBUG
                   2355:        fprintf(msgs, "creating '%s'\n", handle->pathname);
                   2356: #endif DEBUG
                   2357: 
                   2358:        if ( handle->isdirectory == TRUE ) {
                   2359:                if ( dir_storeproc(ServerConnection,handle,content) != -1 ) {
                   2360:                        /* NOT REACHED */
                   2361:                }
                   2362:        } else {
                   2363:                if ( create_file(handle) != -1 ) {
                   2364:                        /* NOT REACHED */
                   2365:                }
                   2366: 
                   2367: #ifdef EXTENSIONS
                   2368:                if ( (handle->type > LAST_FILING_TYPE) && (handle->type != TYPE_Interpress) &&
                   2369:                                        (handle->type != TYPE_VPCanvas) ) {
                   2370:                        SaveExtendedAttributes(handle->file_desc, attributes);
                   2371:                }
                   2372: #endif EXTENSIONS
                   2373:                if ( storeproc(ServerConnection,handle) != -1 ) {
                   2374:                        close_file(handle);
                   2375:                        delete_partial_file(handle);
                   2376:                        ReturnTransferError(FILING_aborted);
                   2377:                        /* NOT REACHED */
                   2378:                }
                   2379: 
                   2380:                close_file(handle);
                   2381:        }
                   2382: 
                   2383:        handle->state= FILE_OPEN;
                   2384:        handle->file_desc= NULL;
                   2385: 
                   2386:        copyhandle(results.file, &handle);
                   2387:        reset_continuance_timer();
                   2388: 
                   2389:        return(results);
                   2390: }
                   2391: 
                   2392: verify_store_attributes(attr, handle)
                   2393: FILING_AttributeSequence attr;
                   2394: file_handle *handle;
                   2395: {
                   2396:        int i;
                   2397:        FILING_AttributeType t;
                   2398:        int got_accesslist, got_childrenuniquelynamed, got_createdon, got_datasize;
                   2399:        int got_defaultaccesslist, got_isdirectory, got_istemporary, got_ordering;
                   2400:        int got_parentID, got_pathname, got_subtreesizelimit, got_type, got_version;
                   2401:        char *pathname;
                   2402:        FILING_Version version;
                   2403:        Boolean childrenuniquelynamed, istemporary;
                   2404:        Cardinal ordering;              
                   2405:        Cardinal subtreesizelimit;
                   2406:        char *AttrToString();
                   2407:        Unspecified *AttrToFileID();
                   2408:        LongCardinal AttrToLongCardinal();
                   2409: 
                   2410: #ifdef FILETOOLCOMPATIBILITY
                   2411:        int got_name, got_4938;
                   2412:        char *name;
                   2413: #endif FILETOOLCOMPATIBILITY
                   2414: 
                   2415: #ifdef DEBUG
                   2416:        fprintf(msgs,"%d store attributes       ",attr.length);
                   2417: #endif DEBUG
                   2418: 
                   2419:        if ( attr.length <= 0 ) {
                   2420:                ReturnAttributeTypeError(FILING_illegal, 0);
                   2421:                /* NOT REACHED */
                   2422:        }
                   2423: 
                   2424:        got_accesslist= got_childrenuniquelynamed= got_createdon= 0;
                   2425:        got_datasize= got_defaultaccesslist= got_isdirectory= 0;
                   2426:        got_istemporary= got_ordering= got_parentID= got_pathname= 0;
                   2427:        got_subtreesizelimit= got_type= got_version= 0;
                   2428: 
                   2429: #ifdef FILETOOLCOMPATIBILITY
                   2430:        got_name= got_4938= 0;
                   2431: #endif FILETOOLCOMPATIBILITY
                   2432: 
                   2433: 
                   2434:        for ( i= 0 ; i < attr.length ; i++ ) {
                   2435:                t= attr.sequence[i].type;
                   2436: #ifdef DEBUG
                   2437:                fprintf(msgs, "%d ",t);
                   2438: #endif DEBUG
                   2439:                if ( t == FILING_createdOn ) {
                   2440: #ifdef DEBUG
                   2441:                        fprintf(msgs,"createdOn  ");
                   2442: #endif DEBUG
                   2443:                        if ( got_createdon ) {
                   2444:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2445:                                /* NOT REACHED */
                   2446:                        }
                   2447:                        got_createdon++;
                   2448: 
                   2449:                        handle->createdon= AttrToLongCardinal(&attr.sequence[i]);
                   2450:                        continue;
                   2451:                }
                   2452: 
                   2453:                if ( t == FILING_dataSize ) {
                   2454: #ifdef DEBUG
                   2455:                        fprintf(msgs,"dataSize  ");
                   2456: #endif DEBUG
                   2457:                        if ( got_datasize ) {
                   2458:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2459:                                /* NOT REACHED */
                   2460:                        }
                   2461:                        got_datasize++;
                   2462: 
                   2463:                        handle->datasize= AttrToLongCardinal(&attr.sequence[i]);
                   2464:                        continue;
                   2465:                }
                   2466: 
                   2467:                if ( t == FILING_isDirectory ) {
                   2468: #ifdef DEBUG
                   2469:                        fprintf(msgs,"isDirectory  ");
                   2470: #endif DEBUG
                   2471:                        if ( got_isdirectory ) {
                   2472:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2473:                                /* NOT REACHED */
                   2474:                        }
                   2475: 
                   2476:                        got_isdirectory++;
                   2477: 
                   2478:                        handle->isdirectory= AttrToBoolean(&attr.sequence[i]);
                   2479:                        continue;
                   2480:                }
                   2481: 
                   2482:                if ( t == FILING_pathname ) {
                   2483: #ifdef DEBUG
                   2484:                        fprintf(msgs,"pathname  ");
                   2485: #endif DEBUG
                   2486:                        if ( got_pathname ) {
                   2487:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2488:                                /* NOT REACHED */
                   2489:                        }
                   2490:                        got_pathname++;
                   2491: 
                   2492:                        pathname= AttrToString(&attr.sequence[i]);
                   2493:                        if ( check_pathname(pathname) != -1 ) {
                   2494:                                /* NOT REACHED */
                   2495:                        }
                   2496:                        continue;
                   2497:                }                       
                   2498:                if ( t == FILING_type ) {
                   2499: #ifdef DEBUG
                   2500:                        fprintf(msgs,"type  ");
                   2501: #endif DEBUG
                   2502:                        if ( got_type ) {
                   2503:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2504:                                /* NOT REACHED */
                   2505:                        }
                   2506:                        got_type++;
                   2507: 
                   2508:                        handle->type= AttrToLongCardinal(&attr.sequence[i]);
                   2509: #ifndef EXTENSIONS
                   2510:                        if ( (handle->type != FILING_tText) &&
                   2511:                                        (handle->type != FILING_tUnspecified) &&
                   2512:                                        (handle->type != FILING_tDirectory) ) {
                   2513:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2514:                                /* NOT REACHED */
                   2515:                        }
                   2516: #endif EXTENSIONS
                   2517:                        continue;
                   2518:                }
                   2519:                if ( t == FILING_version ) {
                   2520: #ifdef DEBUG
                   2521:                        fprintf(msgs,"version  ");
                   2522: #endif DEBUG
                   2523:                        if ( got_version ) {
                   2524:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2525:                                /* NOT REACHED */
                   2526:                        }
                   2527:                        got_version++;
                   2528: 
                   2529:                        version= AttrToCardinal(&attr.sequence[i]);
                   2530:                        if ( version != FILING_highestVersion ) {
                   2531:                                        ReturnAttributeValueError(FILING_unimplemented, t);
                   2532:                                        /* NOT REACHED */
                   2533: 
                   2534:                        }
                   2535:                        continue;
                   2536:                }
                   2537: 
                   2538: #ifdef FILETOOLCOMPATIBILITY
                   2539:                if ( t == FILING_name ) {
                   2540: #ifdef DEBUG
                   2541:                        fprintf(msgs, "name  ");
                   2542: #endif DEBUG
                   2543:                        if ( got_name ) {
                   2544:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2545:                                /* NOT REACHED */
                   2546:                        }
                   2547:                        got_name++;
                   2548: 
                   2549:                        name= AttrToString(&attr.sequence[i]);
                   2550:                        continue;
                   2551:                }
                   2552: 
                   2553:                if ( t == 4938 ) {
                   2554:                        if ( got_4938 ) {
                   2555:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2556:                                /* NOT REACHED */
                   2557:                        }
                   2558: 
                   2559:                        got_4938++;
                   2560:                        continue;
                   2561:                }
                   2562: #endif FILETOOLCOMPATIBILITY
                   2563: 
                   2564: #ifdef SOMEDAY
                   2565:                if ( t == FILING_accessList ) {
                   2566:                        if ( got_accesslist ) {
                   2567:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2568:                                /* NOT REACHED */
                   2569:                        }
                   2570: 
                   2571:                        got_accesslist++;
                   2572: 
                   2573:                        if ( FALSE ) {
                   2574:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2575:                                /* NOT REACHED */
                   2576:                        }
                   2577: 
                   2578:                        continue;
                   2579:                }
                   2580: #endif SOMEDAY
                   2581: 
                   2582:                if ( t == FILING_childrenUniquelyNamed ) {
                   2583:                        if ( got_childrenuniquelynamed ) {
                   2584:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2585:                                /* NOT REACHED */
                   2586:                        }
                   2587: 
                   2588:                        got_childrenuniquelynamed++;
                   2589: 
                   2590:                        childrenuniquelynamed= AttrToBoolean(&attr.sequence[i]);
                   2591:                        if ( childrenuniquelynamed != TRUE ) {
                   2592:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2593:                                /* NOT REACHED */
                   2594:                        }
                   2595: 
                   2596:                        continue;
                   2597:                }
                   2598: 
                   2599: 
                   2600: #ifdef SOMEDAY
                   2601:                if ( t == FILING_defaultAccessList ) {
                   2602:                        if ( got_defaultaccesslist ) {
                   2603:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2604:                                /* NOT REACHED */
                   2605:                        }
                   2606: 
                   2607:                        got_defaultaccesslist++;
                   2608: 
                   2609:                        if ( FALSE ) {
                   2610:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2611:                                /* NOT REACHED */
                   2612:                        }
                   2613: 
                   2614:                        continue;
                   2615:                }
                   2616: #endif SOMEDAY
                   2617: 
                   2618:                if ( t == FILING_isTemporary ) {
                   2619:                        if ( got_istemporary ) {
                   2620:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2621:                                /* NOT REACHED */
                   2622:                        }
                   2623: 
                   2624:                        got_istemporary++;
                   2625: 
                   2626:                        istemporary= AttrToBoolean(&attr.sequence[i]);
                   2627:                        if ( istemporary != FALSE ) {
                   2628:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2629:                                /* NOT REACHED */
                   2630:                        }
                   2631: 
                   2632:                        continue;
                   2633:                }
                   2634: 
                   2635:                if ( t == FILING_ordering ) {
                   2636:                        if ( got_ordering ) {
                   2637:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2638:                                /* NOT REACHED */
                   2639:                        }
                   2640: 
                   2641:                        got_ordering++;
                   2642: 
                   2643:                        if ( FALSE ) {
                   2644:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2645:                                /* NOT REACHED */
                   2646:                        }
                   2647: 
                   2648:                        continue;
                   2649:                }
                   2650: 
                   2651:                if ( t == FILING_subtreeSizeLimit ) {
                   2652:                        if ( got_subtreesizelimit ) {
                   2653:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2654:                                /* NOT REACHED */
                   2655:                        }
                   2656: 
                   2657:                        got_subtreesizelimit++;
                   2658: 
                   2659:                        subtreesizelimit= AttrToCardinal(&attr.sequence[i]);
                   2660:                        if ( subtreesizelimit != FILING_nullSubtreeSizeLimit ) {
                   2661:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   2662:                                /* NOT REACHED */
                   2663:                        }
                   2664: 
                   2665:                        continue;
                   2666:                }
                   2667: 
                   2668:                if ( (t == FILING_fileID) || (t == FILING_modifiedBy) ||
                   2669:                                (t == FILING_modifiedOn) || (t == FILING_name) ||
                   2670:                                (t == FILING_numberOfChildren) || (t == FILING_parentID) ||
                   2671:                                (t == FILING_readBy) || (t == FILING_readOn) ||
                   2672:                                (t == FILING_storedSize) || (t == FILING_subtreeSize) ) {
                   2673:                        ReturnAttributeTypeError(FILING_disallowed, t);
                   2674:                }
                   2675: 
                   2676: #ifndef EXTENSIONS
                   2677:                if ( ( t < 0 ) || (t > FILING_subtreeSizeLimit) ) {
                   2678:                        ReturnAttributeTypeError(FILING_illegal, t);
                   2679:                        /* NOT REACHED */
                   2680:                }
                   2681: 
                   2682:                if ( (t == FILING_checksum) || (t == FILING_createdBy) ||
                   2683:                                                (t == FILING_position) )
                   2684:                        ReturnAttributeTypeError(FILING_unimplemented, t);
                   2685:                else
                   2686:                        ReturnAttributeTypeError(FILING_disallowed, t);
                   2687: 
                   2688: #else EXTENSIONS
                   2689:                if ( t < 0 ) {
                   2690:                        ReturnAttributeTypeError(FILING_illegal, t);
                   2691:                        /* NOT REACHED */
                   2692:                }
                   2693:                if ( handle->type != TYPE_VP ) {
                   2694:                        if ( (t == FILING_checksum) || (t == FILING_createdBy) ||
                   2695:                                                (t == FILING_position) )
                   2696:                                ReturnAttributeTypeError(FILING_unimplemented, t);
                   2697:                        else
                   2698:                                ReturnAttributeTypeError(FILING_disallowed, t);
                   2699:                }
                   2700: #endif EXTENSIONS
                   2701:        }
                   2702: 
                   2703: #ifdef DEBUG
                   2704:        fprintf(msgs, "\n");
                   2705: #endif DEBUG
                   2706: 
                   2707: #ifdef FILETOOLCOMPATIBILITY
                   2708:        if ( !got_pathname && !got_name) {
                   2709:                handle->pathname= SERVICE_ROOT;
                   2710:        } else  if ( !got_pathname )  {
                   2711:                strcat(handle->pathname,name);
                   2712:        } else {
                   2713:                if ( *pathname == '/' )
                   2714:                        strcat(handle->pathname, pathname+1);
                   2715:                else
                   2716:                        strcat(handle->pathname,pathname);
                   2717:                Deallocate(&pathname);
                   2718:        }
                   2719: 
                   2720: #else FILETOOLCOMPATIBILITY
                   2721:        if ( !got_pathname ) {
                   2722:                ReturnAttributeTypeError(FILING_missing, t);
                   2723:                /* NOT REACHED */
                   2724:        } else {
                   2725:                if ( *pathname == '/' )
                   2726:                        strcat(handle->pathname, pathname+1);
                   2727:                else
                   2728:                        strcat(handle->pathname, pathname);
                   2729:                Deallocate(&pathname);
                   2730:        }
                   2731: #endif FILETOOLCOMPATIBILITY
                   2732: 
                   2733:        if ( !got_type )
                   2734:                handle->type= FILING_tUnspecified;
                   2735: 
                   2736:        if ( !got_createdon )
                   2737:                handle->createdon= 0;
                   2738: 
                   2739:        if ( !got_isdirectory ) {
                   2740:                if ( handle->type == FILING_tDirectory )
                   2741:                        handle->isdirectory= TRUE;
                   2742:                else
                   2743:                        handle->isdirectory= FALSE;
                   2744:        } else {
                   2745:                if ( ((handle->isdirectory == TRUE) && (handle->type != FILING_tDirectory)) ||
                   2746:                                ((handle->isdirectory == FALSE) && (handle->type == FILING_tDirectory)) ) {
                   2747:                        ReturnAttributeTypeError(FILING_unreasonable, FILING_isDirectory);
                   2748:                        /* NOT REACHED */
                   2749:                }
                   2750:        }
                   2751: 
                   2752:        return(-1);
                   2753: }
                   2754: 
                   2755: 
                   2756: void FILING_Retrieve(ServerConnection, BDTProc, file, content, session)
                   2757: CourierConnection *ServerConnection;
                   2758: int ( *BDTProc)();
                   2759: FILING_Handle file;
                   2760: BulkData1_Descriptor content;
                   2761: FILING_Session session;
                   2762: {
                   2763:        file_handle *handle;
                   2764: 
                   2765: #ifdef DEBUG
                   2766:        if (msgs == 0) {
                   2767:                char logfile[50];
                   2768:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   2769:                msgs= fopen(logfile,"w");
                   2770:        }
                   2771:        fprintf(msgs, "Retrieve\n");
                   2772: #endif DEBUG
                   2773: 
                   2774:        BDTabort_expected= TRUE;
                   2775: 
                   2776:        if ( verify_session(session) != -1 ) {
                   2777:                /* NOT REACHED */
                   2778:        }
                   2779: 
                   2780:        if ( is_nullHandle(file) == -1 ) {
                   2781:                ReturnHandleError(FILING_nullDisallowed);
                   2782:                /* NOT REACHED */
                   2783:        }
                   2784: 
                   2785:        copyhandle(&handle,file);
                   2786: 
                   2787:        if ( handle->state != FILE_OPEN ) {
                   2788:                ReturnHandleError(FILING_invalid);
                   2789:                /* NOT REACHED */
                   2790:        }
                   2791: 
                   2792:        if ( access_file(handle) != -1 ) {
                   2793:                /* NOT REACHED */
                   2794:        }
                   2795: 
                   2796:        if ( content.designator == BulkData1_null ) {
                   2797:                return;
                   2798:        } else  if ( content.designator != BulkData1_immediate ) {
                   2799:                ReturnTransferError(FILING_aborted);
                   2800:                /* NOT REACHED */
                   2801:        }
                   2802: 
                   2803:        if ( open_file(handle) != -1 ) {
                   2804:                /* NOT REACHED */
                   2805:        }
                   2806: 
                   2807: #ifdef DEBUG
                   2808:        fprintf(msgs, "retrieving '%s'\n", handle->pathname);
                   2809: #endif DEBUG
                   2810: 
                   2811:        if ( retrieveproc(ServerConnection,handle) != -1 ) {
                   2812:                close_file(handle);
                   2813:                ReturnTransferError(FILING_aborted);
                   2814:                /* NOT REACHED */
                   2815:        }
                   2816: 
                   2817:        close_file(handle);
                   2818:        handle->file_desc= NULL;
                   2819:        reset_continuance_timer();
                   2820: 
                   2821:        return;
                   2822: }
                   2823: 
                   2824: 
                   2825: void FILING_Replace(ServerConnection, BDTProc, file, attributes, content, session)
                   2826: CourierConnection *ServerConnection;
                   2827: int ( *BDTProc)();
                   2828: FILING_Handle file;
                   2829: FILING_AttributeSequence attributes;
                   2830: BulkData1_Descriptor content;
                   2831: FILING_Session session;
                   2832: {
                   2833: #ifdef EXTENSIONS
                   2834:        file_handle *handle;
                   2835: 
                   2836: #ifdef DEBUG
                   2837:        if (msgs == 0) {
                   2838:                char logfile[50];
                   2839:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   2840:                msgs= fopen(logfile,"w");
                   2841:        }
                   2842:        fprintf(msgs, "Replace\n");
                   2843: #endif DEBUG
                   2844: 
                   2845:        BDTabort_expected= TRUE;
                   2846: 
                   2847:        if ( verify_session(session) != -1 ) {
                   2848:                /* NOT REACHED */
                   2849:        }
                   2850: 
                   2851:        if ( is_nullHandle(file) == -1 ) {
                   2852:                ReturnHandleError(FILING_nullDisallowed);
                   2853:                /* NOT REACHED */
                   2854:        }
                   2855: 
                   2856:        copyhandle(&handle,file);
                   2857: 
                   2858:        if ( handle->state != FILE_OPEN ) {
                   2859:                ReturnHandleError(FILING_invalid);
                   2860:                /* NOT REACHED */
                   2861:        }
                   2862: 
                   2863:        if ( access_file(handle) != -1 ) {
                   2864:                /* NOT REACHED */
                   2865:        }
                   2866: 
                   2867:        if ( content.designator == BulkData1_null ) {
                   2868:                return;
                   2869:        } else  if ( content.designator != BulkData1_immediate ) {
                   2870:                ReturnTransferError(FILING_aborted);
                   2871:                /* NOT REACHED */
                   2872:        }
                   2873: 
                   2874:        if ( verify_replace_attributes(attributes, handle) != -1 ) {
                   2875:                /* NOT REACHED */
                   2876:        }
                   2877: 
                   2878: #ifdef DEBUG
                   2879:        fprintf(msgs, "replacing '%s'\n", handle->pathname);
                   2880: #endif DEBUG
                   2881: 
                   2882:        if ( make_backup(handle) != -1 ) {
                   2883:                /* NOT REACHED */
                   2884:        }
                   2885: 
                   2886:        if ( open_file(handle) != -1 ) {
                   2887:                /* NOT REACHED */
                   2888:        }
                   2889: 
                   2890:        if ( storeproc(ServerConnection,handle) != -1 ) {
                   2891:                close_file(handle);
                   2892:                recall_backup(handle);
                   2893:                ReturnTransferError(FILING_aborted);
                   2894:                /* NOT REACHED */
                   2895:        }
                   2896: 
                   2897:        close_file(handle);
                   2898:        unlink_backup(handle);
                   2899: 
                   2900:        handle->file_desc= NULL;
                   2901:        reset_continuance_timer();
                   2902: 
                   2903:        return;
                   2904: 
                   2905: #else EXTENSIONS
                   2906:        NoSuchProcedureValue("Filing", 14);
                   2907: #endif EXTENSIONS
                   2908: }
                   2909: 
                   2910: #ifdef EXTENSIONS
                   2911: verify_replace_attributes(attr, handle)
                   2912: FILING_AttributeSequence attr;
                   2913: file_handle *handle;
                   2914: {
                   2915:        int i;
                   2916:        FILING_AttributeType t;
                   2917:        LongCardinal datasize;
                   2918:        int got_createdon, got_datasize;
                   2919:        LongCardinal AttrToLongCardinal();
                   2920: 
                   2921: #ifdef DEBUG
                   2922:        fprintf(msgs,"%d replace attributes     ",attr.length);
                   2923: #endif DEBUG
                   2924: 
                   2925:        if ( attr.length < 0 ) {
                   2926:                ReturnAttributeTypeError(FILING_illegal, 0);
                   2927:                /* NOT REACHED */
                   2928:        }
                   2929: 
                   2930:        got_createdon= 0;
                   2931: 
                   2932:        for ( i= 0 ; i < attr.length ; i++ ) {
                   2933:                t= attr.sequence[i].type;
                   2934: #ifdef DEBUG
                   2935:                fprintf(msgs, "%d ",t);
                   2936: #endif DEBUG
                   2937:                if ( t == FILING_createdOn ) {
                   2938: #ifdef DEBUG
                   2939:                        fprintf(msgs,"createdOn  ");
                   2940: #endif DEBUG
                   2941:                        if ( got_createdon ) {
                   2942:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2943:                                /* NOT REACHED */
                   2944:                        }
                   2945:                        got_createdon++;
                   2946: 
                   2947:                        handle->createdon= AttrToLongCardinal(&attr.sequence[i]);
                   2948:                        continue;
                   2949:                }
                   2950: 
                   2951:                if ( t == FILING_dataSize ) {
                   2952: #ifdef DEBUG
                   2953:                        fprintf(msgs,"dataSize  ");
                   2954: #endif DEBUG
                   2955:                        if ( got_datasize ) {
                   2956:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   2957:                                /* NOT REACHED */
                   2958:                        }
                   2959:                        got_datasize++;
                   2960: 
                   2961:                        datasize= AttrToLongCardinal(&attr.sequence[i]);
                   2962:                        continue;
                   2963:                }
                   2964: 
                   2965:                if ( t < 0 ) {
                   2966:                        ReturnAttributeTypeError(FILING_illegal, t);
                   2967:                        /* NOT REACHED */
                   2968:                }
                   2969: 
                   2970:                if ( (t == FILING_checksum) || (t == FILING_createdBy) ||
                   2971:                                                (t == FILING_position) )
                   2972:                        ReturnAttributeTypeError(FILING_unimplemented, t);
                   2973:                else
                   2974:                        ReturnAttributeTypeError(FILING_disallowed, t);
                   2975: 
                   2976:        }
                   2977: 
                   2978: #ifdef DEBUG
                   2979:        fprintf(msgs, "\n");
                   2980: #endif DEBUG
                   2981: 
                   2982:        return(-1);
                   2983: }
                   2984: #endif EXTENSIONS
                   2985: 
                   2986: 
                   2987: void FILING_Serialize(ServerConnection, BDTProc, file, serializedFile, session)
                   2988: CourierConnection *ServerConnection;
                   2989: int ( *BDTProc)();
                   2990: FILING_Handle file;
                   2991: BulkData1_Descriptor serializedFile;
                   2992: FILING_Session session;
                   2993: {
                   2994: #ifdef EXTENSIONS
                   2995:        file_handle *handle;
                   2996:        LongCardinal type;
                   2997: 
                   2998: #ifdef DEBUG
                   2999:        if (msgs == 0) {
                   3000:                char logfile[50];
                   3001:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   3002:                msgs= fopen(logfile,"w");
                   3003:        }
                   3004:        fprintf(msgs, "Serialize\n");
                   3005: #endif DEBUG
                   3006: 
                   3007:        BDTabort_expected= TRUE;
                   3008: 
                   3009:        if ( verify_session(session) != -1 ) {
                   3010:                /* NOT REACHED */
                   3011:        }
                   3012: 
                   3013:        if ( is_nullHandle(file) == -1 ) {
                   3014:                ReturnHandleError(FILING_nullDisallowed);
                   3015:                /* NOT REACHED */
                   3016:        }
                   3017: 
                   3018:        copyhandle(&handle,file);
                   3019: 
                   3020:        if ( handle->state != FILE_OPEN ) {
                   3021:                ReturnHandleError(FILING_invalid);
                   3022:                /* NOT REACHED */
                   3023:        }
                   3024: 
                   3025:        if ( access_file(handle) != -1 ) {
                   3026:                /* NOT REACHED */
                   3027:        }
                   3028: 
                   3029:        if ( serializedFile.designator == BulkData1_null ) {
                   3030:                return;
                   3031:        } else  if ( serializedFile.designator != BulkData1_immediate ) {
                   3032:                ReturnTransferError(FILING_aborted);
                   3033:                /* NOT REACHED */
                   3034:        }
                   3035: 
                   3036:        /*
                   3037:         * for now, can only serialize files which are already in 'serialized'
                   3038:         * form. This can be assumed if the file is of a Viewpoint file type
                   3039:         * and the stored isDirectory attribute is TRUE.
                   3040:         * NOTE: like all other cases, this is no guarantee...
                   3041:        */
                   3042: 
                   3043:        type= get_type(handle->pathname);
                   3044: 
                   3045:        if ( (type < LAST_FILING_TYPE) || (type == TYPE_Interpress) || (type == TYPE_VPCanvas) ) {
                   3046:                ReturnAccessError(FILING_fileChanged);
                   3047:                /* NOT REACHED */
                   3048:        }
                   3049: 
                   3050:        if ( open_file(handle) != -1 ) {
                   3051:                /* NOT REACHED */
                   3052:        }
                   3053: 
                   3054:        if ( GetDirectoryAttribute(handle->file_desc) != TRUE ) {
                   3055:                close_file(handle);
                   3056:                ReturnAccessError(FILING_fileChanged);
                   3057:                /* NOT REACHED */
                   3058:        }
                   3059: 
                   3060: #ifdef DEBUG
                   3061:        fprintf(msgs, "serializing '%s'\n", handle->pathname);
                   3062: #endif DEBUG
                   3063: 
                   3064:        if ( retrieveproc(ServerConnection,handle) != -1 ) {
                   3065:                close_file(handle);
                   3066:                ReturnTransferError(FILING_aborted);
                   3067:                /* NOT REACHED */
                   3068:        }
                   3069: 
                   3070:        close_file(handle);
                   3071:        handle->file_desc= NULL;
                   3072:        reset_continuance_timer();
                   3073: #else EXTENSIONS
                   3074:        NoSuchProcedureValue("Filing", 15);
                   3075: #endif EXTENSIONS
                   3076: }
                   3077: 
                   3078: 
                   3079: FILING_DeserializeResults FILING_Deserialize(ServerConnection, BDTProc,
                   3080:                 directory, attributes, controls, serializedFile, session)
                   3081: CourierConnection *ServerConnection;
                   3082: int ( *BDTProc)();
                   3083: FILING_Handle directory;
                   3084: FILING_AttributeSequence attributes;
                   3085: FILING_ControlSequence controls;
                   3086: BulkData1_Descriptor serializedFile;
                   3087: FILING_Session session;
                   3088: {
                   3089: #ifdef EXTENSIONS
                   3090:        FILING_DeserializeResults results;
                   3091:        file_handle *handle, *dir_handle;
                   3092: 
                   3093: #ifdef DEBUG
                   3094:        if (msgs == 0) {
                   3095:                char logfile[50];
                   3096:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   3097:                msgs= fopen(logfile,"w");
                   3098:        }
                   3099:        fprintf(msgs, "Deserialize  ");
                   3100: #endif DEBUG
                   3101: 
                   3102:        BDTabort_expected= TRUE;
                   3103: 
                   3104:        if ( verify_session(session) != -1 ) {
                   3105:                /* NOT REACHED */
                   3106:        }
                   3107: 
                   3108: #ifndef FILETOOLCOMPATIBILITY
                   3109:        if ( is_nullControls(controls) != -1) {
                   3110:                ReturnControlTypeError(FILING_disallowed, 0);
                   3111:                /* NOT REACHED */
                   3112:        }
                   3113: 
                   3114:        if ( is_nullHandle(directory) != -1 ) {
                   3115:                ReturnHandleError(FILING_invalid);
                   3116:                /* NOT REACHED */
                   3117:        }
                   3118: #endif FILETOOLCOMPATIBILITY
                   3119: 
                   3120:        if ( serializedFile.designator == BulkData1_null ) {
                   3121:                return;
                   3122:        } else  if ( serializedFile.designator != BulkData1_immediate ) {
                   3123:                ReturnTransferError(FILING_aborted);
                   3124:                /* NOT REACHED */
                   3125:        }
                   3126: 
                   3127:        if ( (handle= (file_handle *)malloc(sizeof(file_handle))) == NULL ) {
                   3128:                ReturnUndefinedError(0);
                   3129:                /* NOT REACHED */
                   3130:        }
                   3131: 
                   3132:        if ( (handle->pathname= (char *)malloc(MAX_FILE_NAME_LENGTH)) == NULL ) {
                   3133:                ReturnUndefinedError(0);
                   3134:                /* NOT REACHED */
                   3135:        }
                   3136: 
                   3137: #ifdef DEBUG
                   3138:        fprintf(msgs, "deserialize handle= %x\n",handle);
                   3139: #endif DEBUG
                   3140: 
                   3141: #ifdef FILETOOLCOMPATIBILITY
                   3142:        copyhandle(&dir_handle,directory);
                   3143: 
                   3144:        if ( dir_handle == 0 ) {
                   3145:                dir_handle= &RootHandle;
                   3146:                strcpy(handle->pathname, SERVICE_ROOT);
                   3147:        } else {
                   3148:                if ( dir_handle->state != FILE_OPEN ) {
                   3149:                        ReturnHandleError(FILING_invalid);
                   3150:                        /* NOT REACHED */
                   3151:                }
                   3152: 
                   3153:                if ( access_file(dir_handle) != -1 ) {
                   3154:                        /* NOT REACHED */
                   3155:                }
                   3156: 
                   3157:                if ( dir_handle->isdirectory != TRUE ) {
                   3158:                        ReturnHandleError(FILING_directoryRequired);
                   3159:                        /* NOT REACHED */
                   3160:                }
                   3161: 
                   3162:                strcpy(handle->pathname,dir_handle->pathname);
                   3163:                if ( strcmp(handle->pathname, "/") != 0 )
                   3164:                        strcat(handle->pathname,"/");
                   3165:        } 
                   3166: #else FILETOOLCOMPATIBILITY
                   3167:        strcpy(handle->pathname, SERVICE_ROOT);
                   3168: #endif FILETOOLCOMPATIBILITY
                   3169: 
                   3170:        if ( verify_deserialize_attributes(attributes, handle) != -1 ) {
                   3171:                /* NOT REACHED */
                   3172:        }
                   3173: 
                   3174: #ifdef DEBUG
                   3175:        fprintf(msgs, "creating '%s'\n", handle->pathname);
                   3176: #endif DEBUG
                   3177: 
                   3178:        if ( create_file(handle) != -1 ) {
                   3179:                /* NOT REACHED */
                   3180:        }
                   3181: 
                   3182:        if ( storeproc(ServerConnection,handle) != -1 ) {
                   3183:                close_file(handle);
                   3184:                delete_partial_file(handle);
                   3185:                ReturnTransferError(FILING_aborted);
                   3186:                /* NOT REACHED */
                   3187:        }
                   3188: 
                   3189:        close_file(handle);
                   3190: 
                   3191:        handle->state= FILE_OPEN;
                   3192:        handle->file_desc= NULL;
                   3193: 
                   3194:        copyhandle(results.file, &handle);
                   3195:        reset_continuance_timer();
                   3196: 
                   3197:        return(results);
                   3198: #else EXTENSIONS
                   3199:        NoSuchProcedureValue("Filing", 16);
                   3200: #endif EXTENSIONS
                   3201: }
                   3202: 
                   3203: #ifdef EXTENSIONS
                   3204: verify_deserialize_attributes(attr, handle)
                   3205: FILING_AttributeSequence attr;
                   3206: file_handle *handle;
                   3207: {
                   3208:        int i;
                   3209:        FILING_AttributeType t;
                   3210:        int got_accesslist, got_defaultaccesslist, got_istemporary;
                   3211:        int got_name, got_pathname, got_subtreesizelimit, got_version;
                   3212:        FILING_Version version;
                   3213:        Boolean istemporary;
                   3214:        char *pathname;
                   3215:        char *name;
                   3216:        char *AttrToString();
                   3217: 
                   3218: #ifdef DEBUG
                   3219:        fprintf(msgs, "%d deserialize attributes     ", attr.length);
                   3220: #endif DEBUG
                   3221: 
                   3222:        if ( attr.length <= 0 ) {
                   3223:                ReturnAttributeTypeError(FILING_illegal, 0);
                   3224:                /* NOT REACHED */
                   3225:        }
                   3226: 
                   3227:        got_accesslist= got_defaultaccesslist= got_istemporary= 0;
                   3228:        got_name= got_pathname= got_subtreesizelimit= got_version= 0;
                   3229: 
                   3230:        for ( i= 0; i < attr.length ; i++ ) {
                   3231:                t= attr.sequence[i].type;
                   3232: 
                   3233:                if ( t == FILING_accessList ) {
                   3234: #ifdef DEBUG
                   3235:                        fprintf(msgs, "accessList  ");
                   3236: #endif DEBUG
                   3237:                        if ( got_accesslist ) {
                   3238:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   3239:                                /* NOT REACHED */
                   3240:                        }
                   3241:                        got_accesslist++;
                   3242: 
                   3243:                        continue;
                   3244:                }
                   3245: 
                   3246: #ifdef SOMEDAY
                   3247:                if ( t == FILING_defaultAccessList ) {
                   3248: #ifdef DEBUG
                   3249:                        fprintf(msgs, "defaultAccessList  ");
                   3250: #endif DEBUG
                   3251:                        if ( got_defaultaccesslist ) {
                   3252:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   3253:                                /* NOT REACHED */
                   3254:                        }
                   3255:                        got_defaultaccesslist++;
                   3256: 
                   3257:                        continue;
                   3258:                }
                   3259: #endif SOMEDAY
                   3260: 
                   3261:                if ( t == FILING_isTemporary ) {
                   3262: #ifdef DEBUG
                   3263:                        fprintf(msgs, "isTemporary  ");
                   3264: #endif DEBUG
                   3265:                        if ( got_istemporary ) {
                   3266:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   3267:                                /* NOT REACHED */
                   3268:                        }
                   3269:                        got_istemporary++;
                   3270: 
                   3271:                        istemporary= AttrToBoolean(&attr.sequence[i]);
                   3272:                        if ( istemporary != FALSE ) {
                   3273:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   3274:                                /*  NOT REACHED */
                   3275:                        }
                   3276:                        continue;
                   3277:                }
                   3278: 
                   3279:                if ( t == FILING_name ) {
                   3280: #ifdef DEBUG
                   3281:                        fprintf(msgs, "name  ");
                   3282: #endif DEBUG
                   3283:                        if ( got_name ) {
                   3284:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   3285:                                /* NOT REACHED */
                   3286:                        }
                   3287:                        got_name++;
                   3288: 
                   3289:                        name= AttrToString(&attr.sequence[i]);
                   3290:                        continue;
                   3291:                }
                   3292: 
                   3293:                if ( t == FILING_pathname ) {
                   3294: #ifdef DEBUG
                   3295:                        fprintf(msgs, "pathname  ");
                   3296: #endif DEBUG
                   3297:                        if ( got_pathname ) {
                   3298:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   3299:                                /* NOT REACHED */
                   3300:                        }
                   3301:                        got_pathname++;
                   3302: 
                   3303:                        pathname= AttrToString(&attr.sequence[i]);
                   3304:                        if ( check_pathname(pathname) != 1 ) {
                   3305:                                /* NOT REACHED */
                   3306:                        }
                   3307:                        continue;
                   3308:                }
                   3309: 
                   3310:                if ( t == FILING_subtreeSizeLimit ) {
                   3311: #ifdef DEBUG
                   3312:                        fprintf(msgs, "subtreeSizeLimit  ");
                   3313: #endif DEBUG
                   3314:                        if ( got_subtreesizelimit ) {
                   3315:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   3316:                                /* NOT REACHED */
                   3317:                        }
                   3318:                        got_subtreesizelimit++;
                   3319: 
                   3320:                        continue;
                   3321:                }
                   3322: 
                   3323:                if ( t == FILING_version ) {
                   3324: #ifdef DEBUG
                   3325:                        fprintf(msgs, "version  ");
                   3326: #endif DEBUG
                   3327:                        if ( got_version ) {
                   3328:                                ReturnAttributeTypeError(FILING_duplicated, t);
                   3329:                                /* NOT REACHED */
                   3330:                        }
                   3331:                        got_version++;
                   3332: 
                   3333:                        version= AttrToCardinal(&attr.sequence[i]);
                   3334:                        if ( version != FILING_highestVersion ) {
                   3335:                                ReturnAttributeValueError(FILING_unimplemented, t);
                   3336:                                /* NOT REACHED */
                   3337:                        }
                   3338:                        continue;
                   3339:                }
                   3340:        }
                   3341: 
                   3342: #ifdef DEBUG
                   3343:        fprintf(msgs, "\n");
                   3344: #endif DEBUG
                   3345: 
                   3346:        if ( !got_pathname && !got_name ) {
                   3347:                handle->pathname= SERVICE_ROOT;
                   3348:        } else if ( !got_pathname ) {
                   3349:                strcat(handle->pathname, name);
                   3350:                Deallocate(&name);
                   3351:        } else {
                   3352:                if ( *pathname == '/' )
                   3353:                        strcat(handle->pathname, pathname+1);
                   3354:                else
                   3355:                        strcat(handle->pathname, pathname);
                   3356:                Deallocate(&pathname);
                   3357:        }
                   3358: 
                   3359:        handle->type= FILING_tSerialized;
                   3360:        handle->createdon= 0;
                   3361: 
                   3362:        return(-1);
                   3363: }
                   3364: #endif EXTENSIONS
                   3365: 
                   3366: FILING_FindResults FILING_Find(ServerConnection, BDTProc, directory, types, scope, controls, session)
                   3367: CourierConnection *ServerConnection;
                   3368: int ( *BDTProc)();
                   3369: FILING_Handle directory;
                   3370: FILING_AttributeTypeSequence types;
                   3371: FILING_ScopeSequence scope;
                   3372: FILING_ControlSequence controls;
                   3373: FILING_Session session;
                   3374: {
                   3375:        NoSuchProcedureValue("Filing", 17);
                   3376: }
                   3377: 
                   3378: 
                   3379: void FILING_List(ServerConnection, BDTProc, directory, types, scope, listing, session)
                   3380: CourierConnection *ServerConnection;
                   3381: int ( *BDTProc)();
                   3382: FILING_Handle directory;
                   3383: FILING_AttributeTypeSequence types;
                   3384: FILING_ScopeSequence scope;
                   3385: BulkData1_Descriptor listing;
                   3386: FILING_Session session;
                   3387: {
                   3388:        char *match_name;
                   3389:        Cardinal count;
                   3390:        file_handle *dir_handle;
                   3391: 
                   3392:        BDTabort_expected= TRUE;
                   3393: 
                   3394: #ifdef DEBUG
                   3395:        if (msgs == 0) {
                   3396:                char logfile[50];
                   3397:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   3398:                msgs= fopen(logfile,"w");
                   3399:        }
                   3400:        fprintf(msgs, "List\n");
                   3401: #endif DEBUG
                   3402: 
                   3403:        if ( verify_session(session) != -1 ) {
                   3404:                /* NOT REACHED */
                   3405:        }
                   3406: 
                   3407: #ifndef FILETOOLCOMPATIBILITY
                   3408:        if ( is_nullHandle(directory) != -1 ) {
                   3409:                ReturnHandleError(FILING_invalid);
                   3410:                /* NOT REACHED */
                   3411:        }
                   3412: #endif FILETOOLCOMPATIBILITY
                   3413: 
                   3414:        if ( listing.designator == BulkData1_null )
                   3415:                return;
                   3416:        else if ( listing.designator != BulkData1_immediate ) {
                   3417:                ReturnTransferError(FILING_aborted);
                   3418:                /* NOT REACHED */
                   3419:        }
                   3420: 
                   3421:        copyhandle(&dir_handle, directory);
                   3422: 
                   3423: #ifdef FILETOOLCOMPATIBILITY
                   3424:        if ( dir_handle == 0 ) {
                   3425:                dir_handle= &RootHandle;
                   3426:        } else {
                   3427:                if ( dir_handle->state != FILE_OPEN ) {
                   3428:                        ReturnHandleError(FILING_invalid);
                   3429:                        /* NOT REACHED */
                   3430:                }
                   3431: 
                   3432:                if ( dir_handle->isdirectory != TRUE ) {
                   3433:                        ReturnHandleError(FILING_directoryRequired);
                   3434:                        /* NOT REACHED */
                   3435:                }
                   3436: 
                   3437:                if ( access_file(dir_handle) != -1 ) {
                   3438:                        /* NOT REACHED */
                   3439:                }
                   3440: 
                   3441:        }
                   3442: #else FILETOOLCOMPATIBILITY
                   3443:        dir_handle= &RootHandle;
                   3444: #endif FILETOOLCOMPATIBILITY
                   3445: 
                   3446:        if ( get_scopes(scope, &count, &match_name) != -1 ) {
                   3447:                /* NOT REACHED */
                   3448:        }
                   3449: 
                   3450:        if ( list_directory(ServerConnection, dir_handle, types, match_name, count) != -1 ) {
                   3451:                /* NOT REACHED */
                   3452:        }
                   3453: 
                   3454:        reset_continuance_timer();
                   3455: 
                   3456:        return;
                   3457: }
                   3458: 
                   3459: get_scopes(scope, count, matches_name)
                   3460: FILING_ScopeSequence scope;
                   3461: Cardinal *count;
                   3462: char **matches_name;
                   3463: {
                   3464:        int got_count, got_filter, got_matches;
                   3465:        int i, scopetype;
                   3466:        FILING_ScopeType t;
                   3467: #ifdef FILETOOLCOMPATIBILITY
                   3468:        int got_equal;
                   3469:        static char *wildcard_all= "*";
                   3470: 
                   3471:                *matches_name= wildcard_all;
                   3472:                *count= FILING_unlimitedCount;
                   3473:        if ( scope.length < 0 ) {
                   3474:                ReturnScopeTypeError(FILING_illegal, 0);
                   3475:                /* NOT REACHED */
                   3476:        } else if ( scope.length == 0 ) {
                   3477:                return(-1);
                   3478:        }
                   3479: #else FILETOOLCOMPATIBILITY
                   3480:        if ( scope.length <= 0 ) {
                   3481:                ReturnScopeTypeError(FILING_illegal, 0);
                   3482:                /* NOT REACHED */
                   3483:        }
                   3484: #endif FILETOOLCOMPATIBILITY
                   3485: 
                   3486: #ifdef DEBUG
                   3487:        fprintf(msgs, "get_scope %d scopes   ",scope.length);
                   3488: #endif DEBUG
                   3489: 
                   3490:        got_count= got_filter= got_matches= 0;
                   3491: 
                   3492:        for ( i= 0 ; i < scope.length ; i++ ) {
                   3493:                t= scope.sequence[i].designator;
                   3494: 
                   3495:                if ( t == FILING_filter ) {
                   3496: #ifdef DEBUG
                   3497:                        fprintf(msgs, "filter  ");
                   3498: #endif DEBUG
                   3499:                        if ( got_filter ) {
                   3500:                                ReturnScopeTypeError(FILING_duplicated, t);
                   3501:                                /* NOT REACHED */
                   3502:                        }
                   3503:                        got_filter++;
                   3504: 
                   3505:                        if ( get_filter(scope.sequence[i].FILING_filter_case,matches_name) != -1 ) {
                   3506:                                /* NOT REACHED */
                   3507:                        }
                   3508:                        continue;
                   3509:                }
                   3510: 
                   3511:                if ( t == FILING_count ) {
                   3512: #ifdef DEBUG
                   3513:                        fprintf(msgs, "count  ");
                   3514: #endif DEBUG
                   3515:                        if ( got_count ) {
                   3516:                                ReturnScopeTypeError(FILING_duplicated, t);
                   3517:                                /* NOT REACHED */
                   3518:                        }
                   3519:                        got_count++;
                   3520: 
                   3521:                        *count= AttrToCardinal(&scope.sequence[i].FILING_count_case);
                   3522: #ifdef DEBUG
                   3523:                        fprintf(msgs, "count = %d  ",*count);
                   3524: #endif DEBUG
                   3525:                        continue;
                   3526:                }
                   3527: 
                   3528:                scopetype= (Cardinal) t;
                   3529:                if ( (scopetype < 0) || (scopetype > (Cardinal) FILING_depth) ) {
                   3530:                        ReturnScopeTypeError(FILING_illegal, t);
                   3531:                        /* NOT REACHED */
                   3532:                }
                   3533: 
                   3534:                ReturnScopeTypeError(FILING_unimplemented, t);
                   3535:                /* NOT REACHED */
                   3536:        }
                   3537: 
                   3538:        if ( !got_count ) {
                   3539:                *count= FILING_unlimitedCount;
                   3540:        }
                   3541: 
                   3542: #ifdef DEBUG
                   3543:        fprintf(msgs, "\n");
                   3544: #endif DEBUG
                   3545: }
                   3546: 
                   3547: get_filter(filter,matches_name)
                   3548: FILING_Filter filter;
                   3549: char **matches_name;
                   3550: {
                   3551: 
                   3552:        int got_matches= 0;
                   3553: #ifdef FILETOOLCOMPATIBILITY
                   3554:        int got_equal= 0;
                   3555:        int got_all= 0;
                   3556: #endif FILETOOLCOMPATIBILITY
                   3557: 
                   3558:        if ( filter.designator == FILING_matches ) {
                   3559:                if ( got_matches ) {
                   3560:                        ReturnScopeValueError(FILING_duplicated, (Cardinal) FILING_filter);
                   3561:                        /* NOT REACHED */
                   3562:                }       
                   3563: 
                   3564:                got_matches++;
                   3565: 
                   3566: #ifdef DEBUG
                   3567:                fprintf(msgs, "matches on %d attribute\n",filter.FILING_matches_case.attribute.type);
                   3568: #endif DEBUG
                   3569: 
                   3570: #ifdef FILETOOLCOMPATIBILITY
                   3571:                if ( (filter.FILING_matches_case.attribute.type != FILING_pathname) &&
                   3572:                                (filter.FILING_matches_case.attribute.type != FILING_name) ) {
                   3573:                        ReturnScopeValueError(FILING_unimplemented, (Cardinal) FILING_filter);
                   3574:                        /* NOT REACHED */
                   3575:                }
                   3576: #else FILETOOLCOMPATIBILITY
                   3577:                if ( filter.FILING_matches_case.attribute.type != FILING_pathname ) {
                   3578:                        ReturnScopeValueError(FILING_unimplemented, (Cardinal) FILING_filter);
                   3579:                        /* NOT REACHED */
                   3580:                }
                   3581: #endif FILETOOLCOMPATIBILITY
                   3582: 
                   3583:                *matches_name= AttrToString(&filter.FILING_matches_case.attribute);
                   3584: 
                   3585: #ifdef DEBUG
                   3586:                fprintf(msgs, "matches name= '%s'\n",*matches_name);
                   3587: #endif DEBUG
                   3588: 
                   3589: #ifdef FILETOOLCOMPATIBILITY
                   3590:        } else if ( filter.designator == FILING_equal ) {
                   3591:                if ( got_equal ) {
                   3592:                        ReturnScopeValueError(FILING_duplicated, (Cardinal) FILING_filter);
                   3593:                        /* NOT REACHED */
                   3594:                }       
                   3595: 
                   3596:                got_equal++;
                   3597: 
                   3598: #ifdef DEBUG
                   3599:                fprintf(msgs, "equal on %d attribute\n",filter.FILING_matches_case.attribute.type);
                   3600: #endif DEBUG
                   3601: 
                   3602:                if ( (filter.FILING_matches_case.attribute.type != FILING_pathname) &&
                   3603:                                (filter.FILING_matches_case.attribute.type != FILING_name) ) {
                   3604:                        ReturnScopeValueError(FILING_unimplemented, (Cardinal) FILING_filter);
                   3605:                        /* NOT REACHED */
                   3606:                }
                   3607: 
                   3608:                *matches_name= AttrToString(&filter.FILING_matches_case.attribute);
                   3609: 
                   3610: #ifdef DEBUG
                   3611:                fprintf(msgs, "matches name= '%s'\n",*matches_name);
                   3612: #endif DEBUG
                   3613: 
                   3614:        } else if ( filter.designator == FILING_all ) {
                   3615:                if ( got_all ) {
                   3616:                        ReturnScopeValueError(FILING_duplicated, (Cardinal) FILING_filter);
                   3617:                        /* NOT REACHED */
                   3618:                }
                   3619:                got_all++;
                   3620: 
                   3621: #ifdef DEBUG
                   3622:                fprintf(msgs, "all");
                   3623: #endif DEBUG
                   3624: #endif FILETOOLCOMPATIBILITY
                   3625:        } else {
                   3626:                ReturnScopeValueError(FILING_unimplemented, (Cardinal) FILING_filter);
                   3627:                /* NOT REACHED */
                   3628:        }
                   3629:        return(-1);
                   3630: }
                   3631: 
                   3632: 
                   3633: FILING_ContinueResults FILING_Continue(ServerConnection, BDTProc, session)
                   3634: CourierConnection *ServerConnection;
                   3635: int ( *BDTProc)();
                   3636: FILING_Session session;
                   3637: {
                   3638:        FILING_ContinueResults results;
                   3639: 
                   3640:        BDTabort_expected= FALSE;
                   3641: 
                   3642: #ifdef DEBUG
                   3643:        if (msgs == 0) {
                   3644:                char logfile[50];
                   3645:                sprintf(logfile, "/tmp/filing%ld.msgs", getpid());
                   3646:                msgs= fopen(logfile,"w");
                   3647:        }
                   3648:        fprintf(msgs, "Continue\n");
                   3649: #endif DEBUG
                   3650: 
                   3651:        if ( verify_session(session) != -1 ) {
                   3652:                /* NOT REACHED */
                   3653:        }
                   3654: 
                   3655:        results.continuance= continuance;
                   3656:        reset_continuance_timer();
                   3657: 
                   3658:        return(results);
                   3659: }
                   3660: 
                   3661: continuance_expiration()
                   3662: {
                   3663:        /*
                   3664:         * if BDT in progress, don't close connection
                   3665:         */
                   3666: 
                   3667:        if ( !BDTabort_expected ) {
                   3668: #ifdef DEBUG
                   3669:                fprintf(msgs, "continuance_expiration, closing connection\n");
                   3670:                fflush(msgs);
                   3671: #endif DEBUG
                   3672:                CourierClose(_serverConnection);
                   3673:                exit(1);
                   3674:        } else {
                   3675:                reset_continuance_timer();
                   3676:        }
                   3677: 
                   3678: }
                   3679: 
                   3680: 
                   3681: void FILING_UnifyAccessLists(ServerConnection, BDTProc, directory, session)
                   3682: CourierConnection *ServerConnection;
                   3683: int ( *BDTProc)();
                   3684: FILING_Handle directory;
                   3685: FILING_Session session;
                   3686: {
                   3687:        NoSuchProcedureValue("Filing", 20);
                   3688: }
                   3689: 
                   3690: 
                   3691: void FILING_RetrieveBytes(ServerConnection, BDTProc, file, range, sink, session)
                   3692: CourierConnection *ServerConnection;
                   3693: int ( *BDTProc)();
                   3694: FILING_Handle file;
                   3695: FILING_ByteRange range;
                   3696: BulkData1_Descriptor sink;
                   3697: FILING_Session session;
                   3698: {
                   3699:        NoSuchProcedureValue("Filing", 22);
                   3700: }
                   3701: 
                   3702: 
                   3703: void FILING_ReplaceBytes(ServerConnection, BDTProc, file, range, source, session)
                   3704: CourierConnection *ServerConnection;
                   3705: int ( *BDTProc)();
                   3706: FILING_Handle file;
                   3707: FILING_ByteRange range;
                   3708: BulkData1_Descriptor source;
                   3709: FILING_Session session;
                   3710: {
                   3711:        NoSuchProcedureValue("Filing", 23);
                   3712: }
                   3713: 
                   3714: 
                   3715: dir_storeproc(conn,handle,content)
                   3716: CourierConnection *conn;
                   3717: file_handle *handle;
                   3718: BulkData1_Descriptor content;
                   3719: {
                   3720:        int count;
                   3721:        char buffer[10];
                   3722: 
                   3723:        if ( content.designator == BulkData1_immediate ) {
                   3724:                if ( (count= BDTread(conn,buffer,sizeof(buffer))) > 0 ) {
                   3725:                        BDTabort(conn);
                   3726:                        ReturnAttributeTypeError(FILING_unreasonable, FILING_isDirectory);
                   3727:                        /* NOT REACHED */
                   3728:                }
                   3729:        }
                   3730: 
                   3731:        if ( create_directory(handle) != -1 ) {
                   3732:                /* NOT REACHED */
                   3733:        }
                   3734: 
                   3735:        return(-1);
                   3736: }
                   3737: 
                   3738: 
                   3739: static Unspecified list_buffer[SPPMAXDATA];
                   3740: static Unspecified *list_end= list_buffer + SPPMAXDATA -1;
                   3741: static Unspecified *list_ptr= list_buffer;
                   3742: 
                   3743: put_next_attribute_sequence(conn,stream_of_attrseq)
                   3744: CourierConnection *conn;
                   3745: FILING_StreamOfAttributeSequence *stream_of_attrseq;
                   3746: {
                   3747:        int ocount;
                   3748: 
                   3749:        stream_of_attrseq->designator= nextSegment;
                   3750: 
                   3751:        if ( (list_ptr + FILING_sizeof_StreamOfAttributeSequence(stream_of_attrseq)) > list_end ) {
                   3752: #ifdef DEBUG
                   3753:                fprintf(msgs,"put_next writing %d bulk data\n",list_ptr-list_buffer);
                   3754: #endif DEBUG
                   3755:                if ( (ocount= BDTwrite(conn, list_buffer, (list_ptr-list_buffer)*sizeof(Cardinal))) <= 0 ) {
                   3756:                        list_ptr= list_buffer;
                   3757:                        BDTabort(conn);
                   3758:                        ReturnTransferError(FILING_aborted);
                   3759:                        /* NOT REACHED */
                   3760:                }
                   3761: 
                   3762:                list_ptr= list_buffer;
                   3763:        }
                   3764: 
                   3765:        list_ptr += FILING_externalize_StreamOfAttributeSequence(stream_of_attrseq, list_ptr);
                   3766: 
                   3767: #ifdef DEBUG
                   3768:        fprintf(msgs, "put_next_attr_seq (out) buf= %x, ptr= %x\n",list_buffer, list_ptr);
                   3769: #endif DEBUG
                   3770: 
                   3771:        return(-1);
                   3772: }
                   3773: 
                   3774: put_last_attribute_sequence(conn)
                   3775: CourierConnection *conn;
                   3776: {
                   3777: 
                   3778:        int ocount;
                   3779:        Cardinal zero= 0, lastseg= (Cardinal) lastSegment;
                   3780: 
                   3781:        if ( (list_ptr + (sizeof_Cardinal(0) * 3)) > list_end ) {
                   3782: #ifdef DEBUG
                   3783:        fprintf(msgs,"put_last writing %d bulk data\n",list_ptr-list_buffer);
                   3784: #endif DEBUG
                   3785:                if ( (ocount= BDTwrite(conn, list_buffer, (list_ptr-list_buffer)*sizeof(Cardinal))) <= 0 ) {
                   3786:                        list_ptr= list_buffer;
                   3787:                        BDTabort(conn);
                   3788:                        ReturnTransferError(FILING_aborted);
                   3789:                        /* NOT REACHED */
                   3790:                }
                   3791:                list_ptr= list_buffer;
                   3792:        }
                   3793: 
                   3794:        list_ptr+= externalize_Cardinal(&lastseg, list_ptr);
                   3795:        list_ptr+= externalize_Cardinal(&zero, list_ptr);
                   3796: 
                   3797: #ifdef DEBUG
                   3798:        fprintf(msgs,"put_last writing %d bulk data\n",list_ptr-list_buffer);
                   3799: #endif DEBUG
                   3800:        if ( (ocount= BDTwrite(conn, list_buffer, (list_ptr-list_buffer)*sizeof(Cardinal))) <= 0 ) {
                   3801:                list_ptr= list_buffer;
                   3802:                BDTabort(conn);
                   3803:                ReturnTransferError(FILING_aborted);
                   3804:                /* NOT REACHED */
                   3805:        }
                   3806: 
                   3807:        list_ptr= list_buffer;
                   3808:        return(-1);
                   3809: }
                   3810: 

unix.superglobalmegacorp.com

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