LibOFX

lib/ofx_containers_misc.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 ofx_proc_rs.cpp
3 -------------------
4 copyright : (C) 2002 by Benoit Grégoire
5 email : benoitg@coeus.ca
6 ***************************************************************************/
13 /***************************************************************************
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
19 * *
20 ***************************************************************************/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <iostream>
27 #include <stdlib.h>
28 #include <string>
29 #include "messages.hh"
30 #include "libofx.h"
31 #include "ofx_error_msg.hh"
32 #include "ofx_utilities.hh"
33 #include "ofx_containers.hh"
34
35 extern OfxMainContainer * MainContainer;
36
37 /***************************************************************************
38 * OfxDummyContainer *
39 ***************************************************************************/
40
41 OfxDummyContainer::OfxDummyContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
42 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
43 {
44 type = "DUMMY";
45 message_out(INFO, "Created OfxDummyContainer to hold unsupported aggregate " + para_tag_identifier);
46 }
47 void OfxDummyContainer::add_attribute(const string identifier, const string value)
48 {
49 message_out(DEBUG, "OfxDummyContainer for " + tag_identifier + " ignored a " + identifier + " (" + value + ")");
50 }
51
52 /***************************************************************************
53 * OfxPushUpContainer *
54 ***************************************************************************/
55
56 OfxPushUpContainer::OfxPushUpContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
57 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
58 {
59 type = "PUSHUP";
60 message_out(DEBUG, "Created OfxPushUpContainer to hold aggregate " + tag_identifier);
61 }
62 void OfxPushUpContainer::add_attribute(const string identifier, const string value)
63 {
64 //message_out(DEBUG, "OfxPushUpContainer for "+tag_identifier+" will push up a "+identifier+" ("+value+") to a "+ parentcontainer->type + " container");
65 if (parentcontainer)
66 parentcontainer->add_attribute(identifier, value);
67 }
68
69 /***************************************************************************
70 * OfxStatusContainer *
71 ***************************************************************************/
72
73 OfxStatusContainer::OfxStatusContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
74 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
75 {
76 memset(&data, 0, sizeof(data));
77 type = "STATUS";
78 if (parentcontainer != NULL)
79 {
80 strncpy(data.ofx_element_name, parentcontainer->tag_identifier.c_str(), OFX_ELEMENT_NAME_LENGTH);
81 data.ofx_element_name_valid = true;
82 }
83
84 }
85 OfxStatusContainer::~OfxStatusContainer()
86 {
87 message_out(DEBUG, "Entering the status's container's destructor");
88
89 libofx_context->statusCallback(data);
90
91 if ( data.server_message_valid )
92 delete [] data.server_message;
93 }
94
95 void OfxStatusContainer::add_attribute(const string identifier, const string value)
96 {
97 ErrorMsg error_msg;
98
99 if ( identifier == "CODE")
100 {
101 data.code = atoi(value.c_str());
102 error_msg = find_error_msg(data.code);
103 data.name = error_msg.name;//memory is already allocated
104 data.description = error_msg.description;//memory is already allocated
105 data.code_valid = true;
106 }
107 else if (identifier == "SEVERITY")
108 {
109 data.severity_valid = true;
110 if (value == "INFO")
111 {
112 data.severity = OfxStatusData::INFO;
113 }
114 else if (value == "WARN")
115 {
116 data.severity = OfxStatusData::WARN;
117 }
118 else if (value == "ERROR")
119 {
120 data.severity = OfxStatusData::ERROR;
121 }
122 else
123 {
124 message_out(ERROR, "WRITEME: Unknown severity " + value + " inside a " + type + " container");
125 data.severity_valid = false;
126 }
127 }
128 else if ((identifier == "MESSAGE") || (identifier == "MESSAGE2"))
129 {
130 data.server_message = new char[value.length() + 1];
131 strcpy(data.server_message, value.c_str());
132 data.server_message_valid = true;
133 }
134 else
135 {
136 /* Redirect unknown identifiers to the base class */
137 OfxGenericContainer::add_attribute(identifier, value);
138 }
139 }
140
141
142
143 /***************************************************************************
144 * OfxBalanceContainer (does not directly abstract a object in libofx.h) *
145 ***************************************************************************/
146
147 OfxBalanceContainer::OfxBalanceContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
148 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
149 {
150 amount_valid = false;
151 date_valid = false;
152 margin_balance_valid = false;
153 short_balance_valid = false;
154 buying_power_valid = false;
155 type = "BALANCE";
156 }
157
158 OfxBalanceContainer::~OfxBalanceContainer()
159 {
160 if (parentcontainer->type == "STATEMENT")
161 {
162 ((OfxStatementContainer*)parentcontainer)->add_balance(this);
163 }
164 else
165 {
166 message_out (ERROR, "I completed a " + type + " element, but I haven't found a suitable parent to save it");
167 }
168 }
169 void OfxBalanceContainer::add_attribute(const string identifier, const string value)
170 {
171 if (identifier == "BALAMT" ||
172 identifier == "AVAILCASH" || // from <INVBAL>
173 identifier == "CASHBAL") // from <INV401KBAL>
174 {
175 amount = ofxamount_to_double(value);
176 amount_valid = true;
177 }
178 else if (identifier == "MARGINBALANCE")
179 {
180 margin_balance = ofxamount_to_double(value);
181 margin_balance_valid = true;
182 }
183 else if (identifier == "SHORTBALANCE")
184 {
185 short_balance = ofxamount_to_double(value);
186 short_balance_valid = true;
187 }
188 else if (identifier == "BUYPOWER")
189 {
190 buying_power = ofxamount_to_double(value);
191 buying_power_valid = true;
192 }
193 else if (identifier == "DTASOF")
194 {
195 date = ofxdate_to_time_t(value);
196 date_valid = true;
197 }
198 else
199 {
200 /* Redirect unknown identifiers to the base class */
201 OfxGenericContainer::add_attribute(identifier, value);
202 }
203 }
204
205 /***************************************************************************
206 * OfxInv401kContainer *
207 * This container is only used to throw away the multiple possible *
208 * <DTSTART>, <DTASOF> and <DTEND> elements that can occur under <INV401K> *
209 * so they don't corrupt the statement dates. *
210 ***************************************************************************/
211
212 OfxInv401kContainer::OfxInv401kContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
213 OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
214 {
215 type = "INV401K";
216 message_out(INFO, "Created OfxInv401kContainer to hold unsupported aggregate " + para_tag_identifier);
217 }
218 void OfxInv401kContainer::add_attribute(const string identifier, const string value)
219 {
220 if (identifier == "DTSTART" || identifier == "DTEND" || identifier == "DTASOF")
221 {
222 message_out(DEBUG, "OfxInv401kContainer for " + tag_identifier + " ignored a " + identifier + " (" + value + ")");
223 }
224 else
225 {
226 /* Redirect unknown identifiers to the base class */
227 OfxGenericContainer::add_attribute(identifier, value);
228 }
229 }
230
ofxamount_to_double
double ofxamount_to_double(const string ofxamount)
Convert OFX amount of money to double float.
Definition: build/libofx-0.10.0/lib/ofx_utilities.cpp:230
OfxInv401kContainer::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_containers_misc.cpp:218
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
INFO
Definition: build/libofx-0.10.0/lib/messages.hh:32
ofx_utilities.hh
Various simple functions for type conversion & al.
OfxStatusData::ERROR
Definition: inc/libofx.h:238
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
OfxStatusData::INFO
Definition: inc/libofx.h:236
LibofxContext
Definition: build/libofx-0.10.0/lib/context.hh:25
ErrorMsg::code
int code
Definition: build/libofx-0.10.0/lib/ofx_error_msg.hh:25
ofxdate_to_time_t
time_t ofxdate_to_time_t(const string ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
Definition: build/libofx-0.10.0/lib/ofx_utilities.cpp:131
OfxStatusData::WARN
Definition: inc/libofx.h:237
OfxPushUpContainer::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_containers_misc.cpp:62
message_out
int message_out(OfxMsgType error_type, const string message)
Message output function.
Definition: build/libofx-0.10.0/lib/messages.cpp:61
ofx_containers.hh
LibOFX internal object code.
OfxGenericContainer::tag_identifier
string tag_identifier
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:37
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.
OfxGenericContainer::type
string type
Definition: build/libofx-0.10.0/lib/ofx_containers.hh:36
OfxStatusContainer::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_containers_misc.cpp:95
OfxDummyContainer::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_containers_misc.cpp:47
DEBUG
Definition: build/libofx-0.10.0/lib/messages.hh:25
find_error_msg
const ErrorMsg find_error_msg(int param_code)
Retreive error code descriptions.
Definition: build/libofx-0.10.0/lib/ofx_error_msg.hh:130
ErrorMsg
An abstraction of an OFX error code sent by an OFX server.
Definition: build/libofx-0.10.0/lib/ofx_error_msg.hh:23
ERROR
Definition: build/libofx-0.10.0/lib/messages.hh:34
ofx_error_msg.hh
OFX error code management functionnality.
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
OfxBalanceContainer::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_containers_misc.cpp:169