int GWEN_XML_ReadFile(GWEN_XMLNODE *n, const char *filepath, uint32_t flags) { GWEN_XML_CONTEXT *ctx; GWEN_SYNCIO *sio; int rv; sio=GWEN_SyncIo_File_new(filepath, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); return rv; } ctx=GWEN_XmlCtxStore_new(n, flags); rv=GWEN_XML__ReadAllFromIo(ctx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); return rv; } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); return 0; }
int GWEN_XMLContext_ReadFromString(GWEN_XML_CONTEXT *ctx, const char *text) { if (text && *text) { GWEN_SYNCIO *sio; int rv; GWEN_BUFFER *tbuf; int i; i=strlen(text)+1; tbuf=GWEN_Buffer_new((char*)text, i, i, 0); /* static buffer, don't resize */ GWEN_Buffer_SubMode(tbuf, GWEN_BUFFER_MODE_DYNAMIC); GWEN_Buffer_AddMode(tbuf, GWEN_BUFFER_MODE_READONLY); sio=GWEN_SyncIo_Memory_new(tbuf, 0); rv=GWEN_XML__ReadAllFromIo(ctx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); GWEN_Buffer_free(tbuf); return rv; } GWEN_SyncIo_free(sio); GWEN_Buffer_free(tbuf); } return 0; }
int GWEN_XMLContext_ReadFromFile(GWEN_XML_CONTEXT *ctx, const char *fname) { GWEN_SYNCIO *sio; int rv; sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); return rv; } rv=GWEN_XML__ReadAllFromIo(ctx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return 0; }
int GWEN_XMLNode_toBuffer(const GWEN_XMLNODE *n, GWEN_BUFFER *buf, uint32_t flags) { GWEN_XML_CONTEXT *ctx; GWEN_SYNCIO *sio; int rv; sio=GWEN_SyncIo_Memory_new(buf, 0); /* create context and io layers */ ctx=GWEN_XmlCtxStore_new(NULL, flags); /* write data to stream */ rv=GWEN_XMLNode_WriteToStream(n, ctx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); return rv; } GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); return 0; }
int AB_ImExporter_ImportFile(AB_IMEXPORTER *ie, AB_IMEXPORTER_CONTEXT *ctx, const char *fname, GWEN_DB_NODE *dbProfile){ GWEN_SYNCIO *sio; int rv; assert(ie); assert(ctx); assert(fname); assert(dbProfile); if (fname) { sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_WARN(AQBANKING_LOGDOMAIN, "Failed to Connect() syncio (%d)", rv); GWEN_SyncIo_free(sio); return rv; } } else { sio=GWEN_SyncIo_File_fromStdin(); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FLAGS_DONTCLOSE); } rv=AB_ImExporter_Import(ie, ctx, sio, dbProfile); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; }
GWEN_XMLNODE *GWEN_XMLNode_fromString(const char *s, int len, uint32_t flags) { #if 0 GWEN_XML_CONTEXT *ctx; GWEN_SYNCIO *sio; GWEN_XMLNODE *n; int rv; if (len==0) len=strlen(s); sio=GWEN_SyncIo_Memory_fromBuffer((const uint8_t*)s, len); n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "doc"); ctx=GWEN_XmlCtxStore_new(n, flags); rv=GWEN_XML__ReadAllFromIo(ctx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); GWEN_XMLNode_free(n); return NULL; } GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); return n; #else GWEN_XML_CONTEXT *ctx; GWEN_SYNCIO *sio; GWEN_XMLNODE *n; int rv; GWEN_BUFFER *tbuf; tbuf=GWEN_Buffer_new((char*)s, len, len, 0); /* static buffer, don't resize */ GWEN_Buffer_SubMode(tbuf, GWEN_BUFFER_MODE_DYNAMIC); GWEN_Buffer_AddMode(tbuf, GWEN_BUFFER_MODE_READONLY); sio=GWEN_SyncIo_Memory_new(tbuf, 0); n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "doc"); ctx=GWEN_XmlCtxStore_new(n, flags); rv=GWEN_XML__ReadAllFromIo(ctx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_XmlCtx_free(ctx); GWEN_XMLNode_free(n); GWEN_SyncIo_free(sio); GWEN_Buffer_free(tbuf); return NULL; } GWEN_XmlCtx_free(ctx); GWEN_SyncIo_free(sio); GWEN_Buffer_free(tbuf); return n; #endif }
int readContext(const char *ctxFile, AB_IMEXPORTER_CONTEXT **pCtx, int mustExist) { AB_IMEXPORTER_CONTEXT *ctx; GWEN_SYNCIO *sio; GWEN_DB_NODE *dbCtx; int rv; if (ctxFile==NULL) { sio=GWEN_SyncIo_File_fromStdin(); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FLAGS_DONTCLOSE | GWEN_SYNCIO_FILE_FLAGS_READ); } else { sio=GWEN_SyncIo_File_new(ctxFile, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { if (!mustExist) { ctx=AB_ImExporterContext_new(); *pCtx=ctx; GWEN_SyncIo_free(sio); return 0; } GWEN_SyncIo_free(sio); return 4; } } /* actually read */ dbCtx=GWEN_DB_Group_new("context"); rv=GWEN_DB_ReadFromIo(dbCtx, sio, GWEN_DB_FLAGS_DEFAULT | GWEN_PATH_FLAGS_CREATE_GROUP); if (rv<0) { DBG_ERROR(0, "Error reading context file (%d)", rv); GWEN_DB_Group_free(dbCtx); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); ctx=AB_ImExporterContext_fromDb(dbCtx); if (!ctx) { DBG_ERROR(0, "No context in input data"); GWEN_DB_Group_free(dbCtx); return GWEN_ERROR_BAD_DATA; } GWEN_DB_Group_free(dbCtx); *pCtx=ctx; return 0; }
int test1(int argc, char **argv) { GWEN_XML_CONTEXT *xmlCtx; GWEN_SYNCIO *sio; int rv; HTML_PROPS *pr; HTML_FONT *fnt; HTML_OBJECT_TREE *ot; if (argc<2) { fprintf(stderr, "Name of testfile needed.\n"); return 1; } sio=GWEN_SyncIo_File_new(argv[1], GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_ERROR(0, "here (%d)", rv); GWEN_SyncIo_free(sio); return 2; } xmlCtx=HtmlCtx_new(0); assert(xmlCtx); pr=HtmlProps_new(); fnt=HtmlCtx_GetFont(xmlCtx, "times new roman", 12, 0); HtmlProps_SetFont(pr, fnt); HtmlFont_free(fnt); HtmlCtx_SetStandardProps(xmlCtx, pr); HtmlProps_free(pr); /* read OFX file into context */ rv=GWEN_XMLContext_ReadFromIo(xmlCtx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; } ot=HtmlCtx_GetObjects(xmlCtx); if (ot) { HTML_OBJECT *o; o=HtmlObject_Tree_GetFirst(ot); dumpObject(o, stderr, 2); } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(xmlCtx); return 0; }
int writeContext(const char *ctxFile, const AB_IMEXPORTER_CONTEXT *ctx) { GWEN_DB_NODE *dbCtx; GWEN_SYNCIO *sio; int rv; if (ctxFile==NULL) { sio=GWEN_SyncIo_File_fromStdout(); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FLAGS_DONTCLOSE | GWEN_SYNCIO_FILE_FLAGS_WRITE); } else { sio=GWEN_SyncIo_File_new(ctxFile, GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE | GWEN_SYNCIO_FILE_FLAGS_GREAD | GWEN_SYNCIO_FILE_FLAGS_GWRITE); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_ERROR(0, "Error selecting output file: %s", strerror(errno)); GWEN_SyncIo_free(sio); return 4; } } dbCtx=GWEN_DB_Group_new("context"); rv=AB_ImExporterContext_toDb(ctx, dbCtx); if (rv<0) { DBG_ERROR(0, "Error writing context to db (%d)", rv); GWEN_DB_Group_free(dbCtx); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; } rv=GWEN_DB_WriteToIo(dbCtx, sio, GWEN_DB_FLAGS_DEFAULT); if (rv<0) { DBG_ERROR(0, "Error writing context (%d)", rv); } else rv=0; GWEN_DB_Group_free(dbCtx); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; }
void GWEN_Process_free(GWEN_PROCESS *pr) { if (pr) { assert(pr->usage); if (--(pr->usage)==0) { /* unlink from list */ GWEN_LIST_DEL(GWEN_PROCESS, pr, &GWEN_Process_ProcessList); GWEN_SyncIo_free(pr->stdIn); GWEN_SyncIo_free(pr->stdOut); GWEN_SyncIo_free(pr->stdErr); GWEN_FREE_OBJECT(pr); } } }
int AB_ImExporterYN_CheckFile(AB_IMEXPORTER *ie, const char *fname) { AB_IMEXPORTER_YELLOWNET *ieh; GWEN_SYNCIO *sio; int rv; uint8_t tbuf[256]; assert(ie); assert(fname); assert(ie); ieh=GWEN_INHERIT_GETDATA(AB_IMEXPORTER, AB_IMEXPORTER_YELLOWNET, ie); assert(ieh); sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); return rv; } rv=GWEN_SyncIo_Read(sio, tbuf, sizeof(tbuf)-1); if (rv<1) { DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is not supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_ERROR_BAD_DATA; } tbuf[rv-1]=0; if (-1!=GWEN_Text_ComparePattern((const char *)tbuf, "*<?xml*", 0) && -1!=GWEN_Text_ComparePattern((const char *)tbuf, "*<KONAUS>*", 0)) { /* match */ DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return 0; } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_ERROR_BAD_DATA; }
GWEN_DBIO_CHECKFILE_RESULT GWEN_DBIO_XmlDb_CheckFile(GWEN_DBIO *dbio, const char *fname){ GWEN_SYNCIO *sio; int rv; uint8_t tbuf[256]; assert(dbio); assert(fname); sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); return GWEN_DBIO_CheckFileResultNotOk; } rv=GWEN_SyncIo_Read(sio, tbuf, sizeof(tbuf)-1); if (rv<1) { DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is not supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_DBIO_CheckFileResultNotOk; } tbuf[rv-1]=0; if (-1!=GWEN_Text_ComparePattern((const char*) tbuf, "*<?xml*", 0)) { /* match */ DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" is supported by this plugin", fname); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); /* don't be too sure about this, we *may* support the file, * so we dont say we don't support this file */ return GWEN_DBIO_CheckFileResultUnknown; } GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return GWEN_DBIO_CheckFileResultNotOk; }
int GWEN_XMLNode_WriteFile(const GWEN_XMLNODE *n, const char *fname, uint32_t flags) { GWEN_XML_CONTEXT *ctx; GWEN_SYNCIO *sio; int rv; sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sio); return rv; } /* create context and io layers */ ctx=GWEN_XmlCtxStore_new(NULL, flags); /* write data to stream */ rv=GWEN_XMLNode_WriteToStream(n, ctx, sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); return rv; } /* close file */ GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); GWEN_XmlCtx_free(ctx); return 0; }
int AB_ImExporter_ExportToBuffer(AB_IMEXPORTER *ie, AB_IMEXPORTER_CONTEXT *ctx, GWEN_BUFFER *buf, GWEN_DB_NODE *dbProfile) { int rv; GWEN_SYNCIO *sio; assert(ie); assert(ctx); assert(buf); assert(dbProfile); /* create io layer for this file (readonly) */ sio=GWEN_SyncIo_Memory_new(buf, 0); rv=AB_ImExporter_Export(ie, ctx, sio, dbProfile); GWEN_SyncIo_free(sio); return rv; }
int mkPinList(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; AB_PROVIDER *pro; GWEN_SYNCIO *sio; AB_USER_LIST2 *ul; int rv; const char *outFile; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "outFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "o", /* short option */ "outfile", /* long option */ "Specify the name of the output file", /* short description */ "Specify the name of the output file" /* long description */ }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */ "help", /* name */ 0, /* minnum */ 0, /* maxnum */ "h", /* short option */ "help", /* long option */ "Show this help screen", /* short description */ "Show this help screen" /* long description */ } }; db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local"); rv=GWEN_Args_Check(argc, argv, 1, 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/, args, db); if (rv==GWEN_ARGS_RESULT_ERROR) { fprintf(stderr, "ERROR: Could not parse arguments\n"); return 1; } else if (rv==GWEN_ARGS_RESULT_HELP) { GWEN_BUFFER *ubuf; ubuf=GWEN_Buffer_new(0, 1024, 0, 1); if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) { fprintf(stderr, "ERROR: Could not create help string\n"); return 1; } fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf)); GWEN_Buffer_free(ubuf); return 0; } outFile=GWEN_DB_GetCharValue(db, "outfile", 0, 0); rv=AB_Banking_Init(ab); if (rv) { DBG_ERROR(0, "Error on init (%d)", rv); return 2; } rv=AB_Banking_OnlineInit(ab); if (rv) { DBG_ERROR(0, "Error on init (%d)", rv); return 2; } pro=AB_Banking_GetProvider(ab, "aqebics"); assert(pro); if (outFile==0) { sio=GWEN_SyncIo_File_fromStdout(); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FLAGS_DONTCLOSE); } else { sio=GWEN_SyncIo_File_new(outFile, GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE | GWEN_SYNCIO_FILE_FLAGS_GREAD | GWEN_SYNCIO_FILE_FLAGS_GWRITE); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_ERROR(0, "Error opening output file: %s", strerror(errno)); return 4; } } GWEN_SyncIo_WriteLine(sio, "# This is a PIN file to be used " "with AqBanking"); GWEN_SyncIo_WriteLine(sio, "# Please insert the PINs/passwords " "for the users below"); ul=AB_Banking_FindUsers(ab, "aqebics", "*", "*", "*", "*"); if (ul) { AB_USER_LIST2_ITERATOR *uit; uit=AB_User_List2_First(ul); if (uit) { AB_USER *u; u=AB_User_List2Iterator_Data(uit); assert(u); while(u) { const char *s; GWEN_BUFFER *nbuf; int rv; GWEN_SyncIo_WriteLine(sio, ""); GWEN_SyncIo_WriteString(sio, "# User \""); s=AB_User_GetUserId(u); assert(s); GWEN_SyncIo_WriteString(sio, s); GWEN_SyncIo_WriteString(sio, "\" at \""); s=AB_User_GetBankCode(u); GWEN_SyncIo_WriteString(sio, s); GWEN_SyncIo_WriteLine(sio, "\""); nbuf=GWEN_Buffer_new(0, 256 ,0 ,1); rv=EBC_User_MkPasswdName(u, nbuf); if (rv==0) { GWEN_BUFFER *obuf; obuf=GWEN_Buffer_new(0, 256 ,0 ,1); if (GWEN_Text_EscapeToBufferTolerant(GWEN_Buffer_GetStart(nbuf), obuf)) { DBG_ERROR(0, "Error escaping name to buffer"); return 3; } GWEN_SyncIo_WriteString(sio, GWEN_Buffer_GetStart(obuf)); GWEN_SyncIo_WriteLine(sio, " = \"\""); GWEN_Buffer_free(obuf); } GWEN_Buffer_free(nbuf); u=AB_User_List2Iterator_Next(uit); } AB_User_List2Iterator_free(uit); } AB_User_List2_free(ul); } rv=GWEN_SyncIo_Disconnect(sio); if (rv<0) { DBG_ERROR_ERR(0, rv); GWEN_SyncIo_free(sio); return 4; } GWEN_SyncIo_free(sio); rv=AB_Banking_OnlineFini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }
int write_hp_file_c(ARGUMENTS *args, GWEN_XMLNODE *node) { int rv; const char *f; GWEN_BUFFER *fname; GWEN_BUFFER *hbuf; const char *s; GWEN_SYNCIO *sio; int err; const char *nacc; const char *constAcc; const char *constName; const char *fromDbAcc; const char *fromDbName; const char *dupAcc; const char *dupName; const char *id; const char *prefix; id=get_struct_property(node, "id", 0); if (!id) { DBG_ERROR(0, "No id for struct"); return -1; } prefix=get_struct_property(node, "prefix", 0); if (!prefix) { DBG_ERROR(0, "No prefix for struct"); return -1; } f=get_struct_property(node, "filename", 0); if (!f) { DBG_ERROR(0, "No filename given"); return -1; } nacc=get_struct_property(node, "access", "public"); constAcc=get_struct_property(node, "constructor-access", nacc); constName=get_struct_property(node, "constructor-name", 0); fromDbAcc=get_struct_property(node, "fromdb-access", nacc); fromDbName=get_struct_property(node, "fromdb-name", 0); dupAcc=get_struct_property(node, "dup-access", nacc); dupName=get_struct_property(node, "fromdb-name", 0); fname=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(fname, f); GWEN_Buffer_AppendString(fname, "_p.h"); sio=GWEN_SyncIo_File_new(GWEN_Buffer_GetStart(fname), GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE | GWEN_SYNCIO_FILE_FLAGS_GREAD | GWEN_SYNCIO_FILE_FLAGS_GWRITE); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_ERROR(0, "open(%s): %s", GWEN_Buffer_GetStart(fname), strerror(errno)); GWEN_Buffer_free(fname); GWEN_SyncIo_free(sio); return -1; } GWEN_Buffer_free(fname); /* Insert the auto-generation warning */ GWEN_SyncIo_WriteString(sio, "/* This file is auto-generated from \""); GWEN_SyncIo_WriteString(sio, f); GWEN_SyncIo_WriteLine(sio, ".xml\" by the typemaker"); GWEN_SyncIo_WriteLine(sio, " tool of Gwenhywfar. "); GWEN_SyncIo_WriteLine(sio, " Do not edit this file -- all changes will be lost! */"); hbuf=GWEN_Buffer_new(0, 256, 0, 1); s=f; while (*s) { GWEN_Buffer_AppendByte(hbuf, toupper(*s)); s++; } GWEN_Buffer_AppendString(hbuf, "_P_H"); GWEN_SyncIo_WriteString(sio, "#ifndef "); GWEN_SyncIo_WriteLine(sio, GWEN_Buffer_GetStart(hbuf)); GWEN_SyncIo_WriteString(sio, "#define "); GWEN_SyncIo_WriteLine(sio, GWEN_Buffer_GetStart(hbuf)); GWEN_SyncIo_WriteLine(sio, ""); if (strcasecmp(get_struct_property(node, "inherit", ""), "private")==0) { GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/inherit.h>"); } if (strcasecmp(get_struct_property(node, "list", ""), "private")==0) { GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/misc.h>"); } if (strcasecmp(get_struct_property(node, "list2", ""), "private")==0) { GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/list2.h>"); } fname=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(fname, f); GWEN_Buffer_AppendString(fname, "_l.h"); GWEN_SyncIo_WriteString(sio, "#include \""); GWEN_SyncIo_WriteString(sio, GWEN_Buffer_GetStart(fname)); GWEN_SyncIo_WriteLine(sio, "\""); GWEN_Buffer_free(fname); GWEN_SyncIo_WriteLine(sio, ""); rv=write_h_struct_c(args, node, sio); if (rv) { GWEN_Buffer_free(hbuf); GWEN_SyncIo_free(sio); return rv; } GWEN_SyncIo_WriteLine(sio, ""); /* include private functions */ if (strcasecmp(constAcc, "private")==0) { GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, " *"); GWEN_SyncIo_WriteString(sio, prefix); if (constName) GWEN_SyncIo_WriteString(sio, constName); else GWEN_SyncIo_WriteString(sio, "_new"); GWEN_SyncIo_WriteLine(sio, "(void);"); } /* FromDb */ if (strcasecmp(fromDbAcc, "private")==0) { GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, " *"); GWEN_SyncIo_WriteString(sio, prefix); if (fromDbName) GWEN_SyncIo_WriteString(sio, fromDbName); else GWEN_SyncIo_WriteString(sio, "_fromDb"); GWEN_SyncIo_WriteLine(sio, "(GWEN_DB_NODE *db);"); } /* dup */ if (strcasecmp(dupAcc, "private")==0) { GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, " *"); GWEN_SyncIo_WriteString(sio, prefix); if (dupName) GWEN_SyncIo_WriteString(sio, dupName); else GWEN_SyncIo_WriteString(sio, "_dup"); GWEN_SyncIo_WriteString(sio, "(const "); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, "*st);"); } if (strcasecmp(nacc, "private")==0) { GWEN_SyncIo_WriteString(sio, "void "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_free("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st);"); GWEN_SyncIo_WriteString(sio, "void "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_Attach("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st);"); /* ReadDb */ GWEN_SyncIo_WriteString(sio, "int "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_ReadDb("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st, GWEN_DB_NODE *db);"); /* ToDb */ GWEN_SyncIo_WriteString(sio, "int "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_toDb(const "); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteString(sio, "*st, GWEN_DB_NODE *db);"); GWEN_SyncIo_WriteString(sio, "int "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_IsModified(const "); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st);"); GWEN_SyncIo_WriteString(sio, "void "); GWEN_SyncIo_WriteString(sio, prefix); GWEN_SyncIo_WriteString(sio, "_SetModified("); GWEN_SyncIo_WriteString(sio, id); GWEN_SyncIo_WriteLine(sio, " *st, int i);"); } rv=write_h_setget_c(args, node, sio, "private"); if (rv) { GWEN_Buffer_free(hbuf); GWEN_SyncIo_free(sio); return rv; } /* write trailing endif */ err=GWEN_SyncIo_WriteLine(sio, ""); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_WriteString(sio, "#endif /* "); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_WriteString(sio, GWEN_Buffer_GetStart(hbuf)); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_WriteLine(sio, " */"); if (err) { DBG_ERROR_ERR(0, err); GWEN_Buffer_free(hbuf); return -1; } err=GWEN_SyncIo_Disconnect(sio); if (err) { DBG_ERROR_ERR(0, err); GWEN_SyncIo_free(sio); GWEN_Buffer_free(hbuf); return -1; } GWEN_Buffer_free(hbuf); return 0; }
/* --------------------------------------------------------------- FUNCTION */ int AH_Job_GetTransactions__ReadTransactions(AH_JOB *j, AB_IMEXPORTER_ACCOUNTINFO *ai, const char *docType, int noted, GWEN_BUFFER *buf){ GWEN_DBIO *dbio; GWEN_SYNCIO *sio; int rv; GWEN_DB_NODE *db; GWEN_DB_NODE *dbDay; GWEN_DB_NODE *dbParams; AB_ACCOUNT *a; AB_USER *u; uint32_t progressId; uint64_t cnt=0; a=AH_AccountJob_GetAccount(j); assert(a); u=AH_Job_GetUser(j); assert(u); dbio=GWEN_DBIO_GetPlugin("swift"); if (!dbio) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Plugin SWIFT is not found"); GWEN_Gui_ProgressLog(0, GWEN_LoggerLevel_Error, I18N("Plugin \"SWIFT\" not found.")); return AB_ERROR_PLUGIN_MISSING; } GWEN_Buffer_Rewind(buf); sio=GWEN_SyncIo_Memory_new(buf, 0); db=GWEN_DB_Group_new("transactions"); dbParams=GWEN_DB_Group_new("params"); GWEN_DB_SetCharValue(dbParams, GWEN_DB_FLAGS_OVERWRITE_VARS, "type", docType); if (AH_User_GetFlags(u) & AH_USER_FLAGS_KEEP_MULTIPLE_BLANKS) GWEN_DB_SetIntValue(dbParams, GWEN_DB_FLAGS_OVERWRITE_VARS, "keepMultipleBlanks", 1); else GWEN_DB_SetIntValue(dbParams, GWEN_DB_FLAGS_OVERWRITE_VARS, "keepMultipleBlanks", 0); rv=GWEN_DBIO_Import(dbio, sio, db, dbParams, GWEN_PATH_FLAGS_CREATE_GROUP); if (rv<0) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Error parsing SWIFT %s (%d)", docType, rv); GWEN_DB_Group_free(dbParams); GWEN_DB_Group_free(db); GWEN_SyncIo_free(sio); GWEN_DBIO_free(dbio); return rv; } GWEN_DB_Group_free(dbParams); GWEN_SyncIo_free(sio); GWEN_DBIO_free(dbio); /* first count the groups */ dbDay=GWEN_DB_FindFirstGroup(db, "day"); while(dbDay) { GWEN_DB_NODE *dbT; dbT=GWEN_DB_FindFirstGroup(dbDay, "transaction"); while(dbT) { cnt++; dbT=GWEN_DB_FindNextGroup(dbT, "transaction"); } /* while */ dbDay=GWEN_DB_FindNextGroup(dbDay, "day"); } /* while */ progressId=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY | GWEN_GUI_PROGRESS_ALLOW_EMBED | GWEN_GUI_PROGRESS_SHOW_PROGRESS | GWEN_GUI_PROGRESS_SHOW_ABORT, I18N("Importing transactions..."), NULL, cnt, 0); /* add transactions to list */ dbDay=GWEN_DB_FindFirstGroup(db, "day"); while(dbDay) { GWEN_DB_NODE *dbT; dbT=GWEN_DB_FindFirstGroup(dbDay, "transaction"); while(dbT) { AB_TRANSACTION *t; t=AB_Transaction_fromDb(dbT); if (!t) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Bad transaction data:"); GWEN_DB_Dump(dbT, 2); } else { const char *s; AB_Transaction_SetLocalBankCode(t, AB_User_GetBankCode(u)); AB_Transaction_SetLocalAccountNumber(t, AB_Account_GetAccountNumber(a)); /* some translations */ s=AB_Transaction_GetRemoteIban(t); if (!(s && *s)) { const char *sAid; /* no remote IBAN set, check whether the bank sends this info in the * fields for national account specifications (instead of the SWIFT * field "?38" which was specified for this case) */ sAid=AB_Transaction_GetRemoteAccountNumber(t); if (sAid && *sAid && AB_Banking_CheckIban(sAid)==0) { /* there is a remote account number specification, and that is an IBAN, * so we set that accordingly */ DBG_INFO(AQBANKING_LOGDOMAIN, "Setting remote IBAN from account number"); AB_Transaction_SetRemoteIban(t, sAid); /* set remote BIC if it not already is */ s=AB_Transaction_GetRemoteBic(t); if (!(s && *s)) { const char *sBid; sBid=AB_Transaction_GetRemoteBankCode(t); if (sBid && *sBid) { DBG_INFO(AQBANKING_LOGDOMAIN, "Setting remote BIC from bank code"); AB_Transaction_SetRemoteBic(t, sBid); } } } } DBG_INFO(AQHBCI_LOGDOMAIN, "Adding transaction"); if (noted) AB_ImExporterAccountInfo_AddNotedTransaction(ai, t); else AB_ImExporterAccountInfo_AddTransaction(ai, t); } if (GWEN_ERROR_USER_ABORTED== GWEN_Gui_ProgressAdvance(progressId, GWEN_GUI_PROGRESS_ONE)) { GWEN_Gui_ProgressEnd(progressId); return GWEN_ERROR_USER_ABORTED; } dbT=GWEN_DB_FindNextGroup(dbT, "transaction"); } /* while */ /* read all endsaldos */ if (!noted) { dbT=GWEN_DB_FindFirstGroup(dbDay, "endSaldo"); while (dbT) { GWEN_DB_NODE *dbX; GWEN_TIME *ti=0; dbX=GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "date"); if (dbX) ti=GWEN_Time_fromDb(dbX); dbX=GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "value"); if (dbX) { AB_VALUE *v; v=AB_Value_fromDb(dbX); if (v) { AB_BALANCE *bal; AB_ACCOUNT_STATUS *as; bal=AB_Balance_new(v, ti); AB_Value_free(v); as=AB_AccountStatus_new(); if (ti) AB_AccountStatus_SetTime(as, ti); AB_AccountStatus_SetNotedBalance(as, bal); AB_Balance_free(bal); AB_ImExporterAccountInfo_AddAccountStatus(ai, as); } } GWEN_Time_free(ti); dbT=GWEN_DB_FindNextGroup(dbT, "endSaldo"); } /* while */ } dbDay=GWEN_DB_FindNextGroup(dbDay, "day"); } /* while */ GWEN_Gui_ProgressEnd(progressId); GWEN_DB_Group_free(db); return 0; }
static int _readLogFile(const char *fname, GWEN_DB_NODE *db) { GWEN_SYNCIO *sio; GWEN_FAST_BUFFER *fb; int rv; GWEN_BUFFER *tbuf = NULL; sio=GWEN_SyncIo_File_new(fname, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_ERROR(0, "Error opening file [%s] (%d)", fname, rv); return rv; } /* create fast buffer around io layer */ fb=GWEN_FastBuffer_new(1024, sio); for (;;) { GWEN_DB_NODE *dbMsg; GWEN_DB_NODE *dbHeader; unsigned int size; /* read header */ dbMsg=GWEN_DB_Group_new("Message"); dbHeader=GWEN_DB_GetGroup(dbMsg, GWEN_DB_FLAGS_DEFAULT, "header"); rv=GWEN_DB_ReadFromFastBuffer(dbHeader, fb, GWEN_DB_FLAGS_HTTP | GWEN_DB_FLAGS_UNTIL_EMPTY_LINE); if (rv<0) { if (rv==GWEN_ERROR_EOF) break; else { GWEN_DB_Group_free(dbMsg); GWEN_FastBuffer_free(fb); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); DBG_ERROR(0, "Error reading header from file [%s] (%d)", fname, rv); GWEN_DB_Dump(db, 2); return rv; } } /* read body */ size=GWEN_DB_GetIntValue(dbHeader, "size", 0, 0); tbuf=GWEN_Buffer_new(0, 2048, 0, 1); while(size) { unsigned int lsize; uint8_t buffer[1024]; lsize=size; if (lsize>sizeof(buffer)) lsize=sizeof(buffer); GWEN_FASTBUFFER_READFORCED(fb, rv, buffer, lsize); if (rv<0) { GWEN_DB_Group_free(dbMsg); GWEN_FastBuffer_free(fb); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); DBG_ERROR(0, "Error reading body from file [%s] (%d)", fname, rv); return rv; } GWEN_Buffer_AppendBytes(tbuf, (const char*)buffer, lsize); size-=lsize; } // while GWEN_DB_SetBinValue(dbMsg, GWEN_DB_FLAGS_OVERWRITE_VARS, "body", GWEN_Buffer_GetStart(tbuf), GWEN_Buffer_GetUsedBytes(tbuf)); GWEN_Buffer_Reset(tbuf); GWEN_DB_AddGroup(db, dbMsg); } GWEN_Buffer_free(tbuf); GWEN_FastBuffer_free(fb); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return 0; }
int logFile(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { int rv; GWEN_DB_NODE *db; GWEN_DB_NODE *dbMessages; const char *s; GWEN_MSGENGINE *e; GWEN_SYNCIO *sioOut=NULL; GWEN_SYNCIO *sioDb=NULL; const char *inFile; const char *outFile; const char *dbOutFile; int i; GWEN_DB_NODE *dbT; int trustLevel; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "xmlfile", /* name */ 0, /* minnum */ 99, /* maxnum */ "x", /* short option */ "xmlfile", /* long option */ "Specify XML files to load", /* short description */ "Specify XML files to load" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "infile", /* name */ 1, /* minnum */ 1, /* maxnum */ "i", /* short option */ "infile", /* long option */ "Specify input file", /* short description */ "Specify input file" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "outfile", /* name */ 0, /* minnum */ 1, /* maxnum */ "o", /* short option */ "outfile", /* long option */ "Specify output file", /* short description */ "Specify output file" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "dboutfile", /* name */ 0, /* minnum */ 1, /* maxnum */ "d", /* short option */ "dbfile", /* long option */ "Specify DB output file", /* short description */ "Specify DB output file" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Int, /* type */ "trustLevel", /* name */ 0, /* minnum */ 1, /* maxnum */ "L", /* short option */ "trustlevel", /* long option */ "Specify the trust level", /* short description */ "Specify the trust level" /* long description */ }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */ "help", /* name */ 0, /* minnum */ 0, /* maxnum */ "h", /* short option */ "help", /* long option */ "Show this help screen", /* short description */ "Show this help screen" /* long description */ } }; db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local"); rv=GWEN_Args_Check(argc, argv, 1, 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/, args, db); if (rv==GWEN_ARGS_RESULT_ERROR) { fprintf(stderr, "ERROR: Could not parse arguments\n"); return 1; } else if (rv==GWEN_ARGS_RESULT_HELP) { GWEN_BUFFER *ubuf; ubuf=GWEN_Buffer_new(0, 1024, 0, 1); if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) { fprintf(stderr, "ERROR: Could not create help string\n"); return 1; } fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf)); GWEN_Buffer_free(ubuf); return 0; } trustLevel=GWEN_DB_GetIntValue(db, "trustLevel", 0, 0); outFile=GWEN_DB_GetCharValue(db, "outFile", 0, NULL); dbOutFile=GWEN_DB_GetCharValue(db, "dbOutFile", 0, NULL); inFile=GWEN_DB_GetCharValue(db, "inFile", 0, NULL); assert(inFile); /* do it */ dbMessages=GWEN_DB_Group_new("Messages"); rv=_readLogFile(inFile, dbMessages); if (rv<0) { DBG_ERROR(0, "Error reading message (%d)", rv); return 2; } /* create message engine, read XML definitions */ e=AH_MsgEngine_new(); for (i=0; i<99; i++) { s=GWEN_DB_GetCharValue(dbArgs, "xmlfile", i, NULL); if (s && *s) { GWEN_XMLNODE *defs; defs=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "defs"); if (GWEN_XML_ReadFile(defs, s, GWEN_XML_FLAGS_DEFAULT)){ fprintf(stderr, "Error parsing.\n"); GWEN_MsgEngine_free(e); return 2; } GWEN_MsgEngine_AddDefinitions(e, defs); GWEN_XMLNode_free(defs); } else { if (i==0) { GWEN_XMLNODE *defs; defs=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "defs"); if (GWEN_XML_ReadFile(defs, XMLDATA_DIR "/hbci.xml", GWEN_XML_FLAGS_DEFAULT)){ fprintf(stderr, "Error parsing.\n"); GWEN_MsgEngine_free(e); return 2; } GWEN_MsgEngine_AddDefinitions(e, defs); GWEN_XMLNode_free(defs); } break; } } if (outFile) { sioOut=GWEN_SyncIo_File_new(outFile, GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sioOut, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE | GWEN_SYNCIO_FILE_FLAGS_APPEND); rv=GWEN_SyncIo_Connect(sioOut); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sioOut); return 2; } } if (dbOutFile) { sioDb=GWEN_SyncIo_File_new(dbOutFile, GWEN_SyncIo_File_CreationMode_CreateAlways); GWEN_SyncIo_AddFlags(sioDb, GWEN_SYNCIO_FILE_FLAGS_READ | GWEN_SYNCIO_FILE_FLAGS_WRITE | GWEN_SYNCIO_FILE_FLAGS_UREAD | GWEN_SYNCIO_FILE_FLAGS_UWRITE | GWEN_SYNCIO_FILE_FLAGS_APPEND); rv=GWEN_SyncIo_Connect(sioDb); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sioDb); return 2; } } dbT=GWEN_DB_GetFirstGroup(dbMessages); while(dbT) { const uint8_t *p; uint32_t len; GWEN_DB_NODE *dbHeader; dbHeader=GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "header"); assert(dbHeader); s=GWEN_DB_GetCharValue(dbHeader, "mode", 0, "PINTAN"); GWEN_MsgEngine_SetMode(e, s); i=GWEN_DB_GetIntValue(dbHeader, "hbciVersion", 0, 220); GWEN_MsgEngine_SetProtocolVersion(e, i); p=GWEN_DB_GetBinValue(dbT, "body", 0, NULL, 0, &len); if (p && len) { GWEN_BUFFER *tbuf; GWEN_DB_NODE *gr; GWEN_MSGENGINE_TRUSTEDDATA *trustedData; GWEN_MSGENGINE_TRUSTEDDATA *ntd; GWEN_DB_NODE *repl; gr=GWEN_DB_Group_new("message"); tbuf=GWEN_Buffer_new((char*) p, len, len, 0); rv=GWEN_MsgEngine_ReadMessage(e, "SEG", tbuf, gr, GWEN_MSGENGINE_READ_FLAGS_TRUSTINFO); if (rv) { fprintf(stderr, "ERROR.\n"); GWEN_Buffer_Dump(tbuf, 2); return 2; } /* work on trust data */ trustedData=GWEN_MsgEngine_TakeTrustInfo(e); if (trustedData) { if (GWEN_MsgEngine_TrustedData_CreateReplacements(trustedData)) { fprintf(stderr, "Could not anonymize log (createReplacements)\n"); GWEN_MsgEngine_TrustedData_free(trustedData); GWEN_MsgEngine_free(e); return 2; } } /* anonymize file */ ntd=trustedData; repl=GWEN_DB_GetGroup(dbHeader, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "replacements"); assert(repl); while(ntd) { if (GWEN_MsgEngine_TrustedData_GetTrustLevel(ntd)>trustLevel) { int pos; unsigned int size; char rbuffer[3]; const char *rpstr; rpstr=GWEN_MsgEngine_TrustedData_GetReplacement(ntd); assert(rpstr); assert(*rpstr); size=strlen(rpstr); if (size==1) { rbuffer[0]=rpstr[0]; rbuffer[1]=0; } else { rbuffer[0]=rpstr[0]; rbuffer[1]=rpstr[1]; rbuffer[2]=0; } GWEN_DB_SetCharValue(repl, GWEN_DB_FLAGS_DEFAULT | GWEN_PATH_FLAGS_CREATE_VAR, rbuffer, GWEN_MsgEngine_TrustedData_GetDescription(ntd)); size=GWEN_MsgEngine_TrustedData_GetSize(ntd); pos=GWEN_MsgEngine_TrustedData_GetFirstPos(ntd); while(pos>=0) { DBG_INFO(0, "Replacing %d bytes at %d", size, pos); GWEN_Buffer_SetPos(tbuf, pos); GWEN_Buffer_ReplaceBytes(tbuf, size, GWEN_MsgEngine_TrustedData_GetReplacement(ntd), size); pos=GWEN_MsgEngine_TrustedData_GetNextPos(ntd); } // while pos } ntd=GWEN_MsgEngine_TrustedData_GetNext(ntd); } // while ntd GWEN_DB_SetIntValue(dbHeader, GWEN_DB_FLAGS_OVERWRITE_VARS, "size", GWEN_Buffer_GetUsedBytes(tbuf)); if (outFile) { rv=dumpMsg(sioOut, dbHeader, (const uint8_t*)GWEN_Buffer_GetStart(tbuf), GWEN_Buffer_GetUsedBytes(tbuf)); if (rv<0) { fprintf(stderr, "Could not anonymize log (dumpMsg)\n"); GWEN_MsgEngine_TrustedData_free(trustedData); GWEN_MsgEngine_free(e); return 2; } } if (dbOutFile) { GWEN_BUFFER *xbuf; GWEN_DB_NODE *dbOut; xbuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(xbuf, "# ========== Message ( "); s=GWEN_DB_GetCharValue(dbHeader, "sender", 0, "UNK"); if (s && *s) { GWEN_Buffer_AppendString(xbuf, "sender="); GWEN_Buffer_AppendString(xbuf, s); GWEN_Buffer_AppendString(xbuf, " "); } s=GWEN_DB_GetCharValue(dbHeader, "crypt", 0, "UNK"); if (s && *s) { GWEN_Buffer_AppendString(xbuf, "crypt="); GWEN_Buffer_AppendString(xbuf, s); GWEN_Buffer_AppendString(xbuf, " "); } GWEN_Buffer_AppendString(xbuf, ") ==========\n"); dbOut=GWEN_DB_Group_new("Message"); GWEN_Buffer_Rewind(tbuf); rv=GWEN_MsgEngine_ReadMessage(e, "SEG", tbuf, dbOut, 0); if (rv) { fprintf(stderr, "ERROR.\n"); GWEN_Buffer_Dump(tbuf, 2); return 2; } rv=GWEN_SyncIo_WriteForced(sioDb, (const uint8_t*) GWEN_Buffer_GetStart(xbuf), GWEN_Buffer_GetUsedBytes(xbuf)); GWEN_Buffer_free(xbuf); if (rv<0) { DBG_INFO(0, "here (%d)", rv); return rv; } rv=GWEN_DB_WriteToIo(dbOut, sioDb, GWEN_DB_FLAGS_DEFAULT); if (rv<0) { DBG_INFO(0, "here (%d)", rv); return 2; } /* append empty line to separate header from data */ rv=GWEN_SyncIo_WriteForced(sioDb, (const uint8_t*) "\n", 1); if (rv<0) { DBG_INFO(0, "here (%d)", rv); return rv; } } GWEN_Buffer_free(tbuf); } dbT=GWEN_DB_GetNextGroup(dbT); } /* close output layer */ if (outFile) { rv=GWEN_SyncIo_Disconnect(sioOut); if (rv<0) { DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sioOut); return 2; } GWEN_SyncIo_free(sioOut); } if (dbOutFile) { rv=GWEN_SyncIo_Disconnect(sioDb); if (rv<0) { DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv); GWEN_SyncIo_free(sioDb); return 2; } GWEN_SyncIo_free(sioDb); } return 0; }
static int readTestData(GWEN_DIALOG *dlg) { AB_CSV_EDIT_PROFILE_DIALOG *xdlg; GWEN_SYNCIO *sio; GWEN_SYNCIO *baseIo; GWEN_BUFFER *dbuf; int i; int ignoreLines=0; int rv; const char *delimiter; GWEN_BUFFER *wbuffer; const char *s; assert(dlg); xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AB_CSV_EDIT_PROFILE_DIALOG, dlg); assert(xdlg); GWEN_StringList_Clear(xdlg->columns); /* create file IO */ sio=GWEN_SyncIo_File_new(xdlg->testFileName, GWEN_SyncIo_File_CreationMode_OpenExisting); GWEN_SyncIo_AddFlags(sio, GWEN_SYNCIO_FILE_FLAGS_READ); baseIo=sio; /* create buffered IO on top of file io to allow for reading of lines below */ sio=GWEN_SyncIo_Buffered_new(baseIo); dbuf=GWEN_Buffer_new(0, 1024, 0, 1); /* skip lines */ ignoreLines=GWEN_Dialog_GetIntProperty(dlg, "ignoreLinesSpin", GWEN_DialogProperty_Value, 0, 0); i=GWEN_Dialog_GetIntProperty(dlg, "headerCheck", GWEN_DialogProperty_Value, 0, 0); if (i) ignoreLines++; delimiter=getCharValueFromDoubleStringsCombo(dlg, "delimiterCombo", csv_delimiters); if (!(delimiter && *delimiter)) delimiter="TAB"; if (strcasecmp(delimiter, "TAB")==0) delimiter="\t"; else if (strcasecmp(delimiter, "SPACE")==0) delimiter=" "; /* open file */ rv=GWEN_SyncIo_Connect(sio); if (rv<0) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(dbuf); GWEN_SyncIo_free(sio); return rv; } for (i=0; i<ignoreLines; i++) { rv=GWEN_SyncIo_Buffered_ReadLineToBuffer(sio, dbuf); if (rv<0) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error reading: %d", rv); GWEN_Buffer_free(dbuf); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; } GWEN_Buffer_Reset(dbuf); } /* read single data line */ rv=GWEN_SyncIo_Buffered_ReadLineToBuffer(sio, dbuf); if (rv<0) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error reading: %d", rv); GWEN_Buffer_free(dbuf); GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); return rv; } GWEN_Dialog_SetCharProperty(dlg, "dataEdit", GWEN_DialogProperty_Value, 0, GWEN_Buffer_GetStart(dbuf), 0); /* we don't need the io layer any longer */ GWEN_SyncIo_Disconnect(sio); GWEN_SyncIo_free(sio); wbuffer=GWEN_Buffer_new(0, 256, 0, 1); s=GWEN_Buffer_GetStart(dbuf); while (*s) { rv=GWEN_Text_GetWordToBuffer(s, delimiter, wbuffer, GWEN_TEXT_FLAGS_DEL_LEADING_BLANKS | GWEN_TEXT_FLAGS_DEL_TRAILING_BLANKS | GWEN_TEXT_FLAGS_NULL_IS_DELIMITER | GWEN_TEXT_FLAGS_DEL_QUOTES, &s); if (rv) { DBG_DEBUG(AQBANKING_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(wbuffer); GWEN_Buffer_free(dbuf); return rv; } GWEN_StringList_AppendString(xdlg->columns, GWEN_Buffer_GetStart(wbuffer), 0, 0); GWEN_Buffer_Reset(wbuffer); if (*s) { if (strchr(delimiter, *s)) s++; } } /* while */ GWEN_Buffer_free(wbuffer); for (i=0; i<DIALOG_MAX_COLUMNS; i++) { char editName[32]; snprintf(editName, sizeof(editName)-1, "col%dDataEdit", i+1); s=GWEN_StringList_StringAt(xdlg->columns, i); if (s==NULL) break; GWEN_Dialog_SetCharProperty(dlg, editName, GWEN_DialogProperty_Value, 0, s, 0); } return 0; }