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-2011 by Benoit Grégoire
00005     email                : benoitg@coeus.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 8
00042 #define LIBOFX_BUILD_VERSION 0
00043 #define LIBOFX_VERSION_RELEASE_STRING "0.9.8"
00044 
00045 #ifdef IN_LIBOFX
00046 #  include "config.h"
00047 #  ifdef HAVE_GCC_VISIBILITY_EXTS
00048 #    pragma GCC visibility push(default)
00049 #  endif
00050 #endif
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #else
00055 #define true 1
00056 #define false 0
00057 #endif
00058 
00059 #define OFX_ELEMENT_NAME_LENGTH         100
00060 #define OFX_SVRTID2_LENGTH             (36 + 1)
00061 #define OFX_CHECK_NUMBER_LENGTH        (12 + 1)
00062 #define OFX_REFERENCE_NUMBER_LENGTH    (32 + 1)
00063 #define OFX_FITID_LENGTH               (255 + 1)
00064 #define OFX_TOKEN2_LENGTH              (36 + 1)
00065 #define OFX_MEMO_LENGTH                (255 + 1)
00066 #define OFX_FIID_LENGTH                (32 + 1)
00067 #define OFX_MEMO2_LENGTH               (390 + 1)
00068 #define OFX_BALANCE_NAME_LENGTH        (32 + 1)
00069 #define OFX_BALANCE_DESCRIPTION_LENGTH (80 + 1)
00070 #define OFX_CURRENCY_LENGTH            (3 + 1) /* In ISO-4217 format */
00071 #define OFX_BANKID_LENGTH              (9 + 1)
00072 #define OFX_BRANCHID_LENGTH            (22 + 1)
00073 #define OFX_ACCTID_LENGTH              (22 + 1)
00074 #define OFX_ACCTKEY_LENGTH             (22 + 1)
00075 #define OFX_BROKERID_LENGTH            (22 + 1)
00076   /* Must be MAX of <BANKID>+<BRANCHID>+<ACCTID>, <ACCTID>+<ACCTKEY> and <ACCTID>+<BROKERID> */
00077 #define OFX_ACCOUNT_ID_LENGTH (OFX_BANKID_LENGTH + OFX_BRANCHID_LENGTH + OFX_ACCTID_LENGTH + 1)
00078 #define OFX_ACCOUNT_NAME_LENGTH        255
00079 #define OFX_MARKETING_INFO_LENGTH      (360 + 1)
00080 #define OFX_TRANSACTION_NAME_LENGTH    (96 + 1)
00081 #define OFX_UNIQUE_ID_LENGTH           (32 + 1)
00082 #define OFX_UNIQUE_ID_TYPE_LENGTH      (10 + 1)
00083 #define OFX_SECNAME_LENGTH             (32 + 1)
00084 #define OFX_TICKER_LENGTH              (32 + 1)
00085 #define OFX_ORG_LENGTH                 (32 + 1)
00086 #define OFX_FID_LENGTH                 (32 + 1)
00087 #define OFX_USERID_LENGTH              (32 + 1)
00088 #define OFX_USERPASS_LENGTH            (32 + 1)
00089 #define OFX_URL_LENGTH                 (500 + 1)
00090 #define OFX_APPID_LENGTH               (32)
00091 #define OFX_APPVER_LENGTH              (32)
00092 #define OFX_HEADERVERSION_LENGTH       (32)
00093 
00094   /*
00095   #define OFX_STATEMENT_CB               0;
00096   #define OFX_ACCOUNT_CB                 1;
00097   #define OFX_TRACSACTION_CB             2;
00098   #define OFX_SECURITY_CB                3;
00099   #define OFX_STATUS_CB                  4;
00100   */
00101 
00102   typedef void * LibofxContextPtr;
00103 
00109   LibofxContextPtr libofx_get_new_context();
00110 
00116   int libofx_free_context( LibofxContextPtr );
00117 
00118   void libofx_set_dtd_dir(LibofxContextPtr libofx_context,
00119                           const char *s);
00120 
00122   enum LibofxFileFormat
00123   {
00124     AUTODETECT, 
00125     OFX, 
00126     OFC, 
00127     QIF, 
00128     UNKNOWN, 
00129     LAST 
00130   };
00131 
00132   struct LibofxFileFormatInfo
00133   {
00134     enum LibofxFileFormat format;
00135     const char * format_name;  
00136     const char * description; 
00137   };
00138 
00139 
00140 #ifndef OFX_AQUAMANIAC_UGLY_HACK1
00141 
00142   const struct LibofxFileFormatInfo LibofxImportFormatList[] =
00143   {
00144     {AUTODETECT, "AUTODETECT", "AUTODETECT (File format will be automatically detected later)"},
00145     {OFX, "OFX", "OFX (Open Financial eXchange (OFX or QFX))"},
00146     {OFC, "OFC", "OFC (Microsoft Open Financial Connectivity)"},
00147     {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
00148     {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
00149   };
00150 
00151   const struct LibofxFileFormatInfo LibofxExportFormatList[] =
00152   {
00153     {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
00154     {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
00155   };
00156 
00168   enum LibofxFileFormat libofx_get_file_format_from_str(const struct LibofxFileFormatInfo format_list[], const char * file_type_string);
00169 
00181   const char * libofx_get_file_format_description(const struct LibofxFileFormatInfo format_list[], enum LibofxFileFormat file_format);
00182 
00183 #endif
00184 
00191   int libofx_proc_file(LibofxContextPtr libofx_context,
00192                        const char * p_filename,
00193                        enum LibofxFileFormat ftype);
00194 
00195 
00208   struct OfxStatusData
00209   {
00214     char ofx_element_name[OFX_ELEMENT_NAME_LENGTH];
00216     int ofx_element_name_valid;
00217 
00222     int code;            
00223     const char* name;          
00224     const char* description;   
00225     int code_valid;      
00228     enum Severity
00229     {
00230       INFO, 
00231       WARN, 
00232       ERROR 
00233     } severity;
00234     int severity_valid;
00235 
00241     char* server_message; 
00243     int server_message_valid;
00245   };
00246 
00247 
00257   typedef int (*LibofxProcStatusCallback)(const struct OfxStatusData data, void * status_data);
00258 
00270   struct OfxAccountData
00271   {
00272 
00284     char account_id[OFX_ACCOUNT_ID_LENGTH];
00285 
00291     char account_name[OFX_ACCOUNT_NAME_LENGTH];
00292     int account_id_valid;/* Use for both account_id and account_name */
00293 
00296     enum AccountType
00297     {
00298       OFX_CHECKING,  
00299       OFX_SAVINGS,   
00300       OFX_MONEYMRKT, 
00301       OFX_CREDITLINE,
00302       OFX_CMA,       
00303       OFX_CREDITCARD,
00304       OFX_INVESTMENT 
00305     } account_type;
00306     int account_type_valid;
00307 
00309     char currency[OFX_CURRENCY_LENGTH];
00310     int currency_valid;
00311 
00313     char account_number[OFX_ACCTID_LENGTH];
00314     int account_number_valid;
00315 
00317     char bank_id[OFX_BANKID_LENGTH];
00318     int bank_id_valid;
00319 
00320     char broker_id[OFX_BROKERID_LENGTH];
00321     int broker_id_valid;
00322 
00323     char branch_id[OFX_BRANCHID_LENGTH];
00324     int branch_id_valid;
00325 
00326   };
00327 
00342   typedef int (*LibofxProcAccountCallback)(const struct OfxAccountData data, void * account_data);
00343 
00351   struct OfxSecurityData
00352   {
00360     char unique_id[OFX_UNIQUE_ID_LENGTH];   
00361     int unique_id_valid;
00362 
00363     char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00365     int unique_id_type_valid;
00366 
00367     char secname[OFX_SECNAME_LENGTH];
00368     int secname_valid;
00369 
00375     char ticker[OFX_TICKER_LENGTH];
00376     int ticker_valid;
00377 
00378     double unitprice;
00380     int unitprice_valid;
00381 
00382     time_t date_unitprice;
00383     int date_unitprice_valid;
00384 
00387     char currency[OFX_CURRENCY_LENGTH];
00388     int currency_valid;
00389 
00390     char memo[OFX_MEMO2_LENGTH];
00391     int memo_valid;
00392 
00395     char fiid[OFX_FIID_LENGTH];
00396     int fiid_valid;
00397 
00398   };/* end struct OfxSecurityData */
00399 
00413   typedef int (*LibofxProcSecurityCallback)(const struct OfxSecurityData data, void * security_data);
00414 
00415   typedef enum
00416   {
00417     OFX_CREDIT,     
00418     OFX_DEBIT,      
00419     OFX_INT,        
00420     OFX_DIV,        
00421     OFX_FEE,        
00422     OFX_SRVCHG,     
00423     OFX_DEP,        
00424     OFX_ATM,        
00425     OFX_POS,        
00426     OFX_XFER,       
00427     OFX_CHECK,      
00428     OFX_PAYMENT,    
00429     OFX_CASH,       
00430     OFX_DIRECTDEP,  
00431     OFX_DIRECTDEBIT,
00432     OFX_REPEATPMT,  
00433     OFX_OTHER       
00434   } TransactionType;
00435 
00436   typedef enum
00437   {
00438     OFX_BUYDEBT,        
00439     OFX_BUYMF,          
00440     OFX_BUYOPT,         
00441     OFX_BUYOTHER,       
00442     OFX_BUYSTOCK,       
00443     OFX_CLOSUREOPT,     
00444     OFX_INCOME,         
00445     OFX_INVEXPENSE,     
00446     OFX_JRNLFUND,       
00447     OFX_JRNLSEC,        
00448     OFX_MARGININTEREST, 
00449     OFX_REINVEST,       
00450     OFX_RETOFCAP,       
00451     OFX_SELLDEBT,       
00452     OFX_SELLMF,         
00453     OFX_SELLOPT,        
00454     OFX_SELLOTHER,      
00455     OFX_SELLSTOCK,      
00456     OFX_SPLIT,          
00457     OFX_TRANSFER        
00458   } InvTransactionType;
00459 
00460   typedef enum
00461   {
00462     DELETE, 
00464     REPLACE 
00466   } FiIdCorrectionAction;
00467 
00474   struct OfxTransactionData
00475   {
00476 
00482     char account_id[OFX_ACCOUNT_ID_LENGTH];
00485     struct OfxAccountData * account_ptr; 
00487     int account_id_valid;
00488 
00489     TransactionType transactiontype;
00490     int transactiontype_valid;
00491 
00495     InvTransactionType invtransactiontype;
00496     int  invtransactiontype_valid;
00497 
00505     double units;
00506     int units_valid;
00507 
00508     double unitprice; 
00510     int unitprice_valid;
00511 
00512     double amount;    
00516     int amount_valid;
00517 
00518     char fi_id[256];  
00521     int fi_id_valid;
00522 
00530     char unique_id[OFX_UNIQUE_ID_LENGTH];
00531     int unique_id_valid;
00532     char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00534     int unique_id_type_valid;
00535 
00536     struct OfxSecurityData *security_data_ptr;  
00537     int security_data_valid;
00538 
00539     time_t date_posted;
00544     int date_posted_valid;
00545 
00546     time_t date_initiated;
00552     int date_initiated_valid;
00553 
00554     time_t date_funds_available;
00557     int date_funds_available_valid;
00558 
00562     char fi_id_corrected[256];
00563     int fi_id_corrected_valid;
00564 
00567     FiIdCorrectionAction fi_id_correction_action;
00568     int fi_id_correction_action_valid;
00569 
00572     char server_transaction_id[OFX_SVRTID2_LENGTH];
00573     int server_transaction_id_valid;
00574 
00578     char check_number[OFX_CHECK_NUMBER_LENGTH];
00579     int check_number_valid;
00580 
00583     char reference_number[OFX_REFERENCE_NUMBER_LENGTH];
00584     int reference_number_valid;
00585 
00586     long int standard_industrial_code;
00588     int standard_industrial_code_valid;
00589 
00590     char payee_id[OFX_SVRTID2_LENGTH];
00591     int payee_id_valid;
00592 
00593     char name[OFX_TRANSACTION_NAME_LENGTH];
00595     int name_valid;
00596 
00597     char memo[OFX_MEMO2_LENGTH];
00598     int memo_valid;
00599 
00600     double commission;
00601     int commission_valid;
00602 
00603     double fees;
00604     int fees_valid;
00605 
00606     double oldunits;     /*number of units held before stock split */
00607     int oldunits_valid;
00608 
00609     double newunits;     /*number of units held after stock split */
00610     int newunits_valid;
00611 
00612 
00613     /*********** NOT YET COMPLETE!!! *********************/
00614   };
00615 
00625   typedef int (*LibofxProcTransactionCallback)(const struct OfxTransactionData data, void * transaction_data);
00626 
00636   struct OfxStatementData
00637   {
00638 
00646     char currency[OFX_CURRENCY_LENGTH]; 
00647     int currency_valid;
00648 
00649     char account_id[OFX_ACCOUNT_ID_LENGTH];
00651     struct OfxAccountData * account_ptr; 
00653     int account_id_valid;
00654 
00657     double ledger_balance;
00658     int ledger_balance_valid;
00659 
00660     time_t ledger_balance_date;
00661     int ledger_balance_date_valid;
00662 
00668     double available_balance; 
00671     int available_balance_valid;
00672 
00673     time_t available_balance_date;
00674     int available_balance_date_valid;
00675 
00680     time_t date_start;
00681     int date_start_valid;
00682 
00687     time_t date_end;
00688     int date_end_valid;
00689 
00692     char marketing_info[OFX_MARKETING_INFO_LENGTH];
00693     int marketing_info_valid;
00694   };
00695 
00703   typedef int (*LibofxProcStatementCallback)(const struct OfxStatementData data, void * statement_data);
00704 
00708   struct OfxCurrency
00709   {
00710     char currency[OFX_CURRENCY_LENGTH]; 
00711     double exchange_rate;  
00712     int must_convert;   
00713   };
00714 
00715 
00722   void ofx_set_status_cb(LibofxContextPtr ctx,
00723                          LibofxProcStatusCallback cb,
00724                          void *user_data);
00725 
00732   void ofx_set_account_cb(LibofxContextPtr ctx,
00733                           LibofxProcAccountCallback cb,
00734                           void *user_data);
00735 
00742   void ofx_set_security_cb(LibofxContextPtr ctx,
00743                            LibofxProcSecurityCallback cb,
00744                            void *user_data);
00745 
00752   void ofx_set_transaction_cb(LibofxContextPtr ctx,
00753                               LibofxProcTransactionCallback cb,
00754                               void *user_data);
00755 
00762   void ofx_set_statement_cb(LibofxContextPtr ctx,
00763                             LibofxProcStatementCallback cb,
00764                             void *user_data);
00765 
00766 
00770   int libofx_proc_buffer(LibofxContextPtr ctx,
00771                          const char *s, unsigned int size);
00772 
00773 
00774   /* **************************************** */
00775 
00781 
00785   struct OfxFiServiceInfo
00786   {
00787     char fid[OFX_FID_LENGTH];
00788     char org[OFX_ORG_LENGTH];
00789     char url[OFX_URL_LENGTH];
00790     int accountlist; 
00791     int statements; 
00792     int billpay; 
00793     int investments; 
00794   };
00795 
00805   struct OfxFiLogin
00806   {
00807     char fid[OFX_FID_LENGTH];
00808     char org[OFX_ORG_LENGTH];
00809     char userid[OFX_USERID_LENGTH];
00810     char userpass[OFX_USERPASS_LENGTH];
00811     char header_version[OFX_HEADERVERSION_LENGTH];
00812     char appid[OFX_APPID_LENGTH];
00813     char appver[OFX_APPVER_LENGTH];
00814   };
00815 
00816 #define OFX_AMOUNT_LENGTH (32 + 1)
00817 #define OFX_PAYACCT_LENGTH (32 + 1)
00818 #define OFX_STATE_LENGTH (5 + 1)
00819 #define OFX_POSTALCODE_LENGTH (11 + 1)
00820 #define OFX_NAME_LENGTH (32 + 1)
00821 
00822   struct OfxPayment
00823   {
00824     char amount[OFX_AMOUNT_LENGTH];
00825     char account[OFX_PAYACCT_LENGTH];
00826     char datedue[9];
00827     char memo[OFX_MEMO_LENGTH];
00828   };
00829 
00830   struct OfxPayee
00831   {
00832     char name[OFX_NAME_LENGTH];
00833     char address1[OFX_NAME_LENGTH];
00834     char city[OFX_NAME_LENGTH];
00835     char state[OFX_STATE_LENGTH];
00836     char postalcode[OFX_POSTALCODE_LENGTH];
00837     char phone[OFX_NAME_LENGTH];
00838   };
00839 
00851   char* libofx_request_statement( const struct OfxFiLogin* fi, const struct OfxAccountData* account, time_t date_from );
00852 
00863   char* libofx_request_accountinfo( const struct OfxFiLogin* login );
00864 
00865   char* libofx_request_payment( const struct OfxFiLogin* login, const struct OfxAccountData* account, const struct OfxPayee* payee, const struct OfxPayment* payment );
00866 
00867   char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid );
00868 
00870 
00871 extern int ofx_PARSER_msg; 
00872 extern int ofx_DEBUG_msg;
00873 extern int ofx_DEBUG1_msg;
00874 extern int ofx_DEBUG2_msg;
00875 extern int ofx_DEBUG3_msg;
00876 extern int ofx_DEBUG4_msg;
00877 extern int ofx_DEBUG5_msg;
00878 extern int ofx_STATUS_msg;
00879 extern int ofx_INFO_msg;
00880 extern int ofx_WARNING_msg;
00881 extern int ofx_ERROR_msg;
00882 extern int ofx_show_position;
00884 #ifdef __cplusplus
00885 } // end of extern "C"
00886 #endif
00887 
00888 #if defined(HAVE_GCC_VISIBILITY_EXTS) && defined(IN_LIBOFX)
00889 #  pragma GCC visibility pop
00890 #endif
00891 
00892 #endif // end of LIBOFX_H