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 std::string time_t_to_ofxdatetime( time_t time )
31 {
32  static char buffer[51];
33 
34  strftime( buffer, 50, "%Y%m%d%H%M%S.000", localtime(&time) );
35  buffer[50] = 0;
36 
37  return std::string(buffer);
38 }
39 
40 std::string time_t_to_ofxdate( time_t time )
41 {
42  static char buffer[51];
43 
44  strftime( buffer, 50, "%Y%m%d", localtime(&time) );
45  buffer[50] = 0;
46 
47  return std::string(buffer);
48 }
49 
50 std::string OfxHeader(const char *hver)
51 {
52  if (hver == NULL || hver[0] == 0)
53  hver = "102";
54 
55  if (strcmp(hver, "103") == 0)
56  /* TODO: check for differences in version 102 and 103 */
57  return std::string("OFXHEADER:100\r\n"
58  "DATA:OFXSGML\r\n"
59  "VERSION:103\r\n"
60  "SECURITY:NONE\r\n"
61  "ENCODING:USASCII\r\n"
62  "CHARSET:1252\r\n"
63  "COMPRESSION:NONE\r\n"
64  "OLDFILEUID:NONE\r\n"
65  "NEWFILEUID:")
66  + time_t_to_ofxdatetime( time(NULL) )
67  + std::string("\r\n\r\n");
68  else
69  return std::string("OFXHEADER:100\r\n"
70  "DATA:OFXSGML\r\n"
71  "VERSION:102\r\n"
72  "SECURITY:NONE\r\n"
73  "ENCODING:USASCII\r\n"
74  "CHARSET:1252\r\n"
75  "COMPRESSION:NONE\r\n"
76  "OLDFILEUID:NONE\r\n"
77  "NEWFILEUID:")
78  + time_t_to_ofxdatetime( time(NULL) )
79  + std::string("\r\n\r\n");
80 }
81 
83 {
84  OfxAggregate fiTag("FI");
85  fiTag.Add( "ORG", m_login.org );
86  if ( strlen(m_login.fid) > 0 )
87  fiTag.Add( "FID", m_login.fid );
88 
89  OfxAggregate sonrqTag("SONRQ");
90  sonrqTag.Add( "DTCLIENT", time_t_to_ofxdatetime( time(NULL) ) );
91  sonrqTag.Add( "USERID", m_login.userid);
92  sonrqTag.Add( "USERPASS", m_login.userpass);
93  sonrqTag.Add( "LANGUAGE", "ENG");
94  sonrqTag.Add( fiTag );
95  if ( strlen(m_login.appid) > 0 )
96  sonrqTag.Add( "APPID", m_login.appid);
97  else
98  sonrqTag.Add( "APPID", "QWIN");
99  if ( strlen(m_login.appver) > 0 )
100  sonrqTag.Add( "APPVER", m_login.appver);
101  else
102  sonrqTag.Add( "APPVER", "1400");
103 
104  if ( strlen(m_login.clientuid) > 0 )
105  sonrqTag.Add( "CLIENTUID", m_login.clientuid);
106 
107  OfxAggregate signonmsgTag("SIGNONMSGSRQV1");
108  signonmsgTag.Add( sonrqTag );
109 
110  return signonmsgTag;
111 }
112 
113 OfxAggregate OfxRequest::RequestMessage(const std::string& _msgType, const std::string& _trnType, const OfxAggregate& _request) const
114 {
115  OfxAggregate trnrqTag( _trnType + "TRNRQ" );
116  trnrqTag.Add( "TRNUID", time_t_to_ofxdatetime( time(NULL) ) );
117  trnrqTag.Add( "CLTCOOKIE", "1" );
118  trnrqTag.Add( _request );
119 
120  OfxAggregate result( _msgType + "MSGSRQV1" );
121  result.Add( trnrqTag );
122 
123  return result;
124 }
OfxAggregate::Add
void Add(const std::string &tag, const std::string &data)
Definition: ofx_aggregate.hh:64
OfxRequest::RequestMessage
OfxAggregate RequestMessage(const std::string &msgtype, const std::string &trntype, const OfxAggregate &aggregate) const
Definition: ofx_request.cpp:113
OfxRequest::SignOnRequest
OfxAggregate SignOnRequest(void) const
Definition: ofx_request.cpp:82
ofx_request.hh
Declaration of an OfxRequests to create an OFX file containing a generic request .
OfxAggregate
A single aggregate as described in the OFX 1.02 specification.
Definition: ofx_aggregate.hh:40
messages.hh
Message IO functionality.