static rc_t AppCtxInit(rc_t rc, AppCtx* ctx) { assert(ctx); memset(ctx, 0 , sizeof *ctx); if (rc) { return rc; } if (rc == 0) { rc = SRAMgrMakeUpdate(&ctx->s_mgr, NULL); DISP_RC(rc, "while calling SRAMgrMakeUpdate"); } if (rc == 0) { rc = KXMLMgrMakeRead(&ctx->x_mgr); DISP_RC(rc, "while calling KXMLMgrMakeRead"); } if (rc == 0) { rc = KDirectoryNativeDir(&ctx->dir); DISP_RC(rc, "while calling KDirectoryNativeDir"); } return rc; }
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; }
rc_t XTocParseXml(struct XTocEntry* xRoot, const KFile* file) { rc_t rc = 0; const KXMLMgr* mgr = NULL; const KXMLDoc* doc = NULL; const KXMLNodeset* root = NULL; const char rootName[] = "/ROOT"; /**** INIT ****/ if (rc == 0) { rc = KXMLMgrMakeRead(&mgr); DISP_RC(rc, "while calling KXMLMgrMakeRead"); } if (rc == 0) { KXMLMgrMakeDocRead(mgr, &doc, file); DISP_RC(rc, "while calling KXMLMgrMakeDocRead"); } if (rc == 0) { rc = KXMLDocOpenNodesetRead(doc, &root, rootName); if (rc != 0) { /* PLOGERR(klogErr, (klogErr, rc, "while calling KXMLDocOpenNodesetRead $(name)", "name=%s", rootName));*/ } } if (rc == 0) { uint32_t count = 0; rc = KXMLNodesetCount(root, &count); if (rc != 0) { /* PLOGERR(klogErr, (klogErr, rc, "while calling KXMLNodesetCount($(name))", "name=%s", rootName));*/ } else if (count != 1) { rc = RC(rcFS, rcXmlDoc, rcReading, rcTag, count ? rcExcessive : rcNotFound); /* PLOGERR(klogErr, (klogErr, rc, "$(name)", "name=%s", rootName));*/ } else if (false) { DBGMSG(DBG_APP,DBG_COND_1, ("KXMLNodesetCount(%s)=%d\n", rootName, count)); } } /**** READ AND PROCESS THE ROOT XML NODE ****/ if (rc == 0) { uint32_t i = 0; const KXMLNode *node = NULL; rc = KXMLNodesetGetNodeRead(root, &node, i); if (rc == 0) { ProcessNode(node, rootName, i, xRoot, xRoot); } /* else { * PLOGERR(klogErr, (klogErr, rc, "while calling KXMLNodesetGetNodeRead($(name), $(i))", "name=%s,i=%d", rootName, i)); }*/ { rc_t rc2 = KXMLNodeRelease(node); if (rc == 0) { rc = rc2; } node = NULL; } } /**** RELEASE ****/ { rc_t rc2 = KXMLDocRelease(doc); if (rc == 0) { rc = rc2; } doc = NULL; } { rc_t rc2 = KXMLNodesetRelease(root); if (rc == 0) { rc = rc2; } root = NULL; } { rc_t rc2 = KXMLMgrRelease(mgr); if (rc == 0) { rc = rc2; } mgr = NULL; } return rc; }