LibOFX

libofx.h

Go to the documentation of this file.
00001 /*-*-c-*-*******************************************************************
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 4
00042 #define LIBOFX_BUILD_VERSION 0
00043 #define LIBOFX_VERSION_RELEASE_STRING "0.9.4"
00044 
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #else
00049 #define true 1
00050 #define false 0
00051 #endif
00052 
00053 #define OFX_ELEMENT_NAME_LENGTH         100
00054 #define OFX_SVRTID2_LENGTH             (36 + 1)
00055 #define OFX_CHECK_NUMBER_LENGTH        (12 + 1)
00056 #define OFX_REFERENCE_NUMBER_LENGTH    (32 + 1)
00057 #define OFX_FITID_LENGTH               (255 + 1)
00058 #define OFX_TOKEN2_LENGTH              (36 + 1)
00059 #define OFX_MEMO_LENGTH                (255 + 1)
00060 #define OFX_MEMO2_LENGTH               (390 + 1)
00061 #define OFX_BALANCE_NAME_LENGTH        (32 + 1)
00062 #define OFX_BALANCE_DESCRIPTION_LENGTH (80 + 1)
00063 #define OFX_CURRENCY_LENGTH            (3 + 1) /* In ISO-4217 format */
00064 #define OFX_BANKID_LENGTH              (9 + 1)
00065 #define OFX_BRANCHID_LENGTH            (22 + 1)
00066 #define OFX_ACCTID_LENGTH              (22 + 1)
00067 #define OFX_ACCTKEY_LENGTH             (22 + 1)
00068 #define OFX_BROKERID_LENGTH            (22 + 1)
00069   /* Must be MAX of <BANKID>+<BRANCHID>+<ACCTID>, <ACCTID>+<ACCTKEY> and <ACCTID>+<BROKERID> */
00070 #define OFX_ACCOUNT_ID_LENGTH (OFX_BANKID_LENGTH + OFX_BRANCHID_LENGTH + OFX_ACCTID_LENGTH + 1)
00071 #define OFX_ACCOUNT_NAME_LENGTH        255
00072 #define OFX_MARKETING_INFO_LENGTH      (360 + 1)
00073 #define OFX_TRANSACTION_NAME_LENGTH    (32 + 1)
00074 #define OFX_UNIQUE_ID_LENGTH           (32 + 1)
00075 #define OFX_UNIQUE_ID_TYPE_LENGTH      (10 + 1)
00076 #define OFX_SECNAME_LENGTH             (32 + 1)
00077 #define OFX_TICKER_LENGTH              (32 + 1)
00078 #define OFX_ORG_LENGTH                 (32 + 1)
00079 #define OFX_FID_LENGTH                 (32 + 1)
00080 #define OFX_USERID_LENGTH              (32 + 1)
00081 #define OFX_USERPASS_LENGTH            (32 + 1)
00082 #define OFX_URL_LENGTH                 (500 + 1)
00083 #define OFX_APPID_LENGTH               (32)
00084 #define OFX_APPVER_LENGTH              (32)
00085 #define OFX_HEADERVERSION_LENGTH       (32)
00086 
00087   /*
00088   #define OFX_STATEMENT_CB               0;
00089   #define OFX_ACCOUNT_CB                 1;
00090   #define OFX_TRACSACTION_CB             2;
00091   #define OFX_SECURITY_CB                3;
00092   #define OFX_STATUS_CB                  4;
00093   */
00094 
00095   typedef void * LibofxContextPtr;
00096 
00102   LibofxContextPtr libofx_get_new_context();
00103 
00109   int libofx_free_context( LibofxContextPtr );
00110 
00111   void libofx_set_dtd_dir(LibofxContextPtr libofx_context,
00112                           const char *s);
00113 
00115   enum LibofxFileFormat
00116   {
00117     AUTODETECT, 
00118     OFX, 
00119     OFC, 
00120     QIF, 
00121     UNKNOWN, 
00122     LAST 
00123   };
00124 
00125   struct LibofxFileFormatInfo
00126   {
00127     enum LibofxFileFormat format;
00128     const char * format_name;  
00129     const char * description; 
00130   };
00131 
00132 
00133 #ifndef OFX_AQUAMANIAC_UGLY_HACK1
00134 
00135   const struct LibofxFileFormatInfo LibofxImportFormatList[] =
00136   {
00137     {AUTODETECT, "AUTODETECT", "AUTODETECT (File format will be automatically detected later)"},
00138     {OFX, "OFX", "OFX (Open Financial eXchange (OFX or QFX))"},
00139     {OFC, "OFC", "OFC (Microsoft Open Financial Connectivity)"},
00140     {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
00141     {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
00142   };
00143 
00144   const struct LibofxFileFormatInfo LibofxExportFormatList[] =
00145   {
00146     {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
00147     {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
00148   };
00149 
00161   enum LibofxFileFormat libofx_get_file_format_from_str(const struct LibofxFileFormatInfo format_list[], const char * file_type_string);
00162 
00174   const char * libofx_get_file_format_description(const struct LibofxFileFormatInfo format_list[], enum LibofxFileFormat file_format);
00175 
00176 #endif
00177 
00184   int libofx_proc_file(LibofxContextPtr libofx_context,
00185                        const char * p_filename,
00186                        enum LibofxFileFormat ftype);
00187 
00188 
00201   struct OfxStatusData
00202   {
00207     char ofx_element_name[OFX_ELEMENT_NAME_LENGTH];
00209     int ofx_element_name_valid;
00210 
00215     int code;            
00216     const char* name;          
00217     const char* description;   
00218     int code_valid;      
00221     enum Severity
00222     {
00223       INFO, 
00224       WARN, 
00225       ERROR 
00226     } severity;
00227     int severity_valid;
00228 
00234     char* server_message; 
00236     int server_message_valid;
00238   };
00239 
00240 
00250   typedef int (*LibofxProcStatusCallback)(const struct OfxStatusData data, void * status_data);
00251 
00263   struct OfxAccountData
00264   {
00265 
00277     char account_id[OFX_ACCOUNT_ID_LENGTH];
00278 
00284     char account_name[OFX_ACCOUNT_NAME_LENGTH];
00285     int account_id_valid;/* Use for both account_id and account_name */
00286 
00289     enum AccountType
00290     {
00291       OFX_CHECKING,  
00292       OFX_SAVINGS,   
00293       OFX_MONEYMRKT, 
00294       OFX_CREDITLINE,
00295       OFX_CMA,       
00296       OFX_CREDITCARD,
00297       OFX_INVESTMENT 
00298     } account_type;
00299     int account_type_valid;
00300 
00302     char currency[OFX_CURRENCY_LENGTH];
00303     int currency_valid;
00304 
00306     char account_number[OFX_ACCTID_LENGTH];
00307     int account_number_valid;
00308 
00310     char bank_id[OFX_BANKID_LENGTH];
00311     int bank_id_valid;
00312 
00313     char broker_id[OFX_BROKERID_LENGTH];
00314     int broker_id_valid;
00315 
00316     char branch_id[OFX_BRANCHID_LENGTH];
00317     int branch_id_valid;
00318 
00319   };
00320 
00335   typedef int (*LibofxProcAccountCallback)(const struct OfxAccountData data, void * account_data);
00336 
00344   struct OfxSecurityData
00345   {
00353     char unique_id[OFX_UNIQUE_ID_LENGTH];   
00354     int unique_id_valid;
00355 
00356     char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00358     int unique_id_type_valid;
00359 
00360     char secname[OFX_SECNAME_LENGTH];
00361     int secname_valid;
00362 
00368     char ticker[OFX_TICKER_LENGTH];
00369     int ticker_valid;
00370 
00371     double unitprice;
00373     int unitprice_valid;
00374 
00375     time_t date_unitprice;
00376     int date_unitprice_valid;
00377 
00380     char currency[OFX_CURRENCY_LENGTH];
00381     int currency_valid;
00382 
00383     char memo[OFX_MEMO2_LENGTH];
00384     int memo_valid;
00385   };/* end struct OfxSecurityData */
00386 
00400   typedef int (*LibofxProcSecurityCallback)(const struct OfxSecurityData data, void * security_data);
00401 
00402   typedef enum
00403   {
00404     OFX_CREDIT,     
00405     OFX_DEBIT,      
00406     OFX_INT,        
00407     OFX_DIV,        
00408     OFX_FEE,        
00409     OFX_SRVCHG,     
00410     OFX_DEP,        
00411     OFX_ATM,        
00412     OFX_POS,        
00413     OFX_XFER,       
00414     OFX_CHECK,      
00415     OFX_PAYMENT,    
00416     OFX_CASH,       
00417     OFX_DIRECTDEP,  
00418     OFX_DIRECTDEBIT,
00419     OFX_REPEATPMT,  
00420     OFX_OTHER       
00421   } TransactionType;
00422 
00423   typedef enum
00424   {
00425     OFX_BUYDEBT,        
00426     OFX_BUYMF,          
00427     OFX_BUYOPT,         
00428     OFX_BUYOTHER,       
00429     OFX_BUYSTOCK,       
00430     OFX_CLOSUREOPT,     
00431     OFX_INCOME,         
00432     OFX_INVEXPENSE,     
00433     OFX_JRNLFUND,       
00434     OFX_JRNLSEC,        
00435     OFX_MARGININTEREST, 
00436     OFX_REINVEST,       
00437     OFX_RETOFCAP,       
00438     OFX_SELLDEBT,       
00439     OFX_SELLMF,         
00440     OFX_SELLOPT,        
00441     OFX_SELLOTHER,      
00442     OFX_SELLSTOCK,      
00443     OFX_SPLIT,          
00444     OFX_TRANSFER        
00445   } InvTransactionType;
00446 
00447   typedef enum
00448   {
00449     DELETE, 
00451     REPLACE 
00453   } FiIdCorrectionAction;
00454 
00461   struct OfxTransactionData
00462   {
00463 
00469     char account_id[OFX_ACCOUNT_ID_LENGTH];
00472     struct OfxAccountData * account_ptr; 
00474     int account_id_valid;
00475 
00476     TransactionType transactiontype;
00477     int transactiontype_valid;
00478 
00482     InvTransactionType invtransactiontype;
00483     int  invtransactiontype_valid;
00484 
00492     double units;
00493     int units_valid;
00494 
00495     double unitprice; 
00497     int unitprice_valid;
00498 
00499     double amount;    
00503     int amount_valid;
00504 
00505     char fi_id[256];  
00508     int fi_id_valid;
00509 
00517     char unique_id[OFX_UNIQUE_ID_LENGTH];
00518     int unique_id_valid;
00519     char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00521     int unique_id_type_valid;
00522 
00523     struct OfxSecurityData *security_data_ptr;  
00524     int security_data_valid;
00525 
00526     time_t date_posted;
00531     int date_posted_valid;
00532 
00533     time_t date_initiated;
00539     int date_initiated_valid;
00540 
00541     time_t date_funds_available;
00544     int date_funds_available_valid;
00545 
00549     char fi_id_corrected[256];
00550     int fi_id_corrected_valid;
00551 
00554     FiIdCorrectionAction fi_id_correction_action;
00555     int fi_id_correction_action_valid;
00556 
00559     char server_transaction_id[OFX_SVRTID2_LENGTH];
00560     int server_transaction_id_valid;
00561 
00565     char check_number[OFX_CHECK_NUMBER_LENGTH];
00566     int check_number_valid;
00567 
00570     char reference_number[OFX_REFERENCE_NUMBER_LENGTH];
00571     int reference_number_valid;
00572 
00573     long int standard_industrial_code;
00575     int standard_industrial_code_valid;
00576 
00577     char payee_id[OFX_SVRTID2_LENGTH];
00578     int payee_id_valid;
00579 
00580     char name[OFX_TRANSACTION_NAME_LENGTH];
00582     int name_valid;
00583 
00584     char memo[OFX_MEMO2_LENGTH];
00585     int memo_valid;
00586 
00587     double commission;
00588     int commission_valid;
00589 
00590     double fees;
00591     int fees_valid;
00592 
00593     double oldunits;     /*number of units held before stock split */
00594     int oldunits_valid;
00595 
00596     double newunits;     /*number of units held after stock split */
00597     int newunits_valid;
00598 
00599 
00600     /*********** NOT YET COMPLETE!!! *********************/
00601   };
00602 
00612   typedef int (*LibofxProcTransactionCallback)(const struct OfxTransactionData data, void * transaction_data);
00613 
00623   struct OfxStatementData
00624   {
00625 
00633     char currency[OFX_CURRENCY_LENGTH]; 
00634     int currency_valid;
00635 
00636     char account_id[OFX_ACCOUNT_ID_LENGTH];
00638     struct OfxAccountData * account_ptr; 
00640     int account_id_valid;
00641 
00644     double ledger_balance;
00645     int ledger_balance_valid;
00646 
00647     time_t ledger_balance_date;
00648     int ledger_balance_date_valid;
00649 
00655     double available_balance; 
00658     int available_balance_valid;
00659 
00660     time_t available_balance_date;
00661     int available_balance_date_valid;
00662 
00667     time_t date_start;
00668     int date_start_valid;
00669 
00674     time_t date_end;
00675     int date_end_valid;
00676 
00679     char marketing_info[OFX_MARKETING_INFO_LENGTH];
00680     int marketing_info_valid;
00681   };
00682 
00690   typedef int (*LibofxProcStatementCallback)(const struct OfxStatementData data, void * statement_data);
00691 
00695   struct OfxCurrency
00696   {
00697     char currency[OFX_CURRENCY_LENGTH]; 
00698     double exchange_rate;  
00699     int must_convert;   
00700   };
00701 
00702 
00709   void ofx_set_status_cb(LibofxContextPtr ctx,
00710                          LibofxProcStatusCallback cb,
00711                          void *user_data);
00712 
00719   void ofx_set_account_cb(LibofxContextPtr ctx,
00720                           LibofxProcAccountCallback cb,
00721                           void *user_data);
00722 
00729   void ofx_set_security_cb(LibofxContextPtr ctx,
00730                            LibofxProcSecurityCallback cb,
00731                            void *user_data);
00732 
00739   void ofx_set_transaction_cb(LibofxContextPtr ctx,
00740                               LibofxProcTransactionCallback cb,
00741                               void *user_data);
00742 
00749   void ofx_set_statement_cb(LibofxContextPtr ctx,
00750                             LibofxProcStatementCallback cb,
00751                             void *user_data);
00752 
00753 
00757   int libofx_proc_buffer(LibofxContextPtr ctx,
00758                          const char *s, unsigned int size);
00759 
00760 
00761   /* **************************************** */
00762 
00768 
00772   struct OfxFiServiceInfo
00773   {
00774     char fid[OFX_FID_LENGTH];
00775     char org[OFX_ORG_LENGTH];
00776     char url[OFX_URL_LENGTH];
00777     int accountlist; 
00778     int statements; 
00779     int billpay; 
00780     int investments; 
00781   };
00782 
00792   struct OfxFiLogin
00793   {
00794     char fid[OFX_FID_LENGTH];
00795     char org[OFX_ORG_LENGTH];
00796     char userid[OFX_USERID_LENGTH];
00797     char userpass[OFX_USERPASS_LENGTH];
00798     char header_version[OFX_HEADERVERSION_LENGTH];
00799     char appid[OFX_APPID_LENGTH];
00800     char appver[OFX_APPVER_LENGTH];
00801   };
00802 
00803 #define OFX_AMOUNT_LENGTH (32 + 1)
00804 #define OFX_PAYACCT_LENGTH (32 + 1)
00805 #define OFX_STATE_LENGTH (5 + 1)
00806 #define OFX_POSTALCODE_LENGTH (11 + 1)
00807 #define OFX_NAME_LENGTH (32 + 1)
00808 
00809   struct OfxPayment
00810   {
00811     char amount[OFX_AMOUNT_LENGTH];
00812     char account[OFX_PAYACCT_LENGTH];
00813     char datedue[9];
00814     char memo[OFX_MEMO_LENGTH];
00815   };
00816 
00817   struct OfxPayee
00818   {
00819     char name[OFX_NAME_LENGTH];
00820     char address1[OFX_NAME_LENGTH];
00821     char city[OFX_NAME_LENGTH];
00822     char state[OFX_STATE_LENGTH];
00823     char postalcode[OFX_POSTALCODE_LENGTH];
00824     char phone[OFX_NAME_LENGTH];
00825   };
00826 
00838   char* libofx_request_statement( const struct OfxFiLogin* fi, const struct OfxAccountData* account, time_t date_from );
00839 
00850   char* libofx_request_accountinfo( const struct OfxFiLogin* login );
00851 
00852   char* libofx_request_payment( const struct OfxFiLogin* login, const struct OfxAccountData* account, const struct OfxPayee* payee, const struct OfxPayment* payment );
00853 
00854   char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid );
00855 
00857 
00858 #ifdef __cplusplus
00859 } // end of extern "C"
00860 #endif
00861 #endif // end of LIBOFX_H