~mterry/ubuntu/natty/libofx/libofx.new-upstream-benoit-sru

« back to all changes in this revision

Viewing changes to inc/libofx.h.in

  • Committer: Bazaar Package Importer
  • Author(s): Saïvann Carignan
  • Date: 2008-02-06 17:25:16 UTC
  • mto: (3.1.2 lenny)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20080206172516-bnzxb29igye8um9h
Tags: upstream-0.9.0
Import upstream version 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
              libofx.h  -  Main header file for the libofx API
 
3
                             -------------------
 
4
    copyright            : (C) 2002 by Benoit Gr�goire
 
5
    email                : bock@step.polymtl.ca
 
6
***************************************************************************/
 
7
/**@file
 
8
 * \brief Main header file containing the LibOfx API
 
9
 *
 
10
 This file should be included for all applications who use this API.  This
 
11
 header file will work with both C and C++ programs.  The entire API is 
 
12
 made of the following structures and functions. 
 
13
 *
 
14
 All of the following ofx_proc_* functions are callbacks (Except
 
15
 ofx_proc_file which is the entry point).  They must be implemented by 
 
16
 your program, but can be left empty if not needed. They are called each
 
17
 time the associated structure is filled by the library.
 
18
 *
 
19
 Important note:  The variables associated with every data element have a 
 
20
 *_valid companion.  Always check that data_valid == true before using. 
 
21
 Not only will you ensure that the data is meaningfull, but also that
 
22
 pointers are valid and strings point to a null terminated string.  
 
23
 Elements listed as mandatory are for information purpose only, do not 
 
24
 trust the bank not to send you non-conforming data...
 
25
*/
 
26
/***************************************************************************
 
27
 *                                                                         *
 
28
 *   This program is free software; you can redistribute it and/or modify  *
 
29
 *   it under the terms of the GNU General Public License as published by  *
 
30
 *   the Free Software Foundation; either version 2 of the License, or     *
 
31
 *   (at your option) any later version.                                   *
 
32
 *                                                                         *
 
33
 ***************************************************************************/
 
34
 
 
35
#ifndef LIBOFX_H
 
36
#define LIBOFX_H
 
37
#include <time.h>
 
38
 
 
39
#define LIBOFX_MAJOR_VERSION @LIBOFX_MAJOR_VERSION@
 
40
#define LIBOFX_MINOR_VERSION @LIBOFX_MINOR_VERSION@
 
41
#define LIBOFX_MICRO_VERSION @LIBOFX_MICRO_VERSION@
 
42
#define LIBOFX_BUILD_VERSION @LIBOFX_BUILD_VERSION@
 
43
#define LIBOFX_VERSION_RELEASE_STRING "@LIBOFX_VERSION_RELEASE_STRING@"
 
44
 
 
45
 
 
46
#ifdef __cplusplus
 
47
#define CFCT extern "C"
 
48
#else
 
49
#define CFCT
 
50
#define true 1
 
51
#define false 0
 
52
#endif
 
53
 
 
54
#define OFX_ELEMENT_NAME_LENGTH         100
 
55
#define OFX_SVRTID2_LENGTH             (36 + 1)
 
56
#define OFX_CHECK_NUMBER_LENGTH        (12 + 1)
 
57
#define OFX_REFERENCE_NUMBER_LENGTH    (32 + 1)
 
58
#define OFX_FITID_LENGTH               (255 + 1)
 
59
#define OFX_TOKEN2_LENGTH              (36 + 1)
 
60
#define OFX_MEMO_LENGTH                (255 + 1)
 
61
#define OFX_MEMO2_LENGTH               (390 + 1)
 
62
#define OFX_BALANCE_NAME_LENGTH        (32 + 1)
 
63
#define OFX_BALANCE_DESCRIPTION_LENGTH (80 + 1)
 
64
#define OFX_CURRENCY_LENGTH            (3 + 1) /* In ISO-4217 format */
 
65
#define OFX_BANKID_LENGTH              (9 + 1)
 
66
#define OFX_BRANCHID_LENGTH            (22 + 1)
 
67
#define OFX_ACCTID_LENGTH              (22 + 1)
 
68
#define OFX_ACCTKEY_LENGTH             (22 + 1)
 
69
#define OFX_BROKERID_LENGTH            (22 + 1)
 
70
/* Must be MAX of <BANKID>+<BRANCHID>+<ACCTID>, <ACCTID>+<ACCTKEY> and <ACCTID>+<BROKERID> */
 
71
#define OFX_ACCOUNT_ID_LENGTH (OFX_BANKID_LENGTH + OFX_BRANCHID_LENGTH + OFX_ACCTID_LENGTH + 1)
 
72
#define OFX_ACCOUNT_NAME_LENGTH        255
 
73
#define OFX_MARKETING_INFO_LENGTH      (360 + 1)
 
74
#define OFX_TRANSACTION_NAME_LENGTH    (32 + 1)
 
75
#define OFX_UNIQUE_ID_LENGTH           (32 + 1)
 
76
#define OFX_UNIQUE_ID_TYPE_LENGTH      (10 + 1)
 
77
#define OFX_SECNAME_LENGTH             (32 + 1)
 
78
#define OFX_TICKER_LENGTH              (32 + 1)
 
79
#define OFX_ORG_LENGTH                 (32 + 1)
 
80
#define OFX_FID_LENGTH                 (32 + 1)
 
81
#define OFX_USERID_LENGTH              (32 + 1)
 
82
#define OFX_USERPASS_LENGTH            (32 + 1)
 
83
#define OFX_URL_LENGTH                 (500 + 1)
 
84
#define OFX_APPID_LENGTH               (32)
 
85
#define OFX_APPVER_LENGTH              (32)
 
86
#define OFX_HEADERVERSION_LENGTH       (32)
 
87
 
 
88
/*
 
89
#define OFX_STATEMENT_CB               0;
 
90
#define OFX_ACCOUNT_CB                 1;
 
91
#define OFX_TRACSACTION_CB             2;
 
92
#define OFX_SECURITY_CB                3;
 
93
#define OFX_STATUS_CB                  4;
 
94
*/
 
95
 
 
96
typedef void * LibofxContextPtr;
 
97
/**
 
98
 * \brief Initialise the library and return a new context. 
 
99
 *
 
100
 @return the new context, to be used by the other functions.
 
101
*/
 
102
CFCT LibofxContextPtr libofx_get_new_context();
 
103
/**
 
104
 * \brief Free all ressources used by this context. 
 
105
 *
 
106
 @return 0 if successfull.
 
107
*/
 
108
CFCT int libofx_free_context( LibofxContextPtr );
 
109
 
 
110
CFCT void libofx_set_dtd_dir(LibofxContextPtr libofx_context,
 
111
                            const char *s);
 
112
 
 
113
/** List of possible file formats */
 
114
enum LibofxFileFormat{ AUTODETECT, /**< Not really a file format, used to tell the library to try to autodetect the format*/
 
115
                     OFX, /**< Open Financial eXchange (OFX/QFX) file */
 
116
                     OFC, /**< Microsoft Open Financial Connectivity (OFC)*/
 
117
                     QIF, /**< Intuit Quicken Interchange Format (QIF) */
 
118
                     UNKNOWN, /**< Unknown file format */
 
119
                     LAST /**< Not a file format, meant as a loop breaking condition */
 
120
};
 
121
 
 
122
struct LibofxFileFormatInfo{
 
123
enum LibofxFileFormat format;/**< The file format enum */
 
124
const char * format_name;  /**< Text version of the enum */
 
125
const char * description; /**< Description of the file format */
 
126
};
 
127
 
 
128
 
 
129
#ifndef OFX_AQUAMANIAC_UGLY_HACK1
 
130
 
 
131
const struct LibofxFileFormatInfo LibofxImportFormatList[] = 
 
132
{
 
133
{AUTODETECT, "AUTODETECT", "AUTODETECT (File format will be automatically detected later)"},
 
134
{OFX, "OFX", "OFX (Open Financial eXchange (OFX or QFX))"},
 
135
{OFC, "OFC", "OFC (Microsoft Open Financial Connectivity)"},
 
136
{QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
 
137
{LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
 
138
};
 
139
 
 
140
const struct LibofxFileFormatInfo LibofxExportFormatList[] = 
 
141
{
 
142
{QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
 
143
{LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
 
144
};
 
145
 
 
146
/**
 
147
 * \brief libofx_get_file_type returns a proper enum from a file type string. 
 
148
 *
 
149
 @format_list The file format list in which the format string should be found, usually LibofxImportFormatList or LibofxExportFormatList
 
150
 @file_type_string The string which contain the file format matching one of the format_name of the list.
 
151
 @return the file format, or UNKNOWN if the format wasn't recognised.
 
152
*/
 
153
CFCT enum LibofxFileFormat libofx_get_file_format_from_str(const struct LibofxFileFormatInfo format_list[], const char * file_type_string);
 
154
 
 
155
/**
 
156
 * \brief get_file_format_description returns a string description of a LibofxFileType. 
 
157
 *
 
158
 @format_list The file format list in which the format should be looked up, usually LibofxImportFormatList or LibofxExportFormatList
 
159
 @file_format The file format which should match one of the formats in the list.
 
160
 @return null terminated string suitable for debugging output or user communication.
 
161
*/
 
162
CFCT const char * libofx_get_file_format_description(const struct LibofxFileFormatInfo format_list[], enum LibofxFileFormat file_format);
 
163
 
 
164
#endif
 
165
 
 
166
/**
 
167
 * \brief libofx_proc_file is the entry point of the library.
 
168
 *
 
169
 *  libofx_proc_file must be called by the client, with a list of 1 or more OFX
 
170
 files to be parsed in command line format.
 
171
*/
 
172
CFCT int libofx_proc_file(LibofxContextPtr libofx_context,
 
173
                          const char * p_filename,
 
174
                          enum LibofxFileFormat ftype);
 
175
 
 
176
 
 
177
/**
 
178
 * \brief An abstraction of an OFX STATUS element.
 
179
 *
 
180
 * The OfxStatusData structure represents a STATUS OFX element sent by the 
 
181
 OFX server.  Be carefull, you do not have much context except the entity 
 
182
 name so your application should probably ignore this status if code==0. 
 
183
 However, you should display a message if the status in non-zero,
 
184
 since an error probably occurred on the server side.  
 
185
 *
 
186
 * In a future version of this API, OfxStatusData structures might be
 
187
 linked from the OFX structures they are related to.
 
188
*/
 
189
struct OfxStatusData{  
 
190
  /** @name Additional information
 
191
   * To give a minimum of context, the name of the OFX SGML element where
 
192
   this <STATUS> is located is available.
 
193
  */
 
194
  char ofx_element_name[OFX_ELEMENT_NAME_LENGTH];/** Name of the OFX element
 
195
                                                     this status is relevant to */
 
196
  int ofx_element_name_valid;
 
197
  
 
198
  /** @name OFX mandatory elements
 
199
   * The OFX spec defines the following elements as mandatory.  The associated
 
200
   variables should all contain valid data but you should not trust the servers.
 
201
   Check if the associated *_valid is true before using them. */
 
202
  int code;            /**< Status code */
 
203
  const char* name;          /**< Code short name */
 
204
  const char* description;   /**< Code long description, from ofx_error_msg.h */
 
205
  int code_valid;      /**< If  code_valid is true, so is name and description
 
206
                          (They are obtained from a lookup table) */
 
207
  /** Severity of the error */
 
208
    enum Severity{INFO, /**< The status is an informational message */
 
209
                WARN, /**< The status is a warning */
 
210
                ERROR /**< The status is a true error */
 
211
  } severity;
 
212
  int severity_valid;
 
213
  
 
214
  /** @name OFX optional elements
 
215
   *  The OFX spec defines the following elements as optional. If the 
 
216
   associated *_valid is true, the corresponding element is present and the 
 
217
   associated variable contains valid data. */  
 
218
 
 
219
  char* server_message; /**< Explanation given by the server for the Status Code.
 
220
                           Especially important for generic errors. */
 
221
  int server_message_valid;
 
222
  /*@}*/
 
223
};
 
224
 
 
225
 
 
226
/**
 
227
 * \brief The callback function for the OfxStatusData stucture. 
 
228
 *
 
229
 * An ofx_proc_status_cb event is sent everytime the server has generated a OFX
 
230
 STATUS element.  As such, it could be received at any time(but not during
 
231
 other events).  An OfxStatusData structure is passed to this event, as well as
 
232
 a pointer to an arbitrary data structure.
 
233
*/
 
234
CFCT typedef int (*LibofxProcStatusCallback)(const struct OfxStatusData data, void * status_data);
 
235
 
 
236
/**
 
237
 * \brief An abstraction of an account
 
238
 *
 
239
 *  The OfxAccountData structure gives information about a specific account, 
 
240
 including it's type, currency and unique id. 
 
241
 *
 
242
 * When an OfxAccountData must be passed to functions which create OFX
 
243
 * requests related to a specific account, it must contain all the info needed
 
244
 * for an OFX request to identify an account.  That is:
 
245
 * account_type, account_number, bank_id and branch_id
 
246
 */
 
247
struct OfxAccountData{
 
248
  
 
249
  /** @name OFX mandatory elements
 
250
   * The OFX spec defines the following elements as mandatory.  The associated
 
251
   variables should all contain valid data but you should not trust the servers.
 
252
   Check if the associated *_valid is true before using them. */  
 
253
 
 
254
  /** The account_id is actually built from <BANKID><BRANCHID><ACCTID> for
 
255
      a bank account, and <ACCTID><ACCTKEY> for a credit card account.
 
256
      account_id is meant to be computer-readable.  It is a worldwide OFX unique
 
257
      identifier wich can be used for account matching, even in system with
 
258
      multiple users.*/
 
259
  char account_id[OFX_ACCOUNT_ID_LENGTH];
 
260
  /** The account_id_name is a string meant to allow the user to identify the
 
261
      account.  Currently it is <ACCTID> for a bank account and a credit 
 
262
      card account an <BROKERID>:<ACCTID> for investment accounts.
 
263
      account_id_name is not meant to be computer-readable and
 
264
      is not garanteed to be unique.*/
 
265
  char account_name[OFX_ACCOUNT_NAME_LENGTH];
 
266
  int account_id_valid;/* Use for both account_id and account_name */
 
267
 
 
268
  /** account_type tells you what kind of account this is.  See the AccountType enum */
 
269
    enum AccountType{
 
270
    OFX_CHECKING,  /**< A standard checking account */
 
271
    OFX_SAVINGS,   /**< A standard savings account */
 
272
    OFX_MONEYMRKT, /**< A money market account */
 
273
    OFX_CREDITLINE,/**< A line of credit */
 
274
    OFX_CMA,       /**< Cash Management Account */
 
275
    OFX_CREDITCARD,/**< A credit card account */
 
276
    OFX_INVESTMENT /**< An investment account */
 
277
  } account_type;
 
278
  int account_type_valid;
 
279
  char currency[OFX_CURRENCY_LENGTH]; /**< The currency is a string in ISO-4217 format */
 
280
  int currency_valid;
 
281
 
 
282
  /** Corresponds to OFX <ACCTID> */
 
283
  char account_number[OFX_ACCTID_LENGTH];
 
284
  int account_number_valid;
 
285
 
 
286
  /** Corresponds to OFX <BANKID> */
 
287
  char bank_id[OFX_BANKID_LENGTH];
 
288
  int bank_id_valid;
 
289
 
 
290
  char broker_id[OFX_BROKERID_LENGTH];
 
291
  int broker_id_valid;
 
292
 
 
293
  char branch_id[OFX_BRANCHID_LENGTH];
 
294
  int branch_id_valid;
 
295
 
 
296
};
 
297
 
 
298
/**
 
299
 * \brief The callback function for the OfxAccountData stucture. 
 
300
 *
 
301
 * The ofx_proc_account_cb event is always generated first, to allow the
 
302
 application to create accounts or ask the user to match an existing
 
303
 account before the ofx_proc_statement and ofx_proc_transaction event are
 
304
 received.  An OfxAccountData is passed to this event.
 
305
 *
 
306
 Note however that this OfxAccountData structure will also be available as
 
307
 part of OfxStatementData structure passed to ofx_proc_statement event, 
 
308
 as well as a pointer to an arbitrary data structure.
 
309
*/
 
310
CFCT typedef int (*LibofxProcAccountCallback)(const struct OfxAccountData data, void * account_data);
 
311
 
 
312
/**
 
313
 * \brief An abstraction of a security, such as a stock, mutual fund, etc.
 
314
 *
 
315
 * The OfxSecurityData stucture is used to hols the securyty information inside
 
316
a OfxTransactionData struct for investment transactions.
 
317
*/
 
318
struct OfxSecurityData{
 
319
  /** @name OFX mandatory elements
 
320
   * The OFX spec defines the following elements as mandatory.  The associated
 
321
   variables should all contain valid data but you should not trust the servers.
 
322
   Check if the associated *_valid is true before using them. */  
 
323
 
 
324
  char unique_id[OFX_UNIQUE_ID_LENGTH];   /**< The id of the security being traded.*/
 
325
  int unique_id_valid;
 
326
  char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];/**< Usially "CUSIP" for FIs in
 
327
                                                    north america*/ 
 
328
  int unique_id_type_valid;
 
329
  char secname[OFX_SECNAME_LENGTH];/**< The full name of the security */ 
 
330
  int secname_valid;
 
331
 
 
332
  /** @name OFX optional elements
 
333
   *  The OFX spec defines the following elements as optional. If the 
 
334
   associated *_valid is true, the corresponding element is present and
 
335
   the associated variable contains valid data. */  
 
336
 
 
337
  char ticker[OFX_TICKER_LENGTH];/**< The ticker symbol of the security */ 
 
338
  int ticker_valid;
 
339
 
 
340
  double unitprice;/**< The price of each unit of the security, as of  
 
341
                      date_unitprice */
 
342
  int unitprice_valid;
 
343
 
 
344
  time_t date_unitprice;/**< The date as of which the unit price was valid. */
 
345
  int date_unitprice_valid;
 
346
 
 
347
  char currency[OFX_CURRENCY_LENGTH]; /**< The currency is a string in ISO-4217 format.
 
348
                                         It overrides the one defined in the statement
 
349
                                         for the unit price */
 
350
  int currency_valid;
 
351
  char memo[OFX_MEMO2_LENGTH];/**< Extra information not included in name */
 
352
  int memo_valid;
 
353
};/* end struct OfxSecurityData */
 
354
 
 
355
/** 
 
356
 * \brief The callback function for the OfxSecurityData stucture. 
 
357
 *
 
358
 * An ofx_proc_security_cb event is generated for any securities listed in the
 
359
 ofx file.  It is generated after ofx_proc_statement but before 
 
360
 ofx_proc_transaction. It is meant to be used to allow the client to 
 
361
 create a new commodity or security (such as a new stock type).  Please note however
 
362
 that this information is usually also available as part of each OfxtransactionData.
 
363
 An OfxSecurityData structure is passed to this event, as well as
 
364
 a pointer to an arbitrary data structure.
 
365
*/
 
366
CFCT typedef int (*LibofxProcSecurityCallback)(const struct OfxSecurityData data, void * security_data);
 
367
 
 
368
typedef enum {
 
369
    OFX_CREDIT,     /**< Generic credit */
 
370
    OFX_DEBIT,      /**< Generic debit */
 
371
    OFX_INT,        /**< Interest earned or paid (Note: Depends on signage of amount) */
 
372
    OFX_DIV,        /**< Dividend */
 
373
    OFX_FEE,        /**< FI fee */
 
374
    OFX_SRVCHG,     /**< Service charge */
 
375
    OFX_DEP,        /**< Deposit */
 
376
    OFX_ATM,        /**< ATM debit or credit (Note: Depends on signage of amount) */
 
377
    OFX_POS,        /**< Point of sale debit or credit (Note: Depends on signage of amount) */
 
378
    OFX_XFER,       /**< Transfer */
 
379
    OFX_CHECK,      /**< Check */
 
380
    OFX_PAYMENT,    /**< Electronic payment */
 
381
    OFX_CASH,       /**< Cash withdrawal */
 
382
    OFX_DIRECTDEP,  /**< Direct deposit */
 
383
    OFX_DIRECTDEBIT,/**< Merchant initiated debit */
 
384
    OFX_REPEATPMT,  /**< Repeating payment/standing order */
 
385
    OFX_OTHER       /**< Somer other type of transaction */
 
386
  } TransactionType;
 
387
 
 
388
typedef  enum{
 
389
    OFX_BUYDEBT,        /**< Buy debt security */
 
390
    OFX_BUYMF,          /**< Buy mutual fund */
 
391
    OFX_BUYOPT,         /**< Buy option */
 
392
    OFX_BUYOTHER,       /**< Buy other security type */
 
393
    OFX_BUYSTOCK,       /**< Buy stock */
 
394
    OFX_CLOSUREOPT,     /**< Close a position for an option */
 
395
    OFX_INCOME,         /**< Investment income is realized as cash into the investment account */
 
396
    OFX_INVEXPENSE,     /**< Misc investment expense that is associated with a specific security */
 
397
    OFX_JRNLFUND,       /**< Journaling cash holdings between subaccounts within the same investment account */
 
398
    OFX_JRNLSEC,        /**< Journaling security holdings between subaccounts within the same investment account */
 
399
    OFX_MARGININTEREST, /**< Margin interest expense */
 
400
    OFX_REINVEST,       /**< Reinvestment of income */
 
401
    OFX_RETOFCAP,       /**< Return of capital */
 
402
    OFX_SELLDEBT,       /**< Sell debt security.  Used when debt is sold, called, or reached maturity */
 
403
    OFX_SELLMF,         /**< Sell mutual fund */
 
404
    OFX_SELLOPT,        /**< Sell option */
 
405
    OFX_SELLOTHER,      /**< Sell other type of security */
 
406
    OFX_SELLSTOCK,      /**< Sell stock */
 
407
    OFX_SPLIT,          /**< Stock or mutial fund split */
 
408
    OFX_TRANSFER        /**< Transfer holdings in and out of the investment account */
 
409
  }  InvTransactionType;
 
410
typedef enum {
 
411
    DELETE, /**< The transaction with a fi_id matching fi_id_corrected should
 
412
               be deleted */
 
413
    REPLACE /**< The transaction with a fi_id matching fi_id_corrected should 
 
414
               be replaced with this one */
 
415
  } FiIdCorrectionAction;
 
416
 
 
417
/**
 
418
 * \brief An abstraction of a transaction in an account.
 
419
 *
 
420
 * The OfxTransactionData stucture contains all available information about
 
421
 an actual transaction in an account.
 
422
*/
 
423
struct OfxTransactionData{
 
424
  
 
425
  /** @name OFX mandatory elements
 
426
   * The OFX spec defines the following elements as mandatory.  The associated
 
427
   variables should all contain valid data but you should not trust the servers.
 
428
   Check if the associated *_valid is true before using them. */  
 
429
 
 
430
  char account_id[OFX_ACCOUNT_ID_LENGTH];/**< Use this for matching with
 
431
                                            the relevant account in your
 
432
                                            application */
 
433
  struct OfxAccountData * account_ptr; /**< Pointer to the full account structure,
 
434
                                          see OfxAccountData */
 
435
  int account_id_valid;
 
436
 
 
437
  TransactionType transactiontype;
 
438
  int transactiontype_valid;
 
439
 
 
440
  /**< Investment transaction type.  You should read this if 
 
441
     transactiontype == OFX_OTHER.  See OFX spec 1.6 p.442 to 445 
 
442
     for details*/
 
443
  InvTransactionType invtransactiontype;
 
444
  int  invtransactiontype_valid;
 
445
 
 
446
  double units;     /**< Variation of the number of units of the commodity
 
447
                     Suppose units is -10, ave unitprice is 1.  If the 
 
448
                     commodity is stock, you have 10 less stock, but 10 more 
 
449
                     dollars in you amccount (fees not considered, see amount).
 
450
                     If commodity is money, you have 10 less dollars in your
 
451
                     pocket, but 10 more in your account */
 
452
  int units_valid;
 
453
  double unitprice; /**< Value of each unit, 1.00 if the commodity is
 
454
                       money */
 
455
  int unitprice_valid;
 
456
  double amount;    /**< Total monetary amount of the transaction, signage 
 
457
                       will determine if money went in or out. 
 
458
                       amount is the total amount:
 
459
                       -(units) * unitprice - various fees */
 
460
  int amount_valid;
 
461
  char fi_id[256];  /**< Generated by the financial institution (fi),
 
462
                        unique id of the transaction, to be used to detect
 
463
                        duplicate downloads */
 
464
  int fi_id_valid;
 
465
  
 
466
  /** @name OFX optional elements
 
467
   *  The OFX spec defines the following elements as optional. If the 
 
468
   associated *_valid is true, the corresponding element is present and
 
469
   the associated variable contains valid data. */  
 
470
  
 
471
  /** The id of the security being traded. Mandatory for investment
 
472
      transactions */
 
473
  char unique_id[OFX_UNIQUE_ID_LENGTH];  
 
474
  int unique_id_valid;
 
475
  char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];/**< Usially "CUSIP" for FIs in
 
476
                                                    north america*/ 
 
477
  int unique_id_type_valid;
 
478
  struct OfxSecurityData *security_data_ptr;  /** A pointer to the security's data.*/
 
479
  int security_data_valid;
 
480
  
 
481
  time_t date_posted;/**< Date the transaction took effect (ex: date it
 
482
                        appeared on your credit card bill).  Setlement date;
 
483
                        for stock split, execution date.
 
484
                        *
 
485
                        Mandatory for bank and credit card transactions */
 
486
  int date_posted_valid;
 
487
  
 
488
  time_t date_initiated;/**< Date the transaction was initiated (ex: 
 
489
                           date you bought something in a store for credit card; 
 
490
                           trade date for stocks;
 
491
                           day of record for stock split)
 
492
                           *
 
493
                           Mandatory for investment transactions */
 
494
  int date_initiated_valid;
 
495
  time_t date_funds_available;/**< Date the funds are available (not always
 
496
                                 provided) (ex: the date you are allowed to 
 
497
                                 withdraw a deposit */
 
498
  int date_funds_available_valid;
 
499
  /** IMPORTANT: if  fi_id_corrected is present, this transaction
 
500
      is meant to replace or delete the transaction with this fi_id. See
 
501
      OfxTransactionData::fi_id_correction_action to know what to do. */
 
502
  char fi_id_corrected[256];
 
503
  int fi_id_corrected_valid;
 
504
  /** The OfxTransactionData::FiIdCorrectionAction enum contains the action
 
505
      to be taken */
 
506
  FiIdCorrectionAction fi_id_correction_action;
 
507
  int fi_id_correction_action_valid;
 
508
  
 
509
  /** Used for user initiated transaction such as payment or funds transfer.
 
510
      Can be seen as a confirmation number. */
 
511
  char server_transaction_id[OFX_SVRTID2_LENGTH];
 
512
  int server_transaction_id_valid;
 
513
  /** The check number is most likely an integer and can probably be 
 
514
      converted properly with atoi().  However the spec allows for up to
 
515
      12 digits, so it is not garanteed to work */
 
516
char check_number[OFX_CHECK_NUMBER_LENGTH];
 
517
  int check_number_valid;
 
518
  /** Might present in addition to or instead of a check_number. 
 
519
      Not necessarily a number */
 
520
  char reference_number[OFX_REFERENCE_NUMBER_LENGTH];
 
521
  int reference_number_valid;
 
522
  long int standard_industrial_code;/**< The standard industrial code can have
 
523
                                       at most 6 digits */
 
524
  int standard_industrial_code_valid;
 
525
  char payee_id[OFX_SVRTID2_LENGTH];/**< The identifier of the payee */
 
526
  int payee_id_valid;
 
527
  char name[OFX_TRANSACTION_NAME_LENGTH];/**< Can be the name of the payee or
 
528
                                            the description of the transaction */
 
529
  int name_valid;
 
530
  char memo[OFX_MEMO2_LENGTH];/**< Extra information not included in name */
 
531
  int memo_valid;
 
532
  double commission;/**< Commission paid to broker (investment transactions only) */
 
533
  int commission_valid;
 
534
  double fees;/**< Fees applied to trade (investment transactions only) */
 
535
  int fees_valid;
 
536
  double oldunits;     /*number of units held before stock split */
 
537
  int oldunits_valid;
 
538
  double newunits;     /*number of units held after stock split */
 
539
  int newunits_valid;
 
540
 
 
541
 
 
542
  /*********** NOT YET COMPLETE!!! *********************/
 
543
};
 
544
 
 
545
/** 
 
546
 * \brief The callback function for the OfxTransactionData stucture. 
 
547
 *
 
548
 * An ofx_proc_transaction_cb event is generated for every transaction in the 
 
549
 ofx response, after ofx_proc_statement (and possibly ofx_proc_security is 
 
550
 generated. An OfxTransactionData structure is passed to this event, as well as
 
551
 a pointer to an arbitrary data structure.
 
552
*/
 
553
CFCT typedef int (*LibofxProcTransactionCallback)(const struct OfxTransactionData data, void * transaction_data);
 
554
 
 
555
/** 
 
556
 * \brief An abstraction of an account statement. 
 
557
 *
 
558
 * The OfxStatementData structure contains information about your account
 
559
 at the time the ofx response was generated, including the balance.  A 
 
560
 client should check that the total of his recorded transactions matches
 
561
 the total given here, and warn the user if they dont.
 
562
*/
 
563
struct OfxStatementData{
 
564
 
 
565
  /** @name OFX mandatory elements
 
566
   * The OFX spec defines the following elements as mandatory.  The 
 
567
   associated variables should all contain valid data but you should not 
 
568
   trust the servers. Check if the associated *_valid is true before using
 
569
   them.
 
570
  */  
 
571
 
 
572
  char currency[OFX_CURRENCY_LENGTH]; /**< The currency is a string in ISO-4217 format */
 
573
  int currency_valid;
 
574
  char account_id[OFX_ACCOUNT_ID_LENGTH];/**< Use this for matching this statement with
 
575
                                            the relevant account in your application */
 
576
  struct OfxAccountData * account_ptr; /**< Pointer to the full account structure, see 
 
577
                                      OfxAccountData */
 
578
  int account_id_valid;
 
579
   /** The actual balance, according to the FI.  The user should be warned
 
580
       of any discrepency between this and the balance in the application */
 
581
  double ledger_balance;
 
582
  int ledger_balance_valid;
 
583
  time_t ledger_balance_date;/**< Time of the ledger_balance snapshot */
 
584
  int ledger_balance_date_valid;
 
585
  
 
586
  /** @name OFX optional elements
 
587
   *  The OFX spec defines the following elements as optional. If the 
 
588
   associated *_valid is true, the corresponding element is present and the 
 
589
   associated variable contains valid data. */  
 
590
  
 
591
  double available_balance; /**< Amount of money available from the account.
 
592
                               Could be the credit left for a credit card, 
 
593
                               or amount that can be withdrawn using INTERAC) */
 
594
  int available_balance_valid;
 
595
  time_t available_balance_date;/** Time of the available_balance snapshot */
 
596
  int available_balance_date_valid;
 
597
  /** The start time of this statement.
 
598
   *
 
599
   All the transactions between date_start and date_end should have been 
 
600
   provided */
 
601
  time_t date_start;
 
602
  int date_start_valid;
 
603
   /** The end time of this statement.
 
604
    *
 
605
    If provided, the user can use this date as the start date of his next
 
606
    statement request.  He is then assured not to miss any transactions. */
 
607
  time_t date_end;
 
608
  int date_end_valid;
 
609
  /** marketing_info could be special offers or messages from the bank,
 
610
      or just about anything else */
 
611
  char marketing_info[OFX_MARKETING_INFO_LENGTH];
 
612
  int marketing_info_valid;
 
613
};
 
614
 
 
615
/**
 
616
 * \brief The callback function for the OfxStatementData stucture. 
 
617
 *
 
618
 * The ofx_proc_statement_cb event is sent after all ofx_proc_transaction 
 
619
 events have been sent. An OfxStatementData is passed to this event, as well as
 
620
 a pointer to an arbitrary data structure.
 
621
*/
 
622
CFCT typedef int (*LibofxProcStatementCallback)(const struct OfxStatementData data, void * statement_data);
 
623
 
 
624
/** 
 
625
    \brief NOT YET SUPPORTED
 
626
*/
 
627
struct OfxCurrency{
 
628
  char currency[OFX_CURRENCY_LENGTH]; /**< Currency in ISO-4217 format */
 
629
  double exchange_rate;  /**< Exchange rate from the normal currency of the account */
 
630
  int must_convert;   /**< true or false */
 
631
};
 
632
 
 
633
 
 
634
/**
 
635
 * Set the status callback in the given context.
 
636
 * @param ctx context
 
637
 * @param cb callback function
 
638
 * @param user_data user data to be passed to the callback
 
639
 */
 
640
CFCT void ofx_set_status_cb(LibofxContextPtr ctx,
 
641
                            LibofxProcStatusCallback cb,
 
642
                            void *user_data);
 
643
/**
 
644
 * Set the account callback in the given context.
 
645
 * @param ctx context
 
646
 * @param cb callback function
 
647
 * @param user_data user data to be passed to the callback
 
648
 */
 
649
CFCT void ofx_set_account_cb(LibofxContextPtr ctx,
 
650
                             LibofxProcAccountCallback cb,
 
651
                             void *user_data);
 
652
/**
 
653
 * Set the security callback in the given context.
 
654
 * @param ctx context
 
655
 * @param cb callback function
 
656
 * @param user_data user data to be passed to the callback
 
657
 */
 
658
CFCT void ofx_set_security_cb(LibofxContextPtr ctx,
 
659
                              LibofxProcSecurityCallback cb,
 
660
                              void *user_data);
 
661
/**
 
662
 * Set the transaction callback in the given context.
 
663
 * @param ctx context
 
664
 * @param cb callback function
 
665
 * @param user_data user data to be passed to the callback
 
666
 */
 
667
CFCT void ofx_set_transaction_cb(LibofxContextPtr ctx,
 
668
                                 LibofxProcTransactionCallback cb,
 
669
                                 void *user_data);
 
670
 
 
671
/**
 
672
 * Set the statement callback in the given context.
 
673
 * @param ctx context
 
674
 * @param cb callback function
 
675
 * @param user_data user data to be passed to the callback
 
676
 */
 
677
CFCT void ofx_set_statement_cb(LibofxContextPtr ctx,
 
678
                               LibofxProcStatementCallback cb,
 
679
                               void *user_data);
 
680
 
 
681
 
 
682
/**
 
683
 * Parses the content of the given buffer.
 
684
 */
 
685
CFCT int libofx_proc_buffer(LibofxContextPtr ctx,
 
686
                            const char *s, unsigned int size);
 
687
                            
 
688
/** @name Creating OFX Files
 
689
 *
 
690
 * This group deals with creating OFX files
 
691
 */
 
692
//@{
 
693
 
 
694
/**
 
695
 * \brief Information returned by the OFX Partner Server about a financial institution 
 
696
 */
 
697
 
 
698
struct OfxFiServiceInfo{
 
699
  char fid[OFX_FID_LENGTH];
 
700
  char org[OFX_ORG_LENGTH];
 
701
  char url[OFX_URL_LENGTH];
 
702
  int accountlist; /**< Whether the FI makes a list of accounts available */ 
 
703
  int statements; /**< Whether the FI supports online statement download */
 
704
  int billpay; /**< Whether the FI supports online bill payment */
 
705
  int investments; /**< Whether the FI supports investments */
 
706
};
 
707
 
 
708
 /**
 
709
 * \brief Information sufficient to log into an financial institution
 
710
 *
 
711
 * Contains all the info needed for a user to log into a financial
 
712
 * institution and make requests for statements or post transactions.
 
713
 * An OfxFiLogin must be passed to all functions which create OFX
 
714
 * requests.
 
715
 */
 
716
 
 
717
struct OfxFiLogin{
 
718
  char fid[OFX_FID_LENGTH];
 
719
  char org[OFX_ORG_LENGTH];
 
720
  char userid[OFX_USERID_LENGTH];
 
721
  char userpass[OFX_USERPASS_LENGTH];
 
722
  char header_version[OFX_HEADERVERSION_LENGTH];
 
723
  char appid[OFX_APPID_LENGTH];
 
724
  char appver[OFX_APPVER_LENGTH];
 
725
};
 
726
 
 
727
#define OFX_AMOUNT_LENGTH (32 + 1)
 
728
#define OFX_PAYACCT_LENGTH (32 + 1)
 
729
#define OFX_STATE_LENGTH (5 + 1)
 
730
#define OFX_POSTALCODE_LENGTH (11 + 1)
 
731
#define OFX_NAME_LENGTH (32 + 1)
 
732
 
 
733
struct OfxPayment{
 
734
  char amount[OFX_AMOUNT_LENGTH];
 
735
  char account[OFX_PAYACCT_LENGTH];
 
736
  char datedue[9];
 
737
  char memo[OFX_MEMO_LENGTH];
 
738
};
 
739
 
 
740
struct OfxPayee{
 
741
  char name[OFX_NAME_LENGTH];
 
742
  char address1[OFX_NAME_LENGTH];
 
743
  char city[OFX_NAME_LENGTH];
 
744
  char state[OFX_STATE_LENGTH];
 
745
  char postalcode[OFX_POSTALCODE_LENGTH];
 
746
  char phone[OFX_NAME_LENGTH];
 
747
};
 
748
 
 
749
/**
 
750
 * \brief Creates an OFX statement request in string form
 
751
 *
 
752
 * Creates a string which should be passed to an OFX server.  This string is
 
753
 * an OFX request suitable to retrieve a statement for the @p account from the
 
754
 * @p fi
 
755
 *
 
756
 * @param fi Identifies the financial institution and the user logging in.
 
757
 * @param account Idenfities the account for which a statement is desired
 
758
 * @return string pointer to the request.  This is allocated via malloc(), and is the callers responsibility to free.
 
759
*/
 
760
 
 
761
CFCT char* libofx_request_statement( const struct OfxFiLogin* fi, const struct OfxAccountData* account, time_t date_from );
 
762
 
 
763
/**
 
764
 * \brief Creates an OFX account info (list) request in string form
 
765
 *
 
766
 * Creates a string which should be passed to an OFX server.  This string is
 
767
 * an OFX request suitable to retrieve a list of accounts from the
 
768
 * @p fi
 
769
 *
 
770
 * @param fi Identifies the financial institution and the user logging in.
 
771
 * @return string pointer to the request.  This is allocated via malloc(), and is the callers responsibility to free.
 
772
*/
 
773
 
 
774
CFCT char* libofx_request_accountinfo( const struct OfxFiLogin* login );
 
775
 
 
776
CFCT char* libofx_request_payment( const struct OfxFiLogin* login, const struct OfxAccountData* account, const struct OfxPayee* payee, const struct OfxPayment* payment );
 
777
 
 
778
CFCT char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid );
 
779
 
 
780
//@}
 
781
 
 
782
#endif
 
783