54bool post(
const char* request,
const char* url,
const char* filename)
56 CURL *curl = curl_easy_init();
61 FILE* file = fopen(filename,
"wb");
64 curl_easy_cleanup(curl);
68 curl_easy_setopt(curl, CURLOPT_URL, url);
69 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
71 struct curl_slist *headerlist = NULL;
72 headerlist = curl_slist_append(headerlist,
"Content-type: application/x-ofx");
73 headerlist = curl_slist_append(headerlist,
"Accept: */*, application/x-ofx");
75 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
76 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
77 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (
void *)file);
79 CURLcode res = curl_easy_perform(curl);
81 curl_easy_cleanup(curl);
82 curl_slist_free_all (headerlist);
89bool post(
const char*,
const char*,
const char*)
91 cerr <<
"ERROR: libox must be configured with libcurl to post this request directly" << endl;
96ostream&
operator<<(ostream& os,
const vector<string>& strvect)
98 for ( vector<string>::const_iterator it = strvect.begin(); it != strvect.end(); ++it)
105int main (
int argc,
char *argv[])
109 if (cmdline_parser (argc, argv, &args_info) != 0)
114 cmdline_parser_print_help();
122 cout <<
"file " << args_info.
inputs[0] << endl;
126 cerr <<
"ERROR: You must specify an output file" << endl;
134 cout <<
"bank " << args_info.
inputs[0] << endl;
138 cerr <<
"ERROR: You must specify an bank" << endl;
155 cerr <<
"fipid " << args_info.
fipid_arg << endl;
156 cerr <<
"contacting partner server..." << endl;
158 cout <<
"fid " << svcinfo.fid << endl;
159 strncpy(fi.fid, svcinfo.fid, OFX_FID_LENGTH - 1);
160 cout <<
"org " << svcinfo.org << endl;
161 strncpy(fi.org, svcinfo.org, OFX_ORG_LENGTH - 1);
162 cout <<
"url " << svcinfo.url << endl;
167 cerr <<
"fid " << args_info.
fid_arg << endl;
168 strncpy(fi.fid, args_info.
fid_arg, OFX_FID_LENGTH - 1);
172 cerr <<
"ERROR: --fid is required" << endl;
178 cerr <<
"org " << args_info.
org_arg << endl;
179 strncpy(fi.org, args_info.
org_arg, OFX_ORG_LENGTH - 1);
183 cerr <<
"ERROR: --org is required" << endl;
189 cerr <<
"user " << args_info.
user_arg << endl;
190 strncpy(fi.userid, args_info.
user_arg, OFX_USERID_LENGTH - 1);
194 cerr <<
"ERROR: --user is required" << endl;
200 cerr <<
"pass " << args_info.
pass_arg << endl;
201 strncpy(fi.userpass, args_info.
pass_arg, OFX_USERPASS_LENGTH - 1);
205 cerr <<
"ERROR: --pass is required" << endl;
215 cerr <<
"Statement request" << endl;
222 cerr <<
"bank " << args_info.
bank_arg << endl;
229 cerr <<
"ERROR: --bank is required for a bank request" << endl;
236 cerr <<
"broker " << args_info.
broker_arg << endl;
237 strncpy(account.broker_id, args_info.
broker_arg, OFX_BROKERID_LENGTH - 1);
243 cerr <<
"ERROR: --broker is required for an investment statement request" << endl;
250 cerr <<
"acct " << args_info.
acct_arg << endl;
255 cerr <<
"ERROR: --acct is required for a statement request" << endl;
261 cerr <<
"type " << args_info.
type_arg << endl;
274 cerr <<
"ERROR: --type is not valid. Must be between 1 and 3" << endl;
280 cerr <<
"ERROR: --type is required for a statement request" << endl;
286 cerr <<
"past " << args_info.
past_arg << endl;
290 cerr <<
"ERROR: --past is required for a statement request" << endl;
298 if ( url.length() && args_info.
inputs_num > 0 )
299 post(request, url.c_str(), args_info.
inputs[0]);
310 memset(tridstr, 0, 33);
316 cerr <<
"trid " << args_info.
trid_arg << endl;
317 snprintf(tridstr, 32,
"%i", args_info.
trid_arg);
321 cerr <<
"ERROR: --trid is required for a payment inquiry request" << endl;
327 char* request = libofx_request_payment_status( &fi, tridstr );
330 fb.open (
"query", ios::out);
335 if ( url.length() && args_info.
inputs_num > 0 )
336 post(request, url.c_str(), args_info.
inputs[0]);
349 memset(&payee, 0,
sizeof(
OfxPayee));
353 strcpy(payee.name,
"MARTIN PREUSS");
354 strcpy(payee.address1,
"1 LAUREL ST");
355 strcpy(payee.city,
"SAN CARLOS");
356 strcpy(payee.state,
"CA");
357 strcpy(payee.postalcode,
"94070");
358 strcpy(payee.phone,
"866-555-1212");
360 strcpy(payment.amount,
"200.00");
361 strcpy(payment.account,
"1234");
362 strcpy(payment.datedue,
"20060301");
363 strcpy(payment.memo,
"This is a test");
369 cerr <<
"bank " << args_info.
bank_arg << endl;
376 cerr <<
"ERROR: --bank is required for a bank request" << endl;
383 cerr <<
"broker " << args_info.
broker_arg << endl;
384 strncpy(account.broker_id, args_info.
broker_arg, OFX_BROKERID_LENGTH - 1);
390 cerr <<
"ERROR: --broker is required for an investment statement request" << endl;
397 cerr <<
"acct " << args_info.
acct_arg << endl;
402 cerr <<
"ERROR: --acct is required for a statement request" << endl;
408 cerr <<
"type " << args_info.
type_arg << endl;
421 cerr <<
"ERROR: --type is not valid. Must be between 1 and 3" << endl;
427 cerr <<
"ERROR: --type is required for a statement request" << endl;
433 char* request = libofx_request_payment( &fi, &account, &payee, &payment );
436 fb.open (
"query", ios::out);
441 if ( url.length() && args_info.
inputs_num > 0 )
442 post(request, url.c_str(), args_info.
inputs[0]);
457 if ( url.length() && args_info.
inputs_num > 0 )
458 post(request, url.c_str(), args_info.
inputs[0]);
468 cout << OfxPartner::BankNames();
473 cout << OfxPartner::FipidForBank(args_info.
inputs[0]);
479 cout <<
"Account List? " << (svcinfo.
accountlist ?
"Yes" :
"No") << endl;
480 cout <<
"Statements? " << (svcinfo.
statements ?
"Yes" :
"No") << endl;
481 cout <<
"Billpay? " << (svcinfo.
billpay ?
"Yes" :
"No") << endl;
482 cout <<
"Investments? " << (svcinfo.
investments ?
"Yes" :
"No") << endl;
487 vector<string> banks = OfxPartner::BankNames();
488 vector<string>::const_iterator it_bank = banks.begin();
489 while ( it_bank != banks.end() )
491 vector<string> fipids = OfxPartner::FipidForBank(*it_bank);
492 vector<string>::const_iterator it_fipid = fipids.begin();
493 while ( it_fipid != fipids.end() )
495 if ( OfxPartner::ServiceInfo(*it_fipid).accountlist )
496 cout << *it_bank << endl;
Main header file containing the LibOfx API.
char * libofx_request_accountinfo(const struct OfxFiLogin *login)
Creates an OFX account info (list) request in string form.
char * libofx_request_statement(const struct OfxFiLogin *fi, const struct OfxAccountData *account, time_t date_from)
Creates an OFX statement request in string form.
Declaration of nodeparser object, which facilitates searching for nodes in an XML file using a notati...
ostream & operator<<(ostream &os, SGMLApplication::CharString s)
Convert OpenSP CharString to a C++ stream.
The header file for the command line option parser generated by GNU Gengetopt version 2....
Methods for connecting to the OFX partner server to retrieve OFX server information.
An abstraction of an account.
char bank_id[OFX_BANKID_LENGTH]
char account_number[OFX_ACCTID_LENGTH]
Information sufficient to log into an financial institution.
Information returned by the OFX Partner Server about a financial institution.
Where the command line options are stored.
unsigned int fid_given
Whether fid was given.
unsigned int paymentinquiry_req_given
Whether paymentinquiry-req was given.
unsigned int type_given
Whether type was given.
int type_arg
Account Type 1=checking 2=invest 3=ccard.
char * user_arg
User name.
unsigned inputs_num
unnamed options number
char * bank_arg
IBAN bank identifier.
unsigned int statement_req_given
Whether statement-req was given.
char ** inputs
unnamed options (options without names)
unsigned int user_given
Whether user was given.
char * fid_arg
FI identifier.
unsigned int allsupport_given
Whether allsupport was given.
unsigned int acct_given
Whether acct was given.
unsigned int bank_fipid_given
Whether bank-fipid was given.
unsigned int accountinfo_req_given
Whether accountinfo-req was given.
int trid_arg
Transaction id.
char * acct_arg
Account ID.
char * fipid_arg
FI partner identifier (looks up fid, org & url from partner server).
long past_arg
How far back to look from today (in days).
unsigned int broker_given
Whether broker was given.
unsigned int bank_list_given
Whether bank-list was given.
char * org_arg
FI org tag.
char * broker_arg
Broker identifier.
unsigned int bank_services_given
Whether bank-services was given.
unsigned int bank_given
Whether bank was given.
unsigned int org_given
Whether org was given.
unsigned int url_given
Whether url was given.
unsigned int fipid_given
Whether fipid was given.
char * url_arg
Url to POST the data to (otherwise goes to stdout).
unsigned int past_given
Whether past was given.
unsigned int pass_given
Whether pass was given.
unsigned int payment_req_given
Whether payment-req was given.
unsigned int trid_given
Whether trid was given.