LIB_EXPORT rc_t CC XFS_InitKKey_ZHR ( const char * EncPass, const char * EncType, struct KKey * Key ) { rc_t RCt; KKeyType Type; RCt = 0; Type = kkeyNone; XFS_CAN ( EncPass ) XFS_CAN ( Key ) RCt = XFS_KeyType_ZHR ( EncType, & Type ); if ( RCt == 0 ) { RCt = KKeyInitRead ( Key, Type, EncPass, string_size ( EncPass ) ); } return RCt; } /* XFS_InitKey_ZHR () */
static rc_t CC _EncAttr_init_check_v1 ( const struct XFSAttrEditor * self, const struct XFSEncEntry ** Entry ) { struct XFSEncNode * Node = NULL; XFS_CSAN ( Entry ) XFS_CAN ( self ) XFS_CAN ( Entry ) Node = ( struct XFSEncNode * ) XFSEditorNode ( & ( self -> Papahen ) ); XFS_CA ( Node, NULL ) XFS_CA ( Node -> entry, NULL ) * Entry = Node -> entry; return 0; } /* _EncAttr_init_check_v1 () */
LIB_EXPORT rc_t CC XFSGapKartNodeMake ( struct XFSNode ** Node, const char * Name, uint32_t ProjectId, const char * Perm ) { rc_t RCt; struct XFSKartNode * KartNode; RCt = 0; KartNode = NULL; XFS_CSAN ( Node ) XFS_CAN ( Node ) XFS_CAN ( Name ) KartNode = calloc ( 1, sizeof ( struct XFSKartNode ) ); if ( KartNode == NULL ) { RCt = XFS_RC ( rcExhausted ); } else { RCt = XFSContNodeInit ( & ( KartNode -> node . node ), Name, Perm, _sFlavorOfGapKart, _KartNodeDispose ); if ( RCt == 0 ) { KartNode -> project_id = ProjectId; RCt = _LoadKart ( KartNode ); if ( RCt == 0 ) { * Node = ( struct XFSNode * ) KartNode; } } } if ( RCt != 0 ) { * Node = NULL; if ( KartNode != NULL ) { XFSNodeDispose ( & ( KartNode -> node . node ) ); KartNode = NULL; } } /* pLogMsg ( klogDebug, "XFSGapKartNodeMake ND[$(node)] NM[$(name)] TP[$(project_id)]", "node=%p,name=%s,project_id=%d", ( void * ) Node, Name, ProjectId ); */ return RCt; } /* XFSGapKartNodeMake () */
static rc_t CC _KartNodeConstructorEx ( const struct XFSModel * Model, const struct XFSModelNode * Template, const char * Alias, XFSNType Type, const struct XFSNode ** Node ) { rc_t RCt; struct XFSNode * TheNode; const char * NodeName; uint32_t ProjectId; const char * Var; RCt = 0; TheNode = NULL; NodeName = NULL; ProjectId = 0; Var = NULL; XFS_CSAN ( Node ) XFS_CAN ( Model ) XFS_CAN ( Template ) XFS_CAN ( Node ) NodeName = Alias == NULL ? XFSModelNodeName ( Template ) : Alias; Var = XFSModelNodeProperty ( Template, XFS_MODEL_PROJECTID ); if ( Var == NULL ) { return XFS_RC ( rcInvalid ); } ProjectId = atol ( Var ); RCt = XFSGapKartNodeMake ( & TheNode, NodeName, ProjectId, XFSModelNodeSecurity ( Template ) ); if ( RCt == 0 ) { * Node = TheNode; } else { * Node = NULL; if ( TheNode != NULL ) { XFSNodeDispose ( TheNode ); } } return RCt; } /* _KartNodeConstructorEx () */
LIB_EXPORT rc_t CC XFS_CopyKKey_ZHR ( const struct KKey * Src, struct KKey * Dst ) { XFS_CAN ( Src ) XFS_CAN ( Dst ) memcpy ( Dst, Src, sizeof ( struct KKey ) ); return 0; } /* XFS_CopyKKey_ZHR () */
/*)) Unnecessary in real life ((*/ static rc_t CC _LaInQty ( const struct _LaIn * self, uint32_t * Qty ) { XFS_CSA ( Qty, 0 ) XFS_CAN ( self ) XFS_CAN ( Qty ) * Qty = self -> q; return 0; } /* _LaInQty () */
static rc_t CC _AddKartItem ( struct XFSKartNode * Node, const struct XFSGapKart * Kart, const char * ItemName ) { rc_t RCt; struct XFSNode * ItemNode; const struct XFSGapKartItem * KartItem; RCt = 0; ItemNode = NULL; KartItem = NULL; XFS_CAN ( Node ) XFS_CAN ( Kart ) XFS_CAN ( ItemName ) KartItem = XFSGapKartGet ( Kart, ItemName ); if ( KartItem == NULL ) { return XFS_RC ( rcInvalid ); } RCt = XFSGapFileNodeMake ( & ItemNode, ItemName, XFSGapKartItemProjectId ( KartItem ), XFSGapKartItemAccession ( KartItem ), XFSGapKartItemObjectId ( KartItem ) ); if ( RCt == 0 ) { RCt = XFSContNodeAddChild ( & ( Node -> node . node ), ItemNode ); if ( GetRCState ( RCt ) == rcExists ) { RCt = 0; } /* We do not dispose node here, but on the caller level */ } if ( RCt != 0 ) { if ( ItemNode != NULL ) { XFSNodeDispose ( ItemNode ); ItemNode = NULL; } } return RCt; } /* _AddKartItem () */
LIB_EXPORT rc_t CC XFSEncryptedFileNodeMake ( const char * Name, const char * Path, const char * Passwd, const char * EncType, struct XFSNode ** Node ) { rc_t RCt; const struct XFSEncEntry * Entry; struct XFSNode * TheNode; RCt = 0; Entry = NULL; TheNode = NULL; XFS_CSAN ( Node ) XFS_CAN ( Name ) XFS_CAN ( Path ) XFS_CAN ( Passwd ) XFS_CAN ( Node ) RCt = XFSEncEntryFindOrCreate ( Path, Passwd, EncType, & Entry ); if ( RCt == 0 ) { RCt = XFSEncNodeMake ( & TheNode, Name, Entry ); if ( RCt == 0 ) { * Node = TheNode; } } if ( RCt != 0 ) { * Node = NULL; if ( TheNode != NULL ) { XFSNodeDispose ( TheNode ); } else { if ( Entry != NULL ) { XFSEncEntryDispose ( Entry ); } } } return RCt; } /* XFSEncryptedFileNodeMake () */
static rc_t CC XFSEncNodeMake ( struct XFSNode ** Node, const char * Name, const struct XFSEncEntry * Entry ) { rc_t RCt; struct XFSEncNode * xNode; RCt = 0; xNode = NULL; XFS_CSAN ( Node ) XFS_CAN ( Node ) XFS_CAN ( Name ) XFS_CAN ( Entry ) xNode = calloc ( 1, sizeof ( struct XFSEncNode ) ); if ( xNode == NULL ) { return XFS_RC ( rcNull ); } RCt = XFSNodeInitVT ( & ( xNode -> node ), Name, ( const union XFSNode_vt * ) & _sEncNodeVT_v1 ); if ( RCt == 0 ) { RCt = XFSEncEntryAddRef ( Entry ); if ( RCt == 0 ) { xNode -> entry = Entry; * Node = & ( xNode -> node ); } } if ( RCt != 0 ) { if ( xNode != NULL ) { RCt = XFSNodeDispose ( & ( xNode -> node ) ); } } return RCt; } /* XFSEncNodeMake () */
static rc_t CC _EncFile_read_v1 ( const struct XFSFileEditor * self, uint64_t Offset, void * Buffer, size_t SizeToRead, size_t * NumReaded ) { rc_t RCt; struct XFSEncFileEditor * Editor; RCt = 0; Editor = ( struct XFSEncFileEditor * ) self; XFS_CAN ( Editor ) XFS_CA ( Editor -> entry, NULL ) RCt = XFSEncEntryRead ( Editor -> entry, Offset, Buffer, SizeToRead, NumReaded ); return RCt; } /* _EncFile_read_v1 () */
LIB_EXPORT rc_t CC XFS_ResolvePath ( bool Absolute, char * Resolved, size_t ResolvedSize, const char * Format, ... ) { rc_t RCt; va_list Args; RCt = 0; XFS_CAN ( Format ) va_start ( Args, Format ); RCt = XFS_VResolvePath ( Absolute, Resolved, ResolvedSize, Format, Args ); va_end ( Args ); return RCt; } /* XFS_ResolvePath () */
static rc_t CC _EncAttr_size_v1 ( const struct XFSAttrEditor * self, uint64_t * Size ) { rc_t RCt; const struct XFSEncEntry * Entry; RCt = 0; Entry = NULL; XFS_CSA ( Size, 0 ) XFS_CAN ( Size ) RCt = _EncAttr_init_check_v1 ( self, & Entry ); if ( RCt == 0 ) { RCt = XFSEncEntrySize ( Entry, Size ); if ( RCt != 0 ) { * Size = 0; } } return RCt; } /* _EncAttr_size_v1 () */
static rc_t CC _EncAttr_date_v1 ( const struct XFSAttrEditor * self, KTime_t * Time ) { rc_t RCt; const struct XFSEncEntry * Entry; RCt = 0; Entry = NULL; XFS_CSA ( Time, 0 ) XFS_CAN ( Time ) RCt = _EncAttr_init_check_v1 ( self, & Entry ); if ( RCt == 0 ) { RCt = XFSEncEntryTime ( Entry, Time ); if ( RCt != 0 ) { * Time = 0; } } return RCt; } /* _EncAttr_date_v1 () */
rc_t CC _EncNodeFile_v1 ( const struct XFSNode * self, const struct XFSFileEditor ** File ) { rc_t RCt; struct XFSEncFileEditor * FileEditor; struct XFSFileEditor * Editor; RCt = 0; FileEditor = NULL; Editor = NULL; XFS_CSAN ( File ) XFS_CAN ( self ) XFS_CAN ( File ) FileEditor = calloc ( 1, sizeof ( struct XFSEncFileEditor ) ); if ( FileEditor == NULL ) { return XFS_RC ( rcExhausted ); } memset ( FileEditor, 0, sizeof ( struct XFSEncFileEditor ) ); Editor = & ( FileEditor -> Papahen ); RCt = XFSEditorInit ( & ( Editor -> Papahen ), self, _EncFile_dispose_v1 ); if ( RCt == 0 ) { Editor -> open = _EncFile_open_v1; Editor -> close = _EncFile_close_v1; Editor -> read = _EncFile_read_v1; * File = Editor; } else { free ( Editor ); } return RCt; } /* _EncNodeFile_v1 () */
static rc_t CC _EncNodeAttr_v1 ( const struct XFSNode * self, const struct XFSAttrEditor ** Attr ) { rc_t RCt; struct XFSAttrEditor * Editor; RCt = 0; Editor = NULL; XFS_CSAN ( Attr ) XFS_CAN ( self ) XFS_CAN ( Attr ) Editor = calloc ( 1, sizeof ( struct XFSAttrEditor ) ); if ( Editor == NULL ) { return XFS_RC ( rcExhausted ); } RCt = XFSEditorInit ( & ( Editor -> Papahen ), self, _EncAttr_dispose_v1 ); if ( RCt == 0 ) { Editor -> permissions = _EncAttr_permissions_v1; Editor -> size = _EncAttr_size_v1; Editor -> date = _EncAttr_date_v1; Editor -> type = _EncAttr_type_v1; * Attr = Editor; } else { free ( Editor ); } return RCt; } /* _EncNodeAttr_v1 () */
LIB_EXPORT rc_t CC XFS_VResolvePath ( bool Absolute, char * Resolved, size_t ResolvedSize, const char * Format, va_list Args ) { rc_t RCt; struct KDirectory * NatDir; RCt = 0; NatDir = NULL; XFS_CAN ( Resolved ) XFS_CAN ( Format ) XFS_CA ( ResolvedSize, 0 ) RCt = KDirectoryNativeDir ( & NatDir ); if ( RCt == 0 ) { RCt = KDirectoryVResolvePath ( NatDir, Absolute, Resolved, ResolvedSize, Format, Args ); KDirectoryRelease ( NatDir ); } if ( RCt != 0 ) { * Resolved = 0; } return 0; } /* XFS_VResolvePath () */
static rc_t CC _LoadKart ( struct XFSKartNode * Node ) { rc_t RCt; const struct XFSGapKart * Kart; struct KNamelist * List; uint32_t ListQ, ListI; const char * ListN; RCt = 0; Kart = NULL; List = NULL; ListQ = ListI = 0; ListN = NULL; XFS_CAN ( Node ) RCt = _AddSignatureFile ( Node ); if ( RCt == 0 ) { RCt = XFSGapKartDepotGet ( & Kart, XFSNodeName ( & ( Node -> node . node ) ) ); if ( RCt == 0 ) { RCt = XFSGapKartList ( Kart, & List, Node -> project_id ); if ( RCt == 0 ) { RCt = KNamelistCount ( List, & ListQ ); if ( RCt == 0 ) { for ( ListI = 0; ListI < ListQ; ListI ++ ) { RCt = KNamelistGet ( List, ListI, & ListN ); if ( RCt != 0 ) { break; } RCt = _AddKartItem ( Node, Kart, ListN ); if ( RCt != 0 ) { break; } } } KNamelistRelease ( List ); } XFSGapKartRelease ( Kart ); } } return RCt; } /* _LoadKart () */
static rc_t CC _AddSignatureFile ( struct XFSKartNode * Node ) { rc_t RCt; struct XFSDoc * Doc; struct XFSNode * Sign; RCt = 0; Doc = NULL; Sign = NULL; XFS_CAN ( Node ) RCt = XFSTextDocMake ( & Doc ); if ( RCt == 0 ) { RCt = XFSTextDocAppend ( Doc, "%d\n", Node -> project_id ); if ( RCt == 0 ) { RCt = XFSDocNodeMakeWithFlavor ( & Sign, Doc, ".#dbgap-mount-tool#", XFSPermRODefNodeChar (), _sFlavorOfFoo ); if ( RCt == 0 ) { RCt = XFSContNodeAddChild ( & ( Node -> node . node ), Sign ); } } XFSDocRelease ( Doc ); } if ( RCt != 0 ) { if ( Sign != NULL ) { XFSNodeDispose ( Sign ); Sign = NULL; } } return RCt; } /* _AddSignatureFile () */
static rc_t CC _LaInMake ( const struct _LaIn ** LaIn ) { struct _LaIn * Ret = NULL; XFS_CSAN ( LaIn ) XFS_CAN ( LaIn ) Ret = calloc ( 1, sizeof ( struct _LaIn ) ); if ( Ret == NULL ) { return XFS_RC ( rcExhausted ); } * LaIn = Ret; return 0; } /* _LaInMake () */
rc_t CC _EncNodeDescribe_v1 ( const struct XFSNode * self, char * Buffer, size_t BufferSize ) { rc_t RCt; size_t NumWrit; const char * Abbr; RCt = 0; NumWrit = 0; Abbr = NULL; XFS_CAN ( Buffer ) XFS_CA ( BufferSize, 0 ) Abbr = "ENC NODE"; if ( self == NULL ) { string_printf ( Buffer, BufferSize, & NumWrit, "NODE (%s)[NULL][NULL]", Abbr ); } else { string_printf ( Buffer, BufferSize, & NumWrit, "NODE (%s)[%s][0x%p]", Abbr, self -> Name, self ); } return RCt; } /* _EncNodeDescribe_v1 () */
static rc_t CC XFS_KeyType_ZHR ( const char * EncType, KKeyType * Type ) { size_t B; const char * C; B = 0; C = NULL; XFS_CAN ( Type ) * Type = kkeyNone; if ( EncType == NULL ) { * Type = KKeyTypeDefault; return 0; } B = string_size ( EncType ); C = "AES128"; if ( strcase_cmp ( C, string_size ( C ), EncType, B, B ) == 0 ) { * Type = kkeyAES128; return 0; } C = "AES192"; if ( strcase_cmp ( C, string_size ( C ), EncType, B, B ) == 0 ) { * Type = kkeyAES192; return 0; } C = "AES256"; if ( strcase_cmp ( C, string_size ( C ), EncType, B, B ) == 0 ) { * Type = kkeyAES256; return 0; } return XFS_RC ( rcInvalid ); } /* XFS_KeyType_ZHR () */
static rc_t CC _EncFile_open_v1 ( const struct XFSFileEditor * self, XFSNMode Mode ) { rc_t RCt; const struct XFSEncNode * Node; struct XFSEncFileEditor * Editor; RCt = 0; Node = NULL; Editor = ( struct XFSEncFileEditor * ) self; if ( Mode != kxfsRead ) { return XFS_RC ( rcInvalid ); } XFS_CAN ( self ) Node = ( const struct XFSEncNode * ) XFSEditorNode ( & ( self -> Papahen ) ); XFS_CA ( Node, NULL ) XFS_CA ( Node -> entry, NULL ) Editor = ( struct XFSEncFileEditor * ) self; if ( Editor -> entry == NULL ) { if ( ! XFSEncEntryIsOpen ( Node -> entry ) ) { RCt = XFSEncEntryOpen ( Node -> entry ); } if ( RCt == 0 ) { Editor -> entry = Node -> entry; } } return RCt; } /* _EncFile_open_v1 () */
static rc_t CC _EncAttr_type_v1 ( const struct XFSAttrEditor * self, XFSNType * Type ) { rc_t RCt; const struct XFSEncEntry * Entry; RCt = 0; Entry = NULL; XFS_CSA ( Type, kxfsNotFound ) XFS_CAN ( Type ) RCt = _EncAttr_init_check_v1 ( self, & Entry ); if ( RCt == 0 ) { * Type = kxfsFile ; } return RCt; } /* _EncAttr_type_v1 () */
static rc_t CC _EncAttr_permissions_v1 ( const struct XFSAttrEditor * self, const char ** Permissions ) { rc_t RCt; const struct XFSEncEntry * Entry; RCt = 0; Entry = NULL; XFS_CSAN ( Permissions ) XFS_CAN ( Permissions ) RCt = _EncAttr_init_check_v1 ( self, & Entry ); if ( RCt == 0 ) { * Permissions = XFSPermRODefNodeChar (); } return RCt; } /* _EncAttr_permissions_v1 () */
static rc_t CC _KartItemMake ( struct XFSGapKartItem ** RetItem, const struct KartItem * Item ) { rc_t RCt; const struct String * TheString; struct XFSGapKartItem * xItem; uint64_t ProjectId, ObjectId; RCt = 0; TheString = NULL; xItem = NULL; ProjectId = ObjectId = 0; XFS_CSAN ( RetItem ) XFS_CAN ( RetItem ) XFS_CAN ( Item ) xItem = calloc ( 1, sizeof ( struct XFSGapKartItem ) ); if ( xItem == NULL ) { return XFS_RC ( rcExhausted ); } KRefcountInit ( & ( xItem -> refcount ), 1, _sXFSGapKartItem_classname, "_KartItemMake", "KartItem" ); RCt = KartItemProjIdNumber ( Item, & ProjectId ); if ( RCt == 0 ) { xItem -> project_id = ( uint32_t ) ProjectId; } if ( RCt == 0 ) { RCt = KartItemItemId ( Item, & TheString ); if ( RCt == 0 && TheString -> len != 0 ) { RCt = KartItemItemIdNumber ( Item, & ObjectId ); if ( RCt == 0 ) { xItem -> object_id = ( uint32_t ) ObjectId; } } else { xItem -> object_id = 0; } } if ( RCt == 0 ) { RCt = KartItemAccession ( Item, & TheString ); if ( RCt == 0 && TheString -> len != 0 ) { RCt = XFS_SStrDup ( TheString, & xItem -> accession ); } else { xItem -> accession = NULL; } } if ( RCt == 0 ) { RCt = KartItemName ( Item, & TheString ); if ( RCt == 0 && TheString -> len != 0 ) { RCt = XFS_SStrDup ( TheString, & xItem -> name ); } else { xItem -> name = NULL; } } if ( RCt == 0 ) { RCt = KartItemItemDesc ( Item, & TheString ); if ( RCt == 0 && TheString -> len != 0 ) { RCt = XFS_SStrDup ( TheString, & xItem -> description ); } else { xItem -> description = NULL; } } if ( xItem -> object_id == 0 && xItem -> accession == NULL ) { RCt = XFS_RC ( rcInvalid ); } if ( RCt == 0 ) { * RetItem = xItem; } else { if ( xItem != NULL ) { _KartItemDispose ( xItem ); } } return RCt; } /* _KartItemMake () */