taler-mdb

GNU Taler Extensions and Integrations
Log | Files | Refs | Submodules | README | LICENSE

commit b18e9662d0bc300d143df8f14b1ed4e4fc609471
parent a267c2dc1633f2231391b54362b088ece1e1758d
Author: Boss Marco <bossm8@students.bfh.ch>
Date:   Tue, 19 Nov 2019 09:40:45 +0100

doxygen added

Diffstat:
M.gitignore | 1-
Msrc/main.c | 219++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Dsrc/taler-mdb | 0
3 files changed, 190 insertions(+), 30 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -23,4 +23,3 @@ stamp-h1 .qmake* build uncrustify.cfg - diff --git a/src/main.c b/src/main.c @@ -81,23 +81,33 @@ along with #define APDU_NOT_FOUND "\x6a\x82" /* upper and lower bounds for mifare targets uid length */ +/** + * Upper lenght of the uid for a valid MIFARE target + */ #define UID_LEN_UPPER 7 +/** + * Lower lenght of the uid for a valid MIFARE target + */ #define UID_LEN_LOWER 4 -/* curl auth header */ -#define SNACK_CURL_AUTH_HEADER "Authorization" - /** * @brief FRAMEBUFFER_DEVICE framebuffer device to diplay qr code */ const char *FRAMEBUFFER_DEVICE = "/dev/fb1"; -/* Wallet AID */ +/** + * Taler wallet application identifier + */ static const uint8_t taler_aid[] = { 0xF0, 0x00, 0x54, 0x41, 0x4c, 0x45, 0x52 }; -/* APDU commands */ +/** + * NFC select file command to select wallet aid + */ static const uint8_t select_file[] = { 0x00, 0xA4, 0x04, 0x00, 0x07 }; +/** + * NFC put command to send data to the wallet + */ static const uint8_t put_data[] = { 0x00, 0xDA, 0x01, 0x00, 0x7c, 0x01 }; #if FUTURE_FEATURES @@ -105,91 +115,196 @@ static const uint8_t put_data[] = { 0x00, 0xDA, 0x01, 0x00, 0x7c, 0x01 }; static const uint8_t get_data[] = { 0x00, 0xCA, 0x01, 0x00, 0x00, 0x00 }; #endif - +/** + * Struct holding the information for a product to sell + */ struct Product { + /** + * The price for the product + */ struct TALER_Amount price; + /** + * Description (or name) of the product + */ char *description; + /** + * Number of the product in the vending machine + */ char *number; + /** + * Key for the product (optional, needed to test the application without vending machine) + */ char key; }; - +/** + * Handle for a payment + */ struct PaymentActivity { + /** + * Handle to a PUT /proposal operation + */ struct TALER_MERCHANT_ProposalOperation *po; + /** + * Handle for a /check-payment operation. + */ struct TALER_MERCHANT_CheckPaymentOperation *cpo; + /** + * Order ID for pending order + */ char *order_id; + /** + * URI needed to pay the pending order + */ char *taler_pay_uri; + /** + * NFC device + */ nfc_device *pnd; + /** + * Target to send the data via NFC + */ nfc_target nt; + /** + * Current task running + */ struct GNUNET_SCHEDULER_Task *task; + /** + * Tasks delayed + */ struct GNUNET_SCHEDULER_Task *delay_task; + /** + * Member to see if the wallet already received a uri + * GNUNET_YES, GNUNET_NO + * If yes, tunneling can be offered to the wallet + */ int wallet_has_uri; }; - +/** + * Handle for the Framebuffer device + */ struct Display { + /** + * File descriptor for the screen + */ int devicefd; + /** + * File descriptor to set backlight information + */ int backlightfd; + /** + * The display memory to set the pixel information + */ uint16_t *memory; + /** + * Original screen information + */ struct fb_var_screeninfo orig_vinfo; + /** + * Variable screen information (color depth ...) + */ struct fb_var_screeninfo var_info; + /** + * Fixed screen informtaion + */ struct fb_fix_screeninfo fix_info; }; - +/** + * NFC context used by the NFC reader + */ static nfc_context *context; +/** + * Global return value + */ static int global_ret; +/** + * Refenence to the keyboard task + */ static struct GNUNET_SCHEDULER_Task *keyboard_task; +/** + * Curl context for communication with taler backend + */ static struct GNUNET_CURL_Context *ctx; +/** + * Closure for #GNUNET_CURL_gnunet_scheduler_reschedule(). + */ static struct GNUNET_CURL_RescheduleContext *rc; +/** + * Currency read from configuration file + */ static char *currency; +/** + * Taler Backend url read from configuration file + */ static char *backendBaseUrl; +/** + * Taler fulfillment url read from configuration file + */ static char *fulfillmentUrl; +/** + * Fulfillment message to display after successfull payment, read from configuration file + */ static char *fulfillmentMsg; +/** + * Authorization for the taler backend + */ static char *authorization; +/** + * Handle for the payment + */ static struct PaymentActivity *payment_activity; +/** + * Products read from configuration file + */ static struct Product *products; -static struct Display qrDisplay; - +/** + * Amount of products + */ static unsigned int products_length; +/** + * Handle for the framebuffer device + */ +static struct Display qrDisplay; #if HAVE_QRENCODE_H #include <qrencode.h> /** - * Create the QR code image for our zone. + * Create the QR code to pay and display it on screen * * @param uri what text to show in the QR code */ @@ -278,7 +393,10 @@ show_qrcode (const char *uri) #endif - +/** + * Cleanup all the data when a order has succeeded or got cancelled + * @param pa the payment activity to clean up + */ static void cleanup_payment (struct PaymentActivity *pa) { @@ -312,7 +430,10 @@ cleanup_payment (struct PaymentActivity *pa) GNUNET_free (pa); } - +/** + * Shutdown the application. + * @param cls closure + */ static void shutdown_task (void *cls) { @@ -394,7 +515,10 @@ connect_target (void *cls); static void wallet_select_aid (void *cls); - +/** + * Transmit the pay uri from taler to the wallet application via NFC + * @param cls closure + */ static void wallet_transmit_uri (void *cls) { @@ -443,7 +567,10 @@ wallet_transmit_uri (void *cls) pa); } - +/** + * Select the taler wallet app via NFC + * @param cls closure + */ static void wallet_select_aid (void *cls) { @@ -499,7 +626,10 @@ wallet_select_aid (void *cls) pa); } - +/** + * Connect the NFC reader with a compatible NFC target + * @param cls closure + */ static void connect_target (void *cls) { @@ -542,9 +672,12 @@ connect_target (void *cls) pa); } - +/** + * Open the NFC reader. + * @param cls closure + */ static void -connect_nfc (void *cls) +open_nfc_reader (void *cls) { struct PaymentActivity *pa = cls; @@ -557,7 +690,7 @@ connect_nfc (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Payment inititation: Unable to open nfc device\n"); pa->task = GNUNET_SCHEDULER_add_delayed (NFC_FAILURE_RETRY_FREQ, - &connect_nfc, + &open_nfc_reader, pa); return; } @@ -657,12 +790,15 @@ check_payment_cb (void *cls, #if HAVE_QRENCODE_H show_qrcode (taler_pay_uri); #endif - pa->task = GNUNET_SCHEDULER_add_now (&connect_nfc, + pa->task = GNUNET_SCHEDULER_add_now (&open_nfc_reader, pa); } } - +/** + * Check the payment status again + * @param cls closure + */ static void check_payment_again (void *cls) { @@ -679,7 +815,14 @@ check_payment_again (void *cls) pa); } - +/** + * Callback for a PUT /order request + * @param cls closure + * @param http_status HTTP status code for this request + * @param ec Taler error code + * @param obj raw response body + * @param order_id order ID of the order created + */ static void proposal_cb (void *cls, unsigned int http_status, @@ -716,7 +859,11 @@ proposal_cb (void *cls, } - +/** + * Launch a new order + * @param product information for product to sell + * @return payment activity for the order, NULL on failure + */ static struct PaymentActivity * launch_payment (const struct Product *product) { @@ -775,7 +922,10 @@ launch_payment (const struct Product *product) static void start_read_keyboard (void); - +/** + * Read the character from stdin and activate the selected task + * @param cls closure + */ static void read_keyboard_command (void *cls) { @@ -825,7 +975,9 @@ read_keyboard_command (void *cls) start_read_keyboard (); } - +/** + * Wait for a keyboard input + */ static void start_read_keyboard () { @@ -844,7 +996,11 @@ start_read_keyboard () NULL); } - +/** + * Read the products from the configuration file + * @param cls closure + * @param section section of the config file to read from + */ static void read_products (void *cls, const char *section) @@ -920,7 +1076,13 @@ read_products (void *cls, tmpProduct); } - +/** + * Start the application + * @param cls closure + * @param args arguments left + * @param cfgfile config file name + * @param cfg handle for the configuation file + */ static void run (void *cls, char *const *args, @@ -1108,7 +1270,6 @@ run (void *cls, start_read_keyboard (); } - int main (int argc, char*const*argv) diff --git a/src/taler-mdb b/src/taler-mdb Binary files differ.