diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/platform.h | 222 | ||||
-rw-r--r-- | src/include/sync_database_lib.h | 2 | ||||
-rw-r--r-- | src/include/sync_service.h | 118 | ||||
-rw-r--r-- | src/include/sync_testing_lib.h | 134 |
4 files changed, 313 insertions, 163 deletions
diff --git a/src/include/platform.h b/src/include/platform.h index 2fbbe24..cfc42eb 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -42,8 +42,197 @@ /* Include the features available for GNU source */ #define _GNU_SOURCE -/* Include GNUnet's platform file */ -#include <gnunet/platform.h> +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifdef __clang__ +#undef HAVE_STATIC_ASSERT +#endif + +/** + * These may be expensive, but good for debugging... + */ +#define ALLOW_EXTRA_CHECKS GNUNET_YES + +/** + * For strptime (glibc2 needs this). + */ +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 499 +#endif + +#ifndef _REENTRANT +#define _REENTRANT +#endif + +/* configuration options */ + +#define VERBOSE_STATS 0 + +#include <netdb.h> +#include <sys/socket.h> +#include <sys/un.h> +#if HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#if HAVE_NETINET_IN_SYSTM_H +#include <netinet/in_systm.h> +#endif +#if HAVE_NETINET_IP_H +#include <netinet/ip.h> /* superset of previous */ +#endif +#include <arpa/inet.h> +#include <netinet/tcp.h> +#include <pwd.h> +#include <sys/ioctl.h> +#include <sys/wait.h> +#include <grp.h> + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <stdarg.h> +#include <stdbool.h> +#include <errno.h> +#include <signal.h> +#include <libgen.h> +#ifdef HAVE_MALLOC_H +#include <malloc.h> /* for mallinfo on GNU */ +#endif +#include <unistd.h> /* KLB_FIX */ +#include <sys/stat.h> +#include <sys/types.h> +#include <dirent.h> /* KLB_FIX */ +#include <fcntl.h> +#include <math.h> +#if HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif +#if HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#include <time.h> +#ifdef BSD +#include <net/if.h> +#endif +#if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) +#include <semaphore.h> +#endif +#ifdef DARWIN +#include <dlfcn.h> +#include <semaphore.h> +#include <net/if.h> +#endif +#if defined(__linux__) || defined(GNU) +#include <net/if.h> +#endif +#ifdef SOLARIS +#include <sys/sockio.h> +#include <sys/filio.h> +#include <sys/loadavg.h> +#include <semaphore.h> +#endif +#if HAVE_UCRED_H +#include <ucred.h> +#endif +#if HAVE_SYS_UCRED_H +#include <sys/ucred.h> +#endif +#if HAVE_IFADDRS_H +#include <ifaddrs.h> +#endif +#include <errno.h> +#include <limits.h> + +#if HAVE_VFORK_H +#include <vfork.h> +#endif + +#include <ctype.h> +#if HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif + +#if HAVE_ENDIAN_H +#include <endian.h> +#endif +#if HAVE_SYS_ENDIAN_H +#include <sys/endian.h> +#endif + +#define DIR_SEPARATOR '/' +#define DIR_SEPARATOR_STR "/" +#define PATH_SEPARATOR ':' +#define PATH_SEPARATOR_STR ":" +#define NEWLINE "\n" + +#include <locale.h> +#include <sys/mman.h> + +/* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */ +#if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__) +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN +#endif + +#ifdef DARWIN +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN +/* not available on darwin, override configure */ +#undef HAVE_STAT64 +#undef HAVE_MREMAP +#endif + +#if ! HAVE_ATOLL +long long +atoll (const char *nptr); + +#endif + +#if ENABLE_NLS +#include "langinfo.h" +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX ((size_t) (-1)) +#endif + +#ifndef O_LARGEFILE +#define O_LARGEFILE 0 +#endif + +/** + * AI_NUMERICSERV not defined in windows. Then we just do without. + */ +#ifndef AI_NUMERICSERV +#define AI_NUMERICSERV 0 +#endif + + +#if defined(__sparc__) +#define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \ + sizeof((val))); \ + __tmp; }) +#else +#define MAKE_UNALIGNED(val) val +#endif + + +#ifndef PATH_MAX +/** + * Assumed maximum path length. + */ +#define PATH_MAX 4096 +#endif + +#if HAVE_THREAD_LOCAL_GCC +#define GNUNET_THREAD_LOCAL __thread +#else +#define GNUNET_THREAD_LOCAL +#endif + /* Do not use shortcuts for gcrypt mpi */ #define GCRYPT_NO_MPI_MACROS 1 @@ -54,22 +243,42 @@ /* LSB-style exit status codes */ #ifndef EXIT_INVALIDARGUMENT +/** + * Command-line arguments are invalid. + * Restarting useless. + */ #define EXIT_INVALIDARGUMENT 2 #endif #ifndef EXIT_NOTIMPLEMENTED +/** + * The requested operation is not implemented. + * Restarting useless. + */ #define EXIT_NOTIMPLEMENTED 3 #endif #ifndef EXIT_NOPERMISSION +/** + * Permissions needed to run are not available. + * Restarting useless. + */ #define EXIT_NOPERMISSION 4 #endif #ifndef EXIT_NOTINSTALLED +/** + * Key resources are not installed. + * Restarting useless. + */ #define EXIT_NOTINSTALLED 5 #endif #ifndef EXIT_NOTCONFIGURED +/** + * Key configuration settings are missing or invalid. + * Restarting useless. + */ #define EXIT_NOTCONFIGURED 6 #endif @@ -78,6 +287,15 @@ #endif +#ifndef EXIT_NO_RESTART +/** + * Exit code from 'main' if we do not want to be restarted, + * except by manual intervention (hard failure). + */ +#define EXIT_NO_RESTART 9 +#endif + + /* Ignore MHD deprecations for now as we want to be compatible to "ancient" MHD releases. */ #define MHD_NO_DEPRECATION 1 diff --git a/src/include/sync_database_lib.h b/src/include/sync_database_lib.h index 2a67ec3..3311ce2 100644 --- a/src/include/sync_database_lib.h +++ b/src/include/sync_database_lib.h @@ -35,7 +35,7 @@ SYNC_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg); /** * Shutdown the plugin. * - * @param plugin plugin to unload + * @param[in] plugin plugin to unload */ void SYNC_DB_plugin_unload (struct SYNC_DatabasePlugin *plugin); diff --git a/src/include/sync_service.h b/src/include/sync_service.h index 8b47f33..1aac1cd 100644 --- a/src/include/sync_service.h +++ b/src/include/sync_service.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2019 Taler Systems SA + Copyright (C) 2019-2023 Taler Systems SA Anastasis is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -138,19 +138,40 @@ enum SYNC_UploadStatus */ struct SYNC_UploadDetails { + + /** + * Taler error code. + */ + enum TALER_ErrorCode ec; + + /** + * HTTP status of the request. + */ + unsigned int http_status; + /** * High level status of the upload operation. */ enum SYNC_UploadStatus us; + /** + * Details depending on @e us. + */ union { /** - * Hash of the synchronized backup, returned if - * @e us is #SYNC_US_SUCCESS. + * Data returned if @e us is #SYNC_US_SUCCESS. */ - const struct GNUNET_HashCode *curr_backup_hash; + struct + { + + /** + * Hash of the synchronized backup. + */ + const struct GNUNET_HashCode *curr_backup_hash; + + } success; /** * Previous backup. Returned if @e us is @@ -177,11 +198,15 @@ struct SYNC_UploadDetails } recovered_backup; - /** - * A taler://pay/-URI with a request to pay the annual fee for - * the service. Returned if @e us is #SYNC_US_PAYMENT_REQUIRED. - */ - const char *payment_request; + struct + { + /** + * A taler://pay/-URI with a request to pay the annual fee for + * the service. Returned if @e us is #SYNC_US_PAYMENT_REQUIRED. + */ + const char *payment_request; + + } payment_required; } details; @@ -192,14 +217,10 @@ struct SYNC_UploadDetails * Function called with the results of a #SYNC_upload(). * * @param cls closure - * @param ec Taler error code - * @param http_status HTTP status of the request * @param ud details about the upload operation */ typedef void (*SYNC_UploadCallback)(void *cls, - enum TALER_ErrorCode ec, - unsigned int http_status, const struct SYNC_UploadDetails *ud); @@ -256,8 +277,8 @@ enum SYNC_PaymentOptions * @param backup_size number of bytes in @a backup * @param backup the encrypted backup, must remain in * memory until we are done with the operation! - * @param payment_requested #GNUNET_YES if the client wants to pay more for the account now * @param po payment options + * @param paid_order_id ID of the paid order, NULL if no payment was made so far * @param cb function to call with the result * @param cb_cls closure for @a cb * @return handle for the operation @@ -280,7 +301,7 @@ SYNC_upload (struct GNUNET_CURL_Context *ctx, * that it did not complete, it is possible that the server did * receive the full request before the upload is aborted. * - * @param uo operation to cancel. + * @param[in] uo operation to cancel. */ void SYNC_upload_cancel (struct SYNC_UploadOperation *uo); @@ -291,50 +312,63 @@ SYNC_upload_cancel (struct SYNC_UploadOperation *uo); */ struct SYNC_DownloadDetails { - /** - * Signature (already verified). - */ - struct SYNC_AccountSignatureP sig; /** - * Hash of the previous version. + * HTTP status code. */ - struct GNUNET_HashCode prev_backup_hash; + unsigned int http_status; /** - * Hash over @e backup and @e backup_size. + * Details depending on @e http_status. */ - struct GNUNET_HashCode curr_backup_hash; + union + { - /** - * The backup we downloaded. - */ - const void *backup; + /** + * Details if status is #MHD_HTTP_OK. + */ + struct + { - /** - * Number of bytes in @e backup. - */ - size_t backup_size; + /** + * Signature (already verified). + */ + struct SYNC_AccountSignatureP sig; + + /** + * Hash of the previous version. + */ + struct GNUNET_HashCode prev_backup_hash; + + /** + * Hash over @e backup and @e backup_size. + */ + struct GNUNET_HashCode curr_backup_hash; + + /** + * The backup we downloaded. + */ + const void *backup; + + /** + * Number of bytes in @e backup. + */ + size_t backup_size; + } ok; + + } details; }; + /** * Function called with the results of a #SYNC_download(). * * @param cls closure - * @param sig signature of the account owner, affirming the - * integrity of the backup (already verified) - * @param prev_backup_hash hash of the previous backup (used - * to verify the signature, could be used by clients - * to verify backup chains) - * @param curr_backup_hash hash over @a backup (verified) - * @param backup_size number of bytes in @a backup - * @param backup the latest backup as downloaded from the - * server and affirmed by @a sig + * @param dd download details */ typedef void (*SYNC_DownloadCallback)(void *cls, - unsigned int http_status, const struct SYNC_DownloadDetails *dd); @@ -365,7 +399,7 @@ SYNC_download (struct GNUNET_CURL_Context *ctx, /** * Cancel the download. * - * @param do operation to cancel. + * @param[in] download operation to cancel. */ void SYNC_download_cancel (struct SYNC_DownloadOperation *download); diff --git a/src/include/sync_testing_lib.h b/src/include/sync_testing_lib.h index 5a0d657..f0737de 100644 --- a/src/include/sync_testing_lib.h +++ b/src/include/sync_testing_lib.h @@ -29,124 +29,6 @@ #include <taler/taler_testing_lib.h> #include <microhttpd.h> -/** - * Index used in #SYNC_TESTING_get_trait_hash() for the current hash. - */ -#define SYNC_TESTING_TRAIT_HASH_CURRENT 0 - -/** - * Index used in #SYNC_TESTING_get_trait_hash() for the previous hash. - */ -#define SYNC_TESTING_TRAIT_HASH_PREVIOUS 1 - - -/** - * Obtain a hash from @a cmd. - * - * @param cmd command to extract the number from. - * @param index the number's index number, #SYNC_TESTING_TRAIT_HASH_CURRENT or - * #SYNC_TESTING_TRAIT_HASH_PREVIOUS - * @param h[out] set to the hash coming from @a cmd. - * @return #GNUNET_OK on success. - */ -int -SYNC_TESTING_get_trait_hash (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct GNUNET_HashCode **h); - - -/** - * Offer a hash. - * - * @param index the number's index number. - * @param h the hash to offer. - * @return #GNUNET_OK on success. - */ -struct TALER_TESTING_Trait -SYNC_TESTING_make_trait_hash (unsigned int index, - const struct GNUNET_HashCode *h); - - -/** - * Obtain an account public key from @a cmd. - * - * @param cmd command to extract the public key from. - * @param index usually 0 - * @param pub[out] set to the account public key used in @a cmd. - * @return #GNUNET_OK on success. - */ -int -SYNC_TESTING_get_trait_account_pub (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct SYNC_AccountPublicKeyP **pub); - - -/** - * Offer an account public key. - * - * @param index usually zero - * @param h the account_pub to offer. - * @return #GNUNET_OK on success. - */ -struct TALER_TESTING_Trait -SYNC_TESTING_make_trait_account_pub (unsigned int index, - const struct SYNC_AccountPublicKeyP *h); - - -/** - * Obtain an account private key from @a cmd. - * - * @param cmd command to extract the number from. - * @param index must be 0 - * @param priv[out] set to the account private key used in @a cmd. - * @return #GNUNET_OK on success. - */ -int -SYNC_TESTING_get_trait_account_priv (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct - SYNC_AccountPrivateKeyP **priv); - - -/** - * Offer an account private key. - * - * @param index usually zero - * @param priv the account_priv to offer. - * @return #GNUNET_OK on success. - */ -struct TALER_TESTING_Trait -SYNC_TESTING_make_trait_account_priv (unsigned int index, - const struct - SYNC_AccountPrivateKeyP *priv); - - -/** - * Start the sync backend process. Assume the port - * is available and the database is clean. Use the "prepare - * sync" function to do such tasks. - * - * @param config_filename configuration filename. - * - * @return the process, or NULL if the process could not - * be started. - */ -struct GNUNET_OS_Process * -SYNC_TESTING_run_sync (const char *config_filename, - const char *sync_url); - - -/** - * Prepare the sync execution. Create tables and check if - * the port is available. - * - * @param config_filename configuration filename. - * @return the base url, or NULL upon errors. Must be freed - * by the caller. - */ -char * -SYNC_TESTING_prepare_sync (const char *config_filename); - /** * Make the "backup download" command for a non-existent upload. @@ -234,4 +116,20 @@ SYNC_TESTING_cmd_backup_upload (const char *label, const void *backup_data, size_t backup_data_size); +/** + * Call @a op on all simple traits. + * + * @param op macro to call + */ +#define SYNC_TESTING_SIMPLE_TRAITS(op) \ + op (account_pub, const struct SYNC_AccountPublicKeyP) \ + op (account_priv, const struct SYNC_AccountPrivateKeyP) \ + op (prev_hash, const struct GNUNET_HashCode) \ + op (curr_hash, const struct GNUNET_HashCode) + + +/* FIXME: eventually switch to libgnunettesting with the SYNC_ prefix for + the symbols instead of TALER_TESTING_! */ +SYNC_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT) + #endif |