- Main Page
- Namespaces
- Data Structures
- Files

# libofx.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002               libofx.h  -  Main header file for the libofx API
    00003                              -------------------
    00004     copyright            : (C) 2002 by Benoit Grégoire
    00005     email                : bock@step.polymtl.ca
    00006 ***************************************************************************/
    00026 /***************************************************************************
    00027  *                                                                         *
    00028  *   This program is free software; you can redistribute it and/or modify  *
    00029  *   it under the terms of the GNU General Public License as published by  *
    00030  *   the Free Software Foundation; either version 2 of the License, or     *
    00031  *   (at your option) any later version.                                   *
    00032  *                                                                         *
    00033  ***************************************************************************/
    00034
    00035 #ifndef LIBOFX_H
    00036 #define LIBOFX_H
    00037 #include <time.h>
    00038
    00039 #define LIBOFX_MAJOR_VERSION 0
    00040 #define LIBOFX_MINOR_VERSION 9
    00041 #define LIBOFX_MICRO_VERSION 0
    00042 #define LIBOFX_BUILD_VERSION 0
    00043 #define LIBOFX_VERSION_RELEASE_STRING "0.9.0"
    00044
    00045
    00046 #ifdef __cplusplus
    00047 #define CFCT extern "C"
    00048 #else
    00049 #define CFCT
    00050 #define true 1
    00051 #define false 0
    00052 #endif
    00053
    00054 #define OFX_ELEMENT_NAME_LENGTH         100
    00055 #define OFX_SVRTID2_LENGTH             (36 + 1)
    00056 #define OFX_CHECK_NUMBER_LENGTH        (12 + 1)
    00057 #define OFX_REFERENCE_NUMBER_LENGTH    (32 + 1)
    00058 #define OFX_FITID_LENGTH               (255 + 1)
    00059 #define OFX_TOKEN2_LENGTH              (36 + 1)
    00060 #define OFX_MEMO_LENGTH                (255 + 1)
    00061 #define OFX_MEMO2_LENGTH               (390 + 1)
    00062 #define OFX_BALANCE_NAME_LENGTH        (32 + 1)
    00063 #define OFX_BALANCE_DESCRIPTION_LENGTH (80 + 1)
    00064 #define OFX_CURRENCY_LENGTH            (3 + 1) /* In ISO-4217 format */
    00065 #define OFX_BANKID_LENGTH              (9 + 1)
    00066 #define OFX_BRANCHID_LENGTH            (22 + 1)
    00067 #define OFX_ACCTID_LENGTH              (22 + 1)
    00068 #define OFX_ACCTKEY_LENGTH             (22 + 1)
    00069 #define OFX_BROKERID_LENGTH            (22 + 1)
    00070 /* Must be MAX of <BANKID>+<BRANCHID>+<ACCTID>, <ACCTID>+<ACCTKEY> and <ACCTID>+<BROKERID> */
    00071 #define OFX_ACCOUNT_ID_LENGTH (OFX_BANKID_LENGTH + OFX_BRANCHID_LENGTH + OFX_ACCTID_LENGTH + 1)
    00072 #define OFX_ACCOUNT_NAME_LENGTH        255
    00073 #define OFX_MARKETING_INFO_LENGTH      (360 + 1)
    00074 #define OFX_TRANSACTION_NAME_LENGTH    (32 + 1)
    00075 #define OFX_UNIQUE_ID_LENGTH           (32 + 1)
    00076 #define OFX_UNIQUE_ID_TYPE_LENGTH      (10 + 1)
    00077 #define OFX_SECNAME_LENGTH             (32 + 1)
    00078 #define OFX_TICKER_LENGTH              (32 + 1)
    00079 #define OFX_ORG_LENGTH                 (32 + 1)
    00080 #define OFX_FID_LENGTH                 (32 + 1)
    00081 #define OFX_USERID_LENGTH              (32 + 1)
    00082 #define OFX_USERPASS_LENGTH            (32 + 1)
    00083 #define OFX_URL_LENGTH                 (500 + 1)
    00084 #define OFX_APPID_LENGTH               (32)
    00085 #define OFX_APPVER_LENGTH              (32)
    00086 #define OFX_HEADERVERSION_LENGTH       (32)
    00087
    00088 /*
    00089 #define OFX_STATEMENT_CB               0;
    00090 #define OFX_ACCOUNT_CB                 1;
    00091 #define OFX_TRACSACTION_CB             2;
    00092 #define OFX_SECURITY_CB                3;
    00093 #define OFX_STATUS_CB                  4;
    00094 */
    00095
    00096 typedef void * LibofxContextPtr;
    00102 CFCT LibofxContextPtr libofx_get_new_context();
    00108 CFCT int libofx_free_context( LibofxContextPtr );
    00109
    00110 CFCT void libofx_set_dtd_dir(LibofxContextPtr libofx_context,
    00111                             const char *s);
    00112
    00114 enum LibofxFileFormat{ AUTODETECT,
    00115                      OFX,
    00116                      OFC,
    00117                      QIF,
    00118                      UNKNOWN,
    00119                      LAST
    00120 };
    00121
    00122 struct LibofxFileFormatInfo{
    00123 enum LibofxFileFormat format;
    00124 const char * format_name;
    00125 const char * description;
    00126 };
    00127
    00128
    00129 #ifndef OFX_AQUAMANIAC_UGLY_HACK1
    00130
    00131 const struct LibofxFileFormatInfo LibofxImportFormatList[] =
    00132 {
    00133 {AUTODETECT, "AUTODETECT", "AUTODETECT (File format will be automatically detected later)"},
    00134 {OFX, "OFX", "OFX (Open Financial eXchange (OFX or QFX))"},
    00135 {OFC, "OFC", "OFC (Microsoft Open Financial Connectivity)"},
    00136 {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
    00137 {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
    00138 };
    00139
    00140 const struct LibofxFileFormatInfo LibofxExportFormatList[] =
    00141 {
    00142 {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
    00143 {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
    00144 };
    00145
    00153 CFCT enum LibofxFileFormat libofx_get_file_format_from_str(const struct LibofxFileFormatInfo format_list[], const char * file_type_string);
    00154
    00162 CFCT const char * libofx_get_file_format_description(const struct LibofxFileFormatInfo format_list[], enum LibofxFileFormat file_format);
    00163
    00164 #endif
    00165
    00172 CFCT int libofx_proc_file(LibofxContextPtr libofx_context,
    00173                           const char * p_filename,
    00174                           enum LibofxFileFormat ftype);
    00175
    00176
    00189 struct OfxStatusData{
    00194   char ofx_element_name[OFX_ELEMENT_NAME_LENGTH];
    00196   int ofx_element_name_valid;
    00197
    00202   int code;
    00203   const char* name;
    00204   const char* description;
    00205   int code_valid;
    00208     enum Severity{INFO,
    00209                 WARN,
    00210                 ERROR
    00211   } severity;
    00212   int severity_valid;
    00213
    00219   char* server_message;
    00221   int server_message_valid;
    00223 };
    00224
    00225
    00234 CFCT typedef int (*LibofxProcStatusCallback)(const struct OfxStatusData data, void * status_data);
    00235
    00247 struct OfxAccountData{
    00248
    00259   char account_id[OFX_ACCOUNT_ID_LENGTH];
    00265   char account_name[OFX_ACCOUNT_NAME_LENGTH];
    00266   int account_id_valid;/* Use for both account_id and account_name */
    00267
    00269     enum AccountType{
    00270     OFX_CHECKING,
    00271     OFX_SAVINGS,
    00272     OFX_MONEYMRKT,
    00273     OFX_CREDITLINE,
    00274     OFX_CMA,
    00275     OFX_CREDITCARD,
    00276     OFX_INVESTMENT
    00277   } account_type;
    00278   int account_type_valid;
    00279   char currency[OFX_CURRENCY_LENGTH];
    00280   int currency_valid;
    00281
    00283   char account_number[OFX_ACCTID_LENGTH];
    00284   int account_number_valid;
    00285
    00287   char bank_id[OFX_BANKID_LENGTH];
    00288   int bank_id_valid;
    00289
    00290   char broker_id[OFX_BROKERID_LENGTH];
    00291   int broker_id_valid;
    00292
    00293   char branch_id[OFX_BRANCHID_LENGTH];
    00294   int branch_id_valid;
    00295
    00296 };
    00297
    00310 CFCT typedef int (*LibofxProcAccountCallback)(const struct OfxAccountData data, void * account_data);
    00311
    00318 struct OfxSecurityData{
    00324   char unique_id[OFX_UNIQUE_ID_LENGTH];
    00325   int unique_id_valid;
    00326   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
    00328   int unique_id_type_valid;
    00329   char secname[OFX_SECNAME_LENGTH];
    00330   int secname_valid;
    00331
    00337   char ticker[OFX_TICKER_LENGTH];
    00338   int ticker_valid;
    00339
    00340   double unitprice;
    00342   int unitprice_valid;
    00343
    00344   time_t date_unitprice;
    00345   int date_unitprice_valid;
    00346
    00347   char currency[OFX_CURRENCY_LENGTH];
    00350   int currency_valid;
    00351   char memo[OFX_MEMO2_LENGTH];
    00352   int memo_valid;
    00353 };/* end struct OfxSecurityData */
    00354
    00366 CFCT typedef int (*LibofxProcSecurityCallback)(const struct OfxSecurityData data, void * security_data);
    00367
    00368 typedef enum {
    00369     OFX_CREDIT,
    00370     OFX_DEBIT,
    00371     OFX_INT,
    00372     OFX_DIV,
    00373     OFX_FEE,
    00374     OFX_SRVCHG,
    00375     OFX_DEP,
    00376     OFX_ATM,
    00377     OFX_POS,
    00378     OFX_XFER,
    00379     OFX_CHECK,
    00380     OFX_PAYMENT,
    00381     OFX_CASH,
    00382     OFX_DIRECTDEP,
    00383     OFX_DIRECTDEBIT,
    00384     OFX_REPEATPMT,
    00385     OFX_OTHER
    00386   } TransactionType;
    00387
    00388 typedef  enum{
    00389     OFX_BUYDEBT,
    00390     OFX_BUYMF,
    00391     OFX_BUYOPT,
    00392     OFX_BUYOTHER,
    00393     OFX_BUYSTOCK,
    00394     OFX_CLOSUREOPT,
    00395     OFX_INCOME,
    00396     OFX_INVEXPENSE,
    00397     OFX_JRNLFUND,
    00398     OFX_JRNLSEC,
    00399     OFX_MARGININTEREST,
    00400     OFX_REINVEST,
    00401     OFX_RETOFCAP,
    00402     OFX_SELLDEBT,
    00403     OFX_SELLMF,
    00404     OFX_SELLOPT,
    00405     OFX_SELLOTHER,
    00406     OFX_SELLSTOCK,
    00407     OFX_SPLIT,
    00408     OFX_TRANSFER
    00409   }  InvTransactionType;
    00410 typedef enum {
    00411     DELETE,
    00413     REPLACE
    00415   } FiIdCorrectionAction;
    00416
    00423 struct OfxTransactionData{
    00424
    00430   char account_id[OFX_ACCOUNT_ID_LENGTH];
    00433   struct OfxAccountData * account_ptr;
    00435   int account_id_valid;
    00436
    00437   TransactionType transactiontype;
    00438   int transactiontype_valid;
    00439
    00443   InvTransactionType invtransactiontype;
    00444   int  invtransactiontype_valid;
    00445
    00446   double units;
    00452   int units_valid;
    00453   double unitprice;
    00455   int unitprice_valid;
    00456   double amount;
    00460   int amount_valid;
    00461   char fi_id[256];
    00464   int fi_id_valid;
    00465
    00473   char unique_id[OFX_UNIQUE_ID_LENGTH];
    00474   int unique_id_valid;
    00475   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
    00477   int unique_id_type_valid;
    00478   struct OfxSecurityData *security_data_ptr;
    00479   int security_data_valid;
    00480
    00481   time_t date_posted;
    00486   int date_posted_valid;
    00487
    00488   time_t date_initiated;
    00494   int date_initiated_valid;
    00495   time_t date_funds_available;
    00498   int date_funds_available_valid;
    00502   char fi_id_corrected[256];
    00503   int fi_id_corrected_valid;
    00506   FiIdCorrectionAction fi_id_correction_action;
    00507   int fi_id_correction_action_valid;
    00508
    00511   char server_transaction_id[OFX_SVRTID2_LENGTH];
    00512   int server_transaction_id_valid;
    00516 char check_number[OFX_CHECK_NUMBER_LENGTH];
    00517   int check_number_valid;
    00520   char reference_number[OFX_REFERENCE_NUMBER_LENGTH];
    00521   int reference_number_valid;
    00522   long int standard_industrial_code;
    00524   int standard_industrial_code_valid;
    00525   char payee_id[OFX_SVRTID2_LENGTH];
    00526   int payee_id_valid;
    00527   char name[OFX_TRANSACTION_NAME_LENGTH];
    00529   int name_valid;
    00530   char memo[OFX_MEMO2_LENGTH];
    00531   int memo_valid;
    00532   double commission;
    00533   int commission_valid;
    00534   double fees;
    00535   int fees_valid;
    00536   double oldunits;     /*number of units held before stock split */
    00537   int oldunits_valid;
    00538   double newunits;     /*number of units held after stock split */
    00539   int newunits_valid;
    00540
    00541
    00542   /*********** NOT YET COMPLETE!!! *********************/
    00543 };
    00544
    00553 CFCT typedef int (*LibofxProcTransactionCallback)(const struct OfxTransactionData data, void * transaction_data);
    00554
    00563 struct OfxStatementData{
    00564
    00572   char currency[OFX_CURRENCY_LENGTH];
    00573   int currency_valid;
    00574   char account_id[OFX_ACCOUNT_ID_LENGTH];
    00576   struct OfxAccountData * account_ptr;
    00578   int account_id_valid;
    00581   double ledger_balance;
    00582   int ledger_balance_valid;
    00583   time_t ledger_balance_date;
    00584   int ledger_balance_date_valid;
    00585
    00591   double available_balance;
    00594   int available_balance_valid;
    00595   time_t available_balance_date;
    00596   int available_balance_date_valid;
    00601   time_t date_start;
    00602   int date_start_valid;
    00607   time_t date_end;
    00608   int date_end_valid;
    00611   char marketing_info[OFX_MARKETING_INFO_LENGTH];
    00612   int marketing_info_valid;
    00613 };
    00614
    00622 CFCT typedef int (*LibofxProcStatementCallback)(const struct OfxStatementData data, void * statement_data);
    00623
    00627 struct OfxCurrency{
    00628   char currency[OFX_CURRENCY_LENGTH];
    00629   double exchange_rate;
    00630   int must_convert;
    00631 };
    00632
    00633
    00640 CFCT void ofx_set_status_cb(LibofxContextPtr ctx,
    00641                             LibofxProcStatusCallback cb,
    00642                             void *user_data);
    00649 CFCT void ofx_set_account_cb(LibofxContextPtr ctx,
    00650                              LibofxProcAccountCallback cb,
    00651                              void *user_data);
    00658 CFCT void ofx_set_security_cb(LibofxContextPtr ctx,
    00659                               LibofxProcSecurityCallback cb,
    00660                               void *user_data);
    00667 CFCT void ofx_set_transaction_cb(LibofxContextPtr ctx,
    00668                                  LibofxProcTransactionCallback cb,
    00669                                  void *user_data);
    00670
    00677 CFCT void ofx_set_statement_cb(LibofxContextPtr ctx,
    00678                                LibofxProcStatementCallback cb,
    00679                                void *user_data);
    00680
    00681
    00685 CFCT int libofx_proc_buffer(LibofxContextPtr ctx,
    00686                             const char *s, unsigned int size);
    00687
    00693
    00698 struct OfxFiServiceInfo{
    00699   char fid[OFX_FID_LENGTH];
    00700   char org[OFX_ORG_LENGTH];
    00701   char url[OFX_URL_LENGTH];
    00702   int accountlist;
    00703   int statements;
    00704   int billpay;
    00705   int investments;
    00706 };
    00707
    00717 struct OfxFiLogin{
    00718   char fid[OFX_FID_LENGTH];
    00719   char org[OFX_ORG_LENGTH];
    00720   char userid[OFX_USERID_LENGTH];
    00721   char userpass[OFX_USERPASS_LENGTH];
    00722   char header_version[OFX_HEADERVERSION_LENGTH];
    00723   char appid[OFX_APPID_LENGTH];
    00724   char appver[OFX_APPVER_LENGTH];
    00725 };
    00726
    00727 #define OFX_AMOUNT_LENGTH (32 + 1)
    00728 #define OFX_PAYACCT_LENGTH (32 + 1)
    00729 #define OFX_STATE_LENGTH (5 + 1)
    00730 #define OFX_POSTALCODE_LENGTH (11 + 1)
    00731 #define OFX_NAME_LENGTH (32 + 1)
    00732
    00733 struct OfxPayment{
    00734   char amount[OFX_AMOUNT_LENGTH];
    00735   char account[OFX_PAYACCT_LENGTH];
    00736   char datedue[9];
    00737   char memo[OFX_MEMO_LENGTH];
    00738 };
    00739
    00740 struct OfxPayee{
    00741   char name[OFX_NAME_LENGTH];
    00742   char address1[OFX_NAME_LENGTH];
    00743   char city[OFX_NAME_LENGTH];
    00744   char state[OFX_STATE_LENGTH];
    00745   char postalcode[OFX_POSTALCODE_LENGTH];
    00746   char phone[OFX_NAME_LENGTH];
    00747 };
    00748
    00761 CFCT char* libofx_request_statement( const struct OfxFiLogin* fi, const struct OfxAccountData* account, time_t date_from );
    00762
    00774 CFCT char* libofx_request_accountinfo( const struct OfxFiLogin* login );
    00775
    00776 CFCT char* libofx_request_payment( const struct OfxFiLogin* login, const struct OfxAccountData* account, const struct OfxPayee* payee, const struct OfxPayment* payment );
    00777
    00778 CFCT char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid );
    00779
    00781
    00782 #endif
    00783