LibOFX

ofx_request.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 ofx_request.cpp
3 -------------------
4 copyright : (C) 2005 by Ace Jones
5 email : acejones@users.sourceforge.net
6 ***************************************************************************/
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <cstring>
25 #include <string>
26 #include "messages.hh"
27 #include "libofx.h"
28 #include "ofx_request.hh"
29
30 using namespace std;
31
32 string time_t_to_ofxdatetime( time_t time )
33 {
34 static char buffer[51];
35
36 strftime( buffer, 50, "%Y%m%d%H%M%S.000", localtime(&time) );
37 buffer[50] = 0;
38
39 return string(buffer);
40 }
41
42 string time_t_to_ofxdate( time_t time )
43 {
44 static char buffer[51];
45
46 strftime( buffer, 50, "%Y%m%d", localtime(&time) );
47 buffer[50] = 0;
48
49 return string(buffer);
50 }
51
52 string OfxHeader(const char *hver)
53 {
54 if (hver == NULL || hver[0] == 0)
55 hver = "102";
56
57 if (strcmp(hver, "103") == 0)
58 /* TODO: check for differences in version 102 and 103 */
59 return string("OFXHEADER:100\r\n"
60 "DATA:OFXSGML\r\n"
61 "VERSION:103\r\n"
62 "SECURITY:NONE\r\n"
63 "ENCODING:USASCII\r\n"
64 "CHARSET:1252\r\n"
65 "COMPRESSION:NONE\r\n"
66 "OLDFILEUID:NONE\r\n"
67 "NEWFILEUID:")
68 + time_t_to_ofxdatetime( time(NULL) )
69 + string("\r\n\r\n");
70 else
71 return string("OFXHEADER:100\r\n"
72 "DATA:OFXSGML\r\n"
73 "VERSION:102\r\n"
74 "SECURITY:NONE\r\n"
75 "ENCODING:USASCII\r\n"
76 "CHARSET:1252\r\n"
77 "COMPRESSION:NONE\r\n"
78 "OLDFILEUID:NONE\r\n"
79 "NEWFILEUID:")
80 + time_t_to_ofxdatetime( time(NULL) )
81 + string("\r\n\r\n");
82 }
83
84 OfxAggregate OfxRequest::SignOnRequest(void) const
85 {
86 OfxAggregate fiTag("FI");
87 fiTag.Add( "ORG", m_login.org );
88 if ( strlen(m_login.fid) > 0 )
89 fiTag.Add( "FID", m_login.fid );
90
91 OfxAggregate sonrqTag("SONRQ");
92 sonrqTag.Add( "DTCLIENT", time_t_to_ofxdatetime( time(NULL) ) );
93 sonrqTag.Add( "USERID", m_login.userid);
94 sonrqTag.Add( "USERPASS", m_login.userpass);
95 sonrqTag.Add( "LANGUAGE", "ENG");
96 sonrqTag.Add( fiTag );
97 if ( strlen(m_login.appid) > 0 )
98 sonrqTag.Add( "APPID", m_login.appid);
99 else
100 sonrqTag.Add( "APPID", "QWIN");
101 if ( strlen(m_login.appver) > 0 )
102 sonrqTag.Add( "APPVER", m_login.appver);
103 else
104 sonrqTag.Add( "APPVER", "1400");
105
106 if ( strlen(m_login.clientuid) > 0 )
107 sonrqTag.Add( "CLIENTUID", m_login.clientuid);
108
109 OfxAggregate signonmsgTag("SIGNONMSGSRQV1");
110 signonmsgTag.Add( sonrqTag );
111
112 return signonmsgTag;
113 }
114
115 OfxAggregate OfxRequest::RequestMessage(const string& _msgType, const string& _trnType, const OfxAggregate& _request) const
116 {
117 OfxAggregate trnrqTag( _trnType + "TRNRQ" );
118 trnrqTag.Add( "TRNUID", time_t_to_ofxdatetime( time(NULL) ) );
119 trnrqTag.Add( "CLTCOOKIE", "1" );
120 trnrqTag.Add( _request );
121
122 OfxAggregate result( _msgType + "MSGSRQV1" );
123 result.Add( trnrqTag );
124
125 return result;
126 }
ofx_request.hh
Declaration of an OfxRequests to create an OFX file containing a generic request .
std
OfxAggregate
A single aggregate as described in the OFX 1.02 specification.
Definition: ofx_aggregate.hh:42
OfxRequest::RequestMessage
OfxAggregate RequestMessage(const string &msgtype, const string &trntype, const OfxAggregate &aggregate) const
Definition: ofx_request.cpp:115
OfxAggregate::Add
void Add(const string &tag, const string &data)
Definition: ofx_aggregate.hh:59
messages.hh
Message IO functionality.
OfxRequest::SignOnRequest
OfxAggregate SignOnRequest(void) const
Definition: ofx_request.cpp:84