LibOFX: ofx_container_account.cpp Source File

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

# ofx_container_account.cpp

Go to the documentation of this file.

    00001 /***************************************************************************
    00002          ofx_container_account.cpp
    00003                              -------------------
    00004     copyright            : (C) 2002 by Benoit Grégoire
    00005     email                : bock@step.polymtl.ca
    00006 ***************************************************************************/
    00011 /***************************************************************************
    00012  *                                                                         *
    00013  *   This program is free software; you can redistribute it and/or modify  *
    00014  *   it under the terms of the GNU General Public License as published by  *
    00015  *   the Free Software Foundation; either version 2 of the License, or     *
    00016  *   (at your option) any later version.                                   *
    00017  *                                                                         *
    00018  ***************************************************************************/
    00019
    00020 #ifdef HAVE_CONFIG_H
    00021 #include <config.h>
    00022 #endif
    00023
    00024 #include <string>
    00025 #include "messages.hh"
    00026 #include "libofx.h"
    00027 #include "ofx_containers.hh"
    00028 #include "ofx_utilities.hh"
    00029
    00030 extern OfxMainContainer * MainContainer;
    00031
    00032 /***************************************************************************
    00033  *                      OfxAccountContainer                                *
    00034  ***************************************************************************/
    00035
    00036 OfxAccountContainer::OfxAccountContainer(LibofxContext *p_libofx_context, OfxGenericContainer *para_parentcontainer, string para_tag_identifier):
    00037   OfxGenericContainer(p_libofx_context, para_parentcontainer, para_tag_identifier)
    00038 {
    00039   memset(&data,0,sizeof(data));
    00040   type="ACCOUNT";
    00041   strcpy(bankid,"");
    00042   strcpy(branchid,"");
    00043   strcpy(acctid,"");
    00044   strcpy(acctkey,"");
    00045   strcpy(brokerid,"");
    00046   if(para_tag_identifier== "CCACCTFROM")
    00047     {
    00048       /*Set the type for a creditcard account.  Bank account specific
    00049         OFX elements will set this attribute elsewhere */
    00050       data.account_type = data.OFX_CREDITCARD;
    00051       data.account_type_valid = true;
    00052     }
    00053   if(para_tag_identifier== "INVACCTFROM")
    00054     {
    00055       /*Set the type for an investment account.  Bank account specific
    00056         OFX elements will set this attribute elsewhere */
    00057       data.account_type = data.OFX_INVESTMENT;
    00058       data.account_type_valid = true;
    00059     }
    00060   if (parentcontainer!=NULL&&((OfxStatementContainer*)parentcontainer)->data.currency_valid==true){
    00061     strncpy(data.currency,((OfxStatementContainer*)parentcontainer)->data.currency,OFX_CURRENCY_LENGTH); /* In ISO-4217 format */
    00062     data.currency_valid=true;
    00063   }
    00064 }
    00065 OfxAccountContainer::~OfxAccountContainer()
    00066 {
    00067   /*  if (parentcontainer->type == "STATEMENT")
    00068       {
    00069       ((OfxStatementContainer*)parentcontainer)->add_account(data);
    00070       }
    00071       ofx_proc_account_cb (data);*/
    00072 }
    00073
    00074 void OfxAccountContainer::add_attribute(const string identifier, const string value)
    00075 {
    00076   if( identifier=="BANKID"){
    00077     strncpy(bankid,value.c_str(),OFX_BANKID_LENGTH);
    00078     data.bank_id_valid=true;
    00079     strncpy(data.bank_id, value.c_str(), OFX_BANKID_LENGTH);
    00080   }
    00081   else if( identifier=="BRANCHID"){
    00082     strncpy(branchid,value.c_str(),OFX_BRANCHID_LENGTH);
    00083     data.branch_id_valid=true;
    00084     strncpy(data.branch_id, value.c_str(), OFX_BRANCHID_LENGTH);
    00085   }
    00086   else if( identifier=="ACCTID"){
    00087     strncpy(acctid,value.c_str(),OFX_ACCTID_LENGTH);
    00088     data.account_number_valid=true;
    00089     strncpy(data.account_number, value.c_str(), OFX_ACCTID_LENGTH);
    00090   }
    00091   else if( identifier=="ACCTKEY"){
    00092     strncpy(acctkey,value.c_str(),OFX_ACCTKEY_LENGTH);
    00093   }
    00094   else if( identifier=="BROKERID"){ /* For investment accounts */
    00095     strncpy(brokerid,value.c_str(),OFX_BROKERID_LENGTH);
    00096     data.broker_id_valid=true;
    00097     strncpy(data.broker_id, value.c_str(), OFX_BROKERID_LENGTH);
    00098   }
    00099   else if((identifier=="ACCTTYPE")||(identifier=="ACCTTYPE2")){
    00100     data.account_type_valid=true;
    00101     if(value=="CHECKING"){
    00102       data.account_type=data.OFX_CHECKING;
    00103     }
    00104     else if(value=="SAVINGS"){
    00105       data.account_type=data.OFX_SAVINGS;
    00106     }
    00107     else if(value=="MONEYMRKT"){
    00108       data.account_type=data.OFX_MONEYMRKT;
    00109     }
    00110     else if(value=="CREDITLINE"){
    00111       data.account_type=data.OFX_CREDITLINE;
    00112     }
    00113     else if(value=="CMA"){
    00114       data.account_type=data.OFX_CMA;
    00115     }
    00116     /* AccountType CREDITCARD is set at object creation, if appropriate */
    00117     else{
    00118       data.account_type_valid=false;
    00119     }
    00120   }
    00121   else{
    00122     /* Redirect unknown identifiers to the base class */
    00123     OfxGenericContainer::add_attribute(identifier, value);
    00124   }
    00125 }//end OfxAccountContainer::add_attribute()
    00126
    00127 int OfxAccountContainer::gen_event()
    00128 {
    00129   libofx_context->accountCallback(data);
    00130   return true;
    00131 }
    00132
    00133 int  OfxAccountContainer::add_to_main_tree()
    00134 {
    00135   gen_account_id ();
    00136
    00137   if(MainContainer != NULL)
    00138     {
    00139       return MainContainer->add_container(this);
    00140     }
    00141   else
    00142     {
    00143       return false;
    00144     }
    00145 }
    00146
    00147 void OfxAccountContainer::gen_account_id(void)
    00148 {
    00149   if(data.account_type==OfxAccountData::OFX_CREDITCARD){
    00150     strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00151     strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00152     strncat(data.account_id,acctkey,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00153
    00154     strncat(data.account_name,"Credit card ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00155     strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00156   }
    00157   else if(data.account_type==OfxAccountData::OFX_INVESTMENT){
    00158     strncat(data.account_id,brokerid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00159     strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00160     strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00161
    00162     strncat(data.account_name,"Investment account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00163     strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00164     strncat(data.account_name," at broker ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00165     strncat(data.account_name,brokerid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00166   }
    00167   else{
    00168     strncat(data.account_id,bankid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00169     strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00170     strncat(data.account_id,branchid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00171     strncat(data.account_id," ",OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00172     strncat(data.account_id,acctid,OFX_ACCOUNT_ID_LENGTH-strlen(data.account_id));
    00173
    00174     strncat(data.account_name,"Bank account ",OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00175     strncat(data.account_name,acctid,OFX_ACCOUNT_NAME_LENGTH-strlen(data.account_name));
    00176   }
    00177   if(strlen(data.account_id)>=0){
    00178     data.account_id_valid=true;
    00179   }
    00180 }//end OfxAccountContainer::gen_account_id()