Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqbanking / src / libs / plugins / backends / aqhbci / banking / provider_accspec.c @ 942309da

History | View | Annotate | Download (3.61 KB)

1
/***************************************************************************
2
    begin       : Tue Jun 03 2018
3
    copyright   : (C) 2018 by Martin Preuss
4
    email       : martin@libchipcard.de
5

6
 ***************************************************************************
7
 *          Please see toplevel file COPYING for license details           *
8
 ***************************************************************************/
9

    
10

    
11
/*
12
 * This file is included by provider.c
13
 */
14

    
15

    
16

    
17
int AH_Provider__CreateTransactionLimitsForAccount(AB_PROVIDER *pro, AB_USER *u, AB_ACCOUNT *acc, AB_TRANSACTION_LIMITS_LIST *tll) {
18
  int rv;
19
  int i;
20
  int jobList[]={
21
    AB_Transaction_CommandGetBalance,
22
    AB_Transaction_CommandGetTransactions,
23
    /*AB_Transaction_CommandLoadCellPhone, */
24
    AB_Transaction_CommandSepaTransfer,
25
    AB_Transaction_CommandSepaDebitNote,
26
    AB_Transaction_CommandSepaFlashDebitNote,
27
    AB_Transaction_CommandSepaCreateStandingOrder,
28
    AB_Transaction_CommandSepaModifyStandingOrder,
29
    AB_Transaction_CommandSepaDeleteStandingOrder,
30
    AB_Transaction_CommandSepaGetStandingOrders,
31
    AB_Transaction_CommandGetEStatements,
32
    AB_Transaction_CommandUnknown};
33

    
34
  i=0;
35
  while(jobList[i]!=AB_Transaction_CommandUnknown) {
36
    AH_JOB *j=NULL;
37
    AB_TRANSACTION_LIMITS *limits=NULL;
38

    
39
    DBG_INFO(AQHBCI_LOGDOMAIN, "Handling job \"%s\"", AB_Transaction_Command_toString(jobList[i]));
40
    DBG_INFO(AQHBCI_LOGDOMAIN, "- creating job");
41
    rv=AH_Provider__CreateHbciJob(pro, u, acc, jobList[i], &j);
42
    if (rv<0) {
43
      if (rv==GWEN_ERROR_NOT_AVAILABLE) {
44
        DBG_INFO(AQHBCI_LOGDOMAIN, "Job \"%s\" is not available", AB_Transaction_Command_toString(jobList[i]));
45
      }
46
      else {
47
        DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
48
        return rv;
49
      }
50
    }
51
    else {
52
      DBG_INFO(AQHBCI_LOGDOMAIN, "- getting limits");
53
      rv=AH_Job_GetLimits(j, &limits);
54
      if (rv<0) {
55
        DBG_INFO(AQHBCI_LOGDOMAIN, "Error getting limits for job \"%s\": %d", AB_Transaction_Command_toString(jobList[i]), rv);
56
        AH_Job_free(j);
57
        return rv;
58
      }
59
      DBG_INFO(AQHBCI_LOGDOMAIN, "- adding limits");
60
      AB_TransactionLimits_List_Add(limits, tll);
61
      AH_Job_free(j);
62
    }
63
    i++;
64
  } /* while i */
65

    
66
  return 0;
67
}
68

    
69

    
70

    
71
int AH_Provider_UpdateAccountSpec(AB_PROVIDER *pro, AB_ACCOUNT_SPEC *as, int doLock) {
72
  int rv;
73
  uint32_t aid=0;
74
  AB_ACCOUNT *a=NULL;
75
  uint32_t uid=0;
76
  AB_USER *u=NULL;
77
  AB_TRANSACTION_LIMITS_LIST *tll;
78

    
79
  /* get unique account id */
80
  aid=AB_AccountSpec_GetUniqueId(as);
81
  if (aid==0) {
82
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Account has no unique id assigned, SNH!");
83
    return GWEN_ERROR_INTERNAL;
84
  }
85

    
86
  /* get corresponding account */
87
  rv=AB_Provider_GetAccount(pro, aid, doLock, doLock, &a);
88
  if (rv<0) {
89
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
90
    AB_Account_free(a);
91
    return rv;
92
  }
93
  assert(a);
94

    
95
  /* get user id */
96
  uid=AB_Account_GetUserId(a);
97
  if (uid==0) {
98
    DBG_ERROR(AQHBCI_LOGDOMAIN, "Account has no user id assigned, SNH!");
99
    return GWEN_ERROR_INTERNAL;
100
  }
101

    
102
  /* get user */
103
  rv=AB_Provider_GetUser(pro, uid, doLock, doLock, &u);
104
  if (rv<0) {
105
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
106
    AB_Account_free(a);
107
    return rv;
108
  }
109

    
110
  /* create and set transaction limits per command */
111
  tll=AB_TransactionLimits_List_new();
112
  rv=AH_Provider__CreateTransactionLimitsForAccount(pro, u, a, tll);
113
  if (rv<0) {
114
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
115
    AB_TransactionLimits_List_free(tll);
116
    AB_User_free(u);
117
    AB_Account_free(a);
118
    return rv;
119
  }
120
  AB_AccountSpec_SetTransactionLimitsList(as, tll);
121

    
122
  AB_User_free(u);
123
  AB_Account_free(a);
124

    
125
  return 0;
126
}
127

    
128

    
129

    
130

    
131

    
132

    
133

    
134

    
135

    
136

    
137