52bool post(
const char* request,
const char* url,
const char* filename)
54 CURL *curl = curl_easy_init();
59 FILE* file = fopen(filename,
"wb");
62 curl_easy_cleanup(curl);
66 curl_easy_setopt(curl, CURLOPT_URL, url);
67 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
69 struct curl_slist *headerlist = NULL;
70 headerlist = curl_slist_append(headerlist,
"Content-type: application/x-ofx");
71 headerlist = curl_slist_append(headerlist,
"Accept: */*, application/x-ofx");
73 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
74 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
75 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (
void *)file);
77 CURLcode res = curl_easy_perform(curl);
79 curl_easy_cleanup(curl);
80 curl_slist_free_all (headerlist);
87bool post(
const char*,
const char*,
const char*)
89 std::cerr <<
"ERROR: libox must be configured with libcurl to post this request directly" << std::endl;
94std::ostream& operator<<(std::ostream& os,
const std::vector<std::string>& strvect)
96 for ( std::vector<std::string>::const_iterator it = strvect.begin(); it != strvect.end(); ++it)
98 os << (*it) << std::endl;
103int main (
int argc,
char *argv[])
107 if (cmdline_parser (argc, argv, &args_info) != 0)
112 cmdline_parser_print_help();
120 std::cout <<
"file " << args_info.
inputs[0] << std::endl;
124 std::cerr <<
"ERROR: You must specify an output file" << std::endl;
132 std::cout <<
"bank " << args_info.
inputs[0] << std::endl;
136 std::cerr <<
"ERROR: You must specify an bank" << std::endl;
153 std::cerr <<
"fipid " << args_info.
fipid_arg << std::endl;
154 std::cerr <<
"contacting partner server..." << std::endl;
156 std::cout <<
"fid " << svcinfo.fid << std::endl;
157 strncpy(fi.fid, svcinfo.fid, OFX_FID_LENGTH - 1);
158 std::cout <<
"org " << svcinfo.org << std::endl;
159 strncpy(fi.org, svcinfo.org, OFX_ORG_LENGTH - 1);
160 std::cout <<
"url " << svcinfo.url << std::endl;
165 std::cerr <<
"fid " << args_info.
fid_arg << std::endl;
166 strncpy(fi.fid, args_info.
fid_arg, OFX_FID_LENGTH - 1);
170 std::cerr <<
"ERROR: --fid is required" << std::endl;
176 std::cerr <<
"org " << args_info.
org_arg << std::endl;
177 strncpy(fi.org, args_info.
org_arg, OFX_ORG_LENGTH - 1);
181 std::cerr <<
"ERROR: --org is required" << std::endl;
187 std::cerr <<
"user " << args_info.
user_arg << std::endl;
188 strncpy(fi.userid, args_info.
user_arg, OFX_USERID_LENGTH - 1);
192 std::cerr <<
"ERROR: --user is required" << std::endl;
198 std::cerr <<
"pass " << args_info.
pass_arg << std::endl;
199 strncpy(fi.userpass, args_info.
pass_arg, OFX_USERPASS_LENGTH - 1);
203 std::cerr <<
"ERROR: --pass is required" << std::endl;
213 std::cerr <<
"Statement request" << std::endl;
220 std::cerr <<
"bank " << args_info.
bank_arg << std::endl;
227 std::cerr <<
"ERROR: --bank is required for a bank request" << std::endl;
234 std::cerr <<
"broker " << args_info.
broker_arg << std::endl;
235 strncpy(account.broker_id, args_info.
broker_arg, OFX_BROKERID_LENGTH - 1);
241 std::cerr <<
"ERROR: --broker is required for an investment statement request" << std::endl;
248 std::cerr <<
"acct " << args_info.
acct_arg << std::endl;
253 std::cerr <<
"ERROR: --acct is required for a statement request" << std::endl;
259 std::cerr <<
"type " << args_info.
type_arg << std::endl;
272 std::cerr <<
"ERROR: --type is not valid. Must be between 1 and 3" << std::endl;
278 std::cerr <<
"ERROR: --type is required for a statement request" << std::endl;
284 std::cerr <<
"past " << args_info.
past_arg << std::endl;
288 std::cerr <<
"ERROR: --past is required for a statement request" << std::endl;
296 if ( url.length() && args_info.
inputs_num > 0 )
297 post(request, url.c_str(), args_info.
inputs[0]);
299 std::cout << request;
308 memset(tridstr, 0, 33);
310 bool is_trid_given =
true;
314 std::cerr <<
"trid " << args_info.
trid_arg << std::endl;
315 snprintf(tridstr, 32,
"%i", args_info.
trid_arg);
319 std::cerr <<
"ERROR: --trid is required for a payment inquiry request" << std::endl;
320 is_trid_given =
false;
325 char* request = libofx_request_payment_status( &fi, tridstr );
328 fb.open (
"query", std::ios::out);
329 std::ostream os(&fb);
333 if ( url.length() && args_info.
inputs_num > 0 )
334 post(request, url.c_str(), args_info.
inputs[0]);
336 std::cout << request;
347 memset(&payee, 0,
sizeof(
OfxPayee));
351 strcpy(payee.name,
"MARTIN PREUSS");
352 strcpy(payee.address1,
"1 LAUREL ST");
353 strcpy(payee.city,
"SAN CARLOS");
354 strcpy(payee.state,
"CA");
355 strcpy(payee.postalcode,
"94070");
356 strcpy(payee.phone,
"866-555-1212");
358 strcpy(payment.amount,
"200.00");
359 strcpy(payment.account,
"1234");
360 strcpy(payment.datedue,
"20060301");
361 strcpy(payment.memo,
"This is a test");
363 bool is_payment_args_given =
true;
367 std::cerr <<
"bank " << args_info.
bank_arg << std::endl;
374 std::cerr <<
"ERROR: --bank is required for a bank request" << std::endl;
375 is_payment_args_given =
false;
381 std::cerr <<
"broker " << args_info.
broker_arg << std::endl;
382 strncpy(account.broker_id, args_info.
broker_arg, OFX_BROKERID_LENGTH - 1);
388 std::cerr <<
"ERROR: --broker is required for an investment statement request" << std::endl;
389 is_payment_args_given =
false;
395 std::cerr <<
"acct " << args_info.
acct_arg << std::endl;
400 std::cerr <<
"ERROR: --acct is required for a statement request" << std::endl;
401 is_payment_args_given =
false;
406 std::cerr <<
"type " << args_info.
type_arg << std::endl;
419 std::cerr <<
"ERROR: --type is not valid. Must be between 1 and 3" << std::endl;
425 std::cerr <<
"ERROR: --type is required for a statement request" << std::endl;
426 is_payment_args_given =
false;
429 if ( is_payment_args_given )
431 char* request = libofx_request_payment( &fi, &account, &payee, &payment );
434 fb.open (
"query", std::ios::out);
435 std::ostream os(&fb);
439 if ( url.length() && args_info.
inputs_num > 0 )
440 post(request, url.c_str(), args_info.
inputs[0]);
442 std::cout << request;
455 if ( url.length() && args_info.
inputs_num > 0 )
456 post(request, url.c_str(), args_info.
inputs[0]);
458 std::cout << request;
466 std::cout << OfxPartner::BankNames();
471 std::cout << OfxPartner::FipidForBank(args_info.
inputs[0]);
477 std::cout <<
"Account List? " << (svcinfo.
accountlist ?
"Yes" :
"No") << std::endl;
478 std::cout <<
"Statements? " << (svcinfo.
statements ?
"Yes" :
"No") << std::endl;
479 std::cout <<
"Billpay? " << (svcinfo.
billpay ?
"Yes" :
"No") << std::endl;
480 std::cout <<
"Investments? " << (svcinfo.
investments ?
"Yes" :
"No") << std::endl;
485 std::vector<std::string> banks = OfxPartner::BankNames();
486 std::vector<std::string>::const_iterator it_bank = banks.begin();
487 while ( it_bank != banks.end() )
489 std::vector<std::string> fipids = OfxPartner::FipidForBank(*it_bank);
490 std::vector<std::string>::const_iterator it_fipid = fipids.begin();
491 while ( it_fipid != fipids.end() )
493 if ( OfxPartner::ServiceInfo(*it_fipid).accountlist )
494 std::cout << *it_bank << std::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...
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.