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   const char* name;          
00190   const 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 
00233 struct OfxAccountData{
00234   
00245   char account_id[OFX_ACCOUNT_ID_LENGTH];
00251   char account_name[OFX_ACCOUNT_NAME_LENGTH];
00252   int account_id_valid;/* Use for both account_id and account_name */
00253 
00255     enum AccountType{
00256     OFX_CHECKING,  
00257     OFX_SAVINGS,   
00258     OFX_MONEYMRKT, 
00259     OFX_CREDITLINE,
00260     OFX_CMA,       
00261     OFX_CREDITCARD,
00262     OFX_INVESTMENT 
00263   } account_type;
00264   int account_type_valid;
00265   char currency[OFX_CURRENCY_LENGTH]; 
00266   int currency_valid;
00267 
00269   char account_number[OFX_ACCTID_LENGTH];
00270   int account_number_valid;
00271 
00273   char bank_id[OFX_BANKID_LENGTH];
00274   int bank_id_valid;
00275 
00276   char broker_id[OFX_BROKERID_LENGTH];
00277   int broker_id_valid;
00278 
00279   char branch_id[OFX_BRANCHID_LENGTH];
00280   int branch_id_valid;
00281 
00282 };
00283 
00296 CFCT typedef int (*LibofxProcAccountCallback)(const struct OfxAccountData data, void * account_data);
00297 
00304 struct OfxSecurityData{
00310   char unique_id[OFX_UNIQUE_ID_LENGTH];   
00311   int unique_id_valid;
00312   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00314   int unique_id_type_valid;
00315   char secname[OFX_SECNAME_LENGTH];
00316   int secname_valid;
00317 
00323   char ticker[OFX_TICKER_LENGTH];
00324   int ticker_valid;
00325 
00326   double unitprice;
00328   int unitprice_valid;
00329 
00330   time_t date_unitprice;
00331   int date_unitprice_valid;
00332 
00333   char currency[OFX_CURRENCY_LENGTH]; 
00336   int currency_valid;
00337   char memo[OFX_MEMO2_LENGTH];
00338   int memo_valid;
00339 };/* end struct OfxSecurityData */
00340 
00352 CFCT typedef int (*LibofxProcSecurityCallback)(const struct OfxSecurityData data, void * security_data);
00353 
00354 typedef enum {
00355     OFX_CREDIT,     
00356     OFX_DEBIT,      
00357     OFX_INT,        
00358     OFX_DIV,        
00359     OFX_FEE,        
00360     OFX_SRVCHG,     
00361     OFX_DEP,        
00362     OFX_ATM,        
00363     OFX_POS,        
00364     OFX_XFER,       
00365     OFX_CHECK,      
00366     OFX_PAYMENT,    
00367     OFX_CASH,       
00368     OFX_DIRECTDEP,  
00369     OFX_DIRECTDEBIT,
00370     OFX_REPEATPMT,  
00371     OFX_OTHER       
00372   } TransactionType;
00373 
00374 typedef  enum{
00375     OFX_BUYDEBT,        
00376     OFX_BUYMF,          
00377     OFX_BUYOPT,         
00378     OFX_BUYOTHER,       
00379     OFX_BUYSTOCK,       
00380     OFX_CLOSUREOPT,     
00381     OFX_INCOME,         
00382     OFX_INVEXPENSE,     
00383     OFX_JRNLFUND,       
00384     OFX_JRNLSEC,        
00385     OFX_MARGININTEREST, 
00386     OFX_REINVEST,       
00387     OFX_RETOFCAP,       
00388     OFX_SELLDEBT,       
00389     OFX_SELLMF,         
00390     OFX_SELLOPT,        
00391     OFX_SELLOTHER,      
00392     OFX_SELLSTOCK,      
00393     OFX_SPLIT,          
00394     OFX_TRANSFER        
00395   }  InvTransactionType;
00396 typedef enum {
00397     DELETE, 
00399     REPLACE 
00401   } FiIdCorrectionAction;
00402 
00409 struct OfxTransactionData{
00410   
00416   char account_id[OFX_ACCOUNT_ID_LENGTH];
00419   struct OfxAccountData * account_ptr; 
00421   int account_id_valid;
00422 
00423   TransactionType transactiontype;
00424   int transactiontype_valid;
00425  
00429   InvTransactionType invtransactiontype;
00430   int  invtransactiontype_valid;
00431 
00432   double units;     
00438   int units_valid;
00439   double unitprice; 
00441   int unitprice_valid;
00442   double amount;    
00446   int amount_valid;
00447   char fi_id[256];  
00450   int fi_id_valid;
00451   
00459   char unique_id[OFX_UNIQUE_ID_LENGTH];  
00460   int unique_id_valid;
00461   char unique_id_type[OFX_UNIQUE_ID_TYPE_LENGTH];
00463   int unique_id_type_valid;
00464   struct OfxSecurityData *security_data_ptr;  
00465   int security_data_valid;
00466   
00467   time_t date_posted;
00472   int date_posted_valid;
00473   
00474   time_t date_initiated;
00480   int date_initiated_valid;
00481   time_t date_funds_available;
00484   int date_funds_available_valid;
00488   char fi_id_corrected[256];
00489   int fi_id_corrected_valid;
00492   FiIdCorrectionAction fi_id_correction_action;
00493   int fi_id_correction_action_valid;
00494   
00497   char server_transaction_id[OFX_SVRTID2_LENGTH];
00498   int server_transaction_id_valid;
00502 char check_number[OFX_CHECK_NUMBER_LENGTH];
00503   int check_number_valid;
00506   char reference_number[OFX_REFERENCE_NUMBER_LENGTH];
00507   int reference_number_valid;
00508   long int standard_industrial_code;
00510   int standard_industrial_code_valid;
00511   char payee_id[OFX_SVRTID2_LENGTH];
00512   int payee_id_valid;
00513   char name[OFX_TRANSACTION_NAME_LENGTH];
00515   int name_valid;
00516   char memo[OFX_MEMO2_LENGTH];
00517   int memo_valid;
00518   double commission;
00519   int commission_valid;
00520   double fees;
00521   int fees_valid;
00522   double oldunits;     /*number of units held before stock split */
00523   int oldunits_valid;
00524   double newunits;     /*number of units held after stock split */
00525   int newunits_valid;
00526 
00527 
00528   /*********** NOT YET COMPLETE!!! *********************/
00529 };
00530 
00539 CFCT typedef int (*LibofxProcTransactionCallback)(const struct OfxTransactionData data, void * transaction_data);
00540 
00549 struct OfxStatementData{
00550 
00558   char currency[OFX_CURRENCY_LENGTH]; 
00559   int currency_valid;
00560   char account_id[OFX_ACCOUNT_ID_LENGTH];
00562   struct OfxAccountData * account_ptr; 
00564   int account_id_valid;
00567   double ledger_balance;
00568   int ledger_balance_valid;
00569   time_t ledger_balance_date;
00570   int ledger_balance_date_valid;
00571   
00577   double available_balance; 
00580   int available_balance_valid;
00581   time_t available_balance_date;
00582   int available_balance_date_valid;
00587   time_t date_start;
00588   int date_start_valid;
00593   time_t date_end;
00594   int date_end_valid;
00597   char marketing_info[OFX_MARKETING_INFO_LENGTH];
00598   int marketing_info_valid;
00599 };
00600 
00608 CFCT typedef int (*LibofxProcStatementCallback)(const struct OfxStatementData data, void * statement_data);
00609 
00613 struct OfxCurrency{
00614   char currency[OFX_CURRENCY_LENGTH]; 
00615   double exchange_rate;  
00616   int must_convert;   
00617 };
00618 
00619 
00626 CFCT void ofx_set_status_cb(LibofxContextPtr ctx,
00627                             LibofxProcStatusCallback cb,
00628                             void *user_data);
00635 CFCT void ofx_set_account_cb(LibofxContextPtr ctx,
00636                              LibofxProcAccountCallback cb,
00637                              void *user_data);
00644 CFCT void ofx_set_security_cb(LibofxContextPtr ctx,
00645                               LibofxProcSecurityCallback cb,
00646                               void *user_data);
00653 CFCT void ofx_set_transaction_cb(LibofxContextPtr ctx,
00654                                  LibofxProcTransactionCallback cb,
00655                                  void *user_data);
00656 
00663 CFCT void ofx_set_statement_cb(LibofxContextPtr ctx,
00664                                LibofxProcStatementCallback cb,
00665                                void *user_data);
00666 
00667 
00671 CFCT int libofx_proc_buffer(LibofxContextPtr ctx,
00672                             const char *s, unsigned int size);
00673                             
00679 
00684 struct OfxFiServiceInfo{
00685   char fid[OFX_FID_LENGTH];
00686   char org[OFX_ORG_LENGTH];
00687   char url[OFX_URL_LENGTH];
00688   int accountlist; 
00689   int statements; 
00690   int billpay; 
00691   int investments; 
00692 };
00693 
00703 struct OfxFiLogin{
00704   char fid[OFX_FID_LENGTH];
00705   char org[OFX_ORG_LENGTH];
00706   char userid[OFX_USERID_LENGTH];
00707   char userpass[OFX_USERPASS_LENGTH];
00708 };
00709 
00710 #define OFX_AMOUNT_LENGTH 32 + 1
00711 #define OFX_PAYACCT_LENGTH 32 + 1
00712 #define OFX_STATE_LENGTH 5 + 1
00713 #define OFX_POSTALCODE_LENGTH 11 + 1
00714 #define OFX_NAME_LENGTH 32 + 1
00715 
00716 struct OfxPayment{
00717   char amount[OFX_AMOUNT_LENGTH];
00718   char account[OFX_PAYACCT_LENGTH];
00719   char datedue[9];
00720   char memo[OFX_MEMO_LENGTH];
00721 };
00722 
00723 struct OfxPayee{
00724   char name[OFX_NAME_LENGTH];
00725   char address1[OFX_NAME_LENGTH];
00726   char city[OFX_NAME_LENGTH];
00727   char state[OFX_STATE_LENGTH];
00728   char postalcode[OFX_POSTALCODE_LENGTH];
00729   char phone[OFX_NAME_LENGTH];
00730 };
00731 
00744 CFCT char* libofx_request_statement( const struct OfxFiLogin* fi, const struct OfxAccountData* account, time_t date_from );
00745 
00757 CFCT char* libofx_request_accountinfo( const struct OfxFiLogin* login );
00758 
00759 CFCT char* libofx_request_payment( const struct OfxFiLogin* login, const struct OfxAccountData* account, const struct OfxPayee* payee, const struct OfxPayment* payment );
00760 
00761 CFCT char* libofx_request_payment_status( const struct OfxFiLogin* login, const char* transactionid );
00762 
00764 
00765 #endif
00766 

Generated on Mon Nov 19 20:27:58 2007 for LibOFX by  doxygen 1.5.3