LIB_EXPORT rc_t CC XFSNodeRelease ( const struct XFSNode * self ) { rc_t RCt; int RefC; RCt = 0; RefC = 0; if ( self != NULL ) { /* pLogMsg ( klogDebug, "XFSNodeRelease ( $(node) )[$(name)]", "node=%p,name=%s", ( void * ) self, self -> Name ); */ RefC = KRefcountDrop ( & ( self -> refcount ), _sXFSNode_classname ); switch ( RefC ) { case krefOkay : case krefZero : RCt = 0; break; case krefWhack : RCt = XFSNodeDispose ( self ); break; case krefNegative : RCt = XFS_RC ( rcInvalid ); break; default : RCt = XFS_RC ( rcUnknown ); break; } } return RCt; } /* XFSNodeRelease () */
static rc_t CC _KartCollectionNodeConstructorEx ( 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; const char * Path; RCt = 0; TheNode = NULL; NodeName = NULL; Path = NULL; if ( Model == NULL || Template == NULL || Node == NULL ) { return XFS_RC ( rcNull ); } * Node = NULL; NodeName = Alias == NULL ? XFSModelNodeName ( Template ) : Alias; Path = XFSModelNodeProperty ( Template, XFS_MODEL_SOURCE ); if ( Path != NULL ) { RCt = XFSKartCollectionNodeMake ( NodeName, Path, XFSModelNodeSecurity ( Template ), & TheNode ); } else { RCt = _KartCollectionNodeMakeFromModel ( NodeName, Model, Template, & TheNode ); } if ( RCt == 0 ) { * Node = TheNode; } else { * Node = NULL; if ( TheNode != NULL ) { XFSNodeDispose ( TheNode ); } } return RCt; } /* _KartCollectionNodeConstructorEx () */
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 () */
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 () */
static rc_t CC _KartCollectionNodeMakeFromModel ( const char * Name, const struct XFSModel * Model, const struct XFSModelNode * Template, struct XFSNode ** Node ) { rc_t RCt; struct XFSKartCollectionNode * KartNode; RCt = 0; KartNode = NULL; if ( Node != NULL ) { * Node = NULL; } if ( Name == NULL || Model == NULL || Template == NULL || Node == NULL ) { return XFS_RC ( rcNull ); } RCt = _KartCollectionNodeMake ( Name, "generic", XFSModelNodeSecurity ( Template ), & KartNode ); if ( RCt == 0 ) { RCt = _LoadKartScanChildren ( Model, Template, KartNode ); if ( RCt == 0 ) { * Node = & ( KartNode -> node . node ); } } if ( RCt != 0 ) { * Node = NULL; if ( KartNode != NULL ) { XFSNodeDispose ( & ( KartNode -> node . node ) ); KartNode = NULL; } } /* printf ( "KartNodeMakeFromModel ND[0x%p] NM[%s] TP[%d]\n", ( void * ) Node, Name, Type ); */ return RCt; } /* _KartCollectionNodeMakeFromModel () */
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 () */
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 () */
LIB_EXPORT rc_t CC XFSKartCollectionNodeMake ( const char * Name, const char * Path, const char * Perm, struct XFSNode ** Node ) { rc_t RCt; struct XFSKartCollectionNode * KartNode; RCt = 0; KartNode = NULL; if ( Node != NULL ) { * Node = NULL; } if ( Node == NULL || Path == NULL || Name == NULL ) { return XFS_RC ( rcNull ); } RCt = _KartCollectionNodeMake ( Name, Path, Perm, & KartNode ); if ( RCt == 0 ) { RCt = _LoadKartScanPath ( KartNode ); if ( RCt == 0 ) { * Node = & ( KartNode -> node . node ); } } if ( RCt != 0 ) { * Node = NULL; if ( KartNode != NULL ) { XFSNodeDispose ( & ( KartNode -> node . node ) ); KartNode = NULL; } } /* printf ( "XFSKartNodeMake ND[0x%p] NM[%s] TP[%d]\n", ( void * ) Node, Name, Type ); */ return RCt; } /* XFSKartCollectionNodeMake () */
static rc_t CC _BogusNodeMake ( const char * NodeName, bool NotFoundType, const struct XFSBogusNode ** Node ) { rc_t RCt; struct XFSBogusNode * TheNode; RCt = 0; TheNode = NULL; if ( NodeName == NULL || Node == NULL ) { return XFS_RC ( rcNull ); } * Node = NULL; TheNode = calloc ( 1, sizeof ( struct XFSBogusNode ) ); if ( TheNode == NULL ) { RCt = XFS_RC ( rcExhausted ); } else { TheNode -> NotFoundType = NotFoundType; RCt = XFSNodeInitVT ( & ( TheNode -> Node ), NodeName, ( const union XFSNode_vt * ) & _sBogusNodeVT_v1 ); if ( RCt == 0 ) { * Node = TheNode; } else { XFSNodeDispose ( ( const struct XFSNode * ) TheNode ); } } /* printf ( "_BogusNodeMake ( %s, 0x%p )\n", NodeName, ( void * ) TheNode ); */ return RCt; } /* _BogusNodeMake () */
LIB_EXPORT rc_t CC XFSDocNodeMakeWithFlavor ( struct XFSNode ** Node, const struct XFSDoc * Doc, const char * Name, const char * Perm, /* Could be NULL */ uint32_t Flavor ) { rc_t RCt; struct XFSDocNode * TheNode; RCt = 0; TheNode = NULL; if ( Node != NULL ) { * Node = NULL; } if ( Node == NULL || Name == NULL || Doc == NULL ) { return XFS_RC ( rcNull ); } TheNode = calloc ( 1, sizeof ( struct XFSDocNode ) ); if ( TheNode == NULL ) { RCt = XFS_RC ( rcExhausted ); } else { RCt = XFSNodeInitVT ( & ( TheNode -> node), Name, ( const union XFSNode_vt * ) & _sDocNodeVT_v1 ); if ( RCt == 0 ) { if ( Perm != NULL ) { RCt = XFS_StrDup ( Perm, & ( TheNode -> perm ) ); } if ( RCt == 0 ) { RCt = XFSDocAddRef ( Doc ); if ( RCt == 0 ) { TheNode -> doc = Doc; TheNode -> flavor = Flavor; * Node = & ( TheNode -> node ); } } } } if ( RCt != 0 ) { if ( TheNode != NULL ) { XFSNodeDispose ( & ( TheNode -> node ) ); TheNode = NULL; } } /* pLogMsg ( klogDebug, "XFSDocNodeMake ND[$(node)] NM[$(name)] Doc[$(doc)]", "node=%p,name=%s,doc=%s", ( void * ) TheNode, Name, Doc ); */ return RCt; } /* XFSDocNodeMakeWithFlavor () */
LIB_EXPORT rc_t CC XFSNodeMake ( const struct XFSModel * Model, const char * NodeName, const char * NameAlias, const struct XFSNode ** Node ) { rc_t RCt; const struct XFSModelNode * ModelNode; const struct XFSTeleport * Teleport; struct XFSNode * NewNode; const char * NewNodeName; RCt = 0; ModelNode = NULL; Teleport = NULL; NewNode = NULL; NewNodeName = NULL; if ( Model == NULL || Node == NULL || NodeName == NULL ) { return XFS_RC ( rcNull ); } * Node = NULL; ModelNode = XFSModelLookupNode ( Model, NodeName ); if ( ModelNode == NULL ) { return XFS_RC ( rcNotFound ); } if ( XFSModelNodeIsRoot ( ModelNode ) ) { NewNodeName = "/"; } else { /* I could use here '?:' operator, but i think that * is more useful, cuz shows names priority: * alias -> label -> name_given */ NewNodeName = NameAlias; if ( NewNodeName == NULL ) { NewNodeName = XFSModelNodeLabel ( ModelNode ); if ( NewNodeName == NULL ) { NewNodeName = NodeName; } } } RCt = XFSTeleportLookup ( XFSModelNodeType ( ModelNode ), & Teleport ); if ( RCt == 0 ) { if ( Teleport == NULL ) { RCt = XFS_RC ( rcInvalid ); } else { if ( Teleport -> Constructor == NULL ) { RCt = XFS_RC ( rcInvalid ); } else { RCt = Teleport -> Constructor ( Model, ModelNode, NameAlias, ( const struct XFSNode ** )& NewNode ); if ( RCt == 0 ) { RCt = _NodeSetName ( NewNode, NewNodeName ); if ( RCt != 0 ) { XFSNodeDispose ( NewNode ); } else { * Node = NewNode; } } } } } /* pLogMsg ( klogDebug, "XFSNodeMake ( \"$(name)\" ) As [$(alias)] ( $(node) ) [$(rc)]", "name=%s,alias=%s,node=%p,rc=%d", NodeName, ( NameAlias == NULL ? "NULL" : NameAlias ), ( void * ) NewNode, RCt ); */ return RCt; } /* XFSNodeMake () */
static rc_t CC _ReadMeNodeConstructor ( const struct XFSModel * Model, const struct XFSModelNode * Template, const char * Alias, const struct XFSNode ** Node ) { rc_t RCt; struct XFSNode * TheNode; const char * NodeName; const char * TextOrSource; struct XFSDoc * ReadMe; RCt = 0; TheNode = NULL; NodeName = NULL; TextOrSource = NULL; ReadMe = NULL; if ( Node != NULL ) { * Node = NULL; } if ( Model == NULL || Template == NULL || Node == NULL ) { return XFS_RC ( rcNull ); } NodeName = Alias == NULL ? XFSModelNodeName ( Template ) : Alias; /*) There could be "text" and "source" parameters, we will leave | source for a future development then, and will use it as text (*/ TextOrSource = XFSModelNodeProperty ( Template, XFS_MODEL_TEXT ); if ( TextOrSource == NULL ) { TextOrSource = XFSModelNodeProperty ( Template, XFS_MODEL_SOURCE ); } if ( TextOrSource == NULL ) { return XFS_RC ( rcInvalid ); } RCt = XFSTextDocMake ( & ReadMe ); if ( RCt == 0 ) { RCt = XFSTextDocAppend ( ReadMe, "README:\n%s\n", TextOrSource ); if ( RCt == 0 ) { RCt = XFSDocNodeMakeWithFlavor ( & TheNode, ReadMe, NodeName, XFSModelNodeSecurity ( Template ), _sFlavorOfReadMe ); if ( RCt == 0 ) { * Node = TheNode; } else { if ( TheNode != NULL ) { XFSNodeDispose ( TheNode ); } } } XFSDocRelease ( ReadMe ); } return RCt; } /* _ReadMeNodeConstructor () */