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_MEMO_LENGTH                255 + 1
00054 #define OFX_MEMO2_LENGTH               390 + 1
00055 #define OFX_BALANCE_NAME_LENGTH        32 + 1
00056 #define OFX_BALANCE_DESCRIPTION_LENGTH 80 + 1
00057 #define OFX_CURRENCY_LENGTH            3 + 1 /* In ISO-4217 format */
00058 #define OFX_BANKID_LENGTH              9 + 1
00059 #define OFX_BRANCHID_LENGTH            22 + 1
00060 #define OFX_ACCTID_LENGTH              22 + 1 
00061 #define OFX_ACCTKEY_LENGTH             22 + 1
00062 #define OFX_BROKERID_LENGTH            22 + 1
00063 /* Must be MAX of <BANKID>+<BRANCHID>+<ACCTID>, <ACCTID>+<ACCTKEY> and <ACCTID>+<BROKERID> */
00064 #define OFX_ACCOUNT_ID_LENGTH OFX_BANKID_LENGTH + OFX_BRANCHID_LENGTH + OFX_ACCTID_LENGTH + 1
00065 #define OFX_ACCOUNT_NAME_LENGTH        255
00066 #define OFX_MARKETING_INFO_LENGTH      360 + 1
00067 #define OFX_TRANSACTION_NAME_LENGTH    32 + 1
00068 #define OFX_UNIQUE_ID_LENGTH           32 + 1
00069 #define OFX_UNIQUE_ID_TYPE_LENGTH      10 + 1
00070 #define OFX_SECNAME_LENGTH             32 + 1
00071 #define OFX_TICKER_LENGTH              32 + 1
00072 #define OFX_ORG_LENGTH                 32 + 1
00073 #define OFX_FID_LENGTH                 32 + 1
00074 #define OFX_USERID_LENGTH              32 + 1
00075 #define OFX_USERPASS_LENGTH            32 + 1
00076 #define OFX_URL_LENGTH                 500 + 1
00077 /*
00078 #define OFX_STATEMENT_CB               0;
00079 #define OFX_ACCOUNT_CB                 1;
00080 #define OFX_TRACSACTION_CB             2;
00081 #define OFX_SECURITY_CB                3;
00082 #define OFX_STATUS_CB                  4;
00083 */
00084 
00085 typedef void * LibofxContextPtr;
00091 CFCT LibofxContextPtr libofx_get_new_context();
00097 CFCT int libofx_free_context( LibofxContextPtr );
00098 
00100 enum LibofxFileFormat{ AUTODETECT, 
00101                      OFX, 
00102                      OFC, 
00103                      QIF, 
00104                      UNKNOWN, 
00105                      LAST 
00106 };
00107 
00108 struct LibofxFileFormatInfo{
00109 enum LibofxFileFormat format;
00110 const char * format_name;  
00111 const char * description; 
00112 };
00113 
00114 
00115 #ifndef OFX_AQUAMANIAC_UGLY_HACK1
00116 
00117 const struct LibofxFileFormatInfo LibofxImportFormatList[] = 
00118 {
00119 {AUTODETECT, "AUTODETECT", "AUTODETECT (File format will be automatically detected later)"},
00120 {OFX, "OFX", "OFX (Open Financial eXchange (OFX or QFX))"},
00121 {OFC, "OFC", "OFC (Microsoft Open Financial Connectivity)"},
00122 {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
00123 {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
00124 };
00125 
00126 const struct LibofxFileFormatInfo LibofxExportFormatList[] = 
00127 {
00128 {QIF, "QIF", "QIF (Intuit Quicken Interchange Format) NOT IMPLEMENTED"},
00129 {LAST, "LAST", "Not a file format, meant as a loop breaking condition"}
00130 };
00131 
00139 CFCT enum LibofxFileFormat libofx_get_file_format_from_str(const struct LibofxFileFormatInfo format_list[], const char * file_type_string);
00140 
00148 CFCT const char * libofx_get_file_format_description(const struct LibofxFileFormatInfo format_list[], enum LibofxFileFormat file_format);
00149 
00150 #endif
00151 
00158 CFCT int libofx_proc_file(LibofxContextPtr libofx_context,
00159                           const char * p_filename,
00160                           enum LibofxFileFormat ftype);
00161 
00162 
00175 struct OfxStatusData{  
00180   char ofx_element_name[OFX_ELEMENT_NAME_LENGTH];
00182   int ofx_element_name_valid;
00183   
00188   int code;            
00189   char* name;          
00190   char* description;   
00191   int code_valid;      
00194     enum Severity{INFO, 
00195                 WARN, 
00196                 ERROR 
00197   } severity;
00198   int severity_valid;
00199   
00205   char* server_message; 
00207   int server_message_valid;
00209 };
00210 
00211 
00220 CFCT typedef int (*LibofxProcStatusCallback)(const struct OfxStatusData data, void * status_data);
00221 
00228 struct OfxAccountData{
00229   
00240   char account_id[OFX_ACCOUNT_ID_LENGTH];
00246   char account_name[OFX_ACCOUNT_NAME_LENGTH];
00247   int account_id_valid;/* Use for both account_id and account_name */
00248 
00250     enum AccountType{
00251     OFX_CHECKING,  
00252     OFX_SAVINGS,   
00253     OFX_MONEYMRKT, 
00254     OFX_CREDITLINE,
00255     OFX_CMA,       
00256     OFX_CREDITCARD,
00257     OFX_INVESTMENT 
00258   } account_type;
00259   int account_type_valid;
00260   char currency[OFX_CURRENCY_LENGTH]; 
00261   int currency_valid;
00262 
00263   char bank_id[OFX_BANKID_LENGTH];
00264   int bank_id_valid;
00265 
00266   char broker_id[OFX_BROKERID_LENGTH];
00267   int broker_id_valid;
00268 
00269   char branch_id[OFX_BRANCHID_LENGTH];
00270   int branch_id_valid;
00271 
00272   char account_number[OFX_ACCTID_LENGTH];
00273   int account_number_valid;
00274 
00275 };
00276 
00289 CFCT typedef int (*LibofxProcAccountCallback)(const struct OfxAccountData data, void * account_data);
00290 
00297 struct OfxSecurityData{
00303   char unique_id[OFX_UNIQUE_ID_LENGTH];   
00304   int unique_id_valid;
00305   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00307   int unique_id_type_valid;
00308   char secname[OFX_SECNAME_LENGTH];
00309   int secname_valid;
00310 
00316   char ticker[OFX_TICKER_LENGTH];
00317   int ticker_valid;
00318 
00319   double unitprice;
00321   int unitprice_valid;
00322 
00323   time_t date_unitprice;
00324   int date_unitprice_valid;
00325 
00326   char currency[OFX_CURRENCY_LENGTH]; 
00329   int currency_valid;
00330   char memo[OFX_MEMO2_LENGTH];
00331   int memo_valid;
00332 };/* end struct OfxSecurityData */
00333 
00345 CFCT typedef int (*LibofxProcSecurityCallback)(const struct OfxSecurityData data, void * security_data);
00346 
00347 typedef enum {
00348     OFX_CREDIT,     
00349     OFX_DEBIT,      
00350     OFX_INT,        
00351     OFX_DIV,        
00352     OFX_FEE,        
00353     OFX_SRVCHG,     
00354     OFX_DEP,        
00355     OFX_ATM,        
00356     OFX_POS,        
00357     OFX_XFER,       
00358     OFX_CHECK,      
00359     OFX_PAYMENT,    
00360     OFX_CASH,       
00361     OFX_DIRECTDEP,  
00362     OFX_DIRECTDEBIT,
00363     OFX_REPEATPMT,  
00364     OFX_OTHER       
00365   } TransactionType;
00366 
00367 typedef  enum{
00368     OFX_BUYDEBT,        
00369     OFX_BUYMF,          
00370     OFX_BUYOPT,         
00371     OFX_BUYOTHER,       
00372     OFX_BUYSTOCK,       
00373     OFX_CLOSUREOPT,     
00374     OFX_INCOME,         
00375     OFX_INVEXPENSE,     
00376     OFX_JRNLFUND,       
00377     OFX_JRNLSEC,        
00378     OFX_MARGININTEREST, 
00379     OFX_REINVEST,       
00380     OFX_RETOFCAP,       
00381     OFX_SELLDEBT,       
00382     OFX_SELLMF,         
00383     OFX_SELLOPT,        
00384     OFX_SELLOTHER,      
00385     OFX_SELLSTOCK,      
00386     OFX_SPLIT,          
00387     OFX_TRANSFER        
00388   }  InvTransactionType;
00389 typedef enum {
00390     DELETE, 
00392     REPLACE 
00394   } FiIdCorrectionAction;
00395 
00402 struct OfxTransactionData{
00403   
00409   char account_id[OFX_ACCOUNT_ID_LENGTH];
00412   struct OfxAccountData * account_ptr; 
00414   int account_id_valid;
00415 
00416   TransactionType transactiontype;
00417   int transactiontype_valid;
00418  
00422   InvTransactionType invtransactiontype;
00423   int  invtransactiontype_valid;
00424 
00425   double units;     
00431   int units_valid;
00432   double unitprice; 
00434   int unitprice_valid;
00435   double amount;    
00439   int amount_valid;
00440   char fi_id[256];  
00443   int fi_id_valid;
00444   
00452   char unique_id[OFX_UNIQUE_ID_LENGTH];  
00453   int unique_id_valid;
00454   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00456   int unique_id_type_valid;
00457   struct OfxSecurityData *security_data_ptr;  
00458   int security_data_valid;
00459   
00460   time_t date_posted;
00465   int date_posted_valid;
00466   
00467   time_t date_initiated;
00473   int date_initiated_valid;
00474   time_t date_funds_available;
00477   int date_funds_available_valid;
00481   char fi_id_corrected[256];
00482   int fi_id_corrected_valid;
00485   FiIdCorrectionAction fi_id_correction_action;
00486   int fi_id_correction_action_valid;
00487   
00490   char server_transaction_id[OFX_SVRTID2_LENGTH];
00491   int server_transaction_id_valid;
00495 char check_number[OFX_CHECK_NUMBER_LENGTH];
00496   int check_number_valid;
00499   char reference_number[OFX_REFERENCE_NUMBER_LENGTH];
00500   int reference_number_valid;
00501   long int standard_industrial_code;
00503   int standard_industrial_code_valid;
00504   char payee_id[OFX_SVRTID2_LENGTH];
00505   int payee_id_valid;
00506   char name[OFX_TRANSACTION_NAME_LENGTH];
00508   int name_valid;
00509   char memo[OFX_MEMO2_LENGTH];
00510   int memo_valid;
00511   double commission;
00512   int commission_valid;
00513   double fees;
00514   int fees_valid;
00515   double oldunits;     /*number of units held before stock split */
00516   int oldunits_valid;
00517   double newunits;     /*number of units held after stock split */
00518   int newunits_valid;
00519 
00520 
00521   /*********** NOT YET COMPLETE!!! *********************/
00522 };
00523 
00532 CFCT typedef int (*LibofxProcTransactionCallback)(const struct OfxTransactionData data, void * transaction_data);
00533 
00542 struct OfxStatementData{
00543 
00551   char currency[OFX_CURRENCY_LENGTH]; 
00552   int currency_valid;
00553   char account_id[OFX_ACCOUNT_ID_LENGTH];
00555   struct OfxAccountData * account_ptr; 
00557   int account_id_valid;
00560   double ledger_balance;
00561   int ledger_balance_valid;
00562   time_t ledger_balance_date;
00563   int ledger_balance_date_valid;
00564   
00570   double available_balance; 
00573   int available_balance_valid;
00574   time_t available_balance_date;
00575   int available_balance_date_valid;
00580   time_t date_start;
00581   int date_start_valid;
00586   time_t date_end;
00587   int date_end_valid;
00590   char marketing_info[OFX_MARKETING_INFO_LENGTH];
00591   int marketing_info_valid;
00592 };
00593 
00601 CFCT typedef int (*LibofxProcStatementCallback)(const struct OfxStatementData data, void * statement_data);
00602 
00606 struct OfxCurrency{
00607   char currency[OFX_CURRENCY_LENGTH]; 
00608   double exchange_rate;  
00609   int must_convert;   
00610 };
00611 
00612 
00619 CFCT void ofx_set_status_cb(LibofxContextPtr ctx,
00620                             LibofxProcStatusCallback cb,
00621                             void *user_data);
00628 CFCT void ofx_set_account_cb(LibofxContextPtr ctx,
00629                              LibofxProcAccountCallback cb,
00630                              void *user_data);
00637 CFCT void ofx_set_security_cb(LibofxContextPtr ctx,
00638                               LibofxProcSecurityCallback cb,
00639                               void *user_data);
00646 CFCT void ofx_set_transaction_cb(LibofxContextPtr ctx,
00647                                  LibofxProcTransactionCallback cb,
00648                                  void *user_data);
00649 
00656 CFCT void ofx_set_statement_cb(LibofxContextPtr ctx,
00657                                LibofxProcStatementCallback cb,
00658                                void *user_data);
00659 
00660 
00664 CFCT int libofx_proc_buffer(LibofxContextPtr ctx,
00665                             const char *s, unsigned int size);
00666                             
00672 
00677 struct OfxFiServiceInfo{
00678   char fid[OFX_FID_LENGTH];
00679   char org[OFX_ORG_LENGTH];
00680   char url[OFX_URL_LENGTH];
00681   int accountlist; 
00682   int statements; 
00683   int billpay; 
00684   int investments; 
00685 };
00686 
00696 struct OfxFiLogin{
00697   char fid[OFX_FID_LENGTH];
00698   char org[OFX_ORG_LENGTH];
00699   char userid[OFX_USERID_LENGTH];
00700   char userpass[OFX_USERPASS_LENGTH];
00701 };
00702 
00703 typedef enum{
00704   OFX_NO_ACCOUNT=0,
00705   OFX_BANK_ACCOUNT,
00706   OFX_INVEST_ACCOUNT,
00707   OFX_CREDITCARD_ACCOUNT,
00708   OFX_INVALID_ACCOUNT
00709 } AccountType;
00710 
00719 struct OfxAccountInfo{
00720   char accountid[OFX_ACCOUNT_ID_LENGTH];
00721   char bankid[OFX_BANKID_LENGTH];
00722   char brokerid[OFX_BROKERID_LENGTH];
00723   AccountType type;
00724 };
00725 
00726 #define OFX_AMOUNT_LENGTH 32 + 1
00727 #define OFX_PAYACCT_LENGTH 32 + 1
00728 #define OFX_STATE_LENGTH 5 + 1
00729 #define OFX_POSTALCODE_LENGTH 11 + 1
00730 #define OFX_NAME_LENGTH 32 + 1
00731 
00732 struct OfxPayment{
00733   char amount[OFX_AMOUNT_LENGTH];
00734   char account[OFX_PAYACCT_LENGTH];
00735   char datedue[9];
00736   char memo[OFX_MEMO_LENGTH];
00737 };
00738 
00739 struct OfxPayee{
00740   char name[OFX_NAME_LENGTH];
00741   char address1[OFX_NAME_LENGTH];
00742   char city[OFX_NAME_LENGTH];
00743   char state[OFX_STATE_LENGTH];
00744   char postalcode[OFX_POSTALCODE_LENGTH];
00745   char phone[OFX_NAME_LENGTH];
00746 };
00747 
00760 CFCT char* libofx_request_statement( const struct OfxFiLogin* fi, const struct OfxAccountInfo* account, time_t date_from );
00761 
00773 CFCT char* libofx_request_accountinfo( const struct OfxFiLogin* login );
00774 
00775 CFCT char* libofx_request_payment( const struct OfxFiLogin* login, const struct OfxAccountInfo* account, const struct OfxPayee* payee, const struct OfxPayment* payment );
00776 
00777 CFCT char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid );
00778 
00780 
00781 #endif
00782 

Generated on Fri Aug 25 13:25:22 2006 for LibOFX by  doxygen 1.4.6