LibOFX: libofx.h Source File

Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

# inc/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 #ifdef __cplusplus
    00040 #define CFCT extern "C"
    00041 #else
    00042 #define CFCT
    00043 #define true 1
    00044 #define false 0
    00045 #endif
    00046
    00047 #define OFX_ELEMENT_NAME_LENGTH         100
    00048 #define OFX_SVRTID2_LENGTH             36 + 1
    00049 #define OFX_CHECK_NUMBER_LENGTH        12 + 1
    00050 #define OFX_REFERENCE_NUMBER_LENGTH    32 + 1
    00051 #define OFX_FITID_LENGTH               255 + 1
    00052 #define OFX_TOKEN2_LENGTH              36 + 1
    00053 #define OFX_MEMO2_LENGTH               390 + 1
    00054 #define OFX_BALANCE_NAME_LENGTH        32 + 1
    00055 #define OFX_BALANCE_DESCRIPTION_LENGTH 80 + 1
    00056 #define OFX_CURRENCY_LENGTH            3 + 1 /* In ISO-4217 format */
    00057 #define OFX_BANKID_LENGTH              9 + 1
    00058 #define OFX_BRANCHID_LENGTH            22 + 1
    00059 #define OFX_ACCTID_LENGTH              22 + 1
    00060 #define OFX_ACCTKEY_LENGTH             22 + 1
    00061 #define OFX_BROKERID_LENGTH            22 + 1
    00062 /* Must be MAX of <BANKID>+<BRANCHID>+<ACCTID>, <ACCTID>+<ACCTKEY> and <ACCTID>+<BROKERID> */
    00063 #define OFX_ACCOUNT_ID_LENGTH OFX_BANKID_LENGTH + OFX_BRANCHID_LENGTH + OFX_ACCTID_LENGTH + 1
    00064 #define OFX_ACCOUNT_NAME_LENGTH        255
    00065 #define OFX_MARKETING_INFO_LENGTH      360 + 1
    00066 #define OFX_TRANSACTION_NAME_LENGTH    32 + 1
    00067 #define OFX_UNIQUE_ID_LENGTH           32 + 1
    00068 #define OFX_UNIQUE_ID_TYPE_LENGTH      10 + 1
    00069 #define OFX_SECNAME_LENGTH             32 + 1
    00070 #define OFX_TICKER_LENGTH              32 + 1
    00071 #define OFX_ORG_LENGTH                 32 + 1
    00072 #define OFX_FID_LENGTH                 32 + 1
    00073 #define OFX_USERID_LENGTH              32 + 1
    00074 #define OFX_USERPASS_LENGTH            32 + 1
    00075
    00076 /*
    00077 #define OFX_STATEMENT_CB               0;
    00078 #define OFX_ACCOUNT_CB                 1;
    00079 #define OFX_TRACSACTION_CB             2;
    00080 #define OFX_SECURITY_CB                3;
    00081 #define OFX_STATUS_CB                  4;
    00082 */
    00083
    00084 typedef void * LibofxContextPtr;
    00090 CFCT LibofxContextPtr libofx_get_new_context();
    00096 CFCT int libofx_free_context( LibofxContextPtr );
    00097
    00099 enum LibofxFileFormat{ AUTODETECT,
    00100                      OFX,
    00101                      OFC,
    00102                      QIF,
    00103                      UNKNOWN,
    00104                      LAST
    00105 };
    00106
    00107 struct LibofxFileFormatInfo{
    00108 enum LibofxFileFormat format;
    00109 const char * format_name;
    00110 const char * description;
    00111 };
    00112
    00113
    00114 #ifndef OFX_AQUAMANIAC_UGLY_HACK1
    00115
    00116 const struct LibofxFileFormatInfo LibofxImportFormatList[] =
    00117 {
    00118 {AUTODETECT, "AUTODETECT", "AUTODETECT (File format will be automatically detected later)"},
    00119 {OFX, "OFX", "OFX (Open Financial eXchange (OFX or QFX))"},
    00120 {OFC, "OFC", "OFC (Microsoft Open Financial Connectivity)"},
    00121 {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
    00122 {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
    00123 };
    00124
    00125 const struct LibofxFileFormatInfo LibofxExportFormatList[] =
    00126 {
    00127 {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
    00128 {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
    00129 };
    00130
    00138 CFCT enum LibofxFileFormat libofx_get_file_format_from_str(const struct LibofxFileFormatInfo format_list[], const char * file_type_string);
    00139
    00147 CFCT const char * libofx_get_file_format_description(const struct LibofxFileFormatInfo format_list[], enum LibofxFileFormat file_format);
    00148
    00149 #endif
    00150
    00157 CFCT int libofx_proc_file(LibofxContextPtr libofx_context,
    00158                           const char * p_filename,
    00159                           enum LibofxFileFormat ftype);
    00160
    00161
    00174 struct OfxStatusData{
    00179   char ofx_element_name[OFX_ELEMENT_NAME_LENGTH];
    00181   int ofx_element_name_valid;
    00182
    00187   int code;
    00188   char* name;
    00189   char* description;
    00190   int code_valid;
    00193     enum Severity{INFO,
    00194                 WARN,
    00195                 ERROR
    00196   } severity;
    00197   int severity_valid;
    00198
    00204   char* server_message;
    00206   int server_message_valid;
    00208 };
    00209
    00210
    00219 CFCT typedef int (*LibofxProcStatusCallback)(const struct OfxStatusData data, void * status_data);
    00220
    00227 struct OfxAccountData{
    00228
    00239   char account_id[OFX_ACCOUNT_ID_LENGTH];
    00245   char account_name[OFX_ACCOUNT_NAME_LENGTH];
    00246   int account_id_valid;/* Use for both account_id and account_name */
    00247
    00249     enum AccountType{
    00250     OFX_CHECKING,
    00251     OFX_SAVINGS,
    00252     OFX_MONEYMRKT,
    00253     OFX_CREDITLINE,
    00254     OFX_CMA,
    00255     OFX_CREDITCARD,
    00256     OFX_INVESTMENT
    00257   } account_type;
    00258   int account_type_valid;
    00259   char currency[OFX_CURRENCY_LENGTH];
    00260   int currency_valid;
    00261
    00262   char bank_id[OFX_BANKID_LENGTH];
    00263   int bank_id_valid;
    00264
    00265   char branch_id[OFX_BRANCHID_LENGTH];
    00266   int branch_id_valid;
    00267
    00268   char account_number[OFX_ACCTID_LENGTH];
    00269   int account_number_valid;
    00270
    00271 };
    00272
    00285 CFCT typedef int (*LibofxProcAccountCallback)(const struct OfxAccountData data, void * account_data);
    00286
    00293 struct OfxSecurityData{
    00299   char unique_id[OFX_UNIQUE_ID_LENGTH];
    00300   int unique_id_valid;
    00301   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
    00303   int unique_id_type_valid;
    00304   char secname[OFX_SECNAME_LENGTH];
    00305   int secname_valid;
    00306
    00312   char ticker[OFX_TICKER_LENGTH];
    00313   int ticker_valid;
    00314
    00315   double unitprice;
    00317   int unitprice_valid;
    00318
    00319   time_t date_unitprice;
    00320   int date_unitprice_valid;
    00321
    00322   char currency[OFX_CURRENCY_LENGTH];
    00325   int currency_valid;
    00326   char memo[OFX_MEMO2_LENGTH];
    00327   int memo_valid;
    00328 };/* end struct OfxSecurityData */
    00329
    00341 CFCT typedef int (*LibofxProcSecurityCallback)(const struct OfxSecurityData data, void * security_data);
    00342
    00343 typedef enum {
    00344     OFX_CREDIT,
    00345     OFX_DEBIT,
    00346     OFX_INT,
    00347     OFX_DIV,
    00348     OFX_FEE,
    00349     OFX_SRVCHG,
    00350     OFX_DEP,
    00351     OFX_ATM,
    00352     OFX_POS,
    00353     OFX_XFER,
    00354     OFX_CHECK,
    00355     OFX_PAYMENT,
    00356     OFX_CASH,
    00357     OFX_DIRECTDEP,
    00358     OFX_DIRECTDEBIT,
    00359     OFX_REPEATPMT,
    00360     OFX_OTHER
    00361   } TransactionType;
    00362
    00363 typedef  enum{
    00364     OFX_BUYDEBT,
    00365     OFX_BUYMF,
    00366     OFX_BUYOPT,
    00367     OFX_BUYOTHER,
    00368     OFX_BUYSTOCK,
    00369     OFX_CLOSUREOPT,
    00370     OFX_INCOME,
    00371     OFX_INVEXPENSE,
    00372     OFX_JRNLFUND,
    00373     OFX_JRNLSEC,
    00374     OFX_MARGININTEREST,
    00375     OFX_REINVEST,
    00376     OFX_RETOFCAP,
    00377     OFX_SELLDEBT,
    00378     OFX_SELLMF,
    00379     OFX_SELLOPT,
    00380     OFX_SELLOTHER,
    00381     OFX_SELLSTOCK,
    00382     OFX_SPLIT,
    00383     OFX_TRANSFER
    00384   }  InvTransactionType;
    00385 typedef enum {
    00386     DELETE,
    00388     REPLACE
    00390   } FiIdCorrectionAction;
    00391
    00398 struct OfxTransactionData{
    00399
    00405   char account_id[OFX_ACCOUNT_ID_LENGTH];
    00408   struct OfxAccountData * account_ptr;
    00410   int account_id_valid;
    00411
    00412   TransactionType transactiontype;
    00413   int transactiontype_valid;
    00414
    00418   InvTransactionType invtransactiontype;
    00419   int  invtransactiontype_valid;
    00420
    00421   double units;
    00427   int units_valid;
    00428   double unitprice;
    00430   int unitprice_valid;
    00431   double amount;
    00435   int amount_valid;
    00436   char fi_id[256];
    00439   int fi_id_valid;
    00440
    00448   char unique_id[OFX_UNIQUE_ID_LENGTH];
    00449   int unique_id_valid;
    00450   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
    00452   int unique_id_type_valid;
    00453   struct OfxSecurityData *security_data_ptr;
    00454   int security_data_valid;
    00455
    00456   time_t date_posted;
    00461   int date_posted_valid;
    00462
    00463   time_t date_initiated;
    00469   int date_initiated_valid;
    00470   time_t date_funds_available;
    00473   int date_funds_available_valid;
    00477   char fi_id_corrected[256];
    00478   int fi_id_corrected_valid;
    00481   FiIdCorrectionAction fi_id_correction_action;
    00482   int fi_id_correction_action_valid;
    00483
    00486   char server_transaction_id[OFX_SVRTID2_LENGTH];
    00487   int server_transaction_id_valid;
    00491 char check_number[OFX_CHECK_NUMBER_LENGTH];
    00492   int check_number_valid;
    00495   char reference_number[OFX_REFERENCE_NUMBER_LENGTH];
    00496   int reference_number_valid;
    00497   long int standard_industrial_code;
    00499   int standard_industrial_code_valid;
    00500   char payee_id[OFX_SVRTID2_LENGTH];
    00501   int payee_id_valid;
    00502   char name[OFX_TRANSACTION_NAME_LENGTH];
    00504   int name_valid;
    00505   char memo[OFX_MEMO2_LENGTH];
    00506   int memo_valid;
    00507
    00508   /*********** NOT YET COMPLETE!!! *********************/
    00509 };
    00510
    00519 CFCT typedef int (*LibofxProcTransactionCallback)(const struct OfxTransactionData data, void * transaction_data);
    00520
    00529 struct OfxStatementData{
    00530
    00538   char currency[OFX_CURRENCY_LENGTH];
    00539   int currency_valid;
    00540   char account_id[OFX_ACCOUNT_ID_LENGTH];
    00542   struct OfxAccountData * account_ptr;
    00544   int account_id_valid;
    00547   double ledger_balance;
    00548   int ledger_balance_valid;
    00549   time_t ledger_balance_date;
    00550   int ledger_balance_date_valid;
    00551
    00557   double available_balance;
    00560   int available_balance_valid;
    00561   time_t available_balance_date;
    00562   int available_balance_date_valid;
    00567   time_t date_start;
    00568   int date_start_valid;
    00573   time_t date_end;
    00574   int date_end_valid;
    00577   char marketing_info[OFX_MARKETING_INFO_LENGTH];
    00578   int marketing_info_valid;
    00579 };
    00580
    00588 CFCT typedef int (*LibofxProcStatementCallback)(const struct OfxStatementData data, void * statement_data);
    00589
    00593 struct OfxCurrency{
    00594   char currency[OFX_CURRENCY_LENGTH];
    00595   double exchange_rate;
    00596   int must_convert;
    00597 };
    00598
    00599
    00606 CFCT void ofx_set_status_cb(LibofxContextPtr ctx,
    00607                             LibofxProcStatusCallback cb,
    00608                             void *user_data);
    00615 CFCT void ofx_set_account_cb(LibofxContextPtr ctx,
    00616                              LibofxProcAccountCallback cb,
    00617                              void *user_data);
    00624 CFCT void ofx_set_security_cb(LibofxContextPtr ctx,
    00625                               LibofxProcSecurityCallback cb,
    00626                               void *user_data);
    00633 CFCT void ofx_set_transaction_cb(LibofxContextPtr ctx,
    00634                                  LibofxProcTransactionCallback cb,
    00635                                  void *user_data);
    00636
    00643 CFCT void ofx_set_statement_cb(LibofxContextPtr ctx,
    00644                                LibofxProcStatementCallback cb,
    00645                                void *user_data);
    00646
    00647
    00651 CFCT int libofx_proc_buffer(LibofxContextPtr ctx,
    00652                             const char *s, unsigned int size);
    00653
    00659
    00669 struct OfxFiLogin{
    00670   char fid[OFX_FID_LENGTH];
    00671   char org[OFX_ORG_LENGTH];
    00672   char userid[OFX_USERID_LENGTH];
    00673   char userpass[OFX_USERPASS_LENGTH];
    00674 };
    00675
    00676 typedef enum{
    00677   OFX_NO_ACCOUNT=0,
    00678   OFX_BANK_ACCOUNT,
    00679   OFX_INVEST_ACCOUNT,
    00680   OFX_CREDITCARD_ACCOUNT,
    00681   OFX_INVALID_ACCOUNT
    00682 } AccountType;
    00683
    00692 struct OfxAccountInfo{
    00693   char accountid[OFX_ACCOUNT_ID_LENGTH];
    00694   char bankid[OFX_BANKID_LENGTH];
    00695   char brokerid[OFX_BROKERID_LENGTH];
    00696   AccountType type;
    00697 };
    00698
    00711 CFCT char* libofx_request_statement( const struct OfxFiLogin* fi, const struct OfxAccountInfo* account, time_t date_from );
    00712
    00724 CFCT char* libofx_request_accountinfo( const struct OfxFiLogin* login );
    00725
    00727
    00728 #endif
    00729