コード例 #1
0
ファイル: yellownet.c プロジェクト: aqbanking/aqbanking
int AB_ImExporterYN__ReadAccountStatus(AB_IMEXPORTER *ie,
				       AB_IMEXPORTER_ACCOUNTINFO *ai,
				       GWEN_XMLNODE *doc) {
  GWEN_XMLNODE *n;

  n=GWEN_XMLNode_FindFirstTag(doc, "SG4", 0, 0);
  while(n) {
    GWEN_XMLNODE *nn;

    nn=GWEN_XMLNode_GetNodeByXPath(n, "LIN/PF:D_0805",
				   GWEN_PATH_FLAGS_NAMEMUSTEXIST);
    if (nn) {
      const char *s;

      s=GWEN_XMLNode_GetProperty(nn, "Value", 0);
      if (s && strcasecmp(s, "LEN")==0) {
	GWEN_XMLNODE *nnn;
	GWEN_TIME *ti=0;
        AB_VALUE *val=0;

        /* read time */
	nnn=GWEN_XMLNode_GetNodeByXPath(n, "SG5/DTM",
					GWEN_PATH_FLAGS_NAMEMUSTEXIST);
	if (nnn)
	  ti=AB_ImExporterYN__ReadTime(ie, nnn, 202);

	/* read value */
	nnn=GWEN_XMLNode_GetNodeByXPath(n, "SG5/MOA",
					GWEN_PATH_FLAGS_NAMEMUSTEXIST);
	if (nnn)
	  val=AB_ImExporterYN__ReadValue(ie, nnn, 343);

	if (val) {
	  AB_ACCOUNT_STATUS *ast;
	  AB_BALANCE *bal;

          AB_Value_SetCurrency(val, AB_ImExporterAccountInfo_GetCurrency(ai));
	  ast=AB_AccountStatus_new();
	  bal=AB_Balance_new(val, ti);

	  AB_AccountStatus_SetBookedBalance(ast, bal);
	  AB_Balance_free(bal);

	  AB_ImExporterAccountInfo_AddAccountStatus(ai, ast);
	}
	AB_Value_free(val);
        GWEN_Time_free(ti);
      }
    }

    n=GWEN_XMLNode_FindNextTag(n, "SG4", 0, 0);
  }

  return 0;
}
コード例 #2
0
ファイル: jobgetbalance.c プロジェクト: aqbanking/aqbanking
/* --------------------------------------------------------------- FUNCTION */
int AH_Job_GetBalance_Process(AH_JOB *j, AB_IMEXPORTER_CONTEXT *ctx){
  AH_JOB_GETBALANCE *aj;
  GWEN_DB_NODE *dbResponses;
  GWEN_DB_NODE *dbCurr;
  int rv;

  DBG_INFO(AQHBCI_LOGDOMAIN, "Processing JobGetBalance");

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

  dbResponses=AH_Job_GetResponses(j);
  assert(dbResponses);

  /* search for "Balance" */
  dbCurr=GWEN_DB_GetFirstGroup(dbResponses);
  while(dbCurr) {
    GWEN_DB_NODE *dbBalance;

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

    dbBalance=GWEN_DB_GetGroup(dbCurr, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                               "data/balance");
    if (!dbBalance)
      dbBalance=GWEN_DB_GetGroup(dbCurr, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                                         "data/balancecreditcard");
    if (dbBalance) {
      AB_ACCOUNT_STATUS *acst;
      GWEN_DB_NODE *dbT;
      AB_ACCOUNT *a;
      AB_IMEXPORTER_ACCOUNTINFO *ai;

      DBG_NOTICE(AQHBCI_LOGDOMAIN, "Got a balance");
      if (GWEN_Logger_GetLevel(0)>=GWEN_LoggerLevel_Debug)
        GWEN_DB_Dump(dbBalance, 2);

      acst=AB_AccountStatus_new();

      /* read booked balance */
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                           "booked");
      if (dbT) {
        AB_BALANCE *bal;

        bal=AH_Job_GetBalance__ReadBalance(dbT);
        if (bal) {
	  AB_AccountStatus_SetBookedBalance(acst, bal);
	  AB_AccountStatus_SetTime(acst, AB_Balance_GetTime(bal));
          AB_Balance_free(bal);
        }
      }

      /* read noted balance */
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                           "noted");
      if (dbT) {
        AB_BALANCE *bal;

        bal=AH_Job_GetBalance__ReadBalance(dbT);
        if (bal) {
	  AB_AccountStatus_SetNotedBalance(acst, bal);
	  if (AB_AccountStatus_GetTime(acst)==NULL)
	    AB_AccountStatus_SetTime(acst, AB_Balance_GetTime(bal));
          AB_Balance_free(bal);
        }
      }

      /* read credit Line */
      dbT=GWEN_DB_GetGroup(dbBalance, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                           "creditLine");
      if (dbT) {
        AB_VALUE *v;

        v=AB_Value_fromDb(dbT);
        if (!v) {
          DBG_ERROR(AQHBCI_LOGDOMAIN, "Error parsing value from DB");
        }
        else {
          AB_AccountStatus_SetBankLine(acst, v);
        }
        AB_Value_free(v);
      }

      a=AH_AccountJob_GetAccount(j);
      assert(a);
      ai=AB_ImExporterContext_GetAccountInfo(ctx,
                                             AB_Account_GetBankCode(a),
                                             AB_Account_GetAccountNumber(a));
      assert(ai);

      /* add new account status */
      AB_ImExporterAccountInfo_AddAccountStatus(ai, acst);
      break; /* break loop, we found the balance */
    } /* if "Balance" */
    dbCurr=GWEN_DB_GetNextGroup(dbCurr);
  }

  return 0;
}
コード例 #3
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;
}