📄 filingd.c
字号:
}#ifdef FILETOOLCOMPATIBILITY if ( !got_pathname && !got_name) { if ( !got_fileID ) { handle->pathname= SERVICE_ROOT; } } else if ( !got_pathname ) { strcat(handle->pathname,name); } else { if ( *pathname == '/' ) strcat(handle->pathname, pathname+1); else strcat(handle->pathname,pathname); Deallocate(&pathname); }#else FILETOOLCOMPATIBILITY if ( !got_pathname ) { handle->pathname= SERVICE_ROOT; } else { if ( *pathname == '/' ) strcat(handle->pathname, pathname+1); else strcat(handle->pathname, pathname); Deallocate(&pathname); }#endif FILETOOLCOMPATIBILITY if ( !got_type ) handle->type= -1; return(-1);}is_nullID(fileid)Unspecified *fileid;{ int i; for ( i= 0 ; i < 6 ; i++ ) { if ( fileid[i] != 0 ) return(0); } return(-1);}void FILING_Close(ServerConnection, BDTProc, file, session)CourierConnection *ServerConnection;int ( *BDTProc)();FILING_Handle file;FILING_Session session;{ file_handle *handle; BDTabort_expected= FALSE;#ifdef DEBUG if (msgs == 0) { char logfile[50]; sprintf(logfile, "/tmp/filing%ld.msgs", getpid()); msgs= fopen(logfile,"w"); } fprintf(msgs, "Close\n");#endif DEBUG if ( verify_session(session) != -1 ) { /* NOT REACHED */ } if ( is_nullHandle(file) == -1 ) { ReturnHandleError(FILING_nullDisallowed); /* NOT REACHED */ } copyhandle(&handle,file);#ifdef DEBUG fprintf(msgs, "closing %x\n",handle);#endif DEBUG if ( handle->state != FILE_OPEN ) { ReturnHandleError(FILING_invalid); /* NOT REACHED */ } if ( access_file(handle) != -1 ) { /* NOT REACHED */ } close_file(handle); /* do it now */ if ( handle->createdon != 0 ) /* set date if needed */ set_create_time(handle); handle->state= FILE_CLOSED; handle->pathname= (char *)0;#ifdef FILETOOLCOMPATIBILITY if ( handle == cur_dir_handle ) cur_dir_handle= &RootHandle;#endif FILETOOLCOMPATIBILITY free(handle); reset_continuance_timer(); return;}FILING_CreateResults FILING_Create(ServerConnection, BDTProc, directory, attributes, controls, session)CourierConnection *ServerConnection;int ( *BDTProc)();FILING_Handle directory;FILING_AttributeSequence attributes;FILING_ControlSequence controls;FILING_Session session;{#ifdef EXTENSIONS FILING_CreateResults results; file_handle *handle, *dir_handle;#ifdef DEBUG if (msgs == 0) { char logfile[50]; sprintf(logfile, "/tmp/filing%ld.msgs", getpid()); msgs= fopen(logfile,"w"); } fprintf(msgs, "Create ");#endif DEBUG BDTabort_expected= TRUE; if ( verify_session(session) != -1 ) { /* NOT REACHED */ }#ifndef FILETOOLCOMPATIBILITY if ( is_nullControls(controls) != -1) { ReturnControlTypeError(FILING_disallowed, 0); /* NOT REACHED */ }#endif FILETOOLCOMPATIBILITY if ( (handle= (file_handle *)malloc(sizeof(file_handle))) == NULL ) { ReturnUndefinedError(0); /* NOT REACHED */ } if ( (handle->pathname= (char *)malloc(MAX_FILE_NAME_LENGTH)) == NULL ) { ReturnUndefinedError(0); /* NOT REACHED */ }#ifdef DEBUG fprintf(msgs, "create handle= %x\n",handle);#endif DEBUG#ifdef FILETOOLCOMPATIBILITY copyhandle(&dir_handle,directory); if ( dir_handle == 0 ) { dir_handle= &RootHandle; strcpy(handle->pathname, SERVICE_ROOT); } else { if ( dir_handle->state != FILE_OPEN ) { ReturnHandleError(FILING_invalid); /* NOT REACHED */ } if ( access_file(dir_handle) != -1 ) { /* NOT REACHED */ } if ( dir_handle->isdirectory != TRUE ) { ReturnHandleError(FILING_directoryRequired); /* NOT REACHED */ } strcpy(handle->pathname,dir_handle->pathname); if ( strcmp(handle->pathname, "/") != 0 ) strcat(handle->pathname,"/"); } #else FILETOOLCOMPATIBILITY strcpy(handle->pathname, SERVICE_ROOT);#endif FILETOOLCOMPATIBILITY if ( verify_create_attributes(attributes, handle) != -1 ) { /* NOT REACHED */ }#ifdef DEBUG fprintf(msgs, "creating '%s'\n", handle->pathname);#endif DEBUG if ( handle->isdirectory == TRUE ) { if ( create_directory(handle) != -1 ) { /* NOT REACHED */ } } else { if ( create_file(handle) != -1 ) { /* NOT REACHED */ } } close_file(handle); handle->state= FILE_OPEN; handle->file_desc= NULL; copyhandle(results.file, &handle); reset_continuance_timer(); return(results);#else EXTENSIONS NoSuchProcedureValue("Filing", 4);#endif EXTENSIONS}#ifdef EXTENSIONSverify_create_attributes(attr, handle)FILING_AttributeSequence attr;file_handle *handle;{ int i; FILING_AttributeType t; int got_accesslist, got_childrenuniquelynamed, got_createdon, got_datasize; int got_defaultaccesslist, got_isdirectory, got_istemporary, got_ordering; int got_pathname, got_subtreesizelimit, got_type, got_version; char *pathname; FILING_Version version; Boolean childrenuniquelynamed, istemporary; Cardinal ordering; Cardinal subtreesizelimit; char *AttrToString(); Unspecified *AttrToFileID(); LongCardinal AttrToLongCardinal();#ifdef FILETOOLCOMPATIBILITY int got_name; char *name;#endif FILETOOLCOMPATIBILITY#ifdef DEBUG fprintf(msgs,"%d create attributes ",attr.length);#endif DEBUG if ( attr.length <= 0 ) { ReturnAttributeTypeError(FILING_illegal, 0); /* NOT REACHED */ } got_accesslist= got_childrenuniquelynamed= got_createdon= 0; got_datasize= got_defaultaccesslist= got_isdirectory= 0; got_istemporary= got_ordering= got_pathname= 0; got_subtreesizelimit= got_type= got_version= 0;#ifdef FILETOOLCOMPATIBILITY got_name= 0;#endif FILETOOLCOMPATIBILITY for ( i= 0 ; i < attr.length ; i++ ) { t= attr.sequence[i].type;#ifdef DEBUG fprintf(msgs, "%d ",t);#endif DEBUG if ( t == FILING_createdOn ) {#ifdef DEBUG fprintf(msgs,"createdOn ");#endif DEBUG if ( got_createdon ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_createdon++; handle->createdon= AttrToLongCardinal(&attr.sequence[i]); continue; } if ( t == FILING_dataSize ) {#ifdef DEBUG fprintf(msgs,"dataSize ");#endif DEBUG if ( got_datasize ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_datasize++; handle->datasize= AttrToLongCardinal(&attr.sequence[i]); continue; } if ( t == FILING_isDirectory ) {#ifdef DEBUG fprintf(msgs,"isDirectory ");#endif DEBUG if ( got_isdirectory ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_isdirectory++; handle->isdirectory= AttrToBoolean(&attr.sequence[i]); continue; } if ( t == FILING_pathname ) {#ifdef DEBUG fprintf(msgs,"pathname ");#endif DEBUG if ( got_pathname ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_pathname++; pathname= AttrToString(&attr.sequence[i]); if ( check_pathname(pathname) != -1 ) { /* NOT REACHED */ } continue; } if ( t == FILING_type ) {#ifdef DEBUG fprintf(msgs,"type ");#endif DEBUG if ( got_type ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_type++; handle->type= AttrToLongCardinal(&attr.sequence[i]); continue; } if ( t == FILING_version ) {#ifdef DEBUG fprintf(msgs,"version ");#endif DEBUG if ( got_version ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_version++; version= AttrToCardinal(&attr.sequence[i]); if ( version != FILING_highestVersion ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; }#ifdef FILETOOLCOMPATIBILITY if ( t == FILING_name ) {#ifdef DEBUG fprintf(msgs, "name ");#endif DEBUG if ( got_name ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_name++; name= AttrToString(&attr.sequence[i]); continue; }#endif FILETOOLCOMPATIBILITY#ifdef SOMEDAY if ( t == FILING_accessList ) { if ( got_accesslist ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_accesslist++; if ( FALSE ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; }#endif SOMEDAY if ( t == FILING_childrenUniquelyNamed ) { if ( got_childrenuniquelynamed ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_childrenuniquelynamed++; childrenuniquelynamed= AttrToBoolean(&attr.sequence[i]); if ( childrenuniquelynamed != TRUE ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; }#ifdef SOMEDAY if ( t == FILING_defaultAccessList ) { if ( got_defaultaccesslist ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_defaultaccesslist++; if ( FALSE ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; }#endif SOMEDAY if ( t == FILING_isTemporary ) { if ( got_istemporary ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_istemporary++; istemporary= AttrToBoolean(&attr.sequence[i]); if ( istemporary != FALSE ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; } if ( t == FILING_ordering ) { if ( got_ordering ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_ordering++; if ( FALSE ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; } if ( t == FILING_subtreeSizeLimit ) { if ( got_subtreesizelimit ) { ReturnAttributeTypeError(FILING_duplicated, t); /* NOT REACHED */ } got_subtreesizelimit++; subtreesizelimit= AttrToCardinal(&attr.sequence[i]); if ( subtreesizelimit != FILING_nullSubtreeSizeLimit ) { ReturnAttributeValueError(FILING_unimplemented, t); /* NOT REACHED */ } continue; } if ( (t == FILING_fileID) || (t == FILING_modifiedBy) || (t == FILING_modifiedOn) || (t == FILING_numberOfChildren) || (t == FILING_parentID) || (t == FILING_readBy) || (t == FILING_readOn) || (t == FILING_storedSize) || (t == FILING_subtreeSize) ) { ReturnAttributeTypeError(FILING_disallowed, t); } if ( t < 0 ) { ReturnAttributeTypeError(FILING_illegal, t); /* NOT REACHED */ } if ( handle->type != TYPE_VP ) { if ( (t == FILING_checksum) || (t == FILING_createdBy) || (t == FILING_position) ) ReturnAttributeTypeError(FILING_unimplemented, t); else ReturnAttributeTypeError(FILING_disallowed, t); } }#ifdef DEBUG fprintf(msgs, "\n");#endif DEBUG#ifdef FILETOOLCOMPATIBILITY if ( !got_pathname && !got_name) { handle->pathname= SERVICE_ROOT; } else if ( !got_pathname ) { strcat(handle->pathname,name); } else { if ( *pathname == '/' ) strcat(handle->pathname, pathname+1); else strcat(handle->pathname,pathname); Deallocate(&pathname); }#else FILETOOLCOMPATIBILITY if ( !got_pathname ) { ReturnAttributeTypeError(FILING_missing, t); /* NOT REACHED */ } else { if ( *pathname == '/' ) strcat(handle->pathname, pathname+1); else strcat(handle->pathname, pathname); Deallocate(&pathname); }#endif FILETOOLCOMPATIBILITY if ( !got_type ) handle->type= FILING_tUnspecified; if ( !got_createdon ) handle->createdon= 0; if ( !got_isdirectory ) { if ( handle->type == FILING_tDirectory ) handle->isdirectory= TRUE; else handle->isdirectory= FALSE; } else { if ( ((handle->isdirectory == TRUE) && (handle->type != FILING_tDirectory)) || ((handle->isdirectory == FALSE) && (handle->type == FILING_tDirectory)) ) { ReturnAttributeTypeError(FILING_unreasonable, FILING_isDirectory); /* NOT REACHED */ } } return(-1);}#endif EXTENSIONSvoid FILING_Delete(ServerConnection, BDTProc, file, session)CourierConnection *ServerConnection;int ( *BDTProc)();FILING_Handle file;FILING_Session session;{ file_handle *handle; BDTabort_expected= FALSE;#ifdef DEBUG if (msgs == 0) { char logfile[50]; sprintf(logfile, "/tmp/filing%ld.msgs", getpid()); msgs= fopen(logfile,"w"); } fprintf(msgs, "Delete\n");#endif DEBUG if ( verify_session(session) != -1 ) { /* NOT REACHED */ } if ( is_nullHandle(file) == -1 ) { ReturnHandleError(FILING_nullDisallowed); /* NOT REACHED */ } copyhandle(&handle,file); if ( handle->state != FILE_OPEN ) { ReturnHandleError(FILING_invalid); /* NOT REACHED */ } if ( access_file(handle) != -1 ) { /* NOT REACHED */ } close_file(handle); /* do it now */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -