int testPcsc9(int argc, char **argv) { LC_CLIENT *cl; LC_CLIENT_RESULT res; LC_CARD *card; GWEN_BUFFER *mbuf; LC_PININFO *pi; int triesLeft=-1; fprintf(stderr, "\n"); fprintf(stderr, "====================================================\n"); fprintf(stderr, "I This test will verify the PIN of the card and I\n"); fprintf(stderr, "I dump the first bank information I\n"); fprintf(stderr, "====================================================\n"); fprintf(stderr, "\n"); cl=LC_Client_new("test", "0.1"); if (!cl) { fprintf(stderr, "ERROR: Could not create client.\n"); return 1; } res=LC_Client_Init(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not init client (%d).\n", res); return 2; } res=LC_Client_Start(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not start using cards (%d).\n", res); return 2; } res=LC_Client_GetNextCard(cl, &card, 20); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: No card found (%d).\n", res); return 2; } fprintf(stderr, "Got this card:\n"); LC_Card_Dump(card, 2); if (LC_ZkaCard_ExtendCard(card)) { fprintf(stderr, "ERROR: Could not extend card as ZKA card\n"); return 2; } fprintf(stderr, "INFO: Opening card\n"); res=LC_Card_Open(card); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Unable to open card (%d).\n", res); return 2; } fprintf(stderr, "Response was %d\n", res); fprintf(stderr, "Selecting MF...\n"); res=LC_Card_SelectMf(card); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } fprintf(stderr, "Response was %d\n", res); fprintf(stderr, "Selecting DF_NOTEPAD...\n"); res=LC_Card_SelectDf(card, "DF_NOTEPAD"); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } fprintf(stderr, "Response was %d\n", res); pi=LC_Card_GetPinInfoByName(card, "ch_pin"); if (pi==NULL) { fprintf(stderr, "ERROR: Pin Info not found.\n"); return 2; } #if 0 if (pi) { GWEN_DB_NODE *dbDEBUG; dbDEBUG=GWEN_DB_Group_new("PinInfo"); LC_PinInfo_toDb(pi, dbDEBUG); GWEN_DB_Dump(dbDEBUG, 2); GWEN_DB_Group_free(dbDEBUG); } #endif fprintf(stderr, "Verifying pin...\n"); res=LC_Card_IsoPerformVerification(card, 0, pi, &triesLeft); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } fprintf(stderr, "Response was %d\n", res); fprintf(stderr, "Selecting EF_NOTEPAD...\n"); res=LC_Card_SelectEf(card, "EF_NOTEPAD"); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } fprintf(stderr, "Response was %d\n", res); fprintf(stderr, "Reading record...\n"); mbuf=GWEN_Buffer_new(0, 256, 0, 1); res=LC_Card_IsoReadRecord(card, LC_CARD_ISO_FLAGS_RECSEL_GIVEN, 1, mbuf); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } fprintf(stderr, "Response was %d\n", res); GWEN_Text_DumpString(GWEN_Buffer_GetStart(mbuf), GWEN_Buffer_GetUsedBytes(mbuf), 2); GWEN_Buffer_Rewind(mbuf); #if 0 dbRecord=GWEN_DB_Group_new("record"); if (LC_Card_ParseRecord(card, 1, mbuf, dbRecord)) { fprintf(stderr, "Error parsing record.\n"); } else { fprintf(stderr, "Parsed record is:\n"); GWEN_DB_Dump(dbRecord, 2); } GWEN_Buffer_Reset(mbuf); if (LC_Card_CreateRecord(card, 1, mbuf, dbRecord)) { fprintf(stderr, "Error creating record.\n"); } else { fprintf(stderr, "Created record is:\n"); GWEN_Buffer_Dump(mbuf, 2); } #endif res=LC_Client_ReleaseCard(cl, card); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Unable to release card (%d).\n", res); return 2; } LC_Card_free(card); res=LC_Client_Stop(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not stop using cards (%d).\n", res); return 2; } res=LC_Client_Fini(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not fini client (%d).\n", res); return 2; } return 0; }
void AB_ImExporterContext_ClearLog(AB_IMEXPORTER_CONTEXT *iec) { assert(iec); GWEN_Buffer_Reset(iec->logs); }
int testPcsc6(int argc, char **argv) { LC_CLIENT *cl; LC_CLIENT_RESULT res; LC_CARD *card; GWEN_BUFFER *mbuf; GWEN_DB_NODE *dbRecord; cl=LC_Client_new("test", "0.1"); if (!cl) { fprintf(stderr, "ERROR: Could not create client.\n"); return 1; } res=LC_Client_Init(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not init client (%d).\n", res); return 2; } res=LC_Client_Start(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not start using cards (%d).\n", res); return 2; } res=LC_Client_GetNextCard(cl, &card, 20); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: No card found (%d).\n", res); return 2; } fprintf(stderr, "Got this card:\n"); LC_Card_Dump(card, 2); if (LC_DDVCard_ExtendCard(card)) { fprintf(stderr, "ERROR: Could not extend card as DDV card\n"); return 2; } fprintf(stderr, "INFO: Opening card\n"); res=LC_Card_Open(card); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Unable to open card (%d).\n", res); return 2; } fprintf(stderr, "Response was %d\n", res); fprintf(stderr, "Selecting EF...\n"); res=LC_Card_SelectEf(card, "EF_BNK"); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } fprintf(stderr, "Response was %d\n", res); fprintf(stderr, "Reading record...\n"); mbuf=GWEN_Buffer_new(0, 256, 0, 1); res=LC_Card_IsoReadRecord(card, LC_CARD_ISO_FLAGS_RECSEL_GIVEN, 1, mbuf); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } fprintf(stderr, "Response was %d\n", res); GWEN_Text_DumpString(GWEN_Buffer_GetStart(mbuf), GWEN_Buffer_GetUsedBytes(mbuf), 2); GWEN_Buffer_Rewind(mbuf); dbRecord=GWEN_DB_Group_new("record"); if (LC_Card_ParseRecord(card, 1, mbuf, dbRecord)) { fprintf(stderr, "Error parsing record.\n"); } else { fprintf(stderr, "Parsed record is:\n"); GWEN_DB_Dump(dbRecord, 2); } GWEN_Buffer_Reset(mbuf); if (LC_Card_CreateRecord(card, 1, mbuf, dbRecord)) { fprintf(stderr, "Error creating record.\n"); } else { fprintf(stderr, "Created record is:\n"); GWEN_Buffer_Dump(mbuf, 2); } res=LC_Client_ReleaseCard(cl, card); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Unable to release card (%d).\n", res); return 2; } LC_Card_free(card); res=LC_Client_Stop(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not stop using cards (%d).\n", res); return 2; } res=LC_Client_Fini(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not fini client (%d).\n", res); return 2; } return 0; }
int testPcsc8(int argc, char **argv) { LC_CLIENT *cl; LC_CLIENT_RESULT res; LC_CARD *card; uint8_t cmdSelectDF[]={ 0x00, 0xa4, 0x04, 0x00, 0x07, 0xa0, 0x00, 0x00, 0x00, 0x04, 0x30, 0x60, 0x00}; uint8_t cmdReadRecord[]={ 0x00, 0xb2, 0x00, 0x0c, 0x00}; GWEN_BUFFER *mbuf; int i; cl=LC_Client_new("test", "0.1"); if (!cl) { fprintf(stderr, "ERROR: Could not create client.\n"); return 1; } res=LC_Client_Init(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not init client (%d).\n", res); return 2; } fprintf(stderr, "Client Start\n"); res=LC_Client_Start(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not start using cards (%d).\n", res); return 2; } fprintf(stderr, "GetNextCard\n"); res=LC_Client_GetNextCard(cl, &card, 20); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: No card found (%d).\n", res); return 2; } fprintf(stderr, "Got this card:\n"); LC_Card_Dump(card, 2); if (LC_ProcessorCard_ExtendCard(card)) { fprintf(stderr, "ERROR: Could not extend card as Processor card\n"); return 2; } fprintf(stderr, "INFO: Opening card\n"); res=LC_Card_Open(card); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Unable to open card (%d).\n", res); return 2; } fprintf(stderr, "Response was %d\n", res); mbuf=GWEN_Buffer_new(0, 256, 0, 1); res=LC_Card_ExecApdu(card, (const char*)cmdSelectDF, sizeof(cmdSelectDF), mbuf, LC_Client_CmdTargetCard); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); return 2; } for (i=1; i<16; i++) { cmdReadRecord[2]=i; /* record number */ res=LC_Card_ExecApdu(card, (const char*)cmdReadRecord, sizeof(cmdReadRecord), mbuf, LC_Client_CmdTargetCard); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Wait timed out.\n"); } else { fprintf(stdout, "Record=%d:\n", i); GWEN_Text_DumpString(GWEN_Buffer_GetStart(mbuf), GWEN_Buffer_GetUsedBytes(mbuf), 2); } GWEN_Buffer_Reset(mbuf); } res=LC_Client_ReleaseCard(cl, card); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Unable to release card (%d).\n", res); return 2; } LC_Card_free(card); res=LC_Client_Stop(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not stop using cards (%d).\n", res); return 2; } res=LC_Client_Fini(cl); if (res!=LC_Client_ResultOk) { fprintf(stderr, "ERROR: Could not fini client (%d).\n", res); return 2; } return 0; }
int AH_Msg_SignPinTan(AH_MSG *hmsg, GWEN_BUFFER *rawBuf, const char *signer) { AH_HBCI *h; GWEN_XMLNODE *node; GWEN_DB_NODE *cfg; GWEN_BUFFER *hbuf; int rv; char ctrlref[15]; const char *p; GWEN_MSGENGINE *e; AB_USER *su; uint32_t uFlags; char pin[64]; uint32_t tm; assert(hmsg); h=AH_Dialog_GetHbci(hmsg->dialog); assert(h); e=AH_Dialog_GetMsgEngine(hmsg->dialog); assert(e); GWEN_MsgEngine_SetMode(e, "pintan"); su=AB_Banking_FindUser(AH_HBCI_GetBankingApi(h), AH_PROVIDER_NAME, "de", "*", signer, "*"); if (!su) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Unknown user \"%s\"", signer); return GWEN_ERROR_NOT_FOUND; } uFlags=AH_User_GetFlags(su); node=GWEN_MsgEngine_FindNodeByPropertyStrictProto(e, "SEG", "id", 0, "SigHead"); if (!node) { DBG_INFO(AQHBCI_LOGDOMAIN, "Segment \"SigHead\" not found"); return GWEN_ERROR_INTERNAL; } /* for iTAN mode: set selected mode (Sicherheitsfunktion, kodiert) */ tm=AH_Msg_GetItanMethod(hmsg); if (tm==0) { tm=AH_Dialog_GetItanMethod(hmsg->dialog); if (tm) /* this is needed by AH_MsgPinTan_PrepareCryptoSeg */ AH_Msg_SetItanMethod(hmsg, tm); } /* prepare config for segment */ cfg=GWEN_DB_Group_new("sighead"); rv=AH_MsgPinTan_PrepareCryptoSeg(hmsg, su, cfg, 0, 1); if (rv) { DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv); GWEN_DB_Group_free(cfg); return rv; } /* set expected signer */ if (!(uFlags & AH_USER_FLAGS_BANK_DOESNT_SIGN)) { const char *remoteId; remoteId=AH_User_GetPeerId(su); if (!remoteId || *remoteId==0) remoteId=AB_User_GetUserId(su); assert(remoteId); assert(*remoteId); DBG_DEBUG(AQHBCI_LOGDOMAIN, "Expecting \"%s\" to sign the response", remoteId); AH_Msg_SetExpectedSigner(hmsg, remoteId); } /* store system id */ p=NULL; if (!hmsg->noSysId) p=AH_User_GetSystemId(su); if (!p) p="0"; GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "SecDetails/SecId", p); if (tm) { GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "function", tm); } /* retrieve control reference for sigtail (to be used later) */ p=GWEN_DB_GetCharValue(cfg, "ctrlref", 0, ""); if (strlen(p)>=sizeof(ctrlref)) { DBG_INFO(AQHBCI_LOGDOMAIN, "Control reference too long (14 bytes maximum)"); GWEN_DB_Group_free(cfg); return -1; } strcpy(ctrlref, p); /* create SigHead */ hbuf=GWEN_Buffer_new(0, 128+GWEN_Buffer_GetUsedBytes(rawBuf), 0, 1); GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "head/seq", hmsg->firstSegment-1); GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "signseq", 1); /* create signature head segment */ rv=GWEN_MsgEngine_CreateMessageFromNode(e, node, hbuf, cfg); GWEN_DB_Group_free(cfg); cfg=0; if (rv) { DBG_INFO(AQHBCI_LOGDOMAIN, "Could not create SigHead"); GWEN_Buffer_free(hbuf); return rv; } /* insert new SigHead at beginning of message buffer */ DBG_DEBUG(AQHBCI_LOGDOMAIN, "Inserting signature head"); GWEN_Buffer_Rewind(hmsg->buffer); GWEN_Buffer_InsertBytes(hmsg->buffer, GWEN_Buffer_GetStart(hbuf), GWEN_Buffer_GetUsedBytes(hbuf)); /* create sigtail */ DBG_DEBUG(AQHBCI_LOGDOMAIN, "Completing signature tail"); cfg=GWEN_DB_Group_new("sigtail"); GWEN_Buffer_Reset(hbuf); GWEN_DB_SetIntValue(cfg, GWEN_DB_FLAGS_DEFAULT, "head/seq", hmsg->lastSegment+1); /* store to DB */ GWEN_DB_SetBinValue(cfg, GWEN_DB_FLAGS_DEFAULT, "signature", "NOSIGNATURE", 11); GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "ctrlref", ctrlref); /* handle pin */ memset(pin, 0, sizeof(pin)); rv=AH_User_InputPin(su, pin, 4, sizeof(pin), 0); if (rv<0) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Error getting pin from medium (%d)", rv); GWEN_DB_Group_free(cfg); GWEN_Buffer_free(hbuf); memset(pin, 0, sizeof(pin)); return rv; } GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "pin", pin); AH_Msg_SetPin(hmsg, pin); memset(pin, 0, sizeof(pin)); /* handle tan */ if (hmsg->needTan) { DBG_NOTICE(AQHBCI_LOGDOMAIN, "This queue needs a TAN"); if (hmsg->usedTan) { DBG_NOTICE(AQHBCI_LOGDOMAIN, "Using existing TAN"); GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "tan", hmsg->usedTan); } else { char tan[16]; memset(tan, 0, sizeof(tan)); DBG_NOTICE(AQHBCI_LOGDOMAIN, "Asking for TAN"); rv=AH_User_InputTan(su, tan, 4, sizeof(tan)); if (rv<0) { DBG_ERROR(AQHBCI_LOGDOMAIN, "Error getting TAN from medium"); GWEN_DB_Group_free(cfg); GWEN_Buffer_free(hbuf); return rv; } GWEN_DB_SetCharValue(cfg, GWEN_DB_FLAGS_DEFAULT, "tan", tan); AH_Msg_SetTan(hmsg, tan); } } else { DBG_NOTICE(AQHBCI_LOGDOMAIN, "This queue doesn't need a TAN"); } /* get node */ node=GWEN_MsgEngine_FindNodeByPropertyStrictProto(e, "SEG", "id", 0, "SigTail"); if (!node) { DBG_INFO(AQHBCI_LOGDOMAIN, "Segment \"SigTail\"not found"); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); return GWEN_ERROR_INTERNAL; } rv=GWEN_MsgEngine_CreateMessageFromNode(e, node, hbuf, cfg); if (rv) { DBG_INFO(AQHBCI_LOGDOMAIN, "Could not create SigTail (%d)", rv); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); return rv; } /* append sigtail */ DBG_DEBUG(AQHBCI_LOGDOMAIN, "Appending signature tail"); if (GWEN_Buffer_AppendBuffer(hmsg->buffer, hbuf)) { DBG_INFO(AQHBCI_LOGDOMAIN, "here"); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); return GWEN_ERROR_MEMORY_FULL; } DBG_DEBUG(AQHBCI_LOGDOMAIN, "Appending signature tail: done"); GWEN_Buffer_free(hbuf); GWEN_DB_Group_free(cfg); /* adjust segment numbers (for next signature and message tail */ hmsg->firstSegment--; hmsg->lastSegment++; return 0; }
LC_CLIENT_RESULT LC_DDVCard_ReadInstituteData(LC_CARD *card, int idx, GWEN_DB_NODE *dbData){ LC_DDVCARD *ddv; LC_CLIENT_RESULT res; GWEN_DB_NODE *dbCurr; int i; unsigned int ctxCount; GWEN_BUFFER *buf; assert(card); ddv=GWEN_INHERIT_GETDATA(LC_CARD, LC_DDVCARD, card); assert(ddv); res=LC_Card_SelectEf(card, "EF_BNK"); if (res!=LC_Client_ResultOk) { DBG_INFO(LC_LOGDOMAIN, "here"); return res; } ctxCount=0; buf=GWEN_Buffer_new(0, 256, 0, 1); for (i=1; i<6; i++) { GWEN_Buffer_Reset(buf); res=LC_Card_IsoReadRecord(card, LC_CARD_ISO_FLAGS_RECSEL_GIVEN, idx?idx:i, buf); if (res!=LC_Client_ResultOk) break; dbCurr=GWEN_DB_Group_new("context"); GWEN_Buffer_Rewind(buf); if (LC_Card_ParseRecord(card, idx?idx:i, buf, dbCurr)) { DBG_ERROR(LC_LOGDOMAIN, "Error parsing record %d", idx?idx:i); GWEN_DB_Group_free(dbCurr); } else { const char *p1; p1=GWEN_DB_GetCharValue(dbCurr, "bankCode", 0, ""); if (p1) { char *p2; char *p3; p2=strdup(p1); while ( (p3=strchr(p2, '=')) ) { *p3='2'; } GWEN_DB_SetCharValue(dbCurr, GWEN_DB_FLAGS_OVERWRITE_VARS, "bankCode", p2); free(p2); } GWEN_DB_AddGroup(dbData, dbCurr); ctxCount++; } if (idx) break; } /* for */ GWEN_Buffer_free(buf); if (!ctxCount) { return LC_Client_ResultDataError; } return LC_Client_ResultOk; }
GWEN_PROCESS_STATE GWEN_Process_Start(GWEN_PROCESS *pr, const char *prg, const char *args) { pid_t pid; char *argv[32]; int argc; const char *p, *p2; GWEN_BUFFER *wbuf; assert(pr); if (GWEN_Process_Redirect(pr)) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirections"); pr->state=GWEN_ProcessStateNotStarted; pr->pid=-1; return GWEN_ProcessStateNotStarted; } pid=fork(); if (pid==-1) { /* error in fork */ pr->state=GWEN_ProcessStateNotStarted; pr->pid=-1; /* close all pipes */ if (pr->filesStdin[0]!=-1) { close(pr->filesStdin[0]); close(pr->filesStdin[1]); } if (pr->filesStdout[0]!=-1) { close(pr->filesStdout[0]); close(pr->filesStdout[1]); } if (pr->filesStderr[0]!=-1) { close(pr->filesStderr[0]); close(pr->filesStderr[1]); } return GWEN_ProcessStateNotStarted; } else if (pid!=0) { /* parent */ DBG_INFO(GWEN_LOGDOMAIN, "Process started with id %d", (int)pid); pr->state=GWEN_ProcessStateRunning; pr->pid=pid; /* setup redirections */ if (pr->filesStdin[0]!=-1) { close(pr->filesStdin[1]); pr->stdIn=GWEN_SyncIo_File_fromFd(pr->filesStdin[0]); } if (pr->filesStdout[0]!=-1) { close(pr->filesStdout[1]); pr->stdOut=GWEN_SyncIo_File_fromFd(pr->filesStdout[0]); } if (pr->filesStderr[0]!=-1) { close(pr->filesStderr[1]); pr->stdErr=GWEN_SyncIo_File_fromFd(pr->filesStdout[0]); } return GWEN_ProcessStateRunning; } /* child, build arguments */ argc=0; DBG_DEBUG(GWEN_LOGDOMAIN, "I'm the child process"); /* setup redirections */ if (pr->filesStdin[0]!=-1) { close(pr->filesStdin[0]); close(0); if (dup(pr->filesStdin[1])==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirection"); } } if (pr->filesStdout[0]!=-1) { close(pr->filesStdout[0]); close(1); if (dup(pr->filesStdout[1])==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirection"); } } if (pr->filesStderr[0]!=-1) { close(pr->filesStderr[0]); close(2); if (dup(pr->filesStderr[1])==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not setup redirection"); } } argv[0]=strdup(prg); argc++; p=args; wbuf=GWEN_Buffer_new(0, 256, 0, 1); while (argc<32 && *p) { while (*p && isspace((int)*p)) p++; if (!(*p)) break; if (GWEN_Text_GetWordToBuffer(p, " ", wbuf, GWEN_TEXT_FLAGS_NULL_IS_DELIMITER | GWEN_TEXT_FLAGS_DEL_QUOTES | GWEN_TEXT_FLAGS_CHECK_BACKSLASH, &p)) break; p2=GWEN_Buffer_GetStart(wbuf); argv[argc]=strdup(p2); GWEN_Buffer_Reset(wbuf); argc++; } /* while */ GWEN_Buffer_free(wbuf); argv[argc]=0; /* parameters ready, exec */ execvp(prg, argv); /* if we reach this point an error occurred */ DBG_ERROR(GWEN_LOGDOMAIN, "Could not start program \"%s\": %s", prg, strerror(errno)); exit(EXIT_FAILURE); }
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; }
int GWEN_XML_ReadFromFastBuffer(GWEN_XML_CONTEXT *ctx, GWEN_FAST_BUFFER *fb) { int oks=0; int startingDepth; GWEN_BUFFER *workBuf; startingDepth=GWEN_XmlCtx_GetDepth(ctx); workBuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_XmlCtx_ResetFinishedElement(ctx); for (;;) { int rv; GWEN_FASTBUFFER_PEEKBYTE(fb, rv); if (rv<0) { if (rv!=GWEN_ERROR_EOF || !oks) { DBG_DEBUG(GWEN_LOGDOMAIN, "here (%d), after reading %d bytes", rv, (int) GWEN_FastBuffer_GetBytesRead(fb)); GWEN_Buffer_free(workBuf); return rv; } GWEN_Buffer_free(workBuf); return 0; } rv=GWEN_XML__ReadData(ctx, fb, GWEN_XmlCtx_GetFlags(ctx)); if (rv) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(workBuf); return rv; } oks=1; GWEN_FASTBUFFER_PEEKBYTE(fb, rv); if (rv<0) { if (rv!=GWEN_ERROR_EOF || !oks || (GWEN_XmlCtx_GetDepth(ctx)!=startingDepth)) { DBG_INFO(GWEN_LOGDOMAIN, "here (rv=%d, oks=%d, depth=%d, startingDepth=%d)", rv, oks, GWEN_XmlCtx_GetDepth(ctx), startingDepth); GWEN_Buffer_free(workBuf); return rv; } GWEN_Buffer_free(workBuf); return 0; } else if (rv=='<') { fb->bufferReadPos++; rv=GWEN_XML__ReadTag(ctx, fb, GWEN_XmlCtx_GetFlags(ctx), workBuf); if (rv) { DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); GWEN_Buffer_free(workBuf); return rv; } GWEN_Buffer_Reset(workBuf); oks=1; } if (GWEN_XmlCtx_GetFinishedElement(ctx) && GWEN_XmlCtx_GetDepth(ctx)==startingDepth) { DBG_INFO(GWEN_LOGDOMAIN, "Finished element at depth %d", GWEN_XmlCtx_GetDepth(ctx)); break; } } if (GWEN_XmlCtx_GetDepth(ctx)!=startingDepth) { DBG_ERROR(GWEN_LOGDOMAIN, "Not on same level where we started...(%d!=%d)", GWEN_XmlCtx_GetDepth(ctx), startingDepth); } GWEN_Buffer_free(workBuf); return 0; }