Adding OFX creation to libofx
ace jones <[email protected]> Sat, 16 Apr 2005 22:07:56 -0700
| Newsgroups | gmane.comp.finance.libofx.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello. I would like to add the facility to create OFX files into
libOFX. Martin Preuss will be able to use this in AqBanking to do OFX
Direct Connect, which in turn will make it available in GnuCash and
KMyMoney.
I already have it working in KMyMoney, and I use it for my personal
banking. So I know this works. I would generalize my code and fit it
into the library.
To begin with, I'd write the statement request OFX files, which would
get Martin going. I also have statement response OFX files working, but
that will take me more time to port over. Once that's in, users can
create their own OFX files. This would enable QIF2OFX for example.
In the future, I'd want to write transaction API's, and round out
support for what all Martin needs in AqBanking.
Ergo, I wanted to ask for CVS write access to libofx to put this work
in. My sf.net login is 'acejones'. As an active developer on KMyMoney
and kionjb, I promise I won't be a danger to the project :-)
Here is my design for integrating the statement request creator into
libOFX. This involves a change to libofx.h, and a new file in src/lib:
/*
* inc/libofx.h
*/
#define OFX_ORG_LENGTH 32 + 1
#define OFX_FID_LENGTH 32 + 1
#define OFX_USERID_LENGTH 32 + 1
#define OFX_USERPASS_LENGTH 32 + 1
#define OFX_BANKID_LENGTH 9 + 1
/**
* \brief Information sufficient to log into an financial institution
*
* Contains all the info needed for a user to log into a financial
* institution and make requests for statements or post transactions.
* An OfxFiLogin must be passed to all functions which create OFX
* requests.
*/
struct OfxFiLogin{
char fiid[OFX_FID_LENGTH];
char fiorg[OFX_ORG_LENGTH];
char bankid[OFX_BANKID_LENGTH];
char userid[OFX_USERID_LENGTH];
char userpassword[OFX_USERPASS_LENGTH];
};
typedef enum{
OFX_NO_ACCT=0,
OFX_BANK_ACCT,
OFX_INVEST_ACCOUNT,
OFX_CREDITCARD_ACCOUNT,
OFX_INVALID_ACCOUNT
} AccountType;
/**
* \brief Information sufficient to identify an account
*
* Contains all the info needed for an OFX request to identify an
account.
* An OfxAccountInfo must be passed to all functions which create OFX
* requests related to a specific account.
*/
struct OfxAccountInfo{
char account_id[OFX_ACCOUNT_ID_LENGTH];
AccountType type;
};
/**
* \brief libofx_request_statement creates an OFX statement request in
string form
*
* Creates a string which should be passed to an OFX server. This
string is an OFX request suitable to retrieve a statement for the @p
account from the @p fi
*
* @param fi Identifies the financial institution and the user logging
in.
* @param account Idenfities the account for which a statement is
desired
* @return string pointer to the request. This is allocated via
malloc(), and is the callers responsibility to free.
*/
CFCT char* libofx_request_statement( OfxFiLogin* fi, OfxAccountInfo*
account, time_t date_from );
/*
* src/lib/ofx_request_statement.cpp
*/
/**
* \brief A single aggregate as described in the OFX 1.02 specification
*
* This aggregate has a tag, and optionally a number of subordinate
elements and aggregates.
*
* An example is:
* <CCACCTINFO> <!-- Begins an aggregate, with the tag
'CCACCTINFO' -->
* <CCACCTFROM> <!-- Begins a subordinate aggregate, with
the tag 'CCACCTFROM' -->
* <ACCTID>1234 <!-- Subordinate element, with tag 'ACCTID',
data '1234' -->
* </CCACCTFROM> <!-- Ends the CCACCTFROM aggregate -->
* <SUPTXDL>Y <!-- Subordinate element, with tag
'SUPTXDL', data 'Y' -->
* <SVCSTATUS>ACTIVE
* </CCACCTINFO> <!-- Ends the CCACCTINFO aggregate -->
*/
class OfxAggregate
{
public:
/**
* Creates a new aggregate, using this tag
*
* @param tag The tag of this aggregate
*/
OfxAggregate( const string& tag);
/**
* Adds an element to this aggregate
*
* @param tag The tag of the element to be added
* @param data The data of the element to be added
*/
void Add( const string& tag, const string& data );
/**
* Adds a subordinate aggregate to this aggregate
*
* @param sub The aggregate to be added
*/
void Add( const OfxAggregate& sub);
/**
* Composes this aggregate into a string
*
* @return string form of this aggregate
*/
string Output( void ) const;
private:
string m_tag;
string m_contents;
};
/**
* \brief A statement request
*
* This is an entire OFX aggregate, with all subordinate aggregates
needed to log onto the OFX server of a single financial institution and
download a statement for a single account.
*/
class OfxStatementRequest: protected OfxAggregate
{
public:
/**
* Creates the request aggregate to obtain a statement from this @p fi
for
* this @p account, starting on this @p start date, ending today.
*
* @param fi The information needed to log on user into one financial
* institution
* @param account The account for which a statement is desired
* @param start The beginning time of the statement period desired
*/
OfxStatementRequest( const OfxFiLogin& fi, const OfxAccountInfo&
account, time_t from );
/**
* Composes this request into a string
*
* @return string form of this aggregate
*/
string Output( void ) const;
protected:
/**
* Creates a signon request aggregate, <SIGNONMSGSRQV1> & <SONRQ>,
sufficient
* to log this user into this financial institution.
*
* @return The request aggregate created
*/
OfxAggregate SignOnRequest(void) const;
/**
* Creates a bank statement request aggregate, <BANKMSGSRQV1>,
<STMTTRNRQ> & <STMTRQ> for this account. Should only be used if this
account is a BANK account.
*
* @return The request aggregate created
*/
OfxAggregate BankStatementRequest(void) const;
/**
* Creates a credit card statement request aggregate,
<CREDITCARDMSGSRQV1>, <CCSTMTTRNRQ> & <CCSTMTRQ> for this account.
Should only be used if this account is a CREDIT CARD account.
*
* @return The request aggregate created
*/
OfxAggregate CreditCardStatementRequest(void) const;
/**
* Creates an investment statement request aggregate,
<INSTMTMSGSRQV1>, <INVSTMTTRNRQ> & <INVSTMTRQ> for this account. Should
only be used if this account is an INVESTMENT account.
*
* @return The request aggregate created
*/
OfxAggregate InvestmentStatementRequest(void) const;
/**
* Creates a message aggregate
*
* @param msgtype The type of message. This will be prepended to
"MSGSRQV1" to become the tagname of the overall aggregate
* @param trntype The type of transactions being requested. This will
be prepended to "TRNRQ" to become the tagname of the subordinate
aggregate.
* @param aggregate The actual contents of the message, which will be
a sub aggregate of the xxxTRNRQ aggregate.
* @return The message aggregate created
*/
OfxAggregate RequestMessage(const string& msgtype, const string&
trntype, const OfxAggregate& aggregate ) const;
private:
OfxFiLogin m_login;
OfxAccountInfo m_account;
time_t date_from;
};
</Ace>
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click