51bool post(
const char* request,
const char* url,
const char* filename)
53 CURL *curl = curl_easy_init();
58 FILE* file = fopen(filename,
"wb");
61 curl_easy_cleanup(curl);
65 curl_easy_setopt(curl, CURLOPT_URL, url);
66 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
68 struct curl_slist *headerlist = NULL;
69 headerlist = curl_slist_append(headerlist,
"Content-type: application/x-ofx");
70 headerlist = curl_slist_append(headerlist,
"Accept: */*, application/x-ofx");
72 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
73 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
74 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (
void *)file);
76 CURLcode res = curl_easy_perform(curl);
78 curl_easy_cleanup(curl);
79 curl_slist_free_all (headerlist);
86bool post(
const char*,
const char*,
const char*)
88 std::cerr <<
"ERROR: libox must be configured with libcurl to post this request directly" << std::endl;
93std::ostream& operator<<(std::ostream& os,
const std::vector<std::string>& strvect)
95 for ( std::vector<std::string>::const_iterator it = strvect.begin(); it != strvect.end(); ++it)
97 os << (*it) << std::endl;
102int main (
int argc,
char *argv[])
106 if (cmdline_parser (argc, argv, &args_info) != 0)
119 std::cout <<
"file " << args_info.
inputs[0] << std::endl;
123 std::cerr <<
"ERROR: You must specify an output file" << std::endl;
129 memset(&fi, 0,
sizeof(OfxFiLogin));
140 std::cerr <<
"fid " << args_info.
fid_arg << std::endl;
141 strncpy(fi.fid, args_info.
fid_arg, OFX_FID_LENGTH - 1);
145 std::cerr <<
"ERROR: --fid is required" << std::endl;
151 std::cerr <<
"org " << args_info.
org_arg << std::endl;
152 strncpy(fi.org, args_info.
org_arg, OFX_ORG_LENGTH - 1);
156 std::cerr <<
"ERROR: --org is required" << std::endl;
162 std::cerr <<
"user " << args_info.
user_arg << std::endl;
163 strncpy(fi.userid, args_info.
user_arg, OFX_USERID_LENGTH - 1);
167 std::cerr <<
"ERROR: --user is required" << std::endl;
173 std::cerr <<
"pass " << args_info.
pass_arg << std::endl;
174 strncpy(fi.userpass, args_info.
pass_arg, OFX_USERPASS_LENGTH - 1);
178 std::cerr <<
"ERROR: --pass is required" << std::endl;
188 std::cerr <<
"Statement request" << std::endl;
190 OfxAccountData account;
191 memset(&account, 0,
sizeof(OfxAccountData));
195 std::cerr <<
"bank " << args_info.
bank_arg << std::endl;
196 strncpy(account.bank_id, args_info.
bank_arg, OFX_BANKID_LENGTH - 1);
202 std::cerr <<
"ERROR: --bank is required for a bank request" << std::endl;
209 std::cerr <<
"broker " << args_info.
broker_arg << std::endl;
210 strncpy(account.broker_id, args_info.
broker_arg, OFX_BROKERID_LENGTH - 1);
216 std::cerr <<
"ERROR: --broker is required for an investment statement request" << std::endl;
223 std::cerr <<
"acct " << args_info.
acct_arg << std::endl;
224 strncpy(account.account_number, args_info.
acct_arg, OFX_ACCTID_LENGTH - 1);
228 std::cerr <<
"ERROR: --acct is required for a statement request" << std::endl;
234 std::cerr <<
"type " << args_info.
type_arg << std::endl;
238 account.account_type = account.OFX_CHECKING;
241 account.account_type = account.OFX_INVESTMENT;
244 account.account_type = account.OFX_CREDITCARD ;
247 std::cerr <<
"ERROR: --type is not valid. Must be between 1 and 3" << std::endl;
253 std::cerr <<
"ERROR: --type is required for a statement request" << std::endl;
259 std::cerr <<
"past " << args_info.
past_arg << std::endl;
263 std::cerr <<
"ERROR: --past is required for a statement request" << std::endl;
269 char* request = libofx_request_statement( &fi, &account, time(NULL) - args_info.
past_arg * 86400L );
271 if ( url.length() && args_info.
inputs_num > 0 )
272 post(request, url.c_str(), args_info.
inputs[0]);
274 std::cout << request;
283 memset(tridstr, 0, 33);
285 bool is_trid_given =
true;
289 std::cerr <<
"trid " << args_info.
trid_arg << std::endl;
290 snprintf(tridstr, 32,
"%i", args_info.
trid_arg);
294 std::cerr <<
"ERROR: --trid is required for a payment inquiry request" << std::endl;
295 is_trid_given =
false;
300 char* request = libofx_request_payment_status( &fi, tridstr );
303 fb.open (
"query", std::ios::out);
304 std::ostream os(&fb);
308 if ( url.length() && args_info.
inputs_num > 0 )
309 post(request, url.c_str(), args_info.
inputs[0]);
311 std::cout << request;
319 OfxAccountData account;
320 memset(&account, 0,
sizeof(OfxAccountData));
322 memset(&payee, 0,
sizeof(OfxPayee));
324 memset(&payment, 0,
sizeof(OfxPayment));
326 strcpy(payee.name,
"MARTIN PREUSS");
327 strcpy(payee.address1,
"1 LAUREL ST");
328 strcpy(payee.city,
"SAN CARLOS");
329 strcpy(payee.state,
"CA");
330 strcpy(payee.postalcode,
"94070");
331 strcpy(payee.phone,
"866-555-1212");
333 strcpy(payment.amount,
"200.00");
334 strcpy(payment.account,
"1234");
335 strcpy(payment.datedue,
"20060301");
336 strcpy(payment.memo,
"This is a test");
338 bool is_payment_args_given =
true;
342 std::cerr <<
"bank " << args_info.
bank_arg << std::endl;
343 strncpy(account.bank_id, args_info.
bank_arg, OFX_BANKID_LENGTH - 1);
349 std::cerr <<
"ERROR: --bank is required for a bank request" << std::endl;
350 is_payment_args_given =
false;
356 std::cerr <<
"broker " << args_info.
broker_arg << std::endl;
357 strncpy(account.broker_id, args_info.
broker_arg, OFX_BROKERID_LENGTH - 1);
363 std::cerr <<
"ERROR: --broker is required for an investment statement request" << std::endl;
364 is_payment_args_given =
false;
370 std::cerr <<
"acct " << args_info.
acct_arg << std::endl;
371 strncpy(account.account_number, args_info.
acct_arg, OFX_ACCTID_LENGTH - 1);
375 std::cerr <<
"ERROR: --acct is required for a statement request" << std::endl;
376 is_payment_args_given =
false;
381 std::cerr <<
"type " << args_info.
type_arg << std::endl;
385 account.account_type = account.OFX_CHECKING;
388 account.account_type = account.OFX_INVESTMENT;
391 account.account_type = account.OFX_CREDITCARD ;
394 std::cerr <<
"ERROR: --type is not valid. Must be between 1 and 3" << std::endl;
400 std::cerr <<
"ERROR: --type is required for a statement request" << std::endl;
401 is_payment_args_given =
false;
404 if ( is_payment_args_given )
406 char* request = libofx_request_payment( &fi, &account, &payee, &payment );
409 fb.open (
"query", std::ios::out);
410 std::ostream os(&fb);
414 if ( url.length() && args_info.
inputs_num > 0 )
415 post(request, url.c_str(), args_info.
inputs[0]);
417 std::cout << request;
428 char* request = libofx_request_accountinfo( &fi );
430 if ( url.length() && args_info.
inputs_num > 0 )
431 post(request, url.c_str(), args_info.
inputs[0]);
433 std::cout << request;
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....
void cmdline_parser_print_help(void)
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 acct_given
Whether acct was given.
unsigned int accountinfo_req_given
Whether accountinfo-req was given.
int trid_arg
Transaction id.
char * acct_arg
Account ID.
long past_arg
How far back to look from today (in days).
unsigned int broker_given
Whether broker was given.
char * org_arg
FI org tag.
char * broker_arg
Broker identifier.
unsigned int bank_given
Whether bank was given.
unsigned int org_given
Whether org was given.
unsigned int url_given
Whether url 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.