From bb81464ede13b1cba93cd031de466bbc8c18f04f Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Sun, 23 Oct 2022 15:00:54 +0900 Subject: NAMESTORE: Introduce GANA-managed error codes --- src/include/.gitignore | 1 + src/include/gnunet_namestore_service.h | 6 +- src/include/gnunet_util_lib.h | 1 + src/namecache/namecache.h | 5 - src/namestore/gnunet-namestore-fcfsd.c | 17 +- src/namestore/gnunet-namestore-zonefile.c | 12 +- src/namestore/gnunet-namestore.c | 61 +----- src/namestore/gnunet-service-namestore.c | 140 ++++++------- src/namestore/gnunet-zoneimport.c | 18 +- src/namestore/namestore.h | 37 +--- src/namestore/namestore_api.c | 80 +++----- src/namestore/perf_namestore_api_import.c | 25 +-- src/namestore/perf_namestore_api_zone_iteration.c | 5 +- src/namestore/plugin_rest_namestore.c | 221 ++++++--------------- src/namestore/test_namestore_api_edit_records.c | 29 ++- src/namestore/test_namestore_api_lookup_nick.c | 10 +- src/namestore/test_namestore_api_monitoring.c | 5 +- .../test_namestore_api_monitoring_existing.c | 5 +- src/namestore/test_namestore_api_remove.c | 16 +- ...test_namestore_api_remove_not_existing_record.c | 16 +- src/namestore/test_namestore_api_store.c | 4 +- src/namestore/test_namestore_api_store_update.c | 8 +- src/namestore/test_namestore_api_tx_rollback.c | 21 +- src/namestore/test_namestore_api_zone_iteration.c | 7 +- .../test_namestore_api_zone_iteration_nick.c | 16 +- ...st_namestore_api_zone_iteration_specific_zone.c | 7 +- .../test_namestore_api_zone_iteration_stop.c | 6 +- src/namestore/test_namestore_api_zone_to_name.c | 8 +- src/reclaim/did_core.c | 7 +- src/reclaim/gnunet-did.c | 9 +- src/reclaim/gnunet-service-reclaim.c | 26 +-- src/reclaim/gnunet-service-reclaim_tickets.c | 27 +-- src/util/.gitignore | 1 + src/util/Makefile.am | 3 +- 34 files changed, 324 insertions(+), 536 deletions(-) (limited to 'src') diff --git a/src/include/.gitignore b/src/include/.gitignore index 6c12255e5..866878f87 100644 --- a/src/include/.gitignore +++ b/src/include/.gitignore @@ -1,2 +1,3 @@ +gnunet_error_codes.h gnu_name_system_record_types.h gnunet_signatures.h diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index f08c4746b..39449be5d 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -41,6 +41,7 @@ #ifndef GNUNET_NAMESTORE_SERVICE_H #define GNUNET_NAMESTORE_SERVICE_H +#include "gnunet_error_codes.h" #include "gnunet_util_lib.h" #include "gnunet_block_lib.h" #include "gnunet_gnsrecord_lib.h" @@ -122,12 +123,11 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h); * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) * #GNUNET_NO if content was already there or not found * #GNUNET_YES (or other positive value) on success - * @param emsg NULL on success, otherwise an error message + * @param ec the #GNUNET_ErrorCode, #GNUNET_EC_NONE on success. */ typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls, - int32_t success, - const char *emsg); + enum GNUNET_ErrorCode ec); /** diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h index cc4f3a01e..ee362f789 100644 --- a/src/include/gnunet_util_lib.h +++ b/src/include/gnunet_util_lib.h @@ -86,6 +86,7 @@ extern "C" #include "gnunet_dnsstub_lib.h" #include "gnunet_dnsparser_lib.h" #include "gnunet_child_management_lib.h" +#include "gnunet_error_codes.h" #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/namecache/namecache.h b/src/namecache/namecache.h index 4c809b4d1..5ed4edd34 100644 --- a/src/namecache/namecache.h +++ b/src/namecache/namecache.h @@ -113,11 +113,6 @@ struct BlockCacheMessage */ struct GNUNET_TIME_AbsoluteNBO expire; - /** - * Signature. - */ - struct GNUNET_CRYPTO_EcdsaSignature signature; - /** * Derived public key. */ diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 4a9c6e874..857b16def 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c @@ -432,31 +432,24 @@ register_error_cb (void *cls) } -/** - * A name/key pair has been successfully registered, or maybe not. - * - * @param cls the connection - * @param status result of the operation - * @param emsg error message if any - */ static void register_done_cb (void *cls, - int32_t status, - const char *emsg) + enum GNUNET_ErrorCode ec) { struct RequestData *rd = cls; MHD_resume_connection (rd->c); rd->searching = NULL; - if ((GNUNET_SYSERR == status) || (GNUNET_NO == status)) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to create record for `%s': %s\n"), rd->register_name, - emsg); + GNUNET_ErrorCode_get_hint (ec)); rd->body = make_json ("error", "true", - "message", emsg, + "message", + GNUNET_ErrorCode_get_hint (ec), NULL); rd->body_length = strlen (rd->body); rd->code = MHD_HTTP_INTERNAL_SERVER_ERROR; diff --git a/src/namestore/gnunet-namestore-zonefile.c b/src/namestore/gnunet-namestore-zonefile.c index f8d876108..ff3b2a565 100644 --- a/src/namestore/gnunet-namestore-zonefile.c +++ b/src/namestore/gnunet-namestore-zonefile.c @@ -184,10 +184,10 @@ do_shutdown (void *cls) } static void -tx_end (void *cls, int32_t success, const char *emsg) +tx_end (void *cls, enum GNUNET_ErrorCode ec) { ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { fprintf (stderr, _ ("Ego `%s' not known to identity service\n"), @@ -320,10 +320,10 @@ origin_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) } static void -add_continuation (void *cls, int32_t success, const char *emsg) +add_continuation (void *cls, enum GNUNET_ErrorCode ec) { ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { fprintf (stderr, _ ("Failed to store records...\n")); @@ -646,10 +646,10 @@ parse (void *cls) } static void -tx_start (void *cls, int32_t success, const char *emsg) +tx_start (void *cls, enum GNUNET_ErrorCode ec) { ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { fprintf (stderr, _ ("Ego `%s' not known to identity service\n"), diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 9ed8f400c..a636644f8 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c @@ -318,28 +318,18 @@ test_finished () } -/** - * Continuation called to notify client about result of the - * operation. - * - * @param cls closure, location of the QueueEntry pointer to NULL out - * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) - * #GNUNET_NO if content was already there - * #GNUNET_YES (or other positive value) on success - * @param emsg NULL on success, otherwise an error message - */ static void -add_continuation (void *cls, int32_t success, const char *emsg) +add_continuation (void *cls, enum GNUNET_ErrorCode ec) { struct GNUNET_NAMESTORE_QueueEntry **qe = cls; *qe = NULL; - if (GNUNET_YES != success) + if (GNUNET_EC_NONE != ec) { fprintf (stderr, _ ("Adding record failed: %s\n"), - (GNUNET_NO == success) ? "record exists" : emsg); - if (GNUNET_NO != success) + GNUNET_ErrorCode_get_hint (ec)); + if (GNUNET_EC_NAMESTORE_RECORD_EXISTS != ec) ret = 1; } ret = 0; @@ -347,34 +337,15 @@ add_continuation (void *cls, int32_t success, const char *emsg) } -/** - * Continuation called to notify client about result of the - * operation. - * - * @param cls closure, unused - * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) - * #GNUNET_NO if content was already there - * #GNUNET_YES (or other positive value) on success - * @param emsg NULL on success, otherwise an error message - */ static void -del_continuation (void *cls, int32_t success, const char *emsg) +del_continuation (void *cls, enum GNUNET_ErrorCode ec) { (void) cls; del_qe = NULL; - if (GNUNET_NO == success) + if (GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND == ec) { fprintf (stderr, - _ ("Deleting record failed, record does not exist%s%s\n"), - (NULL != emsg) ? ": " : "", - (NULL != emsg) ? emsg : ""); - } - if (GNUNET_SYSERR == success) - { - fprintf (stderr, - _ ("Deleting record failed%s%s\n"), - (NULL != emsg) ? ": " : "", - (NULL != emsg) ? emsg : ""); + _ ("Deleting record failed: %s\n"), GNUNET_ErrorCode_get_hint (ec)); } test_finished (); } @@ -898,27 +869,17 @@ parse_expiration (const char *expirationstring, } -/** - * Function called when namestore is done with the replace - * operation. - * - * @param cls NULL - * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) - * #GNUNET_NO if content was already there or not found - * #GNUNET_YES (or other positive value) on success - * @param emsg NULL on success, otherwise an error message - */ static void -replace_cont (void *cls, int success, const char *emsg) +replace_cont (void *cls, enum GNUNET_ErrorCode ec) { (void) cls; set_qe = NULL; - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - _ ("Failed to replace records: %s\n"), - emsg); + _ ("%s\n"), + GNUNET_ErrorCode_get_hint (ec)); ret = 1; /* fail from 'main' */ } GNUNET_SCHEDULER_shutdown (); diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 7cd36f317..0c8b89a91 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -941,11 +941,12 @@ send_lookup_response (struct NamestoreClient *nc, * Send response to the store request to the client. * * @param nc client to talk to - * @param res status of the operation + * @param ec status of the operation * @param rid client's request ID */ static void -send_store_response (struct NamestoreClient *nc, int res, const char *emsg, +send_store_response (struct NamestoreClient *nc, + enum GNUNET_ErrorCode ec, uint32_t rid) { struct GNUNET_MQ_Envelope *env; @@ -958,17 +959,10 @@ send_store_response (struct NamestoreClient *nc, int res, const char *emsg, "Store requests completed", 1, GNUNET_NO); - env = GNUNET_MQ_msg_extra (rcr_msg, - (NULL != emsg) ? strlen (emsg) + 1 : 0, - GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); + env = GNUNET_MQ_msg (rcr_msg, + GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); rcr_msg->gns_header.r_id = htonl (rid); - rcr_msg->op_result = htonl (res); - rcr_msg->reserved = htons (0); - if (NULL != emsg) - { - rcr_msg->emsg_len = htons (strlen (emsg) + 1); - memcpy (&rcr_msg[1], emsg, strlen (emsg) + 1); - } + rcr_msg->ec = htonl (ec); GNUNET_MQ_send (nc->mq, env); } @@ -1043,7 +1037,7 @@ continue_store_activity (struct StoreActivity *sa, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transaction not yet committed, delaying monitor and cache updates\n"); - send_store_response (sa->nc, GNUNET_YES, NULL, sa->rid); + send_store_response (sa->nc, GNUNET_EC_NONE, sa->rid); if (GNUNET_YES == call_continue) GNUNET_SERVICE_client_continue (sa->nc->client); return GNUNET_OK; @@ -1114,7 +1108,7 @@ continue_store_activity (struct StoreActivity *sa, } if (GNUNET_YES == call_continue) GNUNET_SERVICE_client_continue (sa->nc->client); - send_store_response (sa->nc, GNUNET_YES, NULL, sa->rid); + send_store_response (sa->nc, GNUNET_EC_NONE, sa->rid); free_store_activity (sa); return GNUNET_OK; } @@ -1632,24 +1626,26 @@ get_existing_rd_exp (void *cls, } } -static enum GNUNET_GenericReturnValue +static enum GNUNET_ErrorCode store_record_set (struct NamestoreClient *nc, const struct GNUNET_IDENTITY_PrivateKey *private_key, const struct RecordSet *rd_set, - ssize_t *len, - char **emsg) + ssize_t *len) { size_t name_len; size_t rd_ser_len; const char *name_tmp; const char *rd_ser; char *conv_name; + char *emsg; unsigned int rd_count; int res; + enum GNUNET_ErrorCode ec; struct GNUNET_TIME_Absolute new_block_exp; struct LookupExistingRecordsContext lctx; *len = sizeof (struct RecordSet); + ec = GNUNET_EC_NONE; lctx.only_tombstone = GNUNET_NO; lctx.exp = GNUNET_TIME_UNIT_ZERO_ABS; new_block_exp = GNUNET_TIME_UNIT_ZERO_ABS; @@ -1670,27 +1666,26 @@ store_record_set (struct NamestoreClient *nc, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error normalizing name `%s'\n", name_tmp); - *emsg = GNUNET_strdup (_ ("Error normalizing name.")); - return GNUNET_SYSERR; + return GNUNET_EC_NAMESTORE_LABEL_INVALID; } /* Check name for validity */ - if (GNUNET_OK != GNUNET_GNSRECORD_label_check (conv_name, emsg)) + if (GNUNET_OK != GNUNET_GNSRECORD_label_check (conv_name, &emsg)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Label invalid: `%s'\n", - *emsg); + emsg); + GNUNET_free (emsg); GNUNET_free (conv_name); - return -1; + return GNUNET_EC_NAMESTORE_LABEL_INVALID; } if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (rd_ser_len, rd_ser, rd_count, rd)) { - *emsg = GNUNET_strdup (_ ("Error deserializing records.")); GNUNET_free (conv_name); - return GNUNET_SYSERR; + return GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID; } GNUNET_STATISTICS_update (statistics, @@ -1713,7 +1708,7 @@ store_record_set (struct NamestoreClient *nc, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name `%s' does not exist, no deletion required\n", conv_name); - res = GNUNET_NO; + ec = GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND; } else { @@ -1758,10 +1753,14 @@ store_record_set (struct NamestoreClient *nc, &rd_nf_count, &new_block_exp, GNUNET_GNSRECORD_FILTER_NONE, - emsg)) + &emsg)) { GNUNET_free (conv_name); - return GNUNET_SYSERR; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Error normalizing record set: `%s'\n", + emsg); + GNUNET_free (emsg); + return GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u/%u records before tombstone\n", rd_nf_count, @@ -1808,21 +1807,19 @@ store_record_set (struct NamestoreClient *nc, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client tried to remove non-existant record\n"); - *emsg = GNUNET_strdup (_ ("Not records to delete.")); - res = GNUNET_NO; + ec = GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND; } } if (GNUNET_SYSERR == res) { /* store not successful, no need to tell monitors */ - *emsg = GNUNET_strdup (_ ("Store failed")); GNUNET_free (conv_name); - return GNUNET_SYSERR; + return GNUNET_EC_NAMESTORE_STORE_FAILED; } } GNUNET_free (conv_name); - return res; + return ec; } /** @@ -1837,12 +1834,11 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) struct NamestoreClient *nc = cls; uint32_t rid; uint16_t rd_set_count; - char *emsg = NULL; const char *buf; ssize_t read; struct StoreActivity *sa; struct RecordSet *rs; - enum GNUNET_GenericReturnValue res; + enum GNUNET_ErrorCode res; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received NAMESTORE_RECORD_STORE message\n"); @@ -1853,12 +1849,10 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) { rs = (struct RecordSet *) buf; res = store_record_set (nc, &rp_msg->private_key, - rs, &read, &emsg); - if (GNUNET_OK != res) + rs, &read); + if (GNUNET_EC_NONE != res) { - send_store_response (nc, res, emsg, - rid); - GNUNET_free (emsg); + send_store_response (nc, res, rid); GNUNET_SERVICE_client_continue (nc->client); return; } @@ -1882,27 +1876,15 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) } static void -send_tx_response (int rid, int status, char *emsg, struct NamestoreClient *nc) +send_tx_response (int rid, enum GNUNET_ErrorCode ec, struct NamestoreClient *nc) { struct TxControlResultMessage *txr_msg; struct GNUNET_MQ_Envelope *env; - char *err_tmp; - size_t err_len; - err_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; env = - GNUNET_MQ_msg_extra (txr_msg, - err_len, - GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT); - txr_msg->gns_header.header.size = htons (sizeof (struct - TxControlResultMessage) - + err_len); + GNUNET_MQ_msg (txr_msg, GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT); txr_msg->gns_header.r_id = rid; - txr_msg->success = htons (status); - err_tmp = (char *) &txr_msg[1]; - GNUNET_memcpy (err_tmp, emsg, err_len); - if (NULL != emsg) - GNUNET_free (emsg); + txr_msg->ec = htonl (ec); GNUNET_MQ_send (nc->mq, env); } @@ -1929,14 +1911,31 @@ handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) case GNUNET_NAMESTORE_TX_BEGIN: ret = nc->GSN_database->transaction_begin (nc->GSN_database->cls, &emsg); - send_tx_response (tx_msg->gns_header.r_id, ret, emsg, nc); + send_tx_response (tx_msg->gns_header.r_id, + (GNUNET_SYSERR == ret) ? + GNUNET_EC_NAMESTORE_BACKEND_FAILED : GNUNET_EC_NONE, nc); + if (GNUNET_SYSERR == ret) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Databse backend error: `%s'", emsg); + GNUNET_free (emsg); + } GNUNET_SERVICE_client_continue (nc->client); nc->in_transaction = GNUNET_YES; break; case GNUNET_NAMESTORE_TX_COMMIT: ret = nc->GSN_database->transaction_commit (nc->GSN_database->cls, &emsg); - send_tx_response (tx_msg->gns_header.r_id, ret, emsg, nc); + send_tx_response (tx_msg->gns_header.r_id, + (GNUNET_SYSERR == ret) ? + GNUNET_EC_NAMESTORE_BACKEND_FAILED : GNUNET_EC_NONE, + nc); + if (GNUNET_SYSERR == ret) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Databse backend error: `%s'", emsg); + GNUNET_free (emsg); + } if (GNUNET_SYSERR != ret) { nc->in_transaction = GNUNET_NO; @@ -1961,8 +1960,16 @@ handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) case GNUNET_NAMESTORE_TX_ROLLBACK: ret = nc->GSN_database->transaction_rollback (nc->GSN_database->cls, &emsg); - send_tx_response (tx_msg->gns_header.r_id, ret, emsg, nc); + send_tx_response (tx_msg->gns_header.r_id, + (GNUNET_SYSERR == ret) ? + GNUNET_EC_NAMESTORE_BACKEND_FAILED : GNUNET_EC_NONE, nc); GNUNET_SERVICE_client_continue (nc->client); + if (GNUNET_SYSERR == ret) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Databse backend error: `%s'", emsg); + GNUNET_free (emsg); + } if (GNUNET_SYSERR != ret) { nc->in_transaction = GNUNET_NO; @@ -2010,7 +2017,7 @@ struct ZoneToNameCtx * not finding a name for the zone still counts as a 'success' here, * as this field is about the success of executing the IPC protocol. */ - int success; + enum GNUNET_ErrorCode ec; }; @@ -2035,7 +2042,6 @@ handle_zone_to_name_it (void *cls, struct ZoneToNameCtx *ztn_ctx = cls; struct GNUNET_MQ_Envelope *env; struct ZoneToNameResponseMessage *ztnr_msg; - int16_t res; size_t name_len; ssize_t rd_ser_len; size_t msg_size; @@ -2046,20 +2052,20 @@ handle_zone_to_name_it (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found result for zone-to-name lookup: `%s'\n", name); - res = GNUNET_YES; + ztn_ctx->ec = GNUNET_EC_NONE; name_len = (NULL == name) ? 0 : strlen (name) + 1; rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); if (rd_ser_len < 0) { GNUNET_break (0); - ztn_ctx->success = GNUNET_SYSERR; + ztn_ctx->ec = htonl (GNUNET_EC_NAMESTORE_UNKNOWN); return; } msg_size = sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len; if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) { GNUNET_break (0); - ztn_ctx->success = GNUNET_SYSERR; + ztn_ctx->ec = GNUNET_EC_NAMESTORE_RECORD_TOO_BIG; return; } env = @@ -2068,7 +2074,7 @@ handle_zone_to_name_it (void *cls, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); ztnr_msg->gns_header.header.size = htons (msg_size); ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); - ztnr_msg->res = htons (res); + ztnr_msg->ec = htonl (ztn_ctx->ec); ztnr_msg->rd_len = htons (rd_ser_len); ztnr_msg->rd_count = htons (rd_count); ztnr_msg->name_len = htons (name_len); @@ -2079,7 +2085,7 @@ handle_zone_to_name_it (void *cls, GNUNET_assert ( rd_ser_len == GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_tmp)); - ztn_ctx->success = GNUNET_OK; + ztn_ctx->ec = GNUNET_EC_NONE; GNUNET_MQ_send (ztn_ctx->nc->mq, env); } @@ -2101,7 +2107,7 @@ handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME message\n"); ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); ztn_ctx.nc = nc; - ztn_ctx.success = GNUNET_NO; + ztn_ctx.ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; if (GNUNET_SYSERR == nc->GSN_database->zone_to_name (nc->GSN_database->cls, &ztn_msg->zone, &ztn_msg->value_zone, @@ -2114,7 +2120,7 @@ handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) GNUNET_SERVICE_client_drop (nc->client); return; } - if (GNUNET_NO == ztn_ctx.success) + if (GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND == ztn_ctx.ec) { /* no result found, send empty response */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2122,7 +2128,7 @@ handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) env = GNUNET_MQ_msg (ztnr_msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id; - ztnr_msg->res = htons (GNUNET_NO); + ztnr_msg->ec = htonl (GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND); GNUNET_MQ_send (nc->mq, env); } GNUNET_SERVICE_client_continue (nc->client); diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index 9ae0fb146..0094baf0e 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c @@ -924,36 +924,26 @@ process_record (void *cls, const struct GNUNET_DNSPARSER_Record *rec) } -/** - * Continuation called to notify client about result of the - * operation. - * - * @param cls closure with our `struct Request` - * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) - * #GNUNET_NO if content was already there or not found - * #GNUNET_YES (or other positive value) on success - * @param emsg NULL on success, otherwise an error message - */ static void -store_completed_cb (void *cls, int32_t success, const char *emsg) +store_completed_cb (void *cls, enum GNUNET_ErrorCode ec) { static struct GNUNET_TIME_Absolute last; struct Request *req = cls; req->qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to store zone data for `%s': %s\n", req->hostname, - emsg); + GNUNET_ErrorCode_get_hint (ec)); } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored records under `%s' (%d)\n", req->hostname, - success); + ec); } total_reg_proc_dns_ns++; /* finished regular processing */ pending_rs--; diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index ea35269a4..37c1576bc 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h @@ -117,23 +117,10 @@ struct RecordStoreResponseMessage struct GNUNET_NAMESTORE_Header gns_header; /** - * #GNUNET_SYSERR on failure, #GNUNET_OK on success + * GNUNET_ErrorCode */ - int32_t op_result GNUNET_PACKED; + uint32_t ec GNUNET_PACKED; - /** - * Error message length - */ - uint16_t emsg_len GNUNET_PACKED; - - /** - * Reserved for alignment. - */ - uint16_t reserved GNUNET_PACKED; - - /** - * Followed by error message - */ }; @@ -264,10 +251,12 @@ struct ZoneToNameResponseMessage uint16_t rd_count GNUNET_PACKED; /** - * result in NBO: #GNUNET_OK on success, #GNUNET_NO if there were no - * results, #GNUNET_SYSERR on error + * result in NBO: #GNUNET_EC_NONE on success, + * #GNUNET_EC_NAMESTORE_NO_RESULTS if there were no + * results. + * Other error messages on error. */ - int16_t res GNUNET_PACKED; + int32_t ec GNUNET_PACKED; /** * The private key of the zone that contained the name. @@ -361,18 +350,10 @@ struct TxControlResultMessage struct GNUNET_NAMESTORE_Header gns_header; /** - * The type of control message to send - */ - uint16_t control GNUNET_PACKED; - - /** - * Of type GNUNET_GenericReturnValue + * Of type GNUNET_ErrorCode */ - uint16_t success GNUNET_PACKED; + uint32_t ec GNUNET_PACKED; - /* followed by: - * an error message if status != ntohs(GNUNET_OK) - */ }; diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 5111deee9..5c6bf73eb 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -27,6 +27,7 @@ */ #include "platform.h" +#include "gnunet_error_codes.h" #include "gnunet_util_lib.h" #include "gnunet_crypto_lib.h" #include "gnunet_constants.h" @@ -368,25 +369,11 @@ static int check_record_store_response (void *cls, const struct RecordStoreResponseMessage *msg) { - const char *emsg; size_t msg_len; - size_t emsg_len; (void) cls; msg_len = ntohs (msg->gns_header.header.size); - emsg_len = ntohs (msg->emsg_len); - if (0 != ntohs (msg->reserved)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - if (msg_len != sizeof(struct RecordStoreResponseMessage) + emsg_len) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - emsg = (const char *) &msg[1]; - if ((0 != emsg_len) && ('\0' != emsg[emsg_len - 1])) + if (msg_len != sizeof(struct RecordStoreResponseMessage)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -408,20 +395,17 @@ handle_record_store_response (void *cls, { struct GNUNET_NAMESTORE_Handle *h = cls; struct GNUNET_NAMESTORE_QueueEntry *qe; - int res; - const char *emsg; + enum GNUNET_ErrorCode res; qe = find_qe (h, ntohl (msg->gns_header.r_id)); - emsg = (const char *) &msg[1]; - res = ntohl (msg->op_result); + res = ntohl (msg->ec); LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_STORE_RESPONSE with result %d\n", res); if (NULL == qe) return; if (NULL != qe->cont) - qe->cont (qe->cont_cls, res, - (GNUNET_OK == res) ? NULL : emsg); + qe->cont (qe->cont_cls, res); free_qe (qe); } @@ -705,7 +689,7 @@ check_tx_control_result (void *cls, (void) cls; err_len = ntohs (msg->gns_header.header.size) - sizeof (struct TxControlResultMessage); - if ((GNUNET_YES == ntohs (msg->success)) && (err_len > 0)) + if ((GNUNET_EC_NONE == ntohs (msg->ec)) && (err_len > 0)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -725,20 +709,17 @@ handle_tx_control_result (void *cls, { struct GNUNET_NAMESTORE_Handle *h = cls; struct GNUNET_NAMESTORE_QueueEntry *qe; - int res; - const char *emsg; + enum GNUNET_ErrorCode res; qe = find_qe (h, ntohl (msg->gns_header.r_id)); - emsg = (const char *) &msg[1]; - res = ntohs (msg->success); + res = ntohs (msg->ec); LOG (GNUNET_ERROR_TYPE_DEBUG, "Received TX_CONTROL_RESULT with result %d\n", res); if (NULL == qe) return; if (NULL != qe->cont) - qe->cont (qe->cont_cls, res, - (GNUNET_YES == res) ? NULL : emsg); + qe->cont (qe->cont_cls, res); free_qe (qe); } @@ -759,7 +740,7 @@ check_zone_to_name_response (void *cls, const char *name_tmp; (void) cls; - if (GNUNET_OK != ntohs (msg->res)) + if (GNUNET_EC_NONE != ntohl (msg->ec)) return GNUNET_OK; name_len = ntohs (msg->name_len); rd_ser_len = ntohs (msg->rd_len); @@ -792,7 +773,7 @@ handle_zone_to_name_response (void *cls, { struct GNUNET_NAMESTORE_Handle *h = cls; struct GNUNET_NAMESTORE_QueueEntry *qe; - int res; + enum GNUNET_ErrorCode res; size_t name_len; size_t rd_ser_len; unsigned int rd_count; @@ -807,15 +788,12 @@ handle_zone_to_name_response (void *cls, "Response queue already gone...\n"); return; } - res = ntohs (msg->res); + res = ntohl (msg->ec); switch (res) { - case GNUNET_SYSERR: - LOG (GNUNET_ERROR_TYPE_DEBUG, - "An error occurred during zone to name operation\n"); - break; + break; - case GNUNET_NO: + case GNUNET_EC_NAMESTORE_NO_RESULTS: LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n"); if (NULL != qe->proc) @@ -823,7 +801,7 @@ handle_zone_to_name_response (void *cls, free_qe (qe); return; - case GNUNET_YES: + case GNUNET_EC_NONE: LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has result for zone to name mapping \n"); name_len = ntohs (msg->name_len); @@ -848,9 +826,10 @@ handle_zone_to_name_response (void *cls, } default: - GNUNET_break (0); - force_reconnect (h); - return; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "An error occurred during zone to name operation: %s\n", + GNUNET_ErrorCode_get_hint (res)); + break; } /* error case, call continuation with error */ if (NULL != qe->error_cb) @@ -886,10 +865,10 @@ static void reconnect (struct GNUNET_NAMESTORE_Handle *h) { struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size (record_store_response, - GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, - struct RecordStoreResponseMessage, - h), + { GNUNET_MQ_hd_fixed_size (record_store_response, + GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, + struct RecordStoreResponseMessage, + h), GNUNET_MQ_hd_var_size (zone_to_name_response, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE, struct ZoneToNameResponseMessage, @@ -906,10 +885,10 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h) GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, struct LabelLookupResponseMessage, h), - GNUNET_MQ_hd_var_size (tx_control_result, - GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT, - struct TxControlResultMessage, - h), + GNUNET_MQ_hd_fixed_size (tx_control_result, + GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT, + struct TxControlResultMessage, + h), GNUNET_MQ_handler_end () }; struct GNUNET_NAMESTORE_ZoneIterator *it; struct GNUNET_NAMESTORE_QueueEntry *qe; @@ -973,8 +952,7 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h) qe->error_cb (qe->error_cb_cls); if (NULL != qe->cont) qe->cont (qe->cont_cls, - GNUNET_SYSERR, - "failure in communication with namestore service"); + GNUNET_EC_NAMESTORE_UNKNOWN); free_qe (qe); } @@ -1078,7 +1056,7 @@ warn_delay (void *cls) GNUNET_YES)); if (NULL != qe->cont) { - qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout"); + qe->cont (qe->cont_cls, GNUNET_EC_NAMESTORE_UNKNOWN); qe->cont = NULL; } GNUNET_NAMESTORE_cancel (qe); diff --git a/src/namestore/perf_namestore_api_import.c b/src/namestore/perf_namestore_api_import.c index 0bc70b70b..4452de16c 100644 --- a/src/namestore/perf_namestore_api_import.c +++ b/src/namestore/perf_namestore_api_import.c @@ -151,14 +151,13 @@ publish_records_single (void *cls); static void commit_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { struct GNUNET_TIME_Relative delay; (void) cls; qe = NULL; - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); @@ -181,11 +180,10 @@ publish_records_bulk_tx (void *cls); static void put_cont_bulk_tx (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { qe = NULL; - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); @@ -219,8 +217,7 @@ publish_records_bulk_tx (void *cls) static void begin_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { unsigned int sent_rds; qe = GNUNET_NAMESTORE_records_store2 (nsh, @@ -239,14 +236,13 @@ publish_records_bulk (void *cls); static void put_cont_bulk (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { struct GNUNET_TIME_Relative delay; (void) cls; qe = NULL; - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); @@ -268,7 +264,7 @@ put_cont_bulk (void *cls, } (void) cls; qe = NULL; - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); @@ -297,13 +293,12 @@ publish_records_bulk (void *cls) static void put_cont_single (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { struct GNUNET_TIME_Relative delay; (void) cls; qe = NULL; - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c index ce1cddf87..33868784f 100644 --- a/src/namestore/perf_namestore_api_zone_iteration.c +++ b/src/namestore/perf_namestore_api_zone_iteration.c @@ -266,12 +266,11 @@ publish_record (void *cls); static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { (void) cls; qe = NULL; - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index fcc6068e8..05495c23b 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c @@ -25,6 +25,7 @@ */ #include "platform.h" +#include "gnunet_error_codes.h" #include "gnunet_rest_plugin.h" #include "gnunet_gns_service.h" #include "gnunet_namestore_service.h" @@ -44,37 +45,6 @@ */ #define GNUNET_REST_API_NS_NAMESTORE_IMPORT "/namestore/import" -/** - * Error message Unknown Error - */ -#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error" - -/** - * Error message No identity found - */ -#define GNUNET_REST_IDENTITY_NOT_FOUND "Zone not found" - -/** - * Error message No record found - */ -#define GNUNET_REST_RECORD_NOT_FOUND "Record not found" - - -/** - * Error message Failed request - */ -#define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed" - -/** - * Error message invalid data - */ -#define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid" - -/** - * Error message No data - */ -#define GNUNET_REST_NAMESTORE_NO_DATA "No data" - /** * State while collecting all egos */ @@ -287,14 +257,10 @@ struct RequestHandle char *url; /** - * Error response message + * Error code */ - char *emsg; + enum GNUNET_ErrorCode ec; - /** - * Response code - */ - int response_code; }; /** @@ -327,8 +293,6 @@ cleanup_handle (void *cls) GNUNET_free (handle->record_name); if (NULL != handle->url) GNUNET_free (handle->url); - if (NULL != handle->emsg) - GNUNET_free (handle->emsg); if (NULL != handle->rd) { for (int i = 0; i < handle->rd_count; i++) @@ -369,20 +333,22 @@ do_error (void *cls) struct MHD_Response *resp; json_t *json_error = json_object (); char *response; + const char* emsg; + int response_code; - if (NULL == handle->emsg) - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_ERROR_UNKNOWN); - - json_object_set_new (json_error, "error", json_string (handle->emsg)); + if (0 != handle->ec) + emsg = GNUNET_strdup (GNUNET_ErrorCode_get_hint (handle->ec)); + json_object_set_new (json_error, "error", json_string (emsg)); - if (0 == handle->response_code) - handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; + response_code = GNUNET_ErrorCode_get_http_status (handle->ec); + if (0 == response_code) + response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; response = json_dumps (json_error, 0); resp = GNUNET_REST_create_response (response); GNUNET_assert (MHD_YES == MHD_add_response_header (resp, "Content-Type", "application/json")); - handle->proc (handle->proc_cls, resp, handle->response_code); + handle->proc (handle->proc_cls, resp, response_code); json_decref (json_error); GNUNET_free (response); cleanup_handle (handle); @@ -433,35 +399,22 @@ namestore_iteration_error (void *cls) { struct RequestHandle *handle = cls; - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_ITERATION_FAILED; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } -/** - * Create finished callback - * - * @param cls the `struct RequestHandle` - * @param success the success indicating integer, GNUNET_OK on success - * @param emsg the error message (can be NULL) - */ static void -create_finished (void *cls, int32_t success, const char *emsg) +create_finished (void *cls, enum GNUNET_ErrorCode ec) { struct RequestHandle *handle = cls; struct MHD_Response *resp; handle->ns_qe = NULL; - if (GNUNET_YES != success) + handle->ec = ec; + if (GNUNET_EC_NONE != ec) { - if (NULL != emsg) - { - handle->emsg = GNUNET_strdup (emsg); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - handle->emsg = GNUNET_strdup ("Error storing records"); GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -471,35 +424,15 @@ create_finished (void *cls, int32_t success, const char *emsg) } -/** - * Delete finished callback - * - * @param cls the `struct RequestHandle` - * @param success the success indicating integer, GNUNET_OK on success - * @param emsg the error message (can be NULL) - */ static void -del_finished (void *cls, int32_t success, const char *emsg) +del_finished (void *cls, enum GNUNET_ErrorCode ec) { struct RequestHandle *handle = cls; handle->ns_qe = NULL; - if (GNUNET_NO == success) + handle->ec = ec; + if (GNUNET_EC_NONE != ec) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup ("No record found"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - if (GNUNET_SYSERR == success) - { - if (NULL != emsg) - { - handle->emsg = GNUNET_strdup (emsg); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - handle->emsg = GNUNET_strdup ("Deleting record failed"); GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -527,8 +460,7 @@ namestore_list_finished (void *cls) if (NULL == handle->resp_object) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_RECORD_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_EMPTY; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -603,7 +535,7 @@ ns_lookup_error_cb (void *cls) { struct RequestHandle *handle = cls; - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_LOOKUP_ERROR; GNUNET_SCHEDULER_add_now (&do_error, handle); } @@ -633,8 +565,7 @@ ns_get_lookup_cb (void *cls, /** Return 404 if no set was found **/ if (j == 0) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_RECORD_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -672,8 +603,7 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, // set zone to name if given if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url)) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -681,8 +611,7 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, ego_entry = get_egoentry_namestore (handle, egoname); if (NULL == ego_entry) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -738,7 +667,7 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, filter_flags); if (NULL == handle->list_it) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -755,7 +684,7 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, filter_flags); if (NULL == handle->ns_qe) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -790,7 +719,7 @@ ns_lookup_cb (void *cls, handle); if (NULL == handle->ns_qe) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -798,23 +727,17 @@ ns_lookup_cb (void *cls, static void -bulk_tx_commit_cb (void *cls, int32_t success, const char *emsg) +bulk_tx_commit_cb (void *cls, enum GNUNET_ErrorCode ec) { struct RequestHandle *handle = cls; struct MHD_Response *resp; handle->ns_qe = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Commit finished, %d\n", success); - if (GNUNET_YES != success) + "Commit finished (%d)\n", ec); + handle->ec = ec; + if (GNUNET_EC_NONE != ec) { - if (NULL != emsg) - { - handle->emsg = GNUNET_strdup (emsg); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - handle->emsg = GNUNET_strdup ("Error importing records on commit"); GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -824,30 +747,17 @@ bulk_tx_commit_cb (void *cls, int32_t success, const char *emsg) } -/** - * Import callback - * - * @param cls the `struct RequestHandle` - * @param success the success indicating integer, GNUNET_OK on success - * @param emsg the error message (can be NULL) - */ static void -import_next_cb (void *cls, int32_t success, const char *emsg) +import_next_cb (void *cls, enum GNUNET_ErrorCode ec) { struct RequestHandle *handle = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Import finished, %d\n", success); + "Import finished (%d)\n", ec); handle->ns_qe = NULL; - if (GNUNET_YES != success) + handle->ec = ec; + if (GNUNET_EC_NONE != ec) { - if (NULL != emsg) - { - handle->emsg = GNUNET_strdup (emsg); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - handle->emsg = GNUNET_strdup ("Error importing records"); GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -872,7 +782,7 @@ import_next_cb (void *cls, int32_t success, const char *emsg) handle); if ((NULL == handle->ns_qe) && (0 == sent_rds)) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -880,7 +790,7 @@ import_next_cb (void *cls, int32_t success, const char *emsg) } static void -bulk_tx_start (void *cls, int32_t success, const char *emsg) +bulk_tx_start (void *cls, enum GNUNET_ErrorCode ec) { struct RequestHandle *handle = cls; json_t *data_js; @@ -888,10 +798,15 @@ bulk_tx_start (void *cls, int32_t success, const char *emsg) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transaction started...\n"); + handle->ec = ec; + if (GNUNET_EC_NONE != ec) + { + GNUNET_SCHEDULER_add_now (&do_error, handle); + return; + } if (0 >= handle->rest_handle->data_size) { - handle->response_code = MHD_HTTP_BAD_REQUEST; - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA); + handle->ec = GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -903,13 +818,15 @@ bulk_tx_start (void *cls, int32_t success, const char *emsg) data_js = json_loads (term_data, JSON_DECODE_ANY, &err); if (NULL == data_js) { - GNUNET_asprintf (&handle->emsg, "Error parsing data: %s", err.text); + handle->ec = GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error parsing data: %s", err.text); GNUNET_SCHEDULER_add_now (&do_error, handle); return; } if (! json_is_array (data_js)) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); + handle->ec = GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID; GNUNET_SCHEDULER_add_now (&do_error, handle); json_decref (data_js); return; @@ -932,7 +849,7 @@ bulk_tx_start (void *cls, int32_t success, const char *emsg) GNUNET_JSON_spec_end () }; if (GNUNET_OK != GNUNET_JSON_parse (value, gnsspec, NULL, NULL)) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); + handle->ec = GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID; GNUNET_SCHEDULER_add_now (&do_error, handle); json_decref (data_js); return; @@ -958,7 +875,7 @@ bulk_tx_start (void *cls, int32_t success, const char *emsg) handle); if ((NULL == handle->ns_qe) && (0 == sent_rds)) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -986,8 +903,7 @@ namestore_import (struct GNUNET_REST_RequestHandle *con_handle, if (strlen (GNUNET_REST_API_NS_NAMESTORE_IMPORT) + 1 >= strlen ( handle->url)) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -998,8 +914,7 @@ namestore_import (struct GNUNET_REST_RequestHandle *con_handle, if (NULL == ego_entry) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1009,8 +924,7 @@ namestore_import (struct GNUNET_REST_RequestHandle *con_handle, handle->nc = GNUNET_NAMESTORE_connect (cfg); if (NULL == handle->nc) { - handle->response_code = MHD_HTTP_BAD_REQUEST; - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1041,8 +955,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, if (0 >= handle->rest_handle->data_size) { - handle->response_code = MHD_HTTP_BAD_REQUEST; - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA); + handle->ec = GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1057,7 +970,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, GNUNET_JSON_spec_end () }; if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); + handle->ec = GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID; GNUNET_SCHEDULER_add_now (&do_error, handle); json_decref (data_js); return; @@ -1065,8 +978,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, GNUNET_JSON_parse_free (gnsspec); if (0 >= strlen (handle->record_name)) { - handle->response_code = MHD_HTTP_BAD_REQUEST; - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); + handle->ec = GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID; GNUNET_SCHEDULER_add_now (&do_error, handle); json_decref (data_js); return; @@ -1079,8 +991,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, // set zone to name if given if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url)) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1089,8 +1000,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, if (NULL == ego_entry) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1104,7 +1014,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, handle); if (NULL == handle->ns_qe) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1170,8 +1080,7 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, // set zone to name if given if (strlen (GNUNET_REST_API_NS_NAMESTORE) + 1 >= strlen (handle->url)) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1179,8 +1088,7 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, ego_entry = get_egoentry_namestore (handle, egoname); if (NULL == ego_entry) { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); + handle->ec = GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1190,8 +1098,7 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, if (1 >= strlen (labelname)) { /* label is only "/" */ - handle->response_code = MHD_HTTP_BAD_REQUEST; - handle->emsg = GNUNET_strdup ("Label missing"); + handle->ec = GNUNET_EC_NAMESTORE_NO_LABEL_GIVEN; GNUNET_SCHEDULER_add_now (&do_error, handle); } @@ -1205,7 +1112,7 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, handle); if (NULL == handle->ns_qe) { - handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); + handle->ec = GNUNET_EC_NAMESTORE_UNKNOWN; GNUNET_SCHEDULER_add_now (&do_error, handle); return; } @@ -1350,7 +1257,7 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont }, GNUNET_REST_HANDLER_END }; - handle->response_code = 0; + handle->ec = GNUNET_EC_NONE; handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; handle->proc_cls = proc_cls; handle->proc = proc; diff --git a/src/namestore/test_namestore_api_edit_records.c b/src/namestore/test_namestore_api_edit_records.c index c1c64ee9c..ee05f498a 100644 --- a/src/namestore/test_namestore_api_edit_records.c +++ b/src/namestore/test_namestore_api_edit_records.c @@ -112,15 +112,14 @@ fail_cb (void *cls) static void remove_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { nsqe = NULL; - if (GNUNET_YES != success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unable to roll back: `%s'\n"), - emsg); + GNUNET_ErrorCode_get_hint (ec)); if (NULL != endbadly_task) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, @@ -167,19 +166,18 @@ edit_cont_b (void *cls, static void commit_cont_a (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { const char *name = cls; GNUNET_assert (NULL != cls); nsqe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namestore could not store record: `%s'\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); if (endbadly_task != NULL) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); @@ -226,12 +224,11 @@ fail_cb_lock (void *cls) static void begin_cont_b (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { const char *name = cls; - GNUNET_assert (success == GNUNET_YES); + GNUNET_assert (GNUNET_EC_NONE == ec); /** Now, we expect this to "hang" let's see how this behaves in practice. */ nsqe = GNUNET_NAMESTORE_records_edit (nsh2, &privkey, @@ -262,8 +259,7 @@ edit_cont (void *cls, static void begin_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { const char *name = cls; @@ -281,19 +277,18 @@ begin_cont (void *cls, static void preload_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { const char *name = cls; GNUNET_assert (NULL != cls); nsqe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namestore could not store record: `%s'\n", - emsg); + GNUNET_ErroCode_get_hint (ec)); if (endbadly_task != NULL) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c index 7decf39f8..85a7a4025 100644 --- a/src/namestore/test_namestore_api_lookup_nick.c +++ b/src/namestore/test_namestore_api_lookup_nick.c @@ -225,7 +225,7 @@ fail_cb (void *cls) static void -put_cont (void *cls, int32_t success, const char *emsg) +put_cont (void *cls, enum GNUNET_ErrorCode ec) { const char *name = cls; @@ -234,9 +234,9 @@ put_cont (void *cls, int32_t success, const char *emsg) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (ec == GNUNET_EC_NONE) ? "SUCCESS" : "FAIL"); - if (GNUNET_OK != success) + if (GNUNET_EC_NONE != ec) { GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); @@ -254,13 +254,13 @@ put_cont (void *cls, int32_t success, const char *emsg) static void -nick_cont (void *cls, int32_t success, const char *emsg) +nick_cont (void *cls, enum GNUNET_ErrorCode ec) { const char *name = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Nick added : %s\n", - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (ec == GNUNET_EC_NONE) ? "SUCCESS" : "FAIL"); rd_orig.expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; rd_orig.record_type = TEST_RECORD_TYPE; diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c index df0c38608..018cf89b1 100644 --- a/src/namestore/test_namestore_api_monitoring.c +++ b/src/namestore/test_namestore_api_monitoring.c @@ -198,8 +198,7 @@ zone_proc (void *cls, static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { static int c = 0; char *label = cls; @@ -211,7 +210,7 @@ put_cont (void *cls, else if (0 == strcmp (label, s_name_3)) ns_ops[2] = NULL; - if (success == GNUNET_OK) + if (GNUNET_EC_NONE == ec) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index 1803b8ba4..0123613fb 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c @@ -214,8 +214,7 @@ sync_cb (void *cls) static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { static int c = 0; const char *label = cls; @@ -230,7 +229,7 @@ put_cont (void *cls, s_name_3)) ns_ops[2] = NULL; - if (success == GNUNET_OK) + if (GNUNET_EC_NONE == ec) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index c2b70f64a..c6a4549d4 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c @@ -90,15 +90,14 @@ end (void *cls) static void remove_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { nsqe = NULL; - if (GNUNET_YES != success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Records could not be removed: `%s'\n"), - emsg); + GNUNET_ErrorCode_get_hint (ec)); if (NULL != endbadly_task) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, @@ -116,19 +115,18 @@ remove_cont (void *cls, static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { const char *name = cls; GNUNET_assert (NULL != cls); nsqe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namestore could not store record: `%s'\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); if (endbadly_task != NULL) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); @@ -138,7 +136,7 @@ put_cont (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); nsqe = GNUNET_NAMESTORE_records_store (nsh, &privkey, name, diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c index 958ea4bf2..ea95a6b57 100644 --- a/src/namestore/test_namestore_api_remove_not_existing_record.c +++ b/src/namestore/test_namestore_api_remove_not_existing_record.c @@ -87,8 +87,7 @@ end (void *cls) static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { GNUNET_assert (NULL != cls); nsqe = NULL; @@ -97,25 +96,24 @@ put_cont (void *cls, GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = NULL; } - switch (success) + switch (ec) { - case GNUNET_NO: - /* We expected GNUNET_NO, since record was not found */ + case GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND: + /* We expect that the record is not found */ GNUNET_SCHEDULER_add_now (&end, NULL); break; - case GNUNET_OK: + case GNUNET_EC_NONE: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namestore could remove non-existing record: `%s'\n", - (NULL != emsg) ? emsg : ""); + GNUNET_ErrorCode_get_hint (ec)); GNUNET_SCHEDULER_add_now (&endbadly, NULL); break; - case GNUNET_SYSERR: default: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namestore failed: `%s'\n", - (NULL != emsg) ? emsg : ""); + GNUNET_ErrorCode_get_hint (ec)); GNUNET_SCHEDULER_add_now (&endbadly, NULL); break; } diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c index e0b7daa5d..f4f1e36d3 100644 --- a/src/namestore/test_namestore_api_store.c +++ b/src/namestore/test_namestore_api_store.c @@ -87,7 +87,7 @@ end (void *cls) static void -put_cont (void *cls, int32_t success, const char *emsg) +put_cont (void *cls, enum GNUNET_ErrorCode ec) { const char *name = cls; @@ -96,7 +96,7 @@ put_cont (void *cls, int32_t success, const char *emsg) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = NULL; GNUNET_SCHEDULER_add_now (&end, NULL); diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index f48fe5483..8f1f33542 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c @@ -96,8 +96,7 @@ end (void *cls) static void put_cont (void *cls, - int32_t success, - const char *emsg); + enum GNUNET_ErrorCode ec); static void @@ -167,8 +166,7 @@ lookup_success (void *cls, static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { const char *name = cls; struct GNUNET_HashCode derived_hash; @@ -178,7 +176,7 @@ put_cont (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); /* Create derived hash */ GNUNET_GNSRECORD_query_from_private_key (&privkey, name, diff --git a/src/namestore/test_namestore_api_tx_rollback.c b/src/namestore/test_namestore_api_tx_rollback.c index a631160d7..3d0884e24 100644 --- a/src/namestore/test_namestore_api_tx_rollback.c +++ b/src/namestore/test_namestore_api_tx_rollback.c @@ -106,15 +106,14 @@ fail_cb (void *cls) static void remove_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { nsqe = NULL; - if (GNUNET_YES != success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unable to roll back: `%s'\n"), - emsg); + GNUNET_ErrorCode_get_hint (ec)); if (NULL != endbadly_task) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, @@ -139,19 +138,18 @@ remove_cont (void *cls, static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { const char *name = cls; GNUNET_assert (NULL != cls); nsqe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namestore could not store record: `%s'\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); if (endbadly_task != NULL) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); @@ -161,20 +159,19 @@ put_cont (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, remove_cont, (void *) name); } static void begin_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { struct GNUNET_GNSRECORD_Data rd; const char *name = cls; - GNUNET_assert (success == GNUNET_YES); + GNUNET_assert (GNUNET_EC_NONE == ec); privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); GNUNET_IDENTITY_key_get_public (&privkey, diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 55ca901e2..6e07f78f2 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c @@ -253,12 +253,11 @@ zone_proc (void *cls, static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { static int c = 0; - if (success == GNUNET_OK) + if (GNUNET_EC_NONE == ec) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -269,7 +268,7 @@ put_cont (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); res = 1; diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c index c203a63a6..941d43c28 100644 --- a/src/namestore/test_namestore_api_zone_iteration_nick.c +++ b/src/namestore/test_namestore_api_zone_iteration_nick.c @@ -207,12 +207,11 @@ fail_cb (void *cls) static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { static int c = 0; - if (success == GNUNET_OK) + if (GNUNET_EC_NONE == ec) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); @@ -220,7 +219,7 @@ put_cont (void *cls, else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); return; @@ -274,12 +273,11 @@ create_record (unsigned int count) static void nick_2_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Nick added : %s\n", - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); @@ -309,11 +307,11 @@ nick_2_cont (void *cls, static void -nick_1_cont (void *cls, int32_t success, const char *emsg) +nick_1_cont (void *cls, enum GNUNET_ErrorCode ec) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Nick 1 added : %s\n", - (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); + (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); struct GNUNET_GNSRECORD_Data rd; memset (&rd, 0, sizeof(rd)); diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index 70097a69e..daf711c3d 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c @@ -232,12 +232,11 @@ zone_proc_end (void *cls) static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { static int c = 0; - if (success == GNUNET_OK) + if (GNUNET_EC_NONE == ec) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -247,7 +246,7 @@ put_cont (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); GNUNET_break (0); res = 2; GNUNET_SCHEDULER_shutdown (); diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index 71b36ba09..c51224d91 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c @@ -246,11 +246,11 @@ zone_proc_end (void *cls) static void -put_cont (void *cls, int32_t success, const char *emsg) +put_cont (void *cls, enum GNUNET_ErrorCode ec) { static int c = 0; - if (success == GNUNET_OK) + if (GNUNET_EC_NONE == ec) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); @@ -258,7 +258,7 @@ put_cont (void *cls, int32_t success, const char *emsg) else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); return; diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c index 1e2f8248b..c9d781d39 100644 --- a/src/namestore/test_namestore_api_zone_to_name.c +++ b/src/namestore/test_namestore_api_zone_to_name.c @@ -157,16 +157,16 @@ error_cb (void *cls) static void put_cont (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { char *name = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, - (success == GNUNET_OK) ? "SUCCESS" : emsg); - if (success == GNUNET_OK) + (GNUNET_EC_NONE == ec) ? + "SUCCESS" : GNUNET_ErrorCode_get_hint (ec)); + if (GNUNET_EC_NONE == ec) { res = 0; diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c index 8c5e6c812..f3caff707 100644 --- a/src/reclaim/did_core.c +++ b/src/reclaim/did_core.c @@ -121,21 +121,20 @@ DID_resolve (const char *did, static void DID_create_did_store_cb (void *cls, - int32_t success, - const char *emsg) + enum GNUNET_ErrorCode ec) { DID_action_callback *cb = ((struct DID_action_return *) cls)->cb; void *cls_did_create_cb = ((struct DID_action_return *) cls)->cls; free (cls); - if (GNUNET_OK == success) + if (GNUNET_EC_NONE == ec) { cb (GNUNET_OK, (void *) cls_did_create_cb); } else { // TODO: Log emsg. Not writing it to STDOUT - printf ("%s\n", emsg); + printf ("%s\n", GNUNET_ErrorCode_get_hint (ec)); cb (GNUNET_NO, (void *) cls_did_create_cb); } } diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c index 25f571520..b5f5f4922 100644 --- a/src/reclaim/gnunet-did.c +++ b/src/reclaim/gnunet-did.c @@ -223,11 +223,11 @@ struct Event * @param emgs */ static void -remove_did_document_namestore_cb (void *cls, int32_t success, const char *emgs) +remove_did_document_namestore_cb (void *cls, enum GNUNET_ErrorCode ec) { struct Event *event; - if (success != GNUNET_SYSERR) + if (GNUNET_EC_NONE == ec) { event = (struct Event *) cls; @@ -246,10 +246,7 @@ remove_did_document_namestore_cb (void *cls, int32_t success, const char *emgs) else { printf ("Something went wrong when deleting the DID Document\n"); - if (emgs != NULL) - { - printf ("%s\n", emgs); - } + printf ("%s\n", GNUNET_ErrorCode_get_hint (ec)); GNUNET_SCHEDULER_add_now (cleanup, NULL); ret = 0; diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 5290621d6..5c484e55d 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c @@ -970,7 +970,7 @@ handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) * @param emsg error message (NULL if success=GNUNET_OK) */ static void -attr_store_cont (void *cls, int32_t success, const char *emsg) +attr_store_cont (void *cls, enum GNUNET_ErrorCode ec) { struct AttributeStoreHandle *ash = cls; struct GNUNET_MQ_Envelope *env; @@ -981,11 +981,11 @@ attr_store_cont (void *cls, int32_t success, const char *emsg) ash->client->store_op_tail, ash); - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to store attribute %s\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); cleanup_as_handle (ash); GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); return; @@ -1108,7 +1108,7 @@ handle_attribute_store_message (void *cls, * @param emsg error message (NULL if success=GNUNET_OK) */ static void -cred_store_cont (void *cls, int32_t success, const char *emsg) +cred_store_cont (void *cls, enum GNUNET_ErrorCode ec) { struct AttributeStoreHandle *ash = cls; struct GNUNET_MQ_Envelope *env; @@ -1119,11 +1119,11 @@ cred_store_cont (void *cls, int32_t success, const char *emsg) ash->client->store_op_tail, ash); - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to store credential: %s\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); cleanup_as_handle (ash); GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); return; @@ -1395,7 +1395,7 @@ update_tickets (void *cls); * @param emsg error message (NULL if success=GNUNET_OK) */ static void -ticket_updated (void *cls, int32_t success, const char *emsg) +ticket_updated (void *cls, enum GNUNET_ErrorCode ec) { struct AttributeDeleteHandle *adh = cls; @@ -1519,12 +1519,12 @@ static void purge_attributes (void *cls);; static void -offending_attr_delete_cont (void *cls, int32_t success, const char *emsg) +offending_attr_delete_cont (void *cls, enum GNUNET_ErrorCode ec) { struct AttributeDeleteHandle *adh = cls; adh->ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s\n", @@ -1664,12 +1664,12 @@ start_consistency_update (void *cls) * @param emsg error message (NULL if success=GNUNET_OK) */ static void -attr_delete_cont (void *cls, int32_t success, const char *emsg) +attr_delete_cont (void *cls, enum GNUNET_ErrorCode ec) { struct AttributeDeleteHandle *adh = cls; adh->ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s\n", @@ -1755,12 +1755,12 @@ handle_attribute_delete_message (void *cls, * @param emsg error message (NULL if success=GNUNET_OK) */ static void -cred_delete_cont (void *cls, int32_t success, const char *emsg) +cred_delete_cont (void *cls, enum GNUNET_ErrorCode ec) { struct AttributeDeleteHandle *adh = cls; adh->ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting credential `%s'\n", diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index a17dfb0e2..9552094f1 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c @@ -394,7 +394,7 @@ process_tickets (void *cls); * @param emsg (NULL on success) */ static void -ticket_processed (void *cls, int32_t success, const char *emsg) +ticket_processed (void *cls, enum GNUNET_ErrorCode ec) { struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; @@ -596,16 +596,16 @@ move_attrs_cont (void *cls) * @param emsg error message (NULL on success) */ static void -del_attr_finished (void *cls, int32_t success, const char *emsg) +del_attr_finished (void *cls, enum GNUNET_ErrorCode ec) { struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; rvk->ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error removing attribute: %s\n", - emsg); + GNUNET_ErrorCode_get_hint (ec)); rvk->cb (rvk->cb_cls, GNUNET_SYSERR); cleanup_rvk (rvk); return; @@ -625,15 +625,17 @@ del_attr_finished (void *cls, int32_t success, const char *emsg) * @param emsg error message (NULL on success) */ static void -move_attr_finished (void *cls, int32_t success, const char *emsg) +move_attr_finished (void *cls, enum GNUNET_ErrorCode ec) { struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; char *label; rvk->ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error moving attribute: %s\n", + GNUNET_ErrorCode_get_hint (ec)); rvk->cb (rvk->cb_cls, GNUNET_SYSERR); cleanup_rvk (rvk); return; @@ -802,14 +804,15 @@ move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk) * @param emsg error message (NULL on success) */ static void -remove_ticket_cont (void *cls, int32_t success, const char *emsg) +remove_ticket_cont (void *cls, enum GNUNET_ErrorCode ec) { struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; rvk->ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", + GNUNET_ErrorCode_get_hint (ec)); rvk->cb (rvk->cb_cls, GNUNET_SYSERR); cleanup_rvk (rvk); return; @@ -1250,12 +1253,12 @@ cleanup_issue_handle (struct TicketIssueHandle *handle) * @param emsg error message (or NULL on success) */ static void -store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) +store_ticket_issue_cont (void *cls, enum GNUNET_ErrorCode ec) { struct TicketIssueHandle *handle = cls; handle->ns_qe = NULL; - if (GNUNET_SYSERR == success) + if (GNUNET_EC_NONE != ec) { handle->cb (handle->cb_cls, &handle->ticket, diff --git a/src/util/.gitignore b/src/util/.gitignore index 6151c4f7a..937a6841a 100644 --- a/src/util/.gitignore +++ b/src/util/.gitignore @@ -1,3 +1,4 @@ +gnunet_error_codes.c test_common_logging_dummy gnunet-config gnunet-config-diff diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 9cb7da15b..a99072de5 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -105,7 +105,8 @@ libgnunetutil_la_SOURCES = \ tun.c \ uri.c \ speedup.c speedup.h \ - proc_compat.c + proc_compat.c \ + gnunet_error_codes.c if HAVE_LIBATOMIC if DARWIN -- cgit v1.2.3