ofx_request.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002          ofx_request.cpp 
00003                              -------------------
00004     copyright            : (C) 2005 by Ace Jones
00005     email                : acejones@users.sourceforge.net
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_request.hh"
00028 
00029 using namespace std;
00030 
00031 string time_t_to_ofxdatetime( time_t time )
00032 {
00033   static char buffer[51];
00034 
00035   strftime( buffer, 50, "%Y%m%d%H%M%S.000", localtime(&time) );
00036   buffer[50] = 0;
00037   
00038   return string(buffer);
00039 }
00040 
00041 string time_t_to_ofxdate( time_t time )
00042 {
00043   static char buffer[51];
00044 
00045   strftime( buffer, 50, "%Y%m%d", localtime(&time) );
00046   buffer[50] = 0;
00047   
00048   return string(buffer);
00049 }
00050 
00051 string OfxHeader(const char *hver){
00052   if (hver==NULL || hver[0]==0)
00053     hver="102";
00054 
00055   if (strcmp(hver, "103")==0)
00056     /* TODO: check for differences in version 102 and 103 */
00057     return string("OFXHEADER:100\r\n"
00058                   "DATA:OFXSGML\r\n"
00059                   "VERSION:103\r\n"
00060                   "SECURITY:NONE\r\n"
00061                   "ENCODING:USASCII\r\n"
00062                   "CHARSET:1252\r\n"
00063                   "COMPRESSION:NONE\r\n"
00064                   "OLDFILEUID:NONE\r\n"
00065                   "NEWFILEUID:")
00066       + time_t_to_ofxdatetime( time(NULL) )
00067       + string("\r\n\r\n");
00068   else
00069     return string("OFXHEADER:100\r\n"
00070                   "DATA:OFXSGML\r\n"
00071                   "VERSION:102\r\n"
00072                   "SECURITY:NONE\r\n"
00073                   "ENCODING:USASCII\r\n"
00074                   "CHARSET:1252\r\n"
00075                   "COMPRESSION:NONE\r\n"
00076                   "OLDFILEUID:NONE\r\n"
00077                   "NEWFILEUID:")
00078       + time_t_to_ofxdatetime( time(NULL) )
00079       + string("\r\n\r\n");
00080 }
00081 
00082 OfxAggregate OfxRequest::SignOnRequest(void) const
00083 {
00084   OfxAggregate fiTag("FI");
00085   fiTag.Add( "ORG", m_login.org );
00086   if ( strlen(m_login.fid) > 0 )
00087     fiTag.Add( "FID", m_login.fid );
00088 
00089   OfxAggregate sonrqTag("SONRQ");
00090   sonrqTag.Add( "DTCLIENT", time_t_to_ofxdatetime( time(NULL) ) );
00091   sonrqTag.Add( "USERID", m_login.userid);
00092   sonrqTag.Add( "USERPASS", m_login.userpass);
00093   sonrqTag.Add( "LANGUAGE","ENG");
00094   sonrqTag.Add( fiTag );
00095   if ( strlen(m_login.appid) > 0 )
00096       sonrqTag.Add( "APPID", m_login.appid);
00097   else
00098       sonrqTag.Add( "APPID","QWIN");
00099   if ( strlen(m_login.appver) > 0 )
00100     sonrqTag.Add( "APPVER", m_login.appver);
00101   else
00102     sonrqTag.Add( "APPVER","1400");
00103 
00104   OfxAggregate signonmsgTag("SIGNONMSGSRQV1");
00105   signonmsgTag.Add( sonrqTag );
00106 
00107   return signonmsgTag;
00108 }
00109 
00110 OfxAggregate OfxRequest::RequestMessage(const string& _msgType, const string& _trnType, const OfxAggregate& _request) const
00111 {
00112   OfxAggregate trnrqTag( _trnType+"TRNRQ" );
00113   trnrqTag.Add( "TRNUID", time_t_to_ofxdatetime( time(NULL) ) );
00114   trnrqTag.Add( "CLTCOOKIE","1" ); 
00115   trnrqTag.Add( _request );
00116     
00117   OfxAggregate result( _msgType+"MSGSRQV1" );
00118   result.Add( trnrqTag );
00119 
00120   return result;
00121 }

Generated on Mon Feb 9 21:21:59 2009 for LibOFX by  doxygen 1.5.0