LibOFX
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  parentcontainer->add_attribute(identifier, value);
66 }
67 
68 /***************************************************************************
69  * OfxStatusContainer *
70  ***************************************************************************/
71 
72 OfxStatusContainer::OfxStatusContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
73  OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
74 {
75  memset(&data, 0, sizeof(data));
76  type = "STATUS";
77  if (parentcontainer != NULL)
78  {
79  strncpy(data.ofx_element_name, parentcontainer->tag_identifier.c_str(), OFX_ELEMENT_NAME_LENGTH);
80  data.ofx_element_name_valid = true;
81  }
82 
83 }
84 OfxStatusContainer::~OfxStatusContainer()
85 {
86  message_out(DEBUG, "Entering the status's container's destructor");
87 
88  libofx_context->statusCallback(data);
89 
90  if ( data.server_message_valid )
91  delete [] data.server_message;
92 }
93 
94 void OfxStatusContainer::add_attribute(const string identifier, const string value)
95 {
96  ErrorMsg error_msg;
97 
98  if ( identifier == "CODE")
99  {
100  data.code = atoi(value.c_str());
101  error_msg = find_error_msg(data.code);
102  data.name = error_msg.name;//memory is already allocated
103  data.description = error_msg.description;//memory is already allocated
104  data.code_valid = true;
105  }
106  else if (identifier == "SEVERITY")
107  {
108  data.severity_valid = true;
109  if (value == "INFO")
110  {
111  data.severity = OfxStatusData::INFO;
112  }
113  else if (value == "WARN")
114  {
115  data.severity = OfxStatusData::WARN;
116  }
117  else if (value == "ERROR")
118  {
119  data.severity = OfxStatusData::ERROR;
120  }
121  else
122  {
123  message_out(ERROR, "WRITEME: Unknown severity " + value + " inside a " + type + " container");
124  data.severity_valid = false;
125  }
126  }
127  else if ((identifier == "MESSAGE") || (identifier == "MESSAGE2"))
128  {
129  data.server_message = new char[value.length()+1];
130  strcpy(data.server_message, value.c_str());
131  data.server_message_valid = true;
132  }
133  else
134  {
135  /* Redirect unknown identifiers to the base class */
136  OfxGenericContainer::add_attribute(identifier, value);
137  }
138 }
139 
140 
141 
142 /***************************************************************************
143  * OfxBalanceContainer (does not directly abstract a object in libofx.h) *
144  ***************************************************************************/
145 
146 OfxBalanceContainer::OfxBalanceContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
147  OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
148 {
149  amount_valid = false;
150  date_valid = false;
151  type = "BALANCE";
152 }
153 
154 OfxBalanceContainer::~OfxBalanceContainer()
155 {
156  if (parentcontainer->type == "STATEMENT")
157  {
158  ((OfxStatementContainer*)parentcontainer)->add_balance(this);
159  }
160  else
161  {
162  message_out (ERROR, "I completed a " + type + " element, but I havent found a suitable parent to save it");
163  }
164 }
165 void OfxBalanceContainer::add_attribute(const string identifier, const string value)
166 {
167  if (identifier == "BALAMT")
168  {
169  amount = ofxamount_to_double(value);
170  amount_valid = true;
171  }
172  else if (identifier == "DTASOF")
173  {
174  date = ofxdate_to_time_t(value);
175  date_valid = true;
176  }
177  else
178  {
179  /* Redirect unknown identifiers to the base class */
180  OfxGenericContainer::add_attribute(identifier, value);
181  }
182 }
const ErrorMsg find_error_msg(int param_code)
Retreive error code descriptions.
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
Definition: messages.hh:32
OFX error code management functionnality.
const char * description
Definition: inc/libofx.h:225
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
void add_attribute(const string identifier, const string value)
Add data to a container object.
int message_out(OfxMsgType error_type, const string message)
Message output function.
Definition: messages.cpp:60
time_t ofxdate_to_time_t(const string ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
double ofxamount_to_double(const string ofxamount)
Convert OFX amount of money to double float.
char * server_message
Definition: inc/libofx.h:242
Various simple functions for type conversion & al.
Represents a statement for either a bank account or a credit card account.
void add_attribute(const string identifier, const string value)
Add data to a container object.
void add_attribute(const string identifier, const string value)
Add data to a container object.
LibOFX internal object code.
An abstraction of an OFX error code sent by an OFX server.
Message IO functionality.
const char * name
Definition: inc/libofx.h:224
The root container. Created by the <OFX> OFX element or by the export functions.
void add_attribute(const string identifier, const string value)
Add data to a container object.