LibOFX

build/libofx-0.10.0/lib/ofx_container_account.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 ofx_container_account.cpp
3 -------------------
4 copyright : (C) 2002 by Benoit Gr�goire
5 email : benoitg@coeus.ca
6 ***************************************************************************/
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <string>
25 #include "messages.hh"
26 #include "libofx.h"
27 #include "ofx_containers.hh"
28 #include "ofx_utilities.hh"
29
30 extern OfxMainContainer * MainContainer;
31
32 /***************************************************************************
33 * OfxAccountContainer *
34 ***************************************************************************/
35
36 OfxAccountContainer::OfxAccountContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
37 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
38 {
39 memset(&data, 0, sizeof(data));
40 type = "ACCOUNT";
41 strcpy(bankid, "");
42 strcpy(branchid, "");
43 strcpy(acctid, "");
44 strcpy(acctkey, "");
45 strcpy(brokerid, "");
46 if (para_tag_identifier == "CCACCTFROM")
47 {
48 /*Set the type for a creditcard account. Bank account specific
49 OFX elements will set this attribute elsewhere */
50 data.account_type = data.OFX_CREDITCARD;
51 data.account_type_valid = true;
52 }
53 if (para_tag_identifier == "INVACCTFROM")
54 {
55 /*Set the type for an investment account. Bank account specific
56 OFX elements will set this attribute elsewhere */
57 data.account_type = data.OFX_INVESTMENT;
58 data.account_type_valid = true;
59 }
60 if (parentcontainer != NULL && ((OfxStatementContainer*)parentcontainer)->data.currency_valid == true)
61 {
62 strncpy(data.currency, ((OfxStatementContainer*)parentcontainer)->data.currency, OFX_CURRENCY_LENGTH); /* In ISO-4217 format */
63 data.currency_valid = true;
64 }
65 }
66 OfxAccountContainer::~OfxAccountContainer()
67 {
68 /* if (parentcontainer->type == "STATEMENT")
69 {
70 ((OfxStatementContainer*)parentcontainer)->add_account(data);
71 }
72 ofx_proc_account_cb (data);*/
73 }
74
75 void OfxAccountContainer::add_attribute(const string identifier, const string value)
76 {
77 if ( identifier == "BANKID")
78 {
79 strncpy(bankid, value.c_str(), OFX_BANKID_LENGTH);
80 data.bank_id_valid = true;
81 strncpy(data.bank_id, value.c_str(), OFX_BANKID_LENGTH);
82 }
83 else if ( identifier == "BRANCHID")
84 {
85 strncpy(branchid, value.c_str(), OFX_BRANCHID_LENGTH);
86 data.branch_id_valid = true;
87 strncpy(data.branch_id, value.c_str(), OFX_BRANCHID_LENGTH);
88 }
89 else if ( identifier == "ACCTID")
90 {
91 strncpy(acctid, value.c_str(), OFX_ACCTID_LENGTH);
92 data.account_number_valid = true;
93 strncpy(data.account_number, value.c_str(), OFX_ACCTID_LENGTH);
94 }
95 else if ( identifier == "ACCTKEY")
96 {
97 strncpy(acctkey, value.c_str(), OFX_ACCTKEY_LENGTH);
98 }
99 else if ( identifier == "BROKERID") /* For investment accounts */
100 {
101 strncpy(brokerid, value.c_str(), OFX_BROKERID_LENGTH);
102 data.broker_id_valid = true;
103 strncpy(data.broker_id, value.c_str(), OFX_BROKERID_LENGTH);
104 }
105 else if ((identifier == "ACCTTYPE") || (identifier == "ACCTTYPE2"))
106 {
107 data.account_type_valid = true;
108 if (value == "CHECKING")
109 {
110 data.account_type = data.OFX_CHECKING;
111 }
112 else if (value == "SAVINGS")
113 {
114 data.account_type = data.OFX_SAVINGS;
115 }
116 else if (value == "MONEYMRKT")
117 {
118 data.account_type = data.OFX_MONEYMRKT;
119 }
120 else if (value == "CREDITLINE")
121 {
122 data.account_type = data.OFX_CREDITLINE;
123 }
124 else if (value == "CMA")
125 {
126 data.account_type = data.OFX_CMA;
127 }
128 /* AccountType CREDITCARD is set at object creation, if appropriate */
129 else
130 {
131 data.account_type_valid = false;
132 }
133 }
134 else
135 {
136 /* Redirect unknown identifiers to the base class */
137 OfxGenericContainer::add_attribute(identifier, value);
138 }
139 }//end OfxAccountContainer::add_attribute()
140
141 int OfxAccountContainer::gen_event()
142 {
143 libofx_context->accountCallback(data);
144 return true;
145 }
146
147 int OfxAccountContainer::add_to_main_tree()
148 {
149 gen_account_id ();
150
151 if (MainContainer != NULL)
152 {
153 return MainContainer->add_container(this);
154 }
155 else
156 {
157 return false;
158 }
159 }
160
161 void OfxAccountContainer::gen_account_id(void)
162 {
163 if (data.account_type == OfxAccountData::OFX_CREDITCARD)
164 {
165 strncat(data.account_id, acctid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
166 strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
167 strncat(data.account_id, acctkey, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
168
169 strncat(data.account_name, "Credit card ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
170 strncat(data.account_name, acctid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
171 }
172 else if (data.account_type == OfxAccountData::OFX_INVESTMENT)
173 {
174 strncat(data.account_id, brokerid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
175 strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
176 strncat(data.account_id, acctid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
177
178 strncat(data.account_name, "Investment account ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
179 strncat(data.account_name, acctid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
180 strncat(data.account_name, " at broker ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
181 strncat(data.account_name, brokerid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
182 }
183 else
184 {
185 strncat(data.account_id, bankid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
186 strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
187 strncat(data.account_id, branchid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
188 strncat(data.account_id, " ", OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
189 strncat(data.account_id, acctid, OFX_ACCOUNT_ID_LENGTH - strlen(data.account_id));
190
191 strncat(data.account_name, "Bank account ", OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
192 strncat(data.account_name, acctid, OFX_ACCOUNT_NAME_LENGTH - strlen(data.account_name));
193 }
194 //if (strlen(data.account_id) >= 0) // The strlen() is always non-negative
195 {
196 data.account_id_valid = true;
197 }
198 }//end OfxAccountContainer::gen_account_id()
OfxGenericContainer
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:33
ofx_utilities.hh
Various simple functions for type conversion & al.
ofx_containers.hh
LibOFX internal object code.
OfxAccountContainer::gen_event
virtual int gen_event()
Generate libofx.h events.
Definition: build/libofx-0.10.0/lib/ofx_container_account.cpp:141
OfxGenericContainer::add_attribute
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_container_generic.cpp:57
OfxAccountData::OFX_CREDITCARD
Definition: inc/libofx.h:309
LibofxContext
Definition: build/libofx-0.10.0/lib/context.hh:25
OfxAccountContainer::add_attribute
void add_attribute(const string identifier, const string value)
Add data to a container object.
Definition: build/libofx-0.10.0/lib/ofx_container_account.cpp:75
OfxAccountContainer::add_to_main_tree
int add_to_main_tree()
Add this container to the main tree.
Definition: build/libofx-0.10.0/lib/ofx_container_account.cpp:147
OfxStatementContainer
Represents a statement for either a bank account or a credit card account.
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:157
messages.hh
Message IO functionality.
OfxAccountData::OFX_INVESTMENT
Definition: inc/libofx.h:310
OfxMainContainer
The root container. Created by the <OFX> OFX element or by the export functions.
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:291