Esempio n. 1
0
int GWEN_Directory_GetAllEntries(const char *folder,
                                 GWEN_STRINGLIST *sl,
                                 const char *mask) {
  GWEN_DIRECTORY *d;
  int rv;
  char buffer[256];

  d=GWEN_Directory_new();
  rv=GWEN_Directory_Open(d, folder);
  if (rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
    GWEN_Directory_free(d);
    return rv;
  }

  while(0==GWEN_Directory_Read(d, buffer, sizeof(buffer))) {
    if (strcmp(buffer, ".")!=0 &&
        strcmp(buffer, "..")!=0 &&
        (mask==NULL ||
         GWEN_Text_ComparePattern(buffer+1, mask, 0)!=-1))
      GWEN_StringList_AppendString(sl, buffer, 0, 1);
  }

  GWEN_Directory_Close(d);
  GWEN_Directory_free(d);
  return 0;
}
Esempio n. 2
0
void AH_User_LoadSepaDescriptors(AB_USER *u) {
  AH_USER *ue;
  GWEN_DB_NODE *db;
  int rv;

  assert(u);
  ue=GWEN_INHERIT_GETDATA(AB_USER, AH_USER, u);
  assert(ue);

  /* read directly from BPD */

  GWEN_StringList_Clear(ue->sepaDescriptors);
  db=GWEN_DB_Group_new("bpd");
  rv=AH_Job_SampleBpdVersions("JobGetAccountSepaInfo", u, db);
  if (rv<0) {
      DBG_INFO(AQHBCI_LOGDOMAIN, "No BPD for TAN job");
  }
  else {
    GWEN_DB_NODE *dbV;

    dbV=GWEN_DB_GetFirstGroup(db);
    while(dbV) {
      int version;

      version=atoi(GWEN_DB_GroupName(dbV));
      if (version>0) {
	GWEN_DB_NODE *dbT;

	/* always overwrite with latest version received */
	GWEN_StringList_Clear(ue->sepaDescriptors);
	dbT=GWEN_DB_FindFirstGroup(dbV, "SupportedSepaFormats");
	if (!dbT) {
	  DBG_INFO(AQHBCI_LOGDOMAIN, "No SEPA descriptor found");
	}
	while(dbT) {
	  int i;

	  for (i=0; i<100; i++) {
	    const char *s;

	    s=GWEN_DB_GetCharValue(dbT, "format", i, NULL);
	    if (! (s && *s))
	      break;
	    GWEN_StringList_AppendString(ue->sepaDescriptors, s, 0, 1);
	    DBG_INFO(AQHBCI_LOGDOMAIN,
		     "Adding SEPA descriptor [%s] for GV version %d",
		     s, version);
	  }

	  dbT=GWEN_DB_FindNextGroup(dbT, "SupportedSepaFormats");
	}
      }

      dbV=GWEN_DB_GetNextGroup(dbV);
    }
  }
  GWEN_DB_Group_free(db);
}
Esempio n. 3
0
int GWEN_Directory_GetFileEntriesWithType(const char *folder,
    GWEN_STRINGLIST *sl,
    const char *mask) {
  GWEN_DIRECTORY *d;
  int rv;
  char buffer[256];
  GWEN_BUFFER *pbuf;
  uint32_t pos;

  d=GWEN_Directory_new();
  rv=GWEN_Directory_Open(d, folder);
  if (rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
    GWEN_Directory_free(d);
    return rv;
  }

  pbuf=GWEN_Buffer_new(0, 256, 0, 1);
  GWEN_Buffer_AppendString(pbuf, folder);
  GWEN_Buffer_AppendString(pbuf, GWEN_DIR_SEPARATOR_S);
  pos=GWEN_Buffer_GetPos(pbuf);

  while(0==GWEN_Directory_Read(d, buffer+1, sizeof(buffer)-2)) {
    if (strcmp(buffer, ".")!=0 &&
        strcmp(buffer, "..")!=0 &&
        (mask==NULL ||
         GWEN_Text_ComparePattern(buffer+1, mask, 0)!=-1)) {
      struct stat st;

      GWEN_Buffer_AppendString(pbuf, buffer+1);
      if (stat(GWEN_Buffer_GetStart(pbuf), &st)==0) {
        if (S_ISREG(st.st_mode))
          buffer[0]='f';
        else if (S_ISDIR(st.st_mode))
          buffer[0]='d';
        else
          buffer[0]='?';
        GWEN_StringList_AppendString(sl, buffer, 0, 1);
      }
      GWEN_Buffer_Crop(pbuf, 0, pos);
    }
  }

  GWEN_Directory_Close(d);
  GWEN_Directory_free(d);
  return 0;
}
Esempio n. 4
0
GWEN_STRINGLIST *GWEN_PathManager_GetPaths(const char *destLib,
    const char *pathName) {
  GWEN_DB_NODE *dbT;

  assert(gwen__paths);
  dbT=GWEN_DB_GetGroup(gwen__paths, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                       destLib);
  if (dbT) {
    dbT=GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                         pathName);
    if (dbT) {
      GWEN_STRINGLIST *sl;
      int i;
      const char *s;
      GWEN_DB_NODE *dbN;

      sl=GWEN_StringList_new();

      /* then add all paths from other libs */
      dbN=GWEN_DB_FindFirstGroup(dbT, "pair");
      while(dbN) {
        for (i=0; ; i++) {
          s=GWEN_DB_GetCharValue(dbN, "path", i, 0);
          if (!s)
            break;
          GWEN_StringList_AppendString(sl, s, 0, 1);
        }

        dbN=GWEN_DB_FindNextGroup(dbN, "pair");
      }

      if (GWEN_StringList_Count(sl)==0) {
        GWEN_StringList_free(sl);
        DBG_DEBUG(GWEN_LOGDOMAIN, "no entries");
        return 0;
      }

      return sl;
    }
  }

  return 0;
}
Esempio n. 5
0
void AB_Banking_ActivateAllProviders(AB_BANKING *ab) {
    GWEN_PLUGIN_DESCRIPTION_LIST2 *descrs;
    GWEN_PLUGIN_MANAGER *pm;

    pm=GWEN_PluginManager_FindPluginManager("provider");
    if (!pm) {
        DBG_ERROR(AQBANKING_LOGDOMAIN,
                  "Could not find plugin manager for \"%s\"",
                  "provider");
        return;
    }

    descrs=GWEN_PluginManager_GetPluginDescrs(pm);
    if (descrs) {
        GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *it;
        GWEN_PLUGIN_DESCRIPTION *pd;

        it=GWEN_PluginDescription_List2_First(descrs);
        assert(it);
        pd=GWEN_PluginDescription_List2Iterator_Data(it);
        assert(pd);
        while(pd) {
            const char *pname=GWEN_PluginDescription_GetName(pd);
            AB_PROVIDER *pro;

            pro=AB_Banking_GetProvider(ab, pname);
            if (!pro) {
                DBG_WARN(AQBANKING_LOGDOMAIN,
                         "Could not load backend \"%s\", ignoring", pname);
            }
            else {
                GWEN_StringList_AppendString(ab->activeProviders, pname, 0, 1);
            }

            pd=GWEN_PluginDescription_List2Iterator_Next(it);
        } /* while */
        GWEN_PluginDescription_List2Iterator_free(it);
        GWEN_PluginDescription_List2_freeAll(descrs);
    }
}
Esempio n. 6
0
static int addToList(const char *fname, int recursive, GWEN_STRINGLIST *sl) {
  struct stat st;
  int rv;

  /* stat file to be added */
#if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
  rv=lstat(fname, &st);
#else
  rv=stat(fname, &st);
#endif
  if (rv) {
    DBG_ERROR(GSA_LOGDOMAIN, "stat(%s): %d (%s)",
              fname, errno, strerror(errno));
    fprintf(stderr, "Ignoring file \"%s\"\n", fname);
  }
  else {
    /* always append this entry */
    GWEN_StringList_AppendString(sl, fname, 0, 1);
    if (recursive && S_ISDIR(st.st_mode)) {
      GWEN_STRINGLIST *sll;
      GWEN_STRINGLISTENTRY *se;
      GWEN_DIRECTORY *d;
      int rv;
      char buffer[256];
      GWEN_BUFFER *tbuf;
      uint32_t pos;

      /* add entries */
      sll=GWEN_StringList_new();
      d=GWEN_Directory_new();
      rv=GWEN_Directory_Open(d, fname);
      if (rv<0) {
        DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
        GWEN_Directory_free(d);
        GWEN_StringList_free(sll);
        return rv;
      }

      while(0==GWEN_Directory_Read(d, buffer, sizeof(buffer))) {
        if (strcmp(buffer, ".")!=0 &&
            strcmp(buffer, "..")!=0)
          GWEN_StringList_AppendString(sll, buffer, 0, 1);
      }

      GWEN_Directory_Close(d);
      GWEN_Directory_free(d);

      /* recurse */
      tbuf=GWEN_Buffer_new(0, 256, 0, 1);
      GWEN_Buffer_AppendString(tbuf, fname);
      GWEN_Buffer_AppendString(tbuf, GWEN_DIR_SEPARATOR_S);
      pos=GWEN_Buffer_GetPos(tbuf);
      se=GWEN_StringList_FirstEntry(sll);
      while(se) {
        const char *s;

        s=GWEN_StringListEntry_Data(se);
        if (s && *s) {
          GWEN_Buffer_AppendString(tbuf, s);
          rv=addToList(GWEN_Buffer_GetStart(tbuf), recursive, sl);
          if (rv<0) {
            DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
            GWEN_Buffer_free(tbuf);
            GWEN_StringList_free(sll);
            return rv;
          }
        }
        GWEN_Buffer_Crop(tbuf, 0, pos);
        se=GWEN_StringListEntry_Next(se);
      } /* while se */
      GWEN_Buffer_free(tbuf);
      GWEN_StringList_free(sll);
    } /* if dir and recursive */
  } /* if stat was ok */

  return 0;
}
Esempio n. 7
0
int AHB_DTAUS__CreateSetC(GWEN_BUFFER *dst,
                          GWEN_DB_NODE *cfg,
                          GWEN_DB_NODE *xa,
			  AB_VALUE *sumEUR,
                          AB_VALUE *sumDEM,
                          AB_VALUE *sumBankCodes,
                          AB_VALUE *sumAccountIds){
  unsigned int i;
  const char *p;
  char buffer[32];
  int isDebitNote;
  int isEuro;
  unsigned int extSets;
  //unsigned int startPos;
  AB_VALUE *val;
  GWEN_STRINGLIST *purposeList;

  DBG_DEBUG(AQBANKING_LOGDOMAIN, "Creating C set");

  /* ______________________________________________________________________
   * preparations
   */
  purposeList=GWEN_StringList_new();
  /* cut purpose lines into manageable portions (max 27 chars) */
  for (i=0; ; i++) {
    int slen;
    GWEN_BUFFER *nbuf;

    p=GWEN_DB_GetCharValue(xa, "purpose", i, 0);
    if (p==NULL)
      break;
    if (i>14) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many purpose lines (maxmimum is 14)");
      GWEN_StringList_free(purposeList);
      return -1;
    }

    slen=strlen(p);
    nbuf=GWEN_Buffer_new(0, slen+1, 0, 1);
    AB_ImExporter_Utf8ToDta(p, -1, nbuf);
    p=GWEN_Buffer_GetStart(nbuf);

    while(*p) {
      while(*p>0 && *p<33)
	p++;
      slen=strlen(p);
      if (slen==0)
        break;
      else if (slen>27) {
	char *ns;

	ns=(char*) malloc(28);
	assert(ns);
	memmove(ns, p, 27);
	ns[27]=0;
	/* let stringlist take over ownership of the the string */
	GWEN_StringList_AppendString(purposeList, ns, 1, 0);
	p+=27;
      }
      else {
	GWEN_StringList_AppendString(purposeList, p, 0, 0);
	break;
      }
    }
    GWEN_Buffer_free(nbuf);
  } /* for */

  //startPos=GWEN_Buffer_GetPos(dst);
  GWEN_Buffer_AllocRoom(dst, 256);

  isDebitNote=(strcasecmp(GWEN_DB_GetCharValue(cfg, "type", 0, "transfer"),
                          "debitnote")==0);
  isEuro=(strcasecmp(GWEN_DB_GetCharValue(cfg, "currency", 0, "EUR"),
                     "EUR")==0);

  /* compute number of extension sets */
  extSets=0;

  /* add purpose */
  if (GWEN_StringList_Count(purposeList))
    extSets+=GWEN_StringList_Count(purposeList)-1;

  /* add name */
  for (i=1; i<2; i++) { /* max 1 extset for local name */
    if (GWEN_DB_GetCharValue(xa, "localName", i, 0)==0)
      break;
    if (i>1) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many name lines (maxmimum is 2)");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    extSets++;
  } /* for */

  /* add other name */
  for (i=1; i<2; i++) { /* max 1 extset for remote name */
    if (GWEN_DB_GetCharValue(xa, "remoteName", i, 0)==0)
      break;
    if (i>1) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many peer name lines (maxmimum is 2)");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    extSets++;
  } /* for */

  /* check number of extension sets */
  if (extSets>15) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many extension sets (%d)", extSets);
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* ______________________________________________________________________
   * actually write C set
   */

  /* field 1, 2: record header */
  snprintf(buffer, sizeof(buffer), "%04d", 187+(extSets*29));
  GWEN_Buffer_AppendString(dst, buffer);
  GWEN_Buffer_AppendByte(dst, 'C');

  /* field 3: acting bank code */
  if (AHB_DTAUS__AddNum(dst, 8, GWEN_DB_GetCharValue(cfg, "bankCode", 0, ""))) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 4: destination bank code */
  p=GWEN_DB_GetCharValue(xa, "remoteBankCode", 0, 0);
  if (p) {
    val=AB_Value_fromString(p);
    if (val==NULL) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad bank code");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumBankCodes, val);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 8, p)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer bank code missing");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 5: destination account id */
  p=GWEN_DB_GetCharValue(xa, "remoteAccountNumber", 0, 0);
  if (p) {
    val=AB_Value_fromString(p);
    if (val==NULL) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad account id");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumAccountIds, val);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 10, p)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer account id missing");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 6: internal customer number (0s for now) */
  for (i=0; i<13; i++) GWEN_Buffer_AppendByte(dst, '0');

  /* field 7a: text key */
  snprintf(buffer, sizeof(buffer), "%02d", GWEN_DB_GetIntValue(xa, "textkey", 0, isDebitNote?5:51));
  if (AHB_DTAUS__AddNum(dst, 2, buffer)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 7b: text key extension */
  snprintf(buffer, sizeof(buffer), "%03d", GWEN_DB_GetIntValue(xa, "textkeyext", 0, 0));
  if (AHB_DTAUS__AddNum(dst, 3, buffer)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 8: bank internal field */
  GWEN_Buffer_AppendByte(dst, ' ');

  /* field 9: value in DEM */
  if (!isEuro) {
    val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0"));
    if (val==NULL || AB_Value_IsZero(val)) {
      AB_Value_free(val);
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad DEM value:");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumDEM, val);
    snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 11, buffer)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    if (AHB_DTAUS__AddNum(dst, 11, "0")) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }

  /* field 10: local bank code */
  p=GWEN_DB_GetCharValue(xa, "localbankCode", 0, 0);
  if (!p)
    p=GWEN_DB_GetCharValue(cfg, "bankCode", 0, 0);
  if (!p) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "No local bank code");
    GWEN_StringList_free(purposeList);
    return -1;
  }
  if (AHB_DTAUS__AddNum(dst, 8, p)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 11: local account id */
  p=GWEN_DB_GetCharValue(xa, "localAccountNumber", 0, 0);
  if (!p)
    GWEN_DB_GetCharValue(cfg, "accountId", 0, 0);
  if (!p) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "No local account number");
    GWEN_StringList_free(purposeList);
    return -1;
  }
  if (AHB_DTAUS__AddNum(dst, 10, p)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 12: value in EUR */
  if (isEuro) {
    val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0"));
    if (val==NULL || AB_Value_IsZero(val)) {
      AB_Value_free(val);
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad EUR value:");
      GWEN_StringList_free(purposeList);
      return -1;
    }
    AB_Value_AddValue(sumEUR, val);
    snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0);
    AB_Value_free(val);
    if (AHB_DTAUS__AddNum(dst, 11, buffer)) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }
  else {
    if (AHB_DTAUS__AddNum(dst, 11, "0")) {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
      GWEN_StringList_free(purposeList);
      return -1;
    }
  }

  /* field 13: blanks */
  for (i=0; i<3; i++) GWEN_Buffer_AppendByte(dst, ' ');

  /* field 14a: peer name */
  if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "remoteName", 0, ""))) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 14b: blanks */
  for (i=0; i<8; i++) GWEN_Buffer_AppendByte(dst, ' ');

  /* field 15: name */
  if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "localname", 0, ""))) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 16: purpose */
  p=GWEN_StringList_FirstString(purposeList);
  if (p==NULL)
    p="";
  if (AHB_DTAUS__AddWord(dst, 27, p)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  /* field 17a: currency */
  if (isEuro)
    GWEN_Buffer_AppendByte(dst, '1');
  else
    GWEN_Buffer_AppendByte(dst, ' ');

  /* field 17b: blanks */
  for (i=0; i<2; i++) GWEN_Buffer_AppendByte(dst, ' ');

  /* field 18: number of extension sets */
  snprintf(buffer, sizeof(buffer), "%02d", extSets);
  if (AHB_DTAUS__AddNum(dst, 2, buffer)) {
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
    GWEN_StringList_free(purposeList);
    return -1;
  }

  if (extSets) {
    unsigned int writtenExtSets=0;

    /* now append extension sets */

    /* add peer name lines */
    for (i=1; i<2; i++) { /* max: 1 extset */
      unsigned int j;

      p=GWEN_DB_GetCharValue(xa, "remoteName", i, 0);
      if (!p)
	break;

      /* append extension set */
      GWEN_Buffer_AppendString(dst, "01");
      if (AHB_DTAUS__AddWord(dst, 27, p)) {
	DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
	GWEN_StringList_free(purposeList);
	return -1;
      }
      writtenExtSets++;

      if (writtenExtSets==2)
	/* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */
	for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' ');
      else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0)
	/* "C 3-5.Satzabschnitt" complete, align to 128 bytes */
	for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' ');
    } /* for */

    /* add purpose lines */
    for (i=1; i<GWEN_StringList_Count(purposeList); i++) {
      unsigned int j;

      p=GWEN_StringList_StringAt(purposeList, i);
      if (!p)
	break;

      /* append extension set */
      GWEN_Buffer_AppendString(dst, "02");
      /* strings in the list are already in DTA charset */
      if (AHB_DTAUS__AddDtaWord(dst, 27, p)) {
	DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
	GWEN_StringList_free(purposeList);
	return -1;
      }
      writtenExtSets++;

      if (writtenExtSets==2)
	/* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */
	for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' ');
      else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0)
	/* "C 3-5.Satzabschnitt" complete, align to 128 bytes */
	for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' ');
    } /* for */

    /* add name lines */
    for (i=1; i<2; i++) { /* max: 1 extset */
      unsigned int j;

      p=GWEN_DB_GetCharValue(xa, "localname", i, 0);
      if (!p)
	break;

      /* append extension set */
      GWEN_Buffer_AppendString(dst, "03");
      if (AHB_DTAUS__AddWord(dst, 27, p)) {
	DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer");
	GWEN_StringList_free(purposeList);
	return -1;
      }
      writtenExtSets++;

      if (writtenExtSets==2)
	/* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */
	for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' ');
      else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0)
	/* "C 3-5.Satzabschnitt" complete, align to 128 bytes */
	for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' ');
    } /* for */
  }

  i=((GWEN_Buffer_GetUsedBytes(dst)+127) & ~127)-GWEN_Buffer_GetUsedBytes(dst);
  while(i--)
    GWEN_Buffer_AppendByte(dst, ' ');

  GWEN_StringList_free(purposeList);
  return 0;
}
Esempio n. 8
0
void FOX16_HtmlLabel::addMediaPath(const char *s) {
  assert(s);
  GWEN_StringList_AppendString(m_mediaPaths, s, 0, 1);
}
Esempio n. 9
0
void Typemaker2_TypeManager_AddFolder(TYPEMAKER2_TYPEMANAGER *tym, const char *s) {
  assert(tym);
  GWEN_StringList_AppendString(tym->folders, s, 0, 1);
}
Esempio n. 10
0
int AH_Job_GetTransactionsCreditCard_Process(AH_JOB *j, AB_IMEXPORTER_CONTEXT *ctx)
{
  AH_JOB_GETTRANSACTIONS *aj;
  AB_ACCOUNT *a;
  AB_IMEXPORTER_ACCOUNTINFO *ai;
  AB_USER *u;
  GWEN_DB_NODE *dbResponses;
  GWEN_DB_NODE *dbCurr;
  GWEN_BUFFER *tbooked;
  GWEN_BUFFER *tnoted;
  int rv;

  DBG_INFO(AQHBCI_LOGDOMAIN, "Processing JobGetTransactionsCreditCard");

  assert(j);
  aj=GWEN_INHERIT_GETDATA(AH_JOB, AH_JOB_GETTRANSACTIONS, j);
  assert(aj);

  tbooked=GWEN_Buffer_new(0, 1024, 0, 1);
  tnoted=GWEN_Buffer_new(0, 1024, 0, 1);

  dbResponses=AH_Job_GetResponses(j);
  assert(dbResponses);
  DBG_INFO(AQHBCI_LOGDOMAIN, "Response:");
  GWEN_DB_Dump(dbResponses, 2);
  DBG_INFO(AQHBCI_LOGDOMAIN, "Response end");


  a=AH_AccountJob_GetAccount(j);
  assert(a);
  ai=AB_ImExporterContext_GetOrAddAccountInfo(ctx,
                                              AB_Account_GetUniqueId(a),
                                              AB_Account_GetIban(a),
                                              AB_Account_GetBankCode(a),
                                              AB_Account_GetAccountNumber(a),
                                              AB_Account_GetAccountType(a));
  assert(ai);
  AB_ImExporterAccountInfo_SetAccountId(ai, AB_Account_GetUniqueId(a));

  u=AH_Job_GetUser(j);
  assert(u);

  /* search for "Transactions" */
  dbCurr=GWEN_DB_GetFirstGroup(dbResponses);
  while (dbCurr) {
    GWEN_DB_NODE *dbXA;

    rv=AH_Job_CheckEncryption(j, dbCurr);
    if (rv) {
      DBG_INFO(AQHBCI_LOGDOMAIN, "Compromised security (encryption)");
      GWEN_Buffer_free(tbooked);
      GWEN_Buffer_free(tnoted);
      AH_Job_SetStatus(j, AH_JobStatusError);
      return rv;
    }
    rv=AH_Job_CheckSignature(j, dbCurr);
    if (rv) {
      DBG_INFO(AQHBCI_LOGDOMAIN, "Compromised security (signature)");
      GWEN_Buffer_free(tbooked);
      GWEN_Buffer_free(tnoted);
      AH_Job_SetStatus(j, AH_JobStatusError);
      return rv;
    }

    dbXA=GWEN_DB_GetGroup(dbCurr, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                          "data/transactionscreditcard");
    if (dbXA) {
      GWEN_DB_NODE *dbT;
      GWEN_DB_NODE *dbV;
      GWEN_DATE *date;
      GWEN_DATE *valutaDate;
      const char *p;
      const char *ref;
      int i;

      dbT=GWEN_DB_GetGroup(dbXA, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                           "entries");
      while (dbT) {
        AB_VALUE *v1;
        AB_VALUE *v2;
        GWEN_STRINGLIST *purpose;
        AB_TRANSACTION *t;

        /* read date (Buchungsdatum) */
        p=GWEN_DB_GetCharValue(dbT, "date", 0, 0);
        if (p)
          date=GWEN_Date_fromStringWithTemplate(p, "YYYYMMDD");
        else
          date=NULL;

        /* read valutaData (Umsatzdatum) */
        p=GWEN_DB_GetCharValue(dbT, "valutaDate", 0, 0);
        if (p)
          valutaDate=GWEN_Date_fromStringWithTemplate(p, "YYYYMMDD");
        else
          valutaDate=NULL;

        /* read value */
        dbV=GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                             "value");
        if (dbV)
          v1=AB_Value_fromDb(dbV);
        else
          v1=NULL;
        v2=0;
        if (!v1) {
          DBG_ERROR(AQHBCI_LOGDOMAIN, "Error parsing value from DB");
        }
        else {
          p=GWEN_DB_GetCharValue(dbT, "debitMark", 0, 0);
          if (p) {
            if (strcasecmp(p, "D")==0 ||
                strcasecmp(p, "RC")==0) {
              v2=AB_Value_dup(v1);
              AB_Value_Negate(v2);
            }
            else if (strcasecmp(p, "C")==0 ||
                     strcasecmp(p, "RD")==0)
              v2=AB_Value_dup(v1);
            else {
              DBG_ERROR(AQHBCI_LOGDOMAIN, "Bad debit mark \"%s\"", p);
              v2=0;
            }
          }
          AB_Value_free(v1);
        }

        /* read purpose */
        purpose=GWEN_StringList_new();
        for (i=0; i<10; i++) {
          p=GWEN_DB_GetCharValue(dbT, "purpose", i, 0);
          if (!p)
            break;
          GWEN_StringList_AppendString(purpose, p, 0, 0);
        }

        /* read reference */
        ref=GWEN_DB_GetCharValue(dbT, "reference", 0, 0);
        if (ref)
          GWEN_StringList_AppendString(purpose, ref, 0, 0);

        t=AB_Transaction_new();
        if (ref)
          AB_Transaction_SetFiId(t, ref);
        AB_Transaction_SetUniqueAccountId(t, AB_Account_GetUniqueId(a));
        AB_Transaction_SetLocalBankCode(t, AB_User_GetBankCode(u));
        AB_Transaction_SetLocalAccountNumber(t, AB_Account_GetAccountNumber(a));
        AB_Transaction_SetValutaDate(t, valutaDate);
        AB_Transaction_SetDate(t, date);
        AB_Transaction_SetValue(t, v2);
        AB_Transaction_SetPurposeFromStringList(t, purpose);
        DBG_INFO(AQHBCI_LOGDOMAIN, "Adding transaction");
        AB_ImExporterAccountInfo_AddTransaction(ai, t);

        GWEN_StringList_free(purpose);
        AB_Value_free(v2);
        GWEN_Date_free(date);
        GWEN_Date_free(valutaDate);

        dbT = GWEN_DB_FindNextGroup(dbT, "entries");
      } //while (dbT)
    } //if (dbXA)
    dbCurr=GWEN_DB_GetNextGroup(dbCurr);
  }

  return 0;
}
Esempio n. 11
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;
}
Esempio n. 12
0
void AB_TransactionLimits_AddValuesTextKey(AB_TRANSACTION_LIMITS *st, const char *d, int chk){
  assert(st);
  assert(d);
  if (GWEN_StringList_AppendString(st->valuesTextKey, d, 0, chk))
    st->_modified=1;
}
Esempio n. 13
0
int GWEN_Directory_GetMatchingFilesRecursively(const char *folder,
                                               GWEN_STRINGLIST *sl,
                                               const char *mask) {
  GWEN_DIRECTORY *d;
  int rv;
  char buffer[256];
  GWEN_BUFFER *pbuf;
  uint32_t pos;
  GWEN_STRINGLIST *folderList;

  folderList=GWEN_StringList_new();

  d=GWEN_Directory_new();
  rv=GWEN_Directory_Open(d, folder);
  if (rv<0) {
    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
    GWEN_Directory_free(d);
    GWEN_StringList_free(folderList);
    return rv;
  }

  pbuf=GWEN_Buffer_new(0, 256, 0, 1);
  GWEN_Buffer_AppendString(pbuf, folder);
  GWEN_Buffer_AppendString(pbuf, GWEN_DIR_SEPARATOR_S);
  pos=GWEN_Buffer_GetPos(pbuf);

  while(0==GWEN_Directory_Read(d, buffer, sizeof(buffer)-2)) {
    if (strcmp(buffer, ".")!=0 &&
        strcmp(buffer, "..")!=0) {
      struct stat st;

      GWEN_Buffer_AppendString(pbuf, buffer);
      if (stat(GWEN_Buffer_GetStart(pbuf), &st)==0) {
        if (S_ISDIR(st.st_mode))
          /* add folders to the folder list */
          GWEN_StringList_AppendString(folderList, GWEN_Buffer_GetStart(pbuf), 0, 0);
        else {
          if (mask==NULL || GWEN_Text_ComparePattern(buffer, mask, 0)!=-1)
            /* don't check for duplicates here (i.e. last param =0) */
            GWEN_StringList_AppendString(sl, GWEN_Buffer_GetStart(pbuf), 0, 0);
        }
      }
      GWEN_Buffer_Crop(pbuf, 0, pos);
    }
  }

  GWEN_Directory_Close(d);
  GWEN_Directory_free(d);

  if (GWEN_StringList_Count(folderList)) {
    GWEN_STRINGLISTENTRY *se;

    se=GWEN_StringList_FirstEntry(folderList);
    while(se) {
      const char *s;

      s=GWEN_StringListEntry_Data(se);
      if (s && *s)
        GWEN_Directory_GetMatchingFilesRecursively(s, sl, mask);
      se=GWEN_StringListEntry_Next(se);
    }
  }
  GWEN_StringList_free(folderList);
  GWEN_Buffer_free(pbuf);

  return 0;
}
Esempio n. 14
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;
}