payproc.git
8 months agocJSON: Add SPDX identifier and reformat some comments. master
Werner Koch [Mon, 12 Mar 2018 09:25:33 +0000 (10:25 +0100)]
cJSON: Add SPDX identifier and reformat some comments.

17 months agopayproc-jrnl: Allow for -F help
Werner Koch [Tue, 13 Jun 2017 08:03:55 +0000 (10:03 +0200)]
payproc-jrnl: Allow for -F help

* src/payproc-jrnl.c (parse_fieldname): Implement "help " kludge

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoAllow forcing single-time SEPA payment in procpost-test.
Werner Koch [Mon, 12 Jun 2017 13:55:08 +0000 (15:55 +0200)]
Allow forcing single-time SEPA payment in procpost-test.

* src/payproc-post.c (post_sepa): Detect explict value.
--

This allows

  payproc-post --live ABCDEF  10/0

to force a single payment even if the preorder DB says a reccuring
payment was planned.

17 months agoAllow indicating recurring SEPA donations in payproc-post.
Werner Koch [Mon, 12 Jun 2017 13:27:10 +0000 (15:27 +0200)]
Allow indicating recurring SEPA donations in payproc-post.

* src/commands.c (cmd_commitpreorder): Allow for 'Recur' parameter.
* src/preorder.c (preorder_update_record): Handle 'Recur'.  Allow
updating passed dictionary.  Store RECUR in the journal.
* src/payproc-post.c (send_request): Also print failure messages.
(post_sepa): Implement AMOUNT/RECUR syntax.
(listpreorder): Print full timestamp of last payment.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoStore the 'Recur' parameter in the preorder table.
Werner Koch [Fri, 9 Jun 2017 13:21:49 +0000 (15:21 +0200)]
Store the 'Recur' parameter in the preorder table.

* src/preorder.c (open_preorder_db): Add column 'recur'.
(insert_preorder_record): Handle that new column.
(get_columns): Ditto.
(format_columns): Ditto.
* src/payproc-post.c (sepapreorder): Allow inserting a recur value.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoCache Paypal plans.
Werner Koch [Tue, 6 Jun 2017 18:09:18 +0000 (20:09 +0200)]
Cache Paypal plans.

* src/paypal.c (plan_cache, plan_counter): New.
(cache_plan_id): new.
(find_plan): Use the cache.
(paypal_find_create_plan): Insert a new plan in the cache.
--

Paypal has no API to lookup the plan by name.  Thus we need to iterate
over all plans to find a matching one.  This new cache thus avoids
long Paypal transactions.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoCompress the SVG created by ppsepaqr
Werner Koch [Tue, 30 May 2017 18:52:45 +0000 (20:52 +0200)]
Compress the SVG created by ppsepaqr

* src/ppsepaqr.c (encode): Combine x-axis rectangles.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoUse SVG attribute crispEdges for ppsepaqr output.
Werner Koch [Tue, 30 May 2017 18:18:53 +0000 (20:18 +0200)]
Use SVG attribute crispEdges for ppsepaqr output.

* src/ppsepaqr.c (encode): Add attribute.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoNew tool ppsepaqr
Werner Koch [Tue, 30 May 2017 16:08:08 +0000 (18:08 +0200)]
New tool ppsepaqr

* configure.ac: Cehck for libqrencode.
* src/ppsepaqr.c: New.
* src/Makefile.am (bin_PROGRAMS): Add ppsepaqr

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoAppend aliasid to the Paypal cancel URL.
Werner Koch [Tue, 30 May 2017 06:58:42 +0000 (08:58 +0200)]
Append aliasid to the Paypal cancel URL.

* src/paypal.c (paypal_create_subscription): Fix startdate - it really
needs top be 24 hours later (was a typo).
(paypal_checkout_prepare): Append the aliasid also to the cancel URL.
(paypal_create_subscription): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoFix Paypal one-time donations.
Werner Koch [Mon, 22 May 2017 11:10:40 +0000 (13:10 +0200)]
Fix Paypal one-time donations.

* src/paypal.c (paypal_checkout_execute): Use keyvalue_get.
--

Fixes-commit: e11573f6e77ecfdc0e63767677428e6f49d67a44

17 months agoNeed to send Connection:close for HTTP/1.0
Werner Koch [Mon, 22 May 2017 09:14:49 +0000 (11:14 +0200)]
Need to send Connection:close for HTTP/1.0

17 months agoFinish implementation of Paypal recurring donations.
Werner Koch [Mon, 22 May 2017 06:39:36 +0000 (08:39 +0200)]
Finish implementation of Paypal recurring donations.

* src/account.c (open_account_db): Add new column 'paypal_payer_id'
(update_account_record): Update this field.
* src/commands.c (cmd_ppcheckout): Call paypal_create_subscription and
store journal records for recurring payments.
* src/util.c (get_full_isotime): New.
* src/paypal.c (call_paypal): Allow for full URLs.  Debug response
also for non-valid JSON.
(find_execute_url): New.
(find_payer_id): New.
(paypal_find_create_plan): Export _plan_name.
(paypal_create_subscription): New.
(paypal_checkout_prepare): Check that a session id exists.
(paypal_checkout_execute): Support subscriptions.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoFirst changes for Paypal recurring donations.
Werner Koch [Fri, 19 May 2017 08:30:45 +0000 (10:30 +0200)]
First changes for Paypal recurring donations.

* src/commands.c (cmd_ppcheckout): Add some code for recurring
donations.
* src/paypal.c (status_unauthorized_seen): New flag.
(call_paypal): Improve debugging code.  Set that new flag.  Add arg
REQ_METHOD and change callers to provide that.
(get_access_token): Flush cache after a 401 was seen.
(find_plan): New.
(paypal_find_create_plan): New.
* src/t-util.c (test_convert_amount): Add garbage tests.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoDo not fail a call to paypal or stripe with no return data.
Werner Koch [Fri, 19 May 2017 08:22:10 +0000 (10:22 +0200)]
Do not fail a call to paypal or stripe with no return data.

* src/paypal.c (call_paypal): Replace an empty string by a JSON
object.
* src/stripe.c (call_stripe): Ditto.
--

Some Paypal call s do not return data.  This results in an empty
string in our functions which is a non-valid JSON object.  The effect
is that an error is returned and not an "empty" JSON object.  To
mitigate this we return the "null" JSON object in such a case.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoAdd the PATCH method to the http module.
Werner Koch [Thu, 18 May 2017 10:13:00 +0000 (12:13 +0200)]
Add the PATCH method to the http module.

* src/http.h (HTTP_REQ_PATCH): New.
* src/http.c (http_open): Adjust method check.
(send_request): Implement PATCH method.

17 months agoReuse the PayPal OAUTH token
Werner Koch [Thu, 18 May 2017 07:50:14 +0000 (09:50 +0200)]
Reuse the PayPal OAUTH token

* src/paypal.c: Include npth.h and time.h.
(get_access_token): Cache the access_token

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoMark HTTP requests as HTTP/1.1
Werner Koch [Thu, 18 May 2017 06:37:46 +0000 (08:37 +0200)]
Mark HTTP requests as HTTP/1.1

* src/http.c (send_request): Use HTTP/1.1
--

As of now the PayPal servers responds to requests in HTTP 1.0 mode
with "Bad Request".  However that does only happen with the sandbox
servers and not (yet) with the live servers.  Although we _may_ not
fully support HTTP 1.1 we switch to 1.1 anyway.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoMinor rework of paypal.c.
Werner Koch [Wed, 17 May 2017 12:57:03 +0000 (14:57 +0200)]
Minor rework of paypal.c.

* src/paypal.c:  Remove duplicate debug messges.
(paypal_checkout_prepare): Factor OAUTH code out to ...
(get_access_token): new.
--

Also fixed some typos.

17 months agoNew option --debug-paypal for payprocd.
Werner Koch [Wed, 17 May 2017 08:18:21 +0000 (10:18 +0200)]
New option --debug-paypal for payprocd.

* src/paypal.c (call_paypal): Add debug calls.
(paypal_checkout_prepare): Remove debug calls.
(paypal_checkout_execute): Ditto.
* src/paypal-ipn.c (call_verify): Add debug calls
* src/payprocd.h (opt): Add field DEBUG_PAYPAL.
* src/payprocd.c (oDebugPaypal): New.
(opts): Add --debug-paypal.
(parse_options): Set options.

Signed-off-by: Werner Koch <wk@gnupg.org>
17 months agoStore our account_id in the Stripe metadata
Werner Koch [Wed, 17 May 2017 06:33:13 +0000 (08:33 +0200)]
Store our account_id in the Stripe metadata

* src/stripe.c (stripe_create_subscription): Create metadata

18 months agoDo not fail the TLS handshake on warning alerts.
Werner Koch [Tue, 16 May 2017 08:59:47 +0000 (10:59 +0200)]
Do not fail the TLS handshake on warning alerts.

* src/http.c (send_request): Handle handshake warnings.
(cookie_read): Handle server closed connection.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoFix use after free.
Werner Koch [Tue, 16 May 2017 08:58:19 +0000 (10:58 +0200)]
Fix use after free.

* src/payprocd.c (create_socket): Move a free behind last use.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoStore the email in the account table and add a verified flag.
Werner Koch [Tue, 16 May 2017 08:35:45 +0000 (10:35 +0200)]
Store the email in the account table and add a verified flag.

* src/account.c (open_account_db): Add field 'verified' to the account
table.
(update_account_record): Set email field.

18 months agoFix a few memory leaks.
Werner Koch [Mon, 15 May 2017 15:49:24 +0000 (17:49 +0200)]
Fix a few memory leaks.

* src/util.c (keyvalue_putf): Always free VALUE.
(keyvalue_release): Free the node.
* src/commands.c (write_rem_linef): Free BUFFER.
* src/payprocd.c (create_socket): Free SERV_ADDR,
* src/journal.c (write_log): Avoid race between free and malloc.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoAdd Recur field also to payproc-jrnl.
Werner Koch [Fri, 12 May 2017 10:35:13 +0000 (12:35 +0200)]
Add Recur field also to payproc-jrnl.

* src/payproc-jrnl.c (jrnl_field_names): Add new field.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoAdd the Live flag to CHARGECARD in recurring mode.
Werner Koch [Thu, 11 May 2017 19:26:20 +0000 (21:26 +0200)]
Add the Live flag to CHARGECARD in recurring mode.

* src/stripe.c (stripe_create_subscription): Check "livemode".

18 months agoLog infos about subscriptions.
Werner Koch [Thu, 11 May 2017 14:00:35 +0000 (16:00 +0200)]
Log infos about subscriptions.

* src/commands.c (cmd_chargecard): Write a journal record for
subscriptions.
* src/journal.c (jrnl_store_charge_record): New arg RECUR.  Change
callers.  Write subscription record.
* src/jrnl-fields.h (JRNL_FIELD_RECUR): New.
(NO_OF_JRNL_FIELDS): Increment.
* src/payproc-stat.c: Extend stat format.
(one_line): Support subscription records.
(read_stat_line): Ditto.
(postprocess_statrecords): Ditto.
(print_output): Ditto.
--

These changes allow to track the number and the pledged amount of
subscriptions (i.e. recurring donations).

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoSet the payprocd socket permissions.
Werner Koch [Thu, 11 May 2017 07:59:13 +0000 (09:59 +0200)]
Set the payprocd socket permissions.

* src/payprocd.c (create_socket): Set socket permission.
--

We want that the created socket is 0770 so that only the group can use
it.  The owner of the socket is determined from the directory which
should have the sticky bit set for the group.  For example by using

   mkdir -p /var/run/payproc
   chmod g+ws /var/run/payproc
   chown payprocd:www-data /var/run/payproc

18 months agoDo no create a Stripe plan with CHECKAMOUNT
Werner Koch [Thu, 11 May 2017 07:54:59 +0000 (09:54 +0200)]
Do no create a Stripe plan with CHECKAMOUNT

* src/commands.c (cmd_checkamount): Do not call
stripe_find_create_plan.
--

We only want to check that the Recur parameter is valid.  The plan is
anyway created when creating a subscription.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoNew option --debug-client
Werner Koch [Wed, 10 May 2017 16:50:36 +0000 (18:50 +0200)]
New option --debug-client

* src/payprocd.c: Add option
* src/commands.c (connection_handler): Print the request in debug mode.
(write_data_line): Add debug output.
(write_data_line_direct): New.  Use instead of a direst es_fprintf.
(write_ok_line, write_ok_linef): Ditto.
(write_err_line): Ditto.
(write_rem_line, write_rem_linef): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoNew option --debug-stripe.
Werner Koch [Wed, 10 May 2017 09:09:59 +0000 (11:09 +0200)]
New option --debug-stripe.

* src/payprocd.c: Add option --debug-stripe.
* src/stripe.c (call_stripe): Implement here.  Remove other debug
statements.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoCreate account records to track Stripe customer ids.
Werner Koch [Wed, 10 May 2017 08:37:53 +0000 (10:37 +0200)]
Create account records to track Stripe customer ids.

* src/account.c: New.
* src/account.h: New.
* src/Makefile.am (payprocd_SOURCES): Add them.
* src/stripe.c (stripe_create_subscription): Create an account record.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoFactor database timestamp code out to new file.
Werner Koch [Wed, 10 May 2017 08:00:34 +0000 (10:00 +0200)]
Factor database timestamp code out to new file.

* src/preorder.c (db_datetime_now) Move to ...:
* src/dbutil.c: New file.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoMerge t-commands.c into t-util.c
Werner Koch [Wed, 10 May 2017 07:58:31 +0000 (09:58 +0200)]
Merge t-commands.c into t-util.c

--

We only tested function was moved to util.c some time ago.  Thus it
does not make sense to have a test with all these dependencies.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoAdd very basic support for Stripe subscriptions.
Werner Koch [Tue, 9 May 2017 17:24:05 +0000 (19:24 +0200)]
Add very basic support for Stripe subscriptions.

* src/commands.c (cmd_chargecard): Support recurring payments.
(cmd_checkamount): Ditto.
* src/currency.c (valid_recur_p): New.
* src/stripe.c (stripe_find_create_plan): New.
(stripe_create_subscription): New.
--

Example

  $ socat - unix-client:/var/run/payproc-test/daemon
  CHARGECARD
  Currency: USD
  Amount: 15
  Recur: 12
  Desc: Monthly GnuPG donation of 15 USD
  Stmt-Desc: GnuPG donation
  Meta[name]: my test donor
  Email: joe@example.org
  Card-Token: tok_1AHbsp23ctCHxH4kh26K7jrY

  OK
  Email: joe@example.org
  Meta[name]: my test donor
  Stmt-Desc: GnuPG donation
  Desc: Monthly GnuPG Donation of 15 USD
  Recur: 12
  Amount: 15.00
  Currency: USD

18 months agoNew function ascii_strlwr.
Werner Koch [Tue, 9 May 2017 17:19:58 +0000 (19:19 +0200)]
New function ascii_strlwr.

* src/util.c (ascii_strlwr): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoAdd mbox utilities from GnuPG
Werner Koch [Tue, 9 May 2017 17:19:29 +0000 (19:19 +0200)]
Add mbox utilities from GnuPG

* src/mbox-util.c: New.  Comment unneeded code.
* src/mbox-util.h: New.
* src/Makefile.am (common_sources): Add.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoWhen encoding form data skip deleted items
Werner Koch [Tue, 9 May 2017 17:17:32 +0000 (19:17 +0200)]
When encoding form data skip deleted items

* src/form.c (encode_formdata): Skip if values is NULL.
--

Without that check we could run into a NULL-deref when a dictionary
with deleted items is provided.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoNew function decrypt_string.
Werner Koch [Mon, 8 May 2017 11:14:33 +0000 (13:14 +0200)]
New function decrypt_string.

* src/encrypt.c (create_context): Add arg PINMODE.
(encrypt_setup_keys, encrypt_string): Move pinmode setting to above
func.  Do not require all keys.
(decrypt_string): New.
* src/t-encrypt.c: New.
* src/Makefile.am (module_tests): Add test.
(t_encrypt_SOURCES): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoAdd padding to base64 encoding
Werner Koch [Sat, 6 May 2017 06:42:33 +0000 (08:42 +0200)]
Add padding to base64 encoding

* src/util.c (base64_encode): Change to use padding.
(base64_decode): Remove kludge.
* src/t-util.c (do_test_base64_encoding): New.
(test_base64_encoding): More tests.
--

It does not make sense to save 2 padding bytes in exchange for being
non standard compliant.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoNew function encrypt_string.
Werner Koch [Fri, 5 May 2017 13:38:40 +0000 (15:38 +0200)]
New function encrypt_string.

* src/encrypt.c (encrypt_setup_keys): Factor some code out to ...
(create_context): new.
(encrypt_string): New.
* src/encrypt.h (ENCRYPT_TO_DATABASE): New.
(ENCRYPT_TO_BACKOFFICE): New.
* src/util.c (bintoasc): New.
(base64_encode): New.
(base64_decode): New.

* src/t-util.c (test_base64_encoding): New.
(main): Calt that.

18 months agoSetup keys to encrypt data items.
Werner Koch [Fri, 5 May 2017 07:50:17 +0000 (09:50 +0200)]
Setup keys to encrypt data items.

* src/encrypt.c: New.
* src/encrypt.h: New.
* src/Makefile.am (payprocd_SOURCES): Add them.
* src/payprocd.c (check_openpgp_keys): Remove.
(main): Call encrypt_setup_keys instead.  Print infos about the keys.

18 months agoNew options --database-key and --backoffice-key.
Werner Koch [Thu, 4 May 2017 18:42:57 +0000 (20:42 +0200)]
New options --database-key and --backoffice-key.

* src/payprocd.c (oDatabaseKey, oBackofficeKey): New const.
(opts): Add new options.
(parse_options): Impelment.  Also check for unknown args.
(cleanup): Free allocates vars.
(check_openpgp_keys): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoNew option --config and --no-config for the daemon.
Werner Koch [Thu, 4 May 2017 16:43:17 +0000 (18:43 +0200)]
New option --config and --no-config for the daemon.

* src/payprocd.c (main): Make LOGFILE file global.  Factor option
parser out to ...
(parse_options): new.  Add config file parser.
(launch_server): Do not fork with --no-detach.
--

We will soon need a couple more configuration options and thus a
config file will be very helpful

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoSwitch the name of the preorder DB in test mode.
Werner Koch [Fri, 28 Apr 2017 19:15:36 +0000 (21:15 +0200)]
Switch the name of the preorder DB in test mode.

* src/preorder.c (open_preorder_db): Switch socket name.
--

Fixes-commit: 5acc9615b5177f7134ab66e88273da7e71a43477
Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoUpdate config.{guess,sub} and other standard files.
Werner Koch [Fri, 28 Apr 2017 09:53:25 +0000 (11:53 +0200)]
Update config.{guess,sub} and other standard files.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoPrepare for using gpgme.
Werner Koch [Fri, 28 Apr 2017 09:48:49 +0000 (11:48 +0200)]
Prepare for using gpgme.

* m4/gpgme.m4: New.
* src/Makefile.am (payprocd_CFLAGS, payprocd_LDADD): Add GPGME flags.
* src/payprocd.c: Include gpgme.h.
(main): Init gpgme.
* configure.ac (NEED_GPGME_VERSION): New.
--

We require 1.9 because this is anyway new software and thus it does
not harm to require what is current.

Signed-off-by: Werner Koch <wk@gnupg.org>
18 months agoImplement an explicit test mode.
Werner Koch [Mon, 24 Apr 2017 16:17:15 +0000 (18:17 +0200)]
Implement an explicit test mode.

* configure.ac (PAYPROCD_TEST_SOCKET_NAME): New ac_define.
* src/payproc-post.c (opts): New options --live and --test.
(send_request): Use the test socket in test mode.  Print a warning if
neither --live nor --test are given.
* src/payprocd.c (opts): New option --test.
(main): Print a warning if neither --live nor --test are given.
(server_socket_name): New.
(launch_server, cleanup): Use new function.
--

Note that ppipnhd does not yet allow for this.  We need to look at the
received data to decide whether this was test or live data.

Also payproc-post now requires the use of --live because it makes more
sense to default to --test.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 years agoFix segv in poreorder if no Meta field has been given.
Werner Koch [Thu, 12 Nov 2015 16:41:39 +0000 (17:41 +0100)]
Fix segv in poreorder if no Meta field has been given.

* src/preorder.c (get_text_column): Do not call keyvalue_put_meta with
NULL.

3 years agoRelease 0.3.0 payproc-0.3.0
Werner Koch [Thu, 15 Oct 2015 14:57:25 +0000 (16:57 +0200)]
Release 0.3.0

3 years agoAdd a server shutdown feature.
Werner Koch [Thu, 15 Oct 2015 14:48:48 +0000 (16:48 +0200)]
Add a server shutdown feature.

* src/commands.c (cmd_shutdown): New.
(cmdtbl): Add "SHUTDOWN".
* src/payprocd.c (shutdown_server): New.
(connection_thread): Track active connections.
* src/t-commands.c (shutdown_server): New.
* src/payproc-post.c (main): Add command --shutdown.

3 years agoAdd command --list-preorder to payproc-post.
Werner Koch [Thu, 15 Oct 2015 14:08:24 +0000 (16:08 +0200)]
Add command --list-preorder to payproc-post.

* src/commands.c (write_data_line): Factor some code out to ...
(write_data_value): new.
(cmd_listpreorder): New.
* src/preorder.c: Include membuf.h.
(format_columns): New.
(list_preorder_records): New.
(preorder_list_records): New.
* src/payproc-post.c (main): Add command --list-preorder.
(listpreorder): New.

3 years agoAdd functions strtokenize and keyvalue_get_uint.
Werner Koch [Thu, 15 Oct 2015 07:44:42 +0000 (09:44 +0200)]
Add functions strtokenize and keyvalue_get_uint.

* src/util.c (strtokenize): New.  From gnupg/common/stringhelp.c.
(keyvalue_get_uint): New.

--

strtokenize was written by g10 Code in 2015 - license change to GPLv3.

3 years agoWe need sqlite 3.8
Werner Koch [Wed, 14 Oct 2015 20:17:15 +0000 (22:17 +0200)]
We need sqlite 3.8

--

Earlier versions don't feature the extended error codes and
sqlite3_errstr.

3 years agoImplement options --allow-uid and --admin-uid.
Werner Koch [Wed, 14 Oct 2015 16:57:52 +0000 (18:57 +0200)]
Implement options --allow-uid and --admin-uid.

* src/payprocd.c (add_allowed_uid): New.
(main): Implement options.
(connection_thread): Pass UID to the connection handler.
* src/commands.c (cmdtbl): Add field "admin_required".
(connection_handler): Add arg UID and implement checks.

3 years agoNew tool to commit SEPA preorders.
Werner Koch [Wed, 14 Oct 2015 15:42:34 +0000 (17:42 +0200)]
New tool to commit SEPA preorders.

* src/payproc-post.c: New.
* src/util.c (ascii_strupr): New.
(keyvalue_put_idx): New.
(keyvalue_put_meta): New.
* src/t-util.c: New.

* src/preorder.c (open_preorder_db): More prepared statements.
(get_text_column, (get_columns): New.
(get_preorder_record):  New.
(update_preorder_record): New.
(preorder_get_record): New.
(preorder_update_record): New.
* src/journal.c (jrnl_store_charge_record): Write Sepa-Ref.
* src/commands.c (cmd_commitpreorder):
(cmd_getpreorder):
(cmd_ppipnhd): New with code factored out from connection_handler.
(cmd_help): New.
(cmdtbl): New.
(connection_handler): Use a table to dispatch commands.
* src/protocol-io.c (read_data): Ignore comment lines.

3 years agoAdd helper to read server responses.
Werner Koch [Tue, 13 Oct 2015 15:11:27 +0000 (17:11 +0200)]
Add helper to read server responses.

* src/protocol-io.c (protocol_read_response): New.
(protocol_read_request): Factor all code out to...
(read_data): new.  Add arg "filter".
(store_data_line): Add arg "filter".

3 years agoRename and reorganize some files.
Werner Koch [Tue, 13 Oct 2015 06:53:40 +0000 (08:53 +0200)]
Rename and reorganize some files.

* src/commands.c (read_request, store_data_line)
(store_data_line): Move to ...
* src/protocol-io.c: new file.
* src/protocol-io.h: New.

* src/commands.c (convert_amount, reconvert_amount): Move to ...
* src/util.c: here.

* src/connection.c: Rename to src/commands.c
* src/connection.h: Rename to src/commands.h
* src/t-connection.c: Rename to src/t-commands.c

3 years agoAdd command SEPAPREORDER.
Werner Koch [Mon, 9 Mar 2015 19:35:26 +0000 (20:35 +0100)]
Add command SEPAPREORDER.

* configure.ac (SQLITE3): Require SQLite 3.
* src/preorder.c, src/preorder.h: New.
* src/t-preorder.c: New.
* src/connection.c (cmd_sepapreorder): New.
(connection_handler): Add new command.

3 years agoAdd non yet functional options --admin-uid and --admin-gid.
Werner Koch [Mon, 9 Mar 2015 19:34:57 +0000 (20:34 +0100)]
Add non yet functional options --admin-uid and --admin-gid.

* src/payprocd.c (main): Add options.

3 years agoMove timestamp function to util.c.
Werner Koch [Mon, 9 Mar 2015 12:27:58 +0000 (13:27 +0100)]
Move timestamp function to util.c.

* src/journal.c (get_current_time): Move to util.c and make public.
(TIMESTAMP_SIZE): Move to util.h and include terminating Nul.

3 years agoMove field writing functions to util.c.
Werner Koch [Mon, 9 Mar 2015 11:50:59 +0000 (12:50 +0100)]
Move field writing functions to util.c.

* src/journal.c (severe_error): Move to util.c.
(write_escaped_buf, write_escaped, write_meta): Move to util.c.
* src/util.c (write_meta): Rename to write_meta_field.  Do not write
trailing colon.  Adjust caller.
(write_escaped): Do not write trailing colon.  Adjust callers.
(meta_field_to_string): New.
* src/cJSON.c: Include config.h.

3 years agoUse estream functions from libgpg-error.
Werner Koch [Mon, 9 Mar 2015 11:25:35 +0000 (12:25 +0100)]
Use estream functions from libgpg-error.

* configure.ac (NEED_GPG_ERROR_VERSION): Set to 1.18.
(GPGRT_ENABLE_ES_MACROS): New.
(GCRYPT_NO_DEPRECATED): New.
(CLFAGS): Remove -Wno-psabi.
(estream_INIT): Remove.
* m4/estream.m4: Remove.
* src/estream.c, src/estream.h: Remove.
* src/estream-printf.c, src/estream-printf.h: Remove.
* src/Makefile.am (common_sources): Remove estream files.

3 years agoRequire to automake 1.14 and update build-aux scripts.
Werner Koch [Mon, 9 Mar 2015 11:16:18 +0000 (12:16 +0100)]
Require to automake 1.14 and update build-aux scripts.

4 years agoSupport PayPal using their REST service.
Werner Koch [Tue, 21 Oct 2014 17:57:22 +0000 (19:57 +0200)]
Support PayPal using their REST service.

* src/stripe.c (encode_formdata):  Move to ...
* src/form.c: New.
* src/journal.c (jrnl_store_charge_record): Add arg service.
* src/connection.c (cmd_ppcheckout): New.
(cmd_getinfo): Add sub-command "live".
(connection_handler): Add PPCHECKOUT command.
* src/paypal.c: New.
* src/payprocd.c (main): Add option --paypal-key.
(set_account_key): Add arg "service".

4 years agoAdd support for Bearer authentication.
Werner Koch [Tue, 21 Oct 2014 17:51:35 +0000 (19:51 +0200)]
Add support for Bearer authentication.

* src/http.c (make_simple_header_line): New.
(send_request): Support Bearer authentication.
* src/http.h (HTTP_FLAG_AUTH_BEARER): New.

4 years agoAdd session alias mechanism.
Werner Koch [Tue, 21 Oct 2014 17:49:46 +0000 (19:49 +0200)]
Add session alias mechanism.

* src/session.c (MAX_ALIASES_PER_SESSION): New.
(struct session_alias_s, session_alias_s): New.
(aliases, unused_aliases): New.
(session_housekeeping): Destroy aliases.
(session_do_destroy): Ditto.
(session_create): Make sure that all aliases are reset.
(session_get, session_put): Factor lookup out to ...
(get_session_object): new.
(session_create_alias): New.
(do_destroy_alias): New.
(session_destroy_alias): New.
(session_get_sessid): New.
* src/connection.c (cmd_session): Add alias sub-commands.

4 years agoAdd two fields for yearly stats to payproc-stat.
Werner Koch [Fri, 17 Oct 2014 10:35:43 +0000 (12:35 +0200)]
Add two fields for yearly stats to payproc-stat.

4 years agoNew tool payproc-stat.
Werner Koch [Thu, 16 Oct 2014 18:31:14 +0000 (20:31 +0200)]
New tool payproc-stat.

* src/payproc-stat.c: New.
* src/Makefile.am (bin_PROGRAMS): Add payproc-stat.
(payproc_stat_SOURCES): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
4 years agoAdd header file with field names.
Werner Koch [Thu, 16 Oct 2014 09:14:55 +0000 (11:14 +0200)]
Add header file with field names.

* src/jrnl-fields.h: New.
* src/Makefile.am (common_headers): New. Add new file.
(payprocd_SOURCES): Add common_headers.
(payproc_jrnl_SOURCES): Ditto.

4 years agoPost release updates.
Werner Koch [Tue, 9 Sep 2014 19:09:51 +0000 (21:09 +0200)]
Post release updates.

--

4 years agoRelease 0.2.1 payproc-0.2.1
Werner Koch [Tue, 9 Sep 2014 19:05:15 +0000 (21:05 +0200)]
Release 0.2.1

4 years agoSupport exchange rates.
Werner Koch [Tue, 9 Sep 2014 18:52:24 +0000 (20:52 +0200)]
Support exchange rates.

* src/connection.c (currency_table, valid_currency_p): Move to ...
* src/currency.c, src/currency.h: new.
* src/journal.c (jrnl_store_sys_record): Print some more colons.
(jrnl_store_exchange_rate_record): New.
(jrnl_store_charge_record): Print Euro field.
* src/connection.c (cmd_checkamount): Return converted currency.
(cmd_getinfo): Use currency interface.
* src/payprocd.c (housekeeping_thread): Read exchange rates every
hour.
* src/util.h (AMOUNTBUF_SIZE): New.

* src/payproc-jrnl.c (jrnl_field_names): Add "euro".
(one_line): Increase size of field array.

* src/geteuroxref: New.

4 years agoRemove do not use live mode check
Werner Koch [Fri, 13 Jun 2014 18:15:41 +0000 (20:15 +0200)]
Remove do not use live mode check

4 years agoSlightly change the format of the journal.
Werner Koch [Fri, 13 Jun 2014 18:04:12 +0000 (20:04 +0200)]
Slightly change the format of the journal.

* src/journal.c: Split account and live field.  Add field rtxid.
* src/payproc-jrnl.c: Add new fields.

4 years agoUse TSD to improve logging.
Werner Koch [Fri, 13 Jun 2014 17:20:56 +0000 (19:20 +0200)]
Use TSD to improve logging.

* src/payprocd.c (my_tsd_key): New.
(pid_suffix_callback): New.
(main): Setup TSD.
(connection_thread): Store connection ID in the TSD.
* src/paypal-ipn.c (paypal_proc_ipn): Remove arg IDNO.
--

This allows us to print an identifier for the thread with the log
messages.  To further improve on that we may want to move that all to
logging and keep some logging specific information in the TSD.  For
example this could help to decide whether a LF needs to be printed if
a log message from a second thread is to be printed after an
incomplete log message from the first thread.

4 years agoSilence some diagnostics.
Werner Koch [Fri, 13 Jun 2014 13:25:07 +0000 (15:25 +0200)]
Silence some diagnostics.

* src/payprocd.c (housekeeping_thread): Require -vv for log_info.

4 years agoFinish PayPal IPN verification code.
Werner Koch [Fri, 13 Jun 2014 12:39:47 +0000 (14:39 +0200)]
Finish PayPal IPN verification code.

* src/paypal-ipn.c (call_verify): Finish code.
(paypal_proc_ipn): Use another test mail address.
* src/util.c (parse_www_form_urlencoded): Change to not modify the
arg.

4 years agohttp: Print human readable GNUTLS status.
Werner Koch [Fri, 13 Jun 2014 12:37:27 +0000 (14:37 +0200)]
http: Print human readable GNUTLS status.

* src/http.c (send_gnutls_bye): Take care of EAGAIN et al.
(http_verify_server_credentials): Print a human readable status.

4 years agoUpdate http.c and estream.c from GnuPG master.
Werner Koch [Fri, 13 Jun 2014 08:00:53 +0000 (10:00 +0200)]
Update http.c and estream.c from GnuPG master.

4 years agoFirst take on the PPIPNHD command.
Werner Koch [Fri, 13 Jun 2014 06:51:15 +0000 (08:51 +0200)]
First take on the PPIPNHD command.

* src/ppipnhd.c: New.
* src/paypal.h: New.
* src/paypal-ipn.c: New.
* src/Makefile.am: Add new files.
* src/connection.c (release_connection_obj): Move close to ...
(shutdown_connection_obj): new.
(connection_handler): Add command PPIPNHD.
--

Note that the verification does not yet work.

4 years agoAdd a couple of new utility functions.
Werner Koch [Fri, 13 Jun 2014 06:47:49 +0000 (08:47 +0200)]
Add a couple of new utility functions.

* src/logging.c (print_sanitized): New.
(log_printval, log_printkeyval): New.
* src/util.c (keyvalue_remove_nl): New.
(keyvalue_snatch): New.
(parse_www_form_urlencoded): New.

4 years agoMake socket name a configure option.
Werner Koch [Fri, 13 Jun 2014 06:45:41 +0000 (08:45 +0200)]
Make socket name a configure option.

* configure.ac (PAYPROCD_SOCKET_NAME): New var.
* src/payprocd.c (SOCKET_NAME): Replace by PAYPROCD_SOCKET_NAME.

4 years agoNew tool payproc-jrnl.
Werner Koch [Wed, 28 May 2014 06:44:36 +0000 (08:44 +0200)]
New tool payproc-jrnl.

* src/percent.c: New.  From GnuPG master.
* src/util.c (memstr): New.  From my addrutil.c.
(memistr, memicmp): New.  From GnuPG master.
* src/util.h (atoi_1, atoi_2, atoi_4): New.
(xtoi_1, xtoi_2, xtoi_4): New.
* src/payproc-jrnl.c: New.
--

The record selection code has been derived from code I wrote for
addrutil.c.

4 years agoFix brown paper bag allocation bug.
Werner Koch [Mon, 26 May 2014 08:23:49 +0000 (10:23 +0200)]
Fix brown paper bag allocation bug.

* src/util.c (keyvalue_create): Use key and not value for the
allocation.
--

Despite that I have used the pattern of variable length structs for
soooo many times, I got it wrong this time. :-(.  It might be useful
to have a dedicated malloc function+macro to help with that.  This
could actually do the calloc only for the static part of the struct
and copy the string into the dynamic part.

4 years agoPost release updates.
Werner Koch [Fri, 23 May 2014 19:00:49 +0000 (21:00 +0200)]
Post release updates.

--

4 years agoRelease 0.2.0. payproc-0.2.0
Werner Koch [Fri, 23 May 2014 18:58:07 +0000 (20:58 +0200)]
Release 0.2.0.

4 years agoUse -Wno-psabi with gcc.
Werner Koch [Fri, 23 May 2014 18:53:17 +0000 (20:53 +0200)]
Use -Wno-psabi with gcc.

* configure.ac: Rework GCC warning option detection.

4 years agoSESSION - Add command.
Werner Koch [Fri, 23 May 2014 18:45:00 +0000 (20:45 +0200)]
SESSION - Add command.

* configure.ac (NEED_LIBGCRYPT_VERSION): Require Libgcrypt.
* src/session.c, src/session.h: New.
* src/Makefile.am (payprocd_SOURCES): Add them.
(LDADD, AM_CFLAGS): Add Libgcrypt.
(t_connection_CFLAGS, t_connection_LDADD): Ditto.
(t_connection_SOURCES): Add session.c
* src/payprocd.c (TIMERTICK_INTERVAL, HOUSEKEEPING_INTERVAL): New.
(main): Init Libgcrypt.
(time_for_housekeeping_p): New.
(housekeeping_thread): New.
(handle_tick): New.
(server_loop): Call handle_tick.
* src/util.h (JNLIB_GCC_HAVE_PUSH_PRAGMA): New.
* src/connection.c (cmd_session): New.
(connection_handler): Add command SESSION.

4 years agoCHARGECARD - Return a timestamp.
Werner Koch [Fri, 23 May 2014 18:27:40 +0000 (20:27 +0200)]
CHARGECARD - Return a timestamp.

* src/connection.c (cmd_cardtoken): Print timestamp on success.
* src/journal.c (TIMESTAMP_SIZE): New.
(put_current_time): Remove.
(get_current_time): New.
(start_record): Add arg optoonal TIMESTAMP.
(jrnl_store_charge_record): Change arg to a pointer.  Put timestamp
into DICT.

4 years agoAdd zb32_index function.
Werner Koch [Fri, 23 May 2014 17:19:11 +0000 (19:19 +0200)]
Add zb32_index function.

* src/util.c (zb32_index): New.
(zb32_encode): Factor table out to
(zb32asc): .. static global.

4 years agoCheck that GNUTLS 3.0 has been installed.
Werner Koch [Thu, 22 May 2014 14:02:22 +0000 (16:02 +0200)]
Check that GNUTLS 3.0 has been installed.

* configure.ac (NEED_GNUTLS_VERSION): New.
(LIBGNUTLS): Fix gnutls version check.

4 years agoAdd zb32 encoder.
Werner Koch [Thu, 22 May 2014 14:00:16 +0000 (16:00 +0200)]
Add zb32 encoder.

* src/util.c (zb32_encode): New.
--

The code has been taken from current GnuPG master common/zb32.c.

4 years agoMake use of the samethread mode keyword.
Werner Koch [Tue, 15 Apr 2014 14:40:48 +0000 (16:40 +0200)]
Make use of the samethread mode keyword.

* src/connection.c (connection_handler): Open stream with samethread.
* src/payprocd.c (already_running_p): Ditto.
* src/journal.c (start_record): Open memstream with samethread.

4 years agoestream: Implement "samethread" mode keyword.
Werner Koch [Tue, 15 Apr 2014 14:40:48 +0000 (16:40 +0200)]
estream: Implement "samethread" mode keyword.

* src/estream.c (estream_internal): Add field SAMETHREAD.
(init_stream_lock, lock_stream, trylock_stream, unlock_stream): Use it.
(parse_mode): Add arg SAMETHREAD and parse that keyword.
(es_initialize): Rename to ...
(init_stream_obj): this.  Add arg SAMETHREAD.
(es_create): Add arg SAMETHREAD.  Call init_stream_lock after
init_stream_obj.
(doreadline): Call es_create with samethread flag.
(es_fopen, es_mopen, es_fopenmem, es_fopencookie, do_fdopen)
(do_fpopen, do_w32open): Implement "samethread" keyword.
(es_freopen): Take samthread flag from old stream.
(es_tmpfile): Call es)_create w/o samethread.
--

Note: Unfortunately es_tmpfile has no mode arg so that we can't use
samethread.

4 years agoestream: Fix deadlock in s_fileno.
Werner Koch [Tue, 15 Apr 2014 14:40:48 +0000 (16:40 +0200)]
estream: Fix deadlock in s_fileno.

* src/estream.c (es_fileno_unlocked): Call the unlocked functions.

4 years agoestream: Add debug code to the lock functions.
Werner Koch [Tue, 15 Apr 2014 14:40:48 +0000 (16:40 +0200)]
estream: Add debug code to the lock functions.

4 years agoestream: Replace locking macros by functions.
Werner Koch [Tue, 15 Apr 2014 14:40:48 +0000 (16:40 +0200)]
estream: Replace locking macros by functions.

--

The macros were too hard to read and actually blew up the source.

4 years agoMove the command reference to a separate file.
Werner Koch [Tue, 15 Apr 2014 14:40:48 +0000 (16:40 +0200)]
Move the command reference to a separate file.

--