LibOFX
ofx_containers_misc.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002          ofx_proc_rs.cpp
00003                              -------------------
00004     copyright            : (C) 2002 by Benoit Grégoire
00005     email                : benoitg@coeus.ca
00006 ***************************************************************************/
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 
00026 #include <iostream>
00027 #include <stdlib.h>
00028 #include <string>
00029 #include "messages.hh"
00030 #include "libofx.h"
00031 #include "ofx_error_msg.hh"
00032 #include "ofx_utilities.hh"
00033 #include "ofx_containers.hh"
00034 
00035 extern OfxMainContainer * MainContainer;
00036 
00037 /***************************************************************************
00038  *                         OfxDummyContainer                               *
00039  ***************************************************************************/
00040 
00041 OfxDummyContainer::OfxDummyContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00042   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
00043 {
00044   type = "DUMMY";
00045   message_out(INFO, "Created OfxDummyContainer to hold unsupported aggregate " + para_tag_identifier);
00046 }
00047 void OfxDummyContainer::add_attribute(const string identifier, const string value)
00048 {
00049   message_out(DEBUG, "OfxDummyContainer for " + tag_identifier + " ignored a " + identifier + " (" + value + ")");
00050 }
00051 
00052 /***************************************************************************
00053  *                         OfxPushUpContainer                              *
00054  ***************************************************************************/
00055 
00056 OfxPushUpContainer::OfxPushUpContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00057   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
00058 {
00059   type = "PUSHUP";
00060   message_out(DEBUG, "Created OfxPushUpContainer to hold aggregate " + tag_identifier);
00061 }
00062 void OfxPushUpContainer::add_attribute(const string identifier, const string value)
00063 {
00064   //message_out(DEBUG, "OfxPushUpContainer for "+tag_identifier+" will push up a "+identifier+" ("+value+") to a "+ parentcontainer->type + " container");
00065   parentcontainer->add_attribute(identifier, value);
00066 }
00067 
00068 /***************************************************************************
00069  *                         OfxStatusContainer                              *
00070  ***************************************************************************/
00071 
00072 OfxStatusContainer::OfxStatusContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00073   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
00074 {
00075   memset(&data, 0, sizeof(data));
00076   type = "STATUS";
00077   if (parentcontainer != NULL)
00078   {
00079     strncpy(data.ofx_element_name, parentcontainer->tag_identifier.c_str(), OFX_ELEMENT_NAME_LENGTH);
00080     data.ofx_element_name_valid = true;
00081   }
00082 
00083 }
00084 OfxStatusContainer::~OfxStatusContainer()
00085 {
00086   message_out(DEBUG, "Entering the status's container's destructor");
00087 
00088   libofx_context->statusCallback(data);
00089 
00090   if ( data.server_message_valid )
00091     delete [] data.server_message;
00092 }
00093 
00094 void OfxStatusContainer::add_attribute(const string identifier, const string value)
00095 {
00096   ErrorMsg error_msg;
00097 
00098   if ( identifier == "CODE")
00099   {
00100     data.code = atoi(value.c_str());
00101     error_msg = find_error_msg(data.code);
00102     data.name = error_msg.name;//memory is already allocated
00103     data.description = error_msg.description;//memory is already allocated
00104     data.code_valid = true;
00105   }
00106   else if (identifier == "SEVERITY")
00107   {
00108     data.severity_valid = true;
00109     if (value == "INFO")
00110     {
00111       data.severity = OfxStatusData::INFO;
00112     }
00113     else if (value == "WARN")
00114     {
00115       data.severity = OfxStatusData::WARN;
00116     }
00117     else if (value == "ERROR")
00118     {
00119       data.severity = OfxStatusData::ERROR;
00120     }
00121     else
00122     {
00123       message_out(ERROR, "WRITEME: Unknown severity " + value + " inside a " + type + " container");
00124       data.severity_valid = false;
00125     }
00126   }
00127   else if ((identifier == "MESSAGE") || (identifier == "MESSAGE2"))
00128   {
00129     data.server_message = new char[value.length()+1];
00130     strcpy(data.server_message, value.c_str());
00131     data.server_message_valid = true;
00132   }
00133   else
00134   {
00135     /* Redirect unknown identifiers to the base class */
00136     OfxGenericContainer::add_attribute(identifier, value);
00137   }
00138 }
00139 
00140 
00141 
00142 /***************************************************************************
00143  * OfxBalanceContainer  (does not directly abstract a object in libofx.h)  *
00144  ***************************************************************************/
00145 
00146 OfxBalanceContainer::OfxBalanceContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
00147   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
00148 {
00149   amount_valid = false;
00150   date_valid = false;
00151   type = "BALANCE";
00152 }
00153 
00154 OfxBalanceContainer::~OfxBalanceContainer()
00155 {
00156   if (parentcontainer->type == "STATEMENT")
00157   {
00158     ((OfxStatementContainer*)parentcontainer)->add_balance(this);
00159   }
00160   else
00161   {
00162     message_out (ERROR, "I completed a " + type + " element, but I havent found a suitable parent to save it");
00163   }
00164 }
00165 void OfxBalanceContainer::add_attribute(const string identifier, const string value)
00166 {
00167   if (identifier == "BALAMT")
00168   {
00169     amount = ofxamount_to_double(value);
00170     amount_valid = true;
00171   }
00172   else if (identifier == "DTASOF")
00173   {
00174     date = ofxdate_to_time_t(value);
00175     date_valid = true;
00176   }
00177   else
00178   {
00179     /* Redirect unknown identifiers to the base class */
00180     OfxGenericContainer::add_attribute(identifier, value);
00181   }
00182 }