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