int GWEN_DBIO_XmlDb_Export(GWEN_DBIO *dbio, GWEN_SYNCIO *sio, GWEN_DB_NODE *data, GWEN_DB_NODE *cfg, uint32_t flags) { GWEN_XMLNODE *root; GWEN_XMLNODE *nh; int rv; const char *rootName=0; GWEN_XML_CONTEXT *ctx; if (cfg) rootName=GWEN_DB_GetCharValue(cfg, "rootElement", 0, 0); root=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "root"); nh=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "?xml"); GWEN_XMLNode_SetProperty(nh, "version", "1.0"); GWEN_XMLNode_SetProperty(nh, "encoding", "utf-8"); GWEN_XMLNode_AddHeader(root, nh); rv=GWEN_DBIO_XmlDb__ExportGroup(dbio, data, root, rootName); if (rv) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_XMLNode_free(root); return rv; } ctx=GWEN_XmlCtxStore_new(root, GWEN_XML_FLAGS_DEFAULT | GWEN_XML_FLAGS_SIMPLE | GWEN_XML_FLAGS_HANDLE_HEADERS); rv=GWEN_XMLNode_WriteToStream(root, ctx, sio); if (rv) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_XmlCtx_free(ctx); GWEN_XMLNode_free(root); return rv; } GWEN_XmlCtx_free(ctx); GWEN_XMLNode_free(root); return 0; }
void Test_WriteXml(const TEST *p_struct, GWEN_XMLNODE *p_db) { assert(p_struct); /* member "id" */ GWEN_XMLNode_SetProperty(p_db, "id", p_struct->id); /* member "prefix" */ GWEN_XMLNode_SetProperty(p_db, "prefix", p_struct->prefix); /* member "type" */ GWEN_XMLNode_SetProperty(p_db, "type", p_struct->type); /* member "items" is volatile, not writing to xml */ /* member "mode" */ }
int GWEN_DBIO_XmlDb__ExportGroup(GWEN_DBIO *dbio, GWEN_DB_NODE *data, GWEN_XMLNODE *node, const char *newName) { const char *s; GWEN_XMLNODE *n; GWEN_DB_NODE *dbT; int rv; if (newName) s=newName; else s=GWEN_DB_GroupName(data); assert(s && *s); n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, s); GWEN_XMLNode_SetProperty(n, "type", "group"); GWEN_XMLNode_AddChild(node, n); /* store variables */ dbT=GWEN_DB_GetFirstVar(data); while(dbT) { if (!(GWEN_DB_GetNodeFlags(dbT) & GWEN_DB_NODE_FLAGS_VOLATILE)) { rv=GWEN_DBIO_XmlDb__ExportVar(dbio, dbT, n); if (rv) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); return rv; } } dbT=GWEN_DB_GetNextVar(dbT); } /* store groups */ dbT=GWEN_DB_GetFirstGroup(data); while(dbT) { if (!(GWEN_DB_GetNodeFlags(dbT) & GWEN_DB_NODE_FLAGS_VOLATILE)) { rv=GWEN_DBIO_XmlDb__ExportGroup(dbio, dbT, n, 0); if (rv) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); return rv; } } dbT=GWEN_DB_GetNextGroup(dbT); } return 0; }
int GWEN_DBIO_XmlDb__ExportVar(GWEN_DBIO *dbio, GWEN_DB_NODE *data, GWEN_XMLNODE *node) { const char *s; GWEN_XMLNODE *n; GWEN_DB_NODE *dbT; int rv; s=GWEN_DB_VariableName(data); assert(s && *s); n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, s); GWEN_XMLNode_SetProperty(n, "type", "var"); GWEN_XMLNode_AddChild(node, n); /* store variables */ dbT=GWEN_DB_GetFirstValue(data); while(dbT) { if (!(GWEN_DB_GetNodeFlags(dbT) & GWEN_DB_NODE_FLAGS_VOLATILE)) { GWEN_DB_NODE_TYPE vt; GWEN_XMLNODE *vn; vt=GWEN_DB_GetValueType(dbT); switch(vt) { case GWEN_DB_NodeType_ValueChar: s=GWEN_DB_GetCharValueFromNode(dbT); if (s && *s) { GWEN_XMLNODE *dn; GWEN_BUFFER *tbuf; vn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "value"); GWEN_XMLNode_SetProperty(vn, "type", "char"); GWEN_XMLNode_AddChild(n, vn); tbuf=GWEN_Buffer_new(0, 64, 0, 1); rv=GWEN_Text_EscapeXmlToBuffer(s, tbuf); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(tbuf); return rv; } dn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_free(tbuf); GWEN_XMLNode_AddChild(vn, dn); } break; case GWEN_DB_NodeType_ValueInt: { char nbuf[32]; GWEN_XMLNODE *dn; snprintf(nbuf, sizeof(nbuf), "%i", GWEN_DB_GetIntValueFromNode(dbT)); vn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "value"); GWEN_XMLNode_SetProperty(vn, "type", "int"); GWEN_XMLNode_AddChild(n, vn); dn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, nbuf); GWEN_XMLNode_AddChild(vn, dn); break; } case GWEN_DB_NodeType_ValueBin: { const void *vp; unsigned int vsize; vp=GWEN_DB_GetBinValueFromNode(dbT, &vsize); if (vp && vsize) { GWEN_BUFFER *bbuf; GWEN_XMLNODE *dn; bbuf=GWEN_Buffer_new(0, vsize*2, 0, 1); rv=GWEN_Text_ToHexBuffer((const char*)vp, vsize, bbuf, 0, 0, 0); if (rv) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(bbuf); return rv; } vn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "value"); GWEN_XMLNode_SetProperty(vn, "type", "bin"); GWEN_XMLNode_AddChild(n, vn); dn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, GWEN_Buffer_GetStart(bbuf)); GWEN_Buffer_free(bbuf); GWEN_XMLNode_AddChild(vn, dn); } break; } case GWEN_DB_NodeType_ValuePtr: DBG_DEBUG(GWEN_LOGDOMAIN, "Not storing pointer value"); break; default: DBG_ERROR(GWEN_LOGDOMAIN, "Unsupported variable type %d", vt); return GWEN_ERROR_INVALID; } } /* if non-volatile */ dbT=GWEN_DB_GetNextValue(dbT); } return 0; }
GWEN_DIALOG *AB_SetupNewUserDialog_new(AB_BANKING *ab) { GWEN_DIALOG *dlg; AB_SETUP_NEWUSER_DIALOG *xdlg; GWEN_BUFFER *fbuf; int rv; GWEN_XMLNODE *n; GWEN_XMLNODE *nDialog; GWEN_PLUGIN_DESCRIPTION_LIST2 *providers; GWEN_DIALOG_LIST *subDialogs=NULL; dlg=GWEN_Dialog_new("ab_setup_newuser"); GWEN_NEW_OBJECT(AB_SETUP_NEWUSER_DIALOG, xdlg); GWEN_INHERIT_SETDATA(GWEN_DIALOG, AB_SETUP_NEWUSER_DIALOG, dlg, xdlg, AB_SetupNewUserDialog_FreeData); GWEN_Dialog_SetSignalHandler(dlg, AB_SetupNewUserDialog_SignalHandler); xdlg->backendDialogs=GWEN_Dialog_List2_new(); xdlg->backendRadioNames=GWEN_StringList_new(); xdlg->backendNames=GWEN_StringList_new(); /* get path of dialog description file */ fbuf=GWEN_Buffer_new(0, 256, 0, 1); rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR, "aqbanking/dialogs/dlg_setup_newuser.dlg", fbuf); if (rv<0) { DBG_INFO(AQBANKING_LOGDOMAIN, "Dialog description file not found (%d).", rv); GWEN_Buffer_free(fbuf); GWEN_Dialog_free(dlg); return NULL; } /* read XML file, extend it */ n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "root"); rv=GWEN_XML_ReadFile(n, GWEN_Buffer_GetStart(fbuf), GWEN_XML_FLAGS_DEFAULT | GWEN_XML_FLAGS_HANDLE_HEADERS); if (rv<0) { DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv); GWEN_XMLNode_free(n); GWEN_Buffer_free(fbuf); GWEN_Dialog_free(dlg); return NULL; } nDialog=GWEN_XMLNode_FindFirstTag(n, "dialog", NULL, NULL); if (nDialog==NULL) { DBG_INFO(AQBANKING_LOGDOMAIN, "Dialog element not found in XML file [%s]", GWEN_Buffer_GetStart(fbuf)); GWEN_XMLNode_free(n); GWEN_Buffer_free(fbuf); GWEN_Dialog_free(dlg); return NULL; } providers=AB_Banking_GetProviderDescrs(ab); if (providers) { GWEN_XMLNODE *nBackendRadioWidget; nBackendRadioWidget=GWEN_XMLNode_FindFirstTag(nDialog, "widget", "name", "dialogVLayout"); if (nBackendRadioWidget) nBackendRadioWidget=GWEN_XMLNode_FindFirstTag(nBackendRadioWidget, "widget", "name", "wiz_stack"); if (nBackendRadioWidget) nBackendRadioWidget=GWEN_XMLNode_FindFirstTag(nBackendRadioWidget, "widget", "name", "backendRadioWidget"); subDialogs=GWEN_Dialog_List_new(); if (nBackendRadioWidget) { GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *pit; pit=GWEN_PluginDescription_List2_First(providers); if (pit) { GWEN_PLUGIN_DESCRIPTION *pd; pd=GWEN_PluginDescription_List2Iterator_Data(pit); while(pd) { const char *name; name=GWEN_PluginDescription_GetName(pd); if (name && *name) { AB_PROVIDER *pro; pro=AB_Banking_GetProvider(ab, name); if (pro) { GWEN_DIALOG *cdlg; GWEN_BUFFER *tbuf; GWEN_XMLNODE *wn; const char *s; if (AB_Provider_GetFlags(pro) & AB_PROVIDER_FLAGS_HAS_USERTYPE_DIALOG) { cdlg=AB_ProviderGetUserTypeDialog(pro); if (cdlg==NULL) { DBG_WARN(AQBANKING_LOGDOMAIN, "Backend [%s] does not return a userType dialog, using default", name); cdlg=AB_UserTypePageDefaultDialog_new(ab); } } else cdlg=AB_UserTypePageDefaultDialog_new(ab); tbuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(tbuf, "backend_"); GWEN_Buffer_AppendString(tbuf, name); GWEN_Buffer_AppendString(tbuf, "_radio"); wn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "widget"); GWEN_XMLNode_SetProperty(wn, "type", "radioButton"); GWEN_XMLNode_SetProperty(wn, "name", GWEN_Buffer_GetStart(tbuf)); GWEN_StringList_AppendString(xdlg->backendRadioNames, GWEN_Buffer_GetStart(tbuf), 0, 0); GWEN_StringList_AppendString(xdlg->backendNames, name, 0, 0); s=GWEN_PluginDescription_GetShortDescr(pd); if (!(s && *s)) s=name; GWEN_XMLNode_SetProperty(wn, "text", I18N(s)); GWEN_XMLNode_SetProperty(wn, "groupId", "999999"); GWEN_XMLNode_SetProperty(wn, "flags", "fillX justifyLeft"); GWEN_XMLNode_AddChild(nBackendRadioWidget, wn); GWEN_Dialog_List_Add(cdlg, subDialogs); } else { DBG_ERROR(AQBANKING_LOGDOMAIN, "Could not activate backend [%s]", name); } } pd=GWEN_PluginDescription_List2Iterator_Next(pit); } GWEN_PluginDescription_List2Iterator_free(pit); } } else { DBG_ERROR(AQBANKING_LOGDOMAIN, "Dialog description does not contain path [dialogVLayout/wiz_stack/backendRadioWidget]"); GWEN_XMLNode_Dump(nDialog, 2); GWEN_XMLNode_free(n); GWEN_Buffer_free(fbuf); GWEN_Dialog_free(dlg); return NULL; } } /* read dialog from dialog description file */ rv=GWEN_Dialog_ReadXml(dlg, nDialog); if (rv<0) { DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d).", rv); GWEN_Dialog_List_free(subDialogs); GWEN_XMLNode_free(n); GWEN_Buffer_free(fbuf); GWEN_Dialog_free(dlg); return NULL; } GWEN_XMLNode_free(n); GWEN_Buffer_free(fbuf); /* insert pages for each backend */ if (GWEN_Dialog_List_GetCount(subDialogs)) { GWEN_DIALOG *cdlg; while ( (cdlg=GWEN_Dialog_List_First(subDialogs)) ) { GWEN_Dialog_List_Del(cdlg); DBG_NOTICE(AQBANKING_LOGDOMAIN, "Adding dialog %s", GWEN_Dialog_GetId(cdlg)); rv=GWEN_Dialog_AddSubDialog(dlg, "wiz_stack", cdlg); if (rv<0) { DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv); GWEN_Dialog_List_free(subDialogs); GWEN_Dialog_free(cdlg); GWEN_Dialog_free(dlg); return NULL; } GWEN_Dialog_List2_PushBack(xdlg->backendDialogs, cdlg); } } GWEN_Dialog_List_free(subDialogs); xdlg->banking=ab; /* done */ return dlg; }