--- libofx-0.6.6/inc/libofx.h 2003-01-09 19:13:13.000000000 -0500 +++ libofx-devl/inc/libofx.h 2004-01-18 19:37:43.000000000 -0500 @@ -69,6 +69,14 @@ #define OFX_SECNAME_LENGTH 32 + 1 #define OFX_TICKER_LENGTH 32 + 1 +/* +#define OFX_STATEMENT_CB 0; +#define OFX_ACCOUNT_CB 1; +#define OFX_TRACSACTION_CB 2; +#define OFX_SECURITY_CB 3; +#define OFX_STATUS_CB 4; +*/ + CFCT void (*OfxCallbackFunc) (); @@ -135,9 +143,10 @@ * * An ofx_proc_status_cb event is sent everytime the server has generated a OFX STATUS element. As such, it could be received at any time(but not during - other events). An OfxStatusData structure is passed to this even. + other events). An OfxStatusData structure is passed to this event, as well as + a pointer to an arbitrary data structure. */ -CFCT int ofx_proc_status_cb(const struct OfxStatusData data); +CFCT int ofx_proc_status_cb(const struct OfxStatusData data, void * status_data); /** * \brief An abstraction of an account @@ -191,9 +200,10 @@ received. An OfxAccountData is passed to this event. * Note however that this OfxAccountData structure will also be available as - part of OfxStatementData structure passed to ofx_proc_statement event. + part of OfxStatementData structure passed to ofx_proc_statement event, + as well as a pointer to an arbitrary data structure. */ -CFCT int ofx_proc_account_cb(const struct OfxAccountData data); +CFCT int ofx_proc_account_cb(const struct OfxAccountData data, void * account_data); /** * \brief An abstraction of a security, such as a stock, mutual fund, etc. @@ -246,9 +256,10 @@ ofx_proc_transaction. It is meant to be used to allow the client to create a new commodity or security (such as a new stock type). Please note however that this information is usually also available as part of each OfxtransactionData. - An OfxSecurityData structure is passed to this event. + An OfxSecurityData structure is passed to this event, as well as + a pointer to an arbitrary data structure. */ -CFCT int ofx_proc_security_cb(const struct OfxSecurityData data); +CFCT int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_data); /** @@ -419,9 +430,10 @@ * * An ofx_proc_transaction_cb event is generated for every transaction in the ofx response, after ofx_proc_statement (and possibly ofx_proc_security is - generated. An OfxTransactionData structure is passed to this event. + generated. An OfxTransactionData structure is passed to this event, as well as + a pointer to an arbitrary data structure. */ -CFCT int ofx_proc_transaction_cb(const struct OfxTransactionData data); +CFCT int ofx_proc_transaction_cb(const struct OfxTransactionData data, void * transaction_data); /** * \brief An abstraction of an account statement. @@ -487,9 +499,10 @@ * \brief The callback function for the OfxStatementData stucture. * * The ofx_proc_statement_cb event is sent after all ofx_proc_transaction - events have been sent. An OfxStatementData is passed to this event. + events have been sent. An OfxStatementData is passed to this event, as well as + a pointer to an arbitrary data structure. */ -CFCT int ofx_proc_statement_cb(const struct OfxStatementData data); +CFCT int ofx_proc_statement_cb(const struct OfxStatementData data, void * statement_data); /** \brief NOT YET SUPPORTED @@ -500,5 +513,37 @@ int must_convert; /**< true or false */ }; + +struct OfxCallbackRegistry{ + void * statement_data; + int (*ofx_statement_cb)( const struct OfxStatementData data, void *); + void * account_data; + int (*ofx_account_cb)( const struct OfxAccountData data, void *); + void * transaction_data; + int (*ofx_transaction_cb)( const struct OfxTransactionData data, void *); + void * security_data; + int (*ofx_security_cb)( const struct OfxSecurityData data, void *); + void * status_data; + int (*ofx_status_cb)(const struct OfxStatusData data, void *); +}; + +/** + * \brief ofx_prep_cb registers the callbacks to be signaled during processing + * + * Each function will be called with the preceding void * structure as its + * first argument. +*/ +CFCT void ofx_prep_cb( + void *, + int (*ofx_statement_cb)(const struct OfxStatementData data, void *), + void *, + int (*ofx_account_cb)(const struct OfxAccountData data, void *), + void *, + int (*ofx_transaction_cb)(const struct OfxTransactionData data, void *), + void *, + int (*ofx_security_cb)(const struct OfxSecurityData data, void * ), + void *, + int (*ofx_status_cb)(const struct OfxStatusData data, void *) + ); #endif --- libofx-0.6.6/lib/ofx_container_account.cpp 2002-10-15 15:41:05.000000000 -0400 +++ libofx-devl/lib/ofx_container_account.cpp 2004-01-18 19:31:44.000000000 -0500 @@ -28,6 +28,7 @@ #include "ofx_utilities.hh" extern OfxMainContainer * MainContainer; +extern OfxCallbackRegistry cb_registry; /*************************************************************************** * OfxAccountContainer * @@ -118,7 +119,8 @@ int OfxAccountContainer::gen_event() { - ofx_proc_account_cb(data); + cb_registry.ofx_account_cb( data, cb_registry.account_data ); + //ofx_proc_account_cb(data); return true; } --- libofx-0.6.6/lib/ofx_container_security.cpp 2002-10-11 10:58:45.000000000 -0400 +++ libofx-devl/lib/ofx_container_security.cpp 2004-01-18 19:31:44.000000000 -0500 @@ -28,7 +28,7 @@ #include "ofx_utilities.hh" extern OfxMainContainer * MainContainer; - +extern OfxCallbackRegistry cb_registry; /*************************************************************************** * OfxSecurityContainer * @@ -84,7 +84,8 @@ } int OfxSecurityContainer::gen_event() { - ofx_proc_security_cb(data); + cb_registry.ofx_security_cb( data, cb_registry.security_data ); + //ofx_proc_security_cb(data); return true; } --- libofx-0.6.6/lib/ofx_container_statement.cpp 2002-10-15 17:39:39.000000000 -0400 +++ libofx-devl/lib/ofx_container_statement.cpp 2004-01-18 19:34:18.000000000 -0500 @@ -28,6 +28,7 @@ #include "ofx_utilities.hh" extern OfxMainContainer * MainContainer; +extern OfxCallbackRegistry cb_registry; /*************************************************************************** * OfxStatementContainer * @@ -100,7 +101,8 @@ int OfxStatementContainer::gen_event() { - ofx_proc_statement_cb(data); + cb_registry.ofx_statement_cb( data, cb_registry.statement_data ); + //ofx_proc_statement_cb(data); return true; } --- libofx-0.6.6/lib/ofx_container_transaction.cpp 2003-12-06 13:29:42.000000000 -0500 +++ libofx-devl/lib/ofx_container_transaction.cpp 2004-01-18 19:31:44.000000000 -0500 @@ -28,6 +28,7 @@ #include "ofx_utilities.hh" extern OfxMainContainer * MainContainer; +extern OfxCallbackRegistry cb_registry; /*************************************************************************** * OfxTransactionContainer * @@ -72,7 +73,8 @@ data.security_data_valid = true; } } - ofx_proc_transaction_cb(data); + cb_registry.ofx_transaction_cb( data, cb_registry.transaction_data ); + //ofx_proc_transaction_cb(data); return true; } --- libofx-0.6.6/lib/ofx_containers_misc.cpp 2002-10-15 13:17:43.000000000 -0400 +++ libofx-devl/lib/ofx_containers_misc.cpp 2004-01-18 19:31:44.000000000 -0500 @@ -33,6 +33,7 @@ #include "ofx_containers.hh" extern OfxMainContainer * MainContainer; +extern OfxCallbackRegistry cb_registry; /*************************************************************************** * OfxDummyContainer * @@ -82,7 +83,8 @@ } OfxStatusContainer::~OfxStatusContainer() { - ofx_proc_status_cb (data); + cb_registry.ofx_status_cb( data, cb_registry.status_data ); + //ofx_proc_status_cb (data); } void OfxStatusContainer::add_attribute(const string identifier, const string value) { --- libofx-0.6.6/lib/ofx_preproc.cpp 2004-01-14 12:57:24.000000000 -0500 +++ libofx-devl/lib/ofx_preproc.cpp 2004-01-18 19:33:44.000000000 -0500 @@ -31,6 +31,37 @@ using namespace std; const unsigned int READ_BUFFER_SIZE = 1024; +/** + * Instance of the callback registry + */ +struct OfxCallbackRegistry cb_registry; + +void ofx_prep_cb( + void * statementdata, + int (*ofx_statement)( const struct OfxStatementData, void *), + void * accountdata, + int (*ofx_account)(const struct OfxAccountData, void *), + void * transactiondata, + int (*ofx_transaction)(const struct OfxTransactionData, void *), + void * securitydata, + int (*ofx_security)(const struct OfxSecurityData, void *), + void * statusdata, + int (*ofx_status)(const struct OfxStatusData, void *) ) +{ + /* assign callbacks...these can be overridden in client code*/ + + cb_registry.statement_data=statementdata; + cb_registry.ofx_statement_cb=ofx_statement; + cb_registry.transaction_data=transactiondata; + cb_registry.ofx_transaction_cb=ofx_transaction; + cb_registry.security_data=securitydata; + cb_registry.ofx_security_cb=ofx_security; + cb_registry.account_data=accountdata; + cb_registry.ofx_account_cb=ofx_account; + cb_registry.status_data=statusdata; + cb_registry.ofx_status_cb=ofx_status; +}; + int ofx_proc_file(int argc, char *argv[]) { bool ofx_start=false; @@ -64,59 +95,59 @@ } else { - do{ - input_file.getline(buffer, sizeof(buffer),'\n'); - //cout<"))!=string::npos||(ofx_start_idx=s_buffer.find(""))!=string::npos)){ - ofx_start=true; - s_buffer.erase(0,ofx_start_idx);//Fix for really broken files that don't have a newline after the header. - message_out(DEBUG,"ofx_proc_file(): has been found"); + else if( !input_file.eof()&&input_file.fail()) + { + input_file.clear(); + } + int ofx_start_idx; + if(ofx_start==false&&((ofx_start_idx=s_buffer.find(""))!=string::npos||(ofx_start_idx=s_buffer.find(""))!=string::npos)){ + ofx_start=true; + s_buffer.erase(0,ofx_start_idx);//Fix for really broken files that don't have a newline after the header. + message_out(DEBUG,"ofx_proc_file(): has been found"); + } + + if(ofx_start==true&&ofx_end==false){ + s_buffer=sanitize_proprietary_tags(s_buffer); + //cout<< s_buffer<<"\n"; + tmp_file.write(s_buffer.c_str(), s_buffer.length()); } - - if(ofx_start==true&&ofx_end==false){ - s_buffer=sanitize_proprietary_tags(s_buffer); - //cout<< s_buffer<<"\n"; - tmp_file.write(s_buffer.c_str(), s_buffer.length()); - } - - if(ofx_start==true&&(s_buffer.find("")!=string::npos||s_buffer.find("")!=string::npos)){ - ofx_end=true; - message_out(DEBUG,"ofx_proc_file(): has been found"); - } - + + if(ofx_start==true&&(s_buffer.find("")!=string::npos||s_buffer.find("")!=string::npos)){ + ofx_end=true; + message_out(DEBUG,"ofx_proc_file(): has been found"); + } + }while(!input_file.eof()&&!input_file.bad()); } input_file.close(); tmp_file.close(); - + strncpy(filename_openspdtd,find_dtd(OPENSPDCL_FILENAME).c_str(),255);//The opensp sgml dtd file strncpy(filename_ofxdtd,find_dtd(OFX160DTD_FILENAME).c_str(),255);//The ofx dtd file if((string)filename_ofxdtd!="" && (string)filename_openspdtd!="") { - strncpy(filename_ofx,tmp_filename,255);//The processed ofx file - filenames[0]=filename_openspdtd; - filenames[1]=filename_ofxdtd; - filenames[2]=filename_ofx; - ofx_proc_sgml(3,filenames); - if(remove(tmp_filename)!=0) - { - message_out(ERROR,"ofx_proc_file(): Error deleting temporary file "+string(tmp_filename)); - } + strncpy(filename_ofx,tmp_filename,255);//The processed ofx file + filenames[0]=filename_openspdtd; + filenames[1]=filename_ofxdtd; + filenames[2]=filename_ofx; + ofx_proc_sgml(3,filenames); + if(remove(tmp_filename)!=0) + { + message_out(ERROR,"ofx_proc_file(): Error deleting temporary file "+string(tmp_filename)); + } } else { - message_out(ERROR,"ofx_proc_file(): FATAL: Missing DTD, aborting"); + message_out(ERROR,"ofx_proc_file(): FATAL: Missing DTD, aborting"); } } else{ --- libofx-0.6.6/ofxdump/ofxdump.cpp 2004-01-14 15:47:52.000000000 -0500 +++ libofx-devl/ofxdump/ofxdump.cpp 2004-01-20 18:17:03.000000000 -0500 @@ -37,7 +37,6 @@ using namespace std; - int main (int argc, char *argv[]) { /** Tell ofxdump what you want it to send to stderr. See messages.cpp for more details */ @@ -66,7 +65,16 @@ //printf("argv[%d] = %s\n", count, argv[count]); } if (0 == special_options(argv)) ; - else ofx_proc_file(argc, argv); /* Special option not found */ + else{ + ofx_prep_cb( + NULL, ofx_proc_statement_cb, NULL, + ofx_proc_account_cb, NULL, + ofx_proc_transaction_cb, NULL, + ofx_proc_security_cb, NULL, + ofx_proc_status_cb + ); + ofx_proc_file(argc, argv); /* Special option not found */ + } } else { @@ -132,7 +140,7 @@ -int ofx_proc_status_cb(struct OfxStatusData data) +int ofx_proc_status_cb(struct OfxStatusData data, void * status_data) { cout<<"ofx_proc_status():\n"; if(data.ofx_element_name_valid==true){ @@ -160,7 +168,7 @@ return 0; } -int ofx_proc_security_cb(struct OfxSecurityData data) +int ofx_proc_security_cb(struct OfxSecurityData data, void * security_data) { char dest_string[255]; cout<<"ofx_proc_security():\n"; @@ -193,7 +201,7 @@ return 0; } -int ofx_proc_transaction_cb(struct OfxTransactionData data) +int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_data) { char dest_string[255]; cout<<"ofx_proc_transaction():\n"; @@ -335,7 +343,7 @@ } if(data.security_data_valid==true){ cout<<" Security data is available:\n START security_data content----------\n"; - ofx_proc_security_cb(*(data.security_data_ptr)); + ofx_proc_security_cb(*(data.security_data_ptr), NULL ); cout<<" END security_data content----------\n"; } @@ -365,7 +373,7 @@ return 0; }//end ofx_proc_transaction() -int ofx_proc_statement_cb(struct OfxStatementData data) +int ofx_proc_statement_cb(struct OfxStatementData data, void * statement_data) { char dest_string[255]; cout<<"ofx_proc_statement():\n"; @@ -404,14 +412,14 @@ return 0; }//end ofx_proc_statement() -int ofx_proc_account_cb(struct OfxAccountData data) +int ofx_proc_account_cb(struct OfxAccountData data, void * account_data) { cout<<"ofx_proc_account():\n"; if(data.account_id_valid==true){ cout<<" Account ID: "<