File: ofx_request.cpp

package info (click to toggle)
libofx 1%3A0.8.2-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 7,764 kB
  • ctags: 21,113
  • sloc: sh: 8,771; cpp: 5,475; ansic: 2,208; makefile: 200; xml: 61
file content (99 lines) | stat: -rw-r--r-- 3,048 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/***************************************************************************
         ofx_request.cpp 
                             -------------------
    copyright            : (C) 2005 by Ace Jones
    email                : acejones@users.sourceforge.net
***************************************************************************/
/**@file
 * \brief Implementation of an OfxRequests to create an OFX file
 *   containing a generic request .
*/
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string>
#include "messages.hh"
#include "libofx.h"
#include "ofx_request.hh"

using namespace std;

string time_t_to_ofxdatetime( time_t time )
{
  static char buffer[51];

  strftime( buffer, 50, "%Y%m%d%H%M%S.000", localtime(&time) );
  buffer[50] = 0;
  
  return string(buffer);
}

string time_t_to_ofxdate( time_t time )
{
  static char buffer[51];

  strftime( buffer, 50, "%Y%m%d", localtime(&time) );
  buffer[50] = 0;
  
  return string(buffer);
}

string OfxHeader(void)
{
  return string("OFXHEADER:100\r\n"
                 "DATA:OFXSGML\r\n"
                 "VERSION:102\r\n"
                 "SECURITY:NONE\r\n"
                 "ENCODING:USASCII\r\n"
                 "CHARSET:1252\r\n"
                 "COMPRESSION:NONE\r\n"
                 "OLDFILEUID:NONE\r\n"
                 "NEWFILEUID:")
                 + time_t_to_ofxdatetime( time(NULL) )
                 + string("\r\n\r\n");
}

OfxAggregate OfxRequest::SignOnRequest(void) const
{
  OfxAggregate fiTag("FI");
  fiTag.Add( "ORG", m_login.org );
  if ( strlen(m_login.fid) > 0 )
    fiTag.Add( "FID", m_login.fid );

  OfxAggregate sonrqTag("SONRQ");
  sonrqTag.Add( "DTCLIENT", time_t_to_ofxdatetime( time(NULL) ) );
  sonrqTag.Add( "USERID", m_login.userid);
  sonrqTag.Add( "USERPASS", m_login.userpass);
  sonrqTag.Add( "LANGUAGE","ENG");
  sonrqTag.Add( fiTag );
  sonrqTag.Add( "APPID","QWIN");
  sonrqTag.Add( "APPVER","1200");
  
  OfxAggregate signonmsgTag("SIGNONMSGSRQV1");
  signonmsgTag.Add( sonrqTag );

  return signonmsgTag;
}

OfxAggregate OfxRequest::RequestMessage(const string& _msgType, const string& _trnType, const OfxAggregate& _request) const
{
  OfxAggregate trnrqTag( _trnType+"TRNRQ" );
  trnrqTag.Add( "TRNUID", time_t_to_ofxdatetime( time(NULL) ) );
  trnrqTag.Add( "CLTCOOKIE","1" ); 
  trnrqTag.Add( _request );
    
  OfxAggregate result( _msgType+"MSGSRQV1" );
  result.Add( trnrqTag );

  return result;
}