Beispiel #1
0
rc_t TarNode_MakeXML(const KXMLNode* xml_node, FSNode** self, char* errmsg, const char* rel_path)
{
    rc_t rc = 0;

    if( xml_node == NULL || self == NULL ) {
        rc = RC(rcExe, rcNode, rcConstructing, rcParam, rcNull);
    } else {
        char name[4096];
        size_t sz;

        rc = KXMLNodeReadAttrCString(xml_node, "name", name, sizeof(name), &sz);
        if( rc != 0 || sz == 0 || name[0] == '\0' ) {
            strcpy(errmsg, "attribute 'name'");
            rc = rc ? rc : RC(rcExe, rcDoc, rcValidating, rcAttr, rcInvalid);
        } else if( (rc = FSNode_Make(self, name, &TarNode_vtbl)) == 0 ) {
            ((TarNode*)*self)->rel_path = rel_path;
            strcpy(errmsg, "processing Item(s)");
            if( (rc = TarNode_MakeFileList(xml_node, &((TarNode*)*self)->files, errmsg, rel_path, (*self)->name)) != 0 ) {
                FSNode_Release(*self);
                *self = NULL;
            }
        }
    }
    return rc;
}
Beispiel #2
0
static
rc_t XML_Open(const char* path, const FSNode** tree)
{
    rc_t rc = 0;
    char errmsg[4096] = "";
    KDirectory *dir = NULL;
    
    PLOGMSG(klogInfo, (klogInfo, "Reading XML file '$(x)'", PLOG_S(x), path));
    if( (rc = KDirectoryNativeDir(&dir)) == 0 ) {
        const KFile* file = NULL;
        if( (rc = KDirectoryOpenFileRead(dir, &file, "%s", path)) == 0 ) {
            if( (rc = FSNode_Make((FSNode**)tree, "ROOT", &RootNode_vtbl)) == 0 ) {
                const KXMLDoc* xmldoc = NULL;
                if( (rc = KXMLMgrMakeDocRead(g_xmlmgr, &xmldoc, file)) == 0 ) {
                    const KXMLNodeset* ns = NULL;
                    if( (rc = KXMLDocOpenNodesetRead(xmldoc, &ns, "/FUSE/*")) == 0 ) {
                        uint32_t count = 0;
                        if( (rc = KXMLNodesetCount(ns, &count)) == 0 ) {
                            if( count == 0 ) {
                                rc = RC(rcExe, rcDoc, rcValidating, rcData, rcEmpty);
                            } else {
                                uint32_t i = 0;
                                while(rc == 0 && i < count) {
                                    const KXMLNode* n = NULL;
                                    if( (rc = KXMLNodesetGetNodeRead(ns, &n, i++)) == 0 ) {
                                        SRAConfigFlags flags = ~0;
                                        errmsg[0] = '\0';
                                        rc = XML_ValidateNode((FSNode*)*tree, n, flags, errmsg);
                                        ReleaseComplain(KXMLNodeRelease, n);
                                    }
                                }
                                if( rc == 0 ) {
                                    rc = SRAList_NextVersion();
                                }
                            }
                        }
                        ReleaseComplain(KXMLNodesetRelease, ns);
                    }
                    ReleaseComplain(KXMLDocRelease, xmldoc);
                }
                if( rc != 0 ) {
                    FSNode_Release(*tree);
                    *tree = NULL;
                }
            }
            ReleaseComplain(KFileRelease, file);
        }
        ReleaseComplain(KDirectoryRelease, dir);
    }
    if( rc == 0 ) {
        PLOGMSG(klogInfo, (klogInfo, "XML file '$(x)' ok", PLOG_S(x), path));
    } else {
        if( strlen(errmsg) < 1 ) {
            strcpy(errmsg, path);
        }
        LOGERR(klogErr, rc, errmsg);
    }
    return rc;
}
Beispiel #3
0
rc_t TarNode_MakeAuto(const FSNode** cself, const KDirectory* dir, const char* path, const char* file, const char* xml_path)
{
    rc_t rc = 0;

    if( cself == NULL || dir == NULL || path == NULL || file == NULL || xml_path == NULL ) {
        rc = RC(rcExe, rcNode, rcConstructing, rcParam, rcNull);
    } else {
        if( (rc = FSNode_Make((FSNode**)cself, file, &TarNode_vtbl)) == 0 ) {
            ((char*)((*cself)->name))[strlen(file) - 4] = '\0'; /* -= .xml */
            ((TarNode*)*cself)->xml_path = xml_path;
            ((TarNode*)*cself)->rel_path = path;
            if( (rc = FSNode_Touch(*cself)) != 0 ) {
                FSNode_Release(*cself);
                *cself = NULL;
            }
        }
    }
    return rc;
}
Beispiel #4
0
rc_t XML_Make(KDirectory* dir, const char* const work_dir, const char* xml_path, unsigned int sync, uint32_t xml_validate)
{
    rc_t rc = 0; 

    g_xml_sync = sync;
    if( g_xmlmgr == NULL && (rc = KXMLMgrMakeRead(&g_xmlmgr)) != 0 ) {
        g_xmlmgr = NULL;
        LOGERR(klogErr, rc, "XML manager");
    } else {
        char buf[4096];
        if( (rc = KDirectoryResolvePath(dir, true, buf, 4096, "%s", xml_path)) == 0 ) {
            if( (rc = StrDup(buf, &g_xml_path)) == 0 ) {
                DEBUG_MSG(8, ("XML path set to '%s'\n", g_xml_path));
            }
        }
        g_start_dir = work_dir;
        g_xml_validate = xml_validate;
    }
    if( rc == 0 ) {
        rc = FSNode_Make((FSNode**)&g_root, "ROOT", &RootNode_vtbl);
    }
    return rc;
}