sync_api_block_operation_common.h (4789B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU Lesser General Public License as 7 published by the Free Software Foundation; either version 2.1, 8 or (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with TALER; see the file COPYING.LGPL. If not, 17 see <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file lib/sync_api_block_operation_common.h 21 * @brief Internal declarations shared between block append, 22 * block update, and block delete implementations. 23 * @author Iván Ávalos 24 */ 25 #ifndef SYNC_BLOCK_OPERATION_COMMON_H 26 #define SYNC_BLOCK_OPERATION_COMMON_H 27 28 #include "platform.h" 29 #include <curl/curl.h> 30 #include <jansson.h> 31 #include <microhttpd.h> 32 #include <gnunet/gnunet_util_lib.h> 33 #include <gnunet/gnunet_curl_lib.h> 34 #include <gnunet/gnunet_json_lib.h> 35 #include <taler/taler_signatures.h> 36 #include <taler/taler_json_lib.h> 37 #include <taler/taler_curl_lib.h> 38 #include <sync/sync_service.h> 39 #include <sync/sync_signatures.h> 40 #include <sync/sync_util.h> 41 #include "sync_api_curl_defaults.h" 42 43 44 /** 45 * Internal: full definition of the block operation handle. 46 */ 47 struct SYNC_BlockOperation 48 { 49 50 /** 51 * The url for this request. 52 */ 53 char *url; 54 55 /** 56 * Handle for the request. 57 */ 58 struct GNUNET_CURL_Job *job; 59 60 /** 61 * Reference to the execution context. 62 */ 63 struct GNUNET_CURL_Context *ctx; 64 65 /** 66 * Function to call with the result. 67 */ 68 SYNC_BlockOperationCallback cb; 69 70 /** 71 * Closure for @e cb. 72 */ 73 void *cb_cls; 74 75 /** 76 * Context for the POST body. 77 */ 78 struct TALER_CURL_PostContext post_ctx; 79 80 /** 81 * Payment URI from the "Taler" header, or NULL. 82 */ 83 char *pay_uri; 84 85 }; 86 87 88 /** 89 * Build the URL of a resource under the account of @a priv. 90 * 91 * @param base_url base URL of the Sync server 92 * @param priv private key of the account 93 * @param collection collection under the account, e.g. "blocks" 94 * @param id_size number of bytes in @a id 95 * @param id identifier of the resource within @a collection 96 * @return the full URL, to be freed by the caller 97 */ 98 char * 99 SYNC_block_operation_make_url_ ( 100 const char *base_url, 101 const struct SYNC_AccountPrivateKeyP *priv, 102 const char *collection, 103 size_t id_size, 104 const void *id); 105 106 107 /** 108 * Append an ETag-style header with the base32-encoded @a hash 109 * as its value to the headers of @a op. 110 * 111 * @param[in,out] op operation to add the header to 112 * @param header name of the header to add 113 * @param hash hash to encode as the header value 114 */ 115 void 116 SYNC_block_operation_add_etag_ ( 117 struct SYNC_BlockOperation *op, 118 const char *header, 119 const struct GNUNET_HashCode *hash); 120 121 122 /** 123 * Internal shared helper that implements block append, update and 124 * delete. 125 * 126 * @param ctx for HTTP client request processing 127 * @param base_url base URL of the Sync server 128 * @param priv private key of the account 129 * @param args operation parameters (including relinks) 130 * @param cb function to call with the result 131 * @param cb_cls closure for @a cb 132 * @param is_delete true to send DELETE instead of POST/PUT 133 * @return handle for the operation 134 */ 135 struct SYNC_BlockOperation * 136 SYNC_block_operation_internal_ ( 137 struct GNUNET_CURL_Context *ctx, 138 const char *base_url, 139 const struct SYNC_AccountPrivateKeyP *priv, 140 const struct SYNC_BlockOperationArgs *args, 141 SYNC_BlockOperationCallback cb, 142 void *cb_cls, 143 bool is_delete); 144 145 146 /** 147 * Handle HTTP header received by curl. Shared between block 148 * append, update, and delete implementations. 149 * 150 * @param buffer one line of HTTP header data 151 * @param size size of an item 152 * @param nitems number of items passed 153 * @param userdata our `struct SYNC_BlockOperation *` 154 * @return `size * nitems` 155 */ 156 size_t 157 SYNC_block_operation_handle_header_ (char *buffer, 158 size_t size, 159 size_t nitems, 160 void *userdata); 161 162 163 /** 164 * Function called when we're done processing the 165 * HTTP /backups/$KEY/blocks request. Shared between 166 * block append, update, and delete. 167 * 168 * @param cls the `struct SYNC_BlockOperation` 169 * @param response_code HTTP response code, 0 on error 170 * @param response response body parsed as JSON, or NULL 171 */ 172 void 173 SYNC_block_operation_handle_finished_ (void *cls, 174 long response_code, 175 const void *response); 176 177 178 #endif