[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: MESSENGER: adjust code in client side of
From: |
gnunet |
Subject: |
[gnunet] branch master updated: MESSENGER: adjust code in client side of service to reduce warnings |
Date: |
Mon, 02 Sep 2024 19:09:54 +0200 |
This is an automated email from the git hooks/post-receive script.
thejackimonster pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new de5ab1048 MESSENGER: adjust code in client side of service to reduce
warnings
de5ab1048 is described below
commit de5ab1048357428c93a49550dde36679e7d413d2
Author: Jacki <jacki@thejackimonster.de>
AuthorDate: Mon Sep 2 19:09:45 2024 +0200
MESSENGER: adjust code in client side of service to reduce warnings
Signed-off-by: Jacki <jacki@thejackimonster.de>
---
src/cli/messenger/gnunet-messenger.c | 70 +++--
src/lib/util/gnunet_error_codes.c | 1 -
.../messenger/gnunet-service-messenger_handle.c | 6 +-
.../gnunet-service-messenger_message_recv.c | 8 +-
.../gnunet-service-messenger_message_send.c | 11 +-
.../messenger/gnunet-service-messenger_operation.c | 36 +--
src/service/messenger/messenger_api.c | 4 +-
src/service/messenger/messenger_api_contact.c | 7 +-
.../messenger/messenger_api_contact_store.c | 71 ++---
src/service/messenger/messenger_api_handle.c | 48 ++--
src/service/messenger/messenger_api_list_tunnels.c | 103 ++++---
src/service/messenger/messenger_api_message.c | 314 ++++++++++++---------
.../messenger/messenger_api_message_control.c | 63 +++--
src/service/messenger/messenger_api_message_kind.c | 50 ++--
.../messenger/messenger_api_queue_messages.c | 23 +-
src/service/messenger/messenger_api_room.c | 197 ++++++++-----
src/service/messenger/messenger_api_util.c | 18 +-
17 files changed, 624 insertions(+), 406 deletions(-)
diff --git a/src/cli/messenger/gnunet-messenger.c
b/src/cli/messenger/gnunet-messenger.c
index 22045621d..d0112b16c 100644
--- a/src/cli/messenger/gnunet-messenger.c
+++ b/src/cli/messenger/gnunet-messenger.c
@@ -68,7 +68,7 @@ idle (void *cls);
* @param[in] hash Hash of message
* @param[in] flags Flags of message
*/
-void
+static void
on_message (void *cls,
struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_MESSENGER_Contact *sender,
@@ -77,7 +77,11 @@ on_message (void *cls,
const struct GNUNET_HashCode *hash,
enum GNUNET_MESSENGER_MessageFlags flags)
{
- const uint64_t waited = waiting;
+ uint64_t waited;
+ const char *sender_name;
+ const char *recipient_name;
+
+ waited = waiting;
if (GNUNET_YES == talk_mode)
{
@@ -101,8 +105,8 @@ on_message (void *cls,
else if (GNUNET_YES == silence_flag)
goto skip_printing;
- const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender);
- const char *recipient_name = GNUNET_MESSENGER_contact_get_name (recipient);
+ sender_name = GNUNET_MESSENGER_contact_get_name (sender);
+ recipient_name = GNUNET_MESSENGER_contact_get_name (recipient);
if (! sender_name)
sender_name = "anonymous";
@@ -143,7 +147,9 @@ on_message (void *cls,
}
case GNUNET_MESSENGER_KIND_TEXT:
{
- const uint16_t len = strlen (message->body.text.text) + 1;
+ uint16_t len;
+
+ len = strlen (message->body.text.text) + 1;
if (flags & GNUNET_MESSENGER_FLAG_SENT)
{
@@ -186,17 +192,19 @@ skip_printing:
if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) &&
(flags & GNUNET_MESSENGER_FLAG_SENT))
{
+ struct GNUNET_MESSENGER_Message response;
+ const char *name;
+
if (! read_task)
read_task = GNUNET_SCHEDULER_add_with_priority (
GNUNET_SCHEDULER_PRIORITY_IDLE,
idle, room);
- const char *name = GNUNET_MESSENGER_get_name (messenger);
+ name = GNUNET_MESSENGER_get_name (messenger);
if (! name)
return;
- struct GNUNET_MESSENGER_Message response;
response.header.kind = GNUNET_MESSENGER_KIND_NAME;
response.body.name.name = GNUNET_strdup (name);
@@ -230,7 +238,11 @@ struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
static void
shutdown_hook (void *cls)
{
- struct GNUNET_MESSENGER_Room *room = cls;
+ struct GNUNET_MESSENGER_Room *room;
+
+ GNUNET_assert (cls);
+
+ room = cls;
if (read_task)
GNUNET_SCHEDULER_cancel (read_task);
@@ -256,7 +268,11 @@ iterate_send_private_message (void *cls,
struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_MESSENGER_Contact *contact)
{
- struct GNUNET_MESSENGER_Message *message = cls;
+ struct GNUNET_MESSENGER_Message *message;
+
+ GNUNET_assert ((cls) && (room) && (contact));
+
+ message = cls;
if (GNUNET_MESSENGER_contact_get_key (contact))
GNUNET_MESSENGER_send_message (room, message, contact);
@@ -275,14 +291,16 @@ int private_mode;
static void
read_stdio (void *cls)
{
- struct GNUNET_MESSENGER_Room *room = cls;
+ struct GNUNET_MESSENGER_Room *room;
struct GNUNET_MESSENGER_Message message;
-
- read_task = NULL;
-
char buffer[MAX_BUFFER_SIZE];
ssize_t length;
+ GNUNET_assert (cls);
+
+ room = cls;
+ read_task = NULL;
+
length = read (0, buffer, MAX_BUFFER_SIZE - 1);
if ((length <= 0) || (length >= MAX_BUFFER_SIZE))
@@ -331,10 +349,11 @@ read_stdio (void *cls)
static void
listen_stdio (void *cls)
{
- read_task = NULL;
+ struct GNUNET_NETWORK_FDSet *rs;
- struct GNUNET_NETWORK_FDSet *rs = GNUNET_NETWORK_fdset_create ();
+ read_task = NULL;
+ rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set_native (rs, 0);
read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -353,7 +372,11 @@ listen_stdio (void *cls)
static void
idle (void *cls)
{
- struct GNUNET_MESSENGER_Room *room = cls;
+ struct GNUNET_MESSENGER_Room *room;
+
+ GNUNET_assert (cls);
+
+ room = cls;
if ((GNUNET_YES != talk_mode) ||
(GNUNET_YES == silence_flag))
@@ -380,13 +403,17 @@ on_identity (void *cls,
struct GNUNET_MESSENGER_Handle *handle)
{
struct GNUNET_HashCode key;
+ struct GNUNET_MESSENGER_Room *room;
+ struct GNUNET_PeerIdentity door_peer;
+ struct GNUNET_PeerIdentity *door;
+ const char *name;
+
memset (&key, 0, sizeof(key));
if (room_key)
GNUNET_CRYPTO_hash (room_key, strlen (room_key), &key);
- struct GNUNET_PeerIdentity door_peer;
- struct GNUNET_PeerIdentity *door = NULL;
+ door = NULL;
if ((door_id) &&
(GNUNET_OK == GNUNET_CRYPTO_eddsa_public_key_from_string (door_id,
@@ -395,14 +422,12 @@ on_identity (void *cls,
&(door_peer.
public_key))))
door = &door_peer;
-
- struct GNUNET_MESSENGER_Room *room;
if ((GNUNET_YES == talk_mode) ||
(GNUNET_YES == silence_flag))
goto skip_welcome;
- const char *name = GNUNET_MESSENGER_get_name (handle);
+ name = GNUNET_MESSENGER_get_name (handle);
if (! name)
name = "anonymous";
@@ -444,9 +469,10 @@ static void
on_ego_lookup (void *cls,
struct GNUNET_IDENTITY_Ego *ego)
{
+ const struct GNUNET_CRYPTO_PrivateKey *key;
+
ego_lookup = NULL;
- const struct GNUNET_CRYPTO_PrivateKey *key;
key = ego ? GNUNET_IDENTITY_ego_get_private_key (ego) : NULL;
messenger = GNUNET_MESSENGER_connect (config, ego_name, key, &on_message,
diff --git a/src/lib/util/gnunet_error_codes.c
b/src/lib/util/gnunet_error_codes.c
index c286f2e52..11ce2d0c8 100644
--- a/src/lib/util/gnunet_error_codes.c
+++ b/src/lib/util/gnunet_error_codes.c
@@ -17,7 +17,6 @@
SPDX-License-Identifier: AGPL3.0-or-later
*/
-#include "platform.h"
#include "gnunet_error_codes.h"
#include <stddef.h>
#include <microhttpd.h>
diff --git a/src/service/messenger/gnunet-service-messenger_handle.c
b/src/service/messenger/gnunet-service-messenger_handle.c
index 39a49149a..44c3cd8aa 100644
--- a/src/service/messenger/gnunet-service-messenger_handle.c
+++ b/src/service/messenger/gnunet-service-messenger_handle.c
@@ -539,8 +539,10 @@ skip_message_filter:
{
struct GNUNET_MESSENGER_RecvMessage *msg;
struct GNUNET_MQ_Envelope *env;
+ uint16_t length;
+ char *buffer;
- uint16_t length = get_message_size (message, GNUNET_YES);
+ length = get_message_size (message, GNUNET_YES);
env = GNUNET_MQ_msg_extra (msg, length,
GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE);
@@ -560,7 +562,7 @@ skip_message_filter:
if (GNUNET_YES == recent)
msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_RECENT;
- char *buffer = ((char*) msg) + sizeof(*msg);
+ buffer = ((char*) msg) + sizeof(*msg);
encode_message (message, length, buffer, GNUNET_YES);
GNUNET_MQ_send (handle->mq, env);
diff --git a/src/service/messenger/gnunet-service-messenger_message_recv.c
b/src/service/messenger/gnunet-service-messenger_message_recv.c
index 7c07a360d..795817bd1 100644
--- a/src/service/messenger/gnunet-service-messenger_message_recv.c
+++ b/src/service/messenger/gnunet-service-messenger_message_recv.c
@@ -134,17 +134,17 @@ recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room,
for (element = room->basement.head; element; element = element->next)
{
- const struct GNUNET_MESSENGER_Message *message;
+ const struct GNUNET_MESSENGER_Message *msg;
if (! element->hash)
continue;
- message = get_store_message (message_store, element->hash);
+ msg = get_store_message (message_store, element->hash);
- if (! message)
+ if (! msg)
continue;
- forward_tunnel_message (tunnel, message, element->hash);
+ forward_tunnel_message (tunnel, msg, element->hash);
}
}
diff --git a/src/service/messenger/gnunet-service-messenger_message_send.c
b/src/service/messenger/gnunet-service-messenger_message_send.c
index 34531f8c5..41ea9b88e 100644
--- a/src/service/messenger/gnunet-service-messenger_message_send.c
+++ b/src/service/messenger/gnunet-service-messenger_message_send.c
@@ -122,12 +122,15 @@ iterate_notify_about_members (void *cls,
is_member_session_completed (session)))
return GNUNET_YES;
- struct GNUNET_CONTAINER_MultiHashMap *map =
- GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
+ {
+ struct GNUNET_CONTAINER_MultiHashMap *map;
+ map = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
+
+ notify_about_members (notify, session, map, GNUNET_NO);
- notify_about_members (notify, session, map, GNUNET_NO);
+ GNUNET_CONTAINER_multihashmap_destroy (map);
+ }
- GNUNET_CONTAINER_multihashmap_destroy (map);
return GNUNET_YES;
}
diff --git a/src/service/messenger/gnunet-service-messenger_operation.c
b/src/service/messenger/gnunet-service-messenger_operation.c
index 0c32b9942..0ef8d7188 100644
--- a/src/service/messenger/gnunet-service-messenger_operation.c
+++ b/src/service/messenger/gnunet-service-messenger_operation.c
@@ -93,23 +93,25 @@ load_operation (struct GNUNET_MESSENGER_OperationStore
*store,
op = create_operation (&hash);
}
- unsigned long long type_number;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "operation",
- "type",
&type_number))
- switch (type_number)
- {
- case GNUNET_MESSENGER_OP_REQUEST:
- op->type = GNUNET_MESSENGER_OP_REQUEST;
- break;
- case GNUNET_MESSENGER_OP_DELETE:
- op->type = GNUNET_MESSENGER_OP_DELETE;
- break;
- case GNUNET_MESSENGER_OP_MERGE:
- op->type = GNUNET_MESSENGER_OP_MERGE;
- break;
- default:
- break;
- }
+ {
+ unsigned long long type_number;
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "operation",
+ "type",
&type_number))
+ switch (type_number)
+ {
+ case GNUNET_MESSENGER_OP_REQUEST:
+ op->type = GNUNET_MESSENGER_OP_REQUEST;
+ break;
+ case GNUNET_MESSENGER_OP_DELETE:
+ op->type = GNUNET_MESSENGER_OP_DELETE;
+ break;
+ case GNUNET_MESSENGER_OP_MERGE:
+ op->type = GNUNET_MESSENGER_OP_MERGE;
+ break;
+ default:
+ break;
+ }
+ }
if ((GNUNET_MESSENGER_OP_UNKNOWN == op->type) ||
(GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation",
diff --git a/src/service/messenger/messenger_api.c
b/src/service/messenger/messenger_api.c
index 54b57018b..511046777 100644
--- a/src/service/messenger/messenger_api.c
+++ b/src/service/messenger/messenger_api.c
@@ -1115,10 +1115,12 @@ GNUNET_MESSENGER_enter_room (struct
GNUNET_MESSENGER_Handle *handle,
void
GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! room)
return;
- struct GNUNET_MESSENGER_Message *message = create_message_leave ();
+ message = create_message_leave ();
if (! message)
return;
diff --git a/src/service/messenger/messenger_api_contact.c
b/src/service/messenger/messenger_api_contact.c
index 841f72a10..201c66aff 100644
--- a/src/service/messenger/messenger_api_contact.c
+++ b/src/service/messenger/messenger_api_contact.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2020--2023 GNUnet e.V.
+ Copyright (C) 2020--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -29,10 +29,11 @@ struct GNUNET_MESSENGER_Contact*
create_contact (const struct GNUNET_CRYPTO_PublicKey *key,
size_t unique_id)
{
+ struct GNUNET_MESSENGER_Contact *contact;
+
GNUNET_assert (key);
- struct GNUNET_MESSENGER_Contact *contact = GNUNET_new (struct
-
GNUNET_MESSENGER_Contact);
+ contact = GNUNET_new (struct GNUNET_MESSENGER_Contact);
contact->name = NULL;
contact->rc = 0;
diff --git a/src/service/messenger/messenger_api_contact_store.c
b/src/service/messenger/messenger_api_contact_store.c
index 081a8c6e9..cf45023ad 100644
--- a/src/service/messenger/messenger_api_contact_store.c
+++ b/src/service/messenger/messenger_api_contact_store.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2020--2023 GNUnet e.V.
+ Copyright (C) 2020--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -46,7 +46,12 @@ iterate_destroy_contacts (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- struct GNUNET_MESSENGER_Contact *contact = value;
+ struct GNUNET_MESSENGER_Contact *contact;
+
+ GNUNET_assert (value);
+
+ contact = value;
+
destroy_contact (contact);
return GNUNET_YES;
}
@@ -74,10 +79,13 @@ select_store_contact_map (struct
GNUNET_MESSENGER_ContactStore *store,
const struct GNUNET_HashCode *context,
struct GNUNET_HashCode *hash)
{
- const struct GNUNET_CRYPTO_PublicKey *anonymous =
- get_anonymous_public_key ();
-
+ const struct GNUNET_CRYPTO_PublicKey *anonymous;
struct GNUNET_HashCode anonHash;
+
+ GNUNET_assert (hash);
+
+ anonymous = get_anonymous_public_key ();
+
GNUNET_CRYPTO_hash (anonymous, sizeof(*anonymous), &anonHash);
if ((context) && (0 == GNUNET_CRYPTO_hash_cmp (hash, &anonHash)))
@@ -95,14 +103,14 @@ get_store_contact_raw (struct
GNUNET_MESSENGER_ContactStore *store,
const struct GNUNET_HashCode *context,
const struct GNUNET_HashCode *key_hash)
{
+ struct GNUNET_CONTAINER_MultiHashMap *map;
+ struct GNUNET_HashCode hash;
+
GNUNET_assert ((store) && (store->contacts) && (context) && (key_hash));
- struct GNUNET_HashCode hash;
GNUNET_memcpy (&hash, key_hash, sizeof(*key_hash));
- struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map (
- store, context, &hash
- );
+ map = select_store_contact_map (store, context, &hash);
return GNUNET_CONTAINER_multihashmap_get (map, &hash);
}
@@ -113,23 +121,24 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore
*store,
const struct GNUNET_HashCode *context,
const struct GNUNET_CRYPTO_PublicKey *pubkey)
{
+ struct GNUNET_CONTAINER_MultiHashMap *map;
+ struct GNUNET_MESSENGER_Contact *contact;
+ struct GNUNET_HashCode hash;
+
GNUNET_assert ((store) && (store->contacts) && (pubkey));
- struct GNUNET_HashCode hash;
GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
- struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map (
- store, context, &hash);
-
- struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multihashmap_get
(
- map, &hash);
+ map = select_store_contact_map (store, context, &hash);
+ contact = GNUNET_CONTAINER_multihashmap_get (map, &hash);
if (contact)
{
if (0 != GNUNET_memcmp (pubkey, get_contact_key (contact)))
{
- char *str = GNUNET_CRYPTO_public_key_to_string (get_contact_key (
- contact));
+ char *str;
+ str = GNUNET_CRYPTO_public_key_to_string (get_contact_key (contact));
+
GNUNET_log (GNUNET_ERROR_TYPE_INVALID,
"Contact in store uses wrong key: %s\n", str);
GNUNET_free (str);
@@ -158,19 +167,19 @@ update_store_contact (struct
GNUNET_MESSENGER_ContactStore *store,
const struct GNUNET_HashCode *next_context,
const struct GNUNET_CRYPTO_PublicKey *pubkey)
{
- GNUNET_assert ((store) && (store->contacts) && (contact) && (pubkey));
+ const struct GNUNET_CRYPTO_PublicKey *oldkey;
+ struct GNUNET_CONTAINER_MultiHashMap *map;
+ struct GNUNET_HashCode hash;
- const struct GNUNET_CRYPTO_PublicKey *oldkey = get_contact_key (contact);
+ GNUNET_assert ((store) && (store->contacts) && (contact) && (pubkey));
- struct GNUNET_HashCode hash;
+ oldkey = get_contact_key (contact);
GNUNET_CRYPTO_hash (oldkey, sizeof(*oldkey), &hash);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update contact store entry: %s\n",
GNUNET_h2s (&hash));
- struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map (
- store, context, &hash
- );
+ map = select_store_contact_map (store, context, &hash);
if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
{
@@ -178,9 +187,7 @@ update_store_contact (struct GNUNET_MESSENGER_ContactStore
*store,
GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
- map = select_store_contact_map (
- store, next_context, &hash
- );
+ map = select_store_contact_map (store, next_context, &hash);
if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
@@ -196,19 +203,19 @@ remove_store_contact (struct
GNUNET_MESSENGER_ContactStore *store,
struct GNUNET_MESSENGER_Contact *contact,
const struct GNUNET_HashCode *context)
{
- GNUNET_assert ((store) && (store->contacts) && (contact));
+ const struct GNUNET_CRYPTO_PublicKey *pubkey;
+ struct GNUNET_CONTAINER_MultiHashMap *map;
+ struct GNUNET_HashCode hash;
- const struct GNUNET_CRYPTO_PublicKey *pubkey = get_contact_key (contact);
+ GNUNET_assert ((store) && (store->contacts) && (contact));
- struct GNUNET_HashCode hash;
+ pubkey = get_contact_key (contact);
GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Remove contact store entry: %s\n",
GNUNET_h2s (&hash));
- struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map (
- store, context, &hash
- );
+ map = select_store_contact_map (store, context, &hash);
if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Removing a contact failed: %s\n",
diff --git a/src/service/messenger/messenger_api_handle.c
b/src/service/messenger/messenger_api_handle.c
index 1cf2bccf0..6d0d8408d 100644
--- a/src/service/messenger/messenger_api_handle.c
+++ b/src/service/messenger/messenger_api_handle.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2020--2023 GNUnet e.V.
+ Copyright (C) 2020--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -33,10 +33,11 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle
*cfg,
GNUNET_MESSENGER_MessageCallback msg_callback,
void *msg_cls)
{
+ struct GNUNET_MESSENGER_Handle *handle;
+
GNUNET_assert (cfg);
- struct GNUNET_MESSENGER_Handle *handle = GNUNET_new (struct
-
GNUNET_MESSENGER_Handle);
+ handle = GNUNET_new (struct GNUNET_MESSENGER_Handle);
handle->cfg = cfg;
handle->mq = NULL;
@@ -64,10 +65,13 @@ iterate_destroy_room (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- struct GNUNET_MESSENGER_Room *room = value;
+ struct GNUNET_MESSENGER_Room *room;
- destroy_room (room);
+ GNUNET_assert (value);
+
+ room = value;
+ destroy_room (room);
return GNUNET_YES;
}
@@ -195,24 +199,29 @@ struct GNUNET_MESSENGER_Contact*
get_handle_contact (struct GNUNET_MESSENGER_Handle *handle,
const struct GNUNET_HashCode *key)
{
+ struct GNUNET_MESSENGER_Room *room;
+ const struct GNUNET_ShortHashCode *contact_id;
+
GNUNET_assert ((handle) && (key));
- struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
- handle->rooms, key);
+ room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
if (! room)
return NULL;
- const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room);
+ contact_id = get_room_sender_id (room);
if (! contact_id)
return NULL;
- struct GNUNET_HashCode context;
- get_context_from_member (key, contact_id, &context);
+ {
+ struct GNUNET_HashCode context;
+ get_context_from_member (key, contact_id, &context);
- return get_store_contact (get_handle_contact_store (handle), &context,
- get_handle_pubkey (handle));
+ return get_store_contact (get_handle_contact_store (handle),
+ &context,
+ get_handle_pubkey (handle));
+ }
}
@@ -220,10 +229,11 @@ void
open_handle_room (struct GNUNET_MESSENGER_Handle *handle,
const struct GNUNET_HashCode *key)
{
+ struct GNUNET_MESSENGER_Room *room;
+
GNUNET_assert ((handle) && (key));
- struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
- handle->rooms, key);
+ room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
if (room)
room->opened = GNUNET_YES;
@@ -235,10 +245,11 @@ entry_handle_room_at (struct GNUNET_MESSENGER_Handle
*handle,
const struct GNUNET_PeerIdentity *door,
const struct GNUNET_HashCode *key)
{
+ struct GNUNET_MESSENGER_Room *room;
+
GNUNET_assert ((handle) && (door) && (key));
- struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
- handle->rooms, key);
+ room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
if (room)
add_to_list_tunnels (&(room->entries), door, NULL);
@@ -249,10 +260,11 @@ void
close_handle_room (struct GNUNET_MESSENGER_Handle *handle,
const struct GNUNET_HashCode *key)
{
+ struct GNUNET_MESSENGER_Room *room;
+
GNUNET_assert ((handle) && (key));
- struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (
- handle->rooms, key);
+ room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (
handle->rooms, key, room)))
diff --git a/src/service/messenger/messenger_api_list_tunnels.c
b/src/service/messenger/messenger_api_list_tunnels.c
index bb500233b..f027d73c6 100644
--- a/src/service/messenger/messenger_api_list_tunnels.c
+++ b/src/service/messenger/messenger_api_list_tunnels.c
@@ -38,13 +38,15 @@ init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels
*tunnels)
void
clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels)
{
+ struct GNUNET_MESSENGER_ListTunnel *element;
+
GNUNET_assert (tunnels);
- struct GNUNET_MESSENGER_ListTunnel *element;
- for (element = tunnels->head; element;
- element = remove_from_list_tunnels (tunnels, element))
+ element = tunnels->head;
+ while (element)
+ element = remove_from_list_tunnels (tunnels, element);
- tunnels->head = NULL;
+ tunnels->head = NULL;
tunnels->tail = NULL;
}
@@ -56,6 +58,8 @@ compare_list_tunnels (void *cls,
{
struct GNUNET_PeerIdentity peer0, peer1;
+ GNUNET_assert ((element0) && (element1));
+
GNUNET_PEER_resolve (element0->peer, &peer0);
GNUNET_PEER_resolve (element1->peer, &peer1);
@@ -68,10 +72,11 @@ add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels
*tunnels,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HashCode *hash)
{
+ struct GNUNET_MESSENGER_ListTunnel *element;
+
GNUNET_assert ((tunnels) && (peer));
- struct GNUNET_MESSENGER_ListTunnel *element = GNUNET_new (struct
-
GNUNET_MESSENGER_ListTunnel);
+ element = GNUNET_new (struct GNUNET_MESSENGER_ListTunnel);
element->peer = GNUNET_PEER_intern (peer);
element->hash = hash ? GNUNET_memdup (hash, sizeof (struct GNUNET_HashCode))
:
@@ -90,11 +95,11 @@ find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels
*tunnels,
const struct GNUNET_PeerIdentity *peer,
size_t *index)
{
- GNUNET_assert ((tunnels) && (peer));
-
struct GNUNET_MESSENGER_ListTunnel *element;
struct GNUNET_PeerIdentity pid;
+ GNUNET_assert ((tunnels) && (peer));
+
if (index)
*index = 0;
@@ -117,11 +122,11 @@ struct GNUNET_MESSENGER_ListTunnel*
find_list_tunnels_alternate (struct GNUNET_MESSENGER_ListTunnels *tunnels,
const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_assert ((tunnels) && (peer));
-
struct GNUNET_MESSENGER_ListTunnel *element;
struct GNUNET_PeerIdentity pid;
+ GNUNET_assert ((tunnels) && (peer));
+
for (element = tunnels->head; element; element = element->next)
{
GNUNET_PEER_resolve (element->peer, &pid);
@@ -140,11 +145,11 @@ verify_list_tunnels_flag_token (const struct
const struct GNUNET_PeerIdentity *peer,
enum GNUNET_MESSENGER_ConnectionFlags flag)
{
- GNUNET_assert ((tunnels) && (peer) && (flag));
-
struct GNUNET_MESSENGER_ListTunnel *element;
struct GNUNET_PeerIdentity pid;
+ GNUNET_assert ((tunnels) && (peer) && (flag));
+
for (element = tunnels->head; element; element = element->next)
{
if ((element->connection.flags & flag) != flag)
@@ -165,11 +170,11 @@ update_to_list_tunnels (struct
GNUNET_MESSENGER_ListTunnels *tunnels,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HashCode *hash)
{
+ struct GNUNET_MESSENGER_ListTunnel *element;
+
GNUNET_assert ((tunnels) && (peer));
- struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (tunnels,
- peer,
- NULL);
+ element = find_list_tunnels (tunnels, peer, NULL);
if (! element)
return;
@@ -203,9 +208,11 @@ struct GNUNET_MESSENGER_ListTunnel*
remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
struct GNUNET_MESSENGER_ListTunnel *element)
{
+ struct GNUNET_MESSENGER_ListTunnel *next;
+
GNUNET_assert ((tunnels) && (element));
- struct GNUNET_MESSENGER_ListTunnel *next = element->next;
+ next = element->next;
if ((tunnels->head) && (tunnels->tail))
GNUNET_CONTAINER_DLL_remove (tunnels->head, tunnels->tail, element);
@@ -215,7 +222,6 @@ remove_from_list_tunnels (struct
GNUNET_MESSENGER_ListTunnels *tunnels,
GNUNET_PEER_change_rc (element->peer, -1);
GNUNET_free (element);
-
return next;
}
@@ -224,6 +230,8 @@ void
load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
const char *path)
{
+ struct GNUNET_DISK_FileHandle *handle;
+
GNUNET_assert ((tunnels) && (path));
if (GNUNET_YES != GNUNET_DISK_file_test (path))
@@ -232,30 +240,31 @@ load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels
*tunnels,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load list of tunnels from path: %s\n",
path);
- enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ
- |
GNUNET_DISK_PERM_USER_WRITE
- );
-
- struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open (
- path, GNUNET_DISK_OPEN_READ, permission
- );
+ {
+ enum GNUNET_DISK_AccessPermissions permission;
+
+ permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+ handle = GNUNET_DISK_file_open (path, GNUNET_DISK_OPEN_READ, permission);
+ }
if (! handle)
return;
GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET);
- struct GNUNET_PeerIdentity peer;
- ssize_t len;
+ {
+ struct GNUNET_PeerIdentity peer;
+ ssize_t len;
- do {
- len = GNUNET_DISK_file_read (handle, &peer, sizeof(peer));
+ do {
+ len = GNUNET_DISK_file_read (handle, &peer, sizeof(peer));
- if (len != sizeof(peer))
- break;
+ if (len != sizeof(peer))
+ break;
- add_to_list_tunnels (tunnels, &peer, NULL);
- } while (len == sizeof(peer));
+ add_to_list_tunnels (tunnels, &peer, NULL);
+ } while (len == sizeof(peer));
+ }
GNUNET_DISK_file_close (handle);
}
@@ -265,32 +274,36 @@ void
save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels,
const char *path)
{
+ struct GNUNET_DISK_FileHandle *handle;
+
GNUNET_assert ((tunnels) && (path));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Save list of tunnels to path: %s\n",
path);
- enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ
- |
GNUNET_DISK_PERM_USER_WRITE
- );
-
- struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open (
- path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission
- );
+ {
+ enum GNUNET_DISK_AccessPermissions permission;
+
+ permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+ handle = GNUNET_DISK_file_open (
+ path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission);
+ }
if (! handle)
return;
GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET);
- struct GNUNET_MESSENGER_ListTunnel *element;
- struct GNUNET_PeerIdentity pid;
-
- for (element = tunnels->head; element; element = element->next)
{
- GNUNET_PEER_resolve (element->peer, &pid);
+ struct GNUNET_MESSENGER_ListTunnel *element;
+ struct GNUNET_PeerIdentity pid;
- GNUNET_DISK_file_write (handle, &pid, sizeof(pid));
+ for (element = tunnels->head; element; element = element->next)
+ {
+ GNUNET_PEER_resolve (element->peer, &pid);
+
+ GNUNET_DISK_file_write (handle, &pid, sizeof(pid));
+ }
}
GNUNET_DISK_file_sync (handle);
diff --git a/src/service/messenger/messenger_api_message.c
b/src/service/messenger/messenger_api_message.c
index 4150e658a..12158acc9 100644
--- a/src/service/messenger/messenger_api_message.c
+++ b/src/service/messenger/messenger_api_message.c
@@ -29,6 +29,9 @@
#include "gnunet_messenger_service.h"
#include "gnunet_signatures.h"
+const uint16_t encryption_overhead =
+ GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES;
+
struct GNUNET_MESSENGER_MessageSignature
{
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
@@ -44,9 +47,9 @@ struct GNUNET_MESSENGER_ShortMessage
struct GNUNET_MESSENGER_Message*
create_message (enum GNUNET_MESSENGER_MessageKind kind)
{
- struct GNUNET_MESSENGER_Message *message = GNUNET_new (struct
-
GNUNET_MESSENGER_Message);
-
+ struct GNUNET_MESSENGER_Message *message;
+
+ message = GNUNET_new (struct GNUNET_MESSENGER_Message);
message->header.kind = kind;
switch (message->header.kind)
@@ -89,11 +92,11 @@ create_message (enum GNUNET_MESSENGER_MessageKind kind)
struct GNUNET_MESSENGER_Message*
copy_message (const struct GNUNET_MESSENGER_Message *message)
{
- GNUNET_assert (message);
+ struct GNUNET_MESSENGER_Message *copy;
- struct GNUNET_MESSENGER_Message *copy = GNUNET_new (struct
-
GNUNET_MESSENGER_Message);
+ GNUNET_assert (message);
+ copy = GNUNET_new (struct GNUNET_MESSENGER_Message);
GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
switch (message->header.kind)
@@ -158,9 +161,11 @@ void
copy_message_header (struct GNUNET_MESSENGER_Message *message,
const struct GNUNET_MESSENGER_MessageHeader *header)
{
+ enum GNUNET_MESSENGER_MessageKind kind;
+
GNUNET_assert ((message) && (header));
- enum GNUNET_MESSENGER_MessageKind kind = message->header.kind;
+ kind = message->header.kind;
GNUNET_memcpy (&(message->header), header,
sizeof(struct GNUNET_MESSENGER_MessageHeader));
@@ -173,6 +178,8 @@ static void
destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind,
struct GNUNET_MESSENGER_MessageBody *body)
{
+ GNUNET_assert (body);
+
switch (kind)
{
case GNUNET_MESSENGER_KIND_NAME:
@@ -278,7 +285,9 @@ unfold_short_message (struct GNUNET_MESSENGER_ShortMessage
*shortened,
static uint16_t
get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind)
{
- uint16_t length = 0;
+ uint16_t length;
+
+ length = 0;
switch (kind)
{
@@ -358,7 +367,9 @@ uint16_t
get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind,
enum GNUNET_GenericReturnValue include_header)
{
- uint16_t length = 0;
+ uint16_t length;
+
+ length = 0;
if (GNUNET_YES == include_header)
{
@@ -377,7 +388,9 @@ static uint16_t
get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind,
const struct GNUNET_MESSENGER_MessageBody *body)
{
- uint16_t length = 0;
+ uint16_t length;
+
+ length = 0;
switch (kind)
{
@@ -424,9 +437,11 @@ uint16_t
get_message_size (const struct GNUNET_MESSENGER_Message *message,
enum GNUNET_GenericReturnValue include_header)
{
- GNUNET_assert (message);
+ uint16_t length;
- uint16_t length = 0;
+ GNUNET_assert (message);
+
+ length = 0;
if (GNUNET_YES == include_header)
length += GNUNET_CRYPTO_signature_get_length (
@@ -443,7 +458,9 @@ static uint16_t
get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message,
enum GNUNET_GenericReturnValue include_body)
{
- const uint16_t minimum_size = sizeof(struct GNUNET_HashCode) +
sizeof(kind_t);
+ uint16_t minimum_size;
+
+ minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
if (message)
return minimum_size + get_message_body_kind_size (message->kind)
@@ -457,9 +474,11 @@ get_short_message_size (const struct
GNUNET_MESSENGER_ShortMessage *message,
static uint16_t
calc_usual_padding ()
{
- uint16_t padding = 0;
+ uint16_t padding;
uint16_t kind_size;
+ padding = 0;
+
for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
{
kind_size = get_message_kind_size ((enum GNUNET_MESSENGER_MessageKind) i,
@@ -479,11 +498,12 @@ static uint16_t
calc_padded_length (uint16_t length)
{
static uint16_t usual_padding = 0;
+ uint16_t padded_length;
if (! usual_padding)
usual_padding = calc_usual_padding ();
- const uint16_t padded_length = max (
+ padded_length = max (
length + GNUNET_MESSENGER_PADDING_MIN,
usual_padding
);
@@ -541,6 +561,9 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind,
uint16_t offset)
{
uint32_t value0, value1;
+
+ GNUNET_assert ((body) && (buffer));
+
switch (kind)
{
case GNUNET_MESSENGER_KIND_INFO:
@@ -662,18 +685,23 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind
kind,
if (offset >= length)
return;
- const uint16_t padding = length - offset;
- const uint16_t used_padding = sizeof(padding) + sizeof(char);
+ {
+ uint16_t padding;
+ uint16_t used_padding;
+
+ padding = length - offset;
+ used_padding = sizeof(padding) + sizeof(char);
- GNUNET_assert (padding >= used_padding);
+ GNUNET_assert (padding >= used_padding);
- buffer[offset++] = '\0';
+ buffer[offset++] = '\0';
- if (padding > used_padding)
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, buffer + offset,
- padding - used_padding);
+ if (padding > used_padding)
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, buffer + offset,
+ padding - used_padding);
- GNUNET_memcpy (buffer + length - sizeof(padding), &padding, sizeof(padding));
+ GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
sizeof(padding));
+ }
}
@@ -683,15 +711,18 @@ encode_message (const struct GNUNET_MESSENGER_Message
*message,
char *buffer,
enum GNUNET_GenericReturnValue include_header)
{
+ uint16_t offset;
+ kind_t kind;
+
GNUNET_assert ((message) && (buffer));
- uint16_t offset = 0;
+ offset = 0;
if (GNUNET_YES == include_header)
encode_step_signature (buffer, offset, &(message->header.signature),
length);
- const kind_t kind = GNUNET_htobe32 ((kind_t) message->header.kind);
+ kind = GNUNET_htobe32 ((kind_t) message->header.kind);
if (GNUNET_YES == include_header)
{
@@ -713,9 +744,13 @@ encode_short_message (const struct
GNUNET_MESSENGER_ShortMessage *message,
char *buffer)
{
struct GNUNET_HashCode hash;
- uint16_t offset = sizeof(hash);
+ uint16_t offset;
+ kind_t kind;
+
+ GNUNET_assert ((message) && (buffer));
- const kind_t kind = GNUNET_htobe32 ((kind_t) message->kind);
+ offset = sizeof(hash);
+ kind = GNUNET_htobe32 ((kind_t) message->kind);
encode_step (buffer, offset, &kind);
@@ -764,21 +799,28 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind
*kind,
const char *buffer,
uint16_t offset)
{
- uint16_t padding = 0;
+ uint16_t padding;
+ uint32_t value0, value1;
+
+ GNUNET_assert ((kind) && (body) && (buffer));
+
+ padding = 0;
GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
if (padding > length - offset)
padding = 0;
- const uint16_t end_zero = length - padding;
+ {
+ uint16_t end_zero;
+ end_zero = length - padding;
- if ((padding) && (buffer[end_zero] != '\0'))
- padding = 0;
+ if ((padding) && (buffer[end_zero] != '\0'))
+ padding = 0;
+ }
length -= padding;
- uint32_t value0, value1;
switch (*kind)
{
case GNUNET_MESSENGER_KIND_INFO:
@@ -931,6 +973,10 @@ decode_message (struct GNUNET_MESSENGER_Message *message,
enum GNUNET_GenericReturnValue include_header,
uint16_t *padding)
{
+ uint16_t offset;
+ uint16_t count;
+ kind_t kind;
+
GNUNET_assert (
(message) &&
(buffer) &&
@@ -938,13 +984,14 @@ decode_message (struct GNUNET_MESSENGER_Message *message,
include_header))
);
- uint16_t offset = 0;
+ offset = 0;
if (GNUNET_YES == include_header)
{
- ssize_t result = GNUNET_CRYPTO_read_signature_from_buffer (
- &(message->header.signature), buffer, length - offset
- );
+ ssize_t result;
+
+ result = GNUNET_CRYPTO_read_signature_from_buffer (
+ &(message->header.signature), buffer, length - offset);
if (result < 0)
return GNUNET_NO;
@@ -952,14 +999,11 @@ decode_message (struct GNUNET_MESSENGER_Message *message,
offset += result;
}
- const uint16_t count = length - offset;
-
+ count = length - offset;
if (count < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN,
include_header))
return GNUNET_NO;
- kind_t kind;
-
if (GNUNET_YES == include_header)
{
decode_step (buffer, offset, &(message->header.timestamp));
@@ -975,12 +1019,14 @@ decode_message (struct GNUNET_MESSENGER_Message *message,
if (count < get_message_kind_size (message->header.kind, include_header))
return GNUNET_NO;
- const uint16_t result = decode_message_body (&(message->header.kind),
- &(message->body), length,
buffer,
- offset);
+ {
+ uint16_t result;
+ result = decode_message_body (&(message->header.kind),
+ &(message->body), length, buffer, offset);
- if (padding)
- *padding = result;
+ if (padding)
+ *padding = result;
+ }
return GNUNET_YES;
}
@@ -992,7 +1038,12 @@ decode_short_message (struct
GNUNET_MESSENGER_ShortMessage *message,
const char *buffer)
{
struct GNUNET_HashCode expected, hash;
- uint16_t offset = sizeof(hash);
+ uint16_t offset;
+ kind_t kind;
+
+ GNUNET_assert ((message) && (buffer));
+
+ offset = sizeof(hash);
if (length < get_short_message_size (NULL, GNUNET_NO))
return GNUNET_NO;
@@ -1002,14 +1053,11 @@ decode_short_message (struct
GNUNET_MESSENGER_ShortMessage *message,
GNUNET_CRYPTO_hash (
buffer + sizeof(hash),
length - sizeof(hash),
- &expected
- );
+ &expected);
if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
return GNUNET_NO;
- kind_t kind;
-
decode_step (buffer, offset, &kind);
message->kind = (enum GNUNET_MESSENGER_MessageKind) GNUNET_be32toh (kind);
@@ -1033,11 +1081,11 @@ hash_message (const struct GNUNET_MESSENGER_Message
*message,
const char *buffer,
struct GNUNET_HashCode *hash)
{
+ ssize_t offset;
+
GNUNET_assert ((message) && (buffer) && (hash));
- const ssize_t offset = GNUNET_CRYPTO_signature_get_length (
- &(message->header.signature)
- );
+ offset = GNUNET_CRYPTO_signature_get_length (&(message->header.signature));
GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
}
@@ -1055,18 +1103,22 @@ sign_message (struct GNUNET_MESSENGER_Message *message,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
GNUNET_h2s (hash));
- struct GNUNET_MESSENGER_MessageSignature signature;
+ {
+ struct GNUNET_MESSENGER_MessageSignature signature;
- signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
- signature.purpose.size = htonl (sizeof(signature));
+ signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
+ signature.purpose.size = htonl (sizeof(signature));
- GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
- GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
+ GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
+ GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
+ }
message->header.signature.type = key->type;
- uint16_t offset = 0;
- encode_step_signature (buffer, offset, &(message->header.signature), length);
+ {
+ uint16_t offset = 0;
+ encode_step_signature (buffer, offset, &(message->header.signature),
length);
+ }
}
@@ -1082,20 +1134,23 @@ sign_message_by_peer (struct GNUNET_MESSENGER_Message
*message,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
GNUNET_h2s (hash));
- struct GNUNET_MESSENGER_MessageSignature signature;
-
- signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
- signature.purpose.size = htonl (sizeof(signature));
-
- GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
- GNUNET_CRYPTO_sign_by_peer_identity (cfg, &(signature.purpose),
- &(message->header.signature.
- eddsa_signature));
+ {
+ struct GNUNET_MESSENGER_MessageSignature signature;
+ signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
+ signature.purpose.size = htonl (sizeof(signature));
+
+ GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
+ GNUNET_CRYPTO_sign_by_peer_identity (cfg, &(signature.purpose),
+ &(message->header.signature.
+ eddsa_signature));
+ }
message->header.signature.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
- uint16_t offset = 0;
- encode_step_signature (buffer, offset, &(message->header.signature), length);
+ {
+ uint16_t offset = 0;
+ encode_step_signature (buffer, offset, &(message->header.signature),
length);
+ }
}
@@ -1104,13 +1159,13 @@ verify_message (const struct GNUNET_MESSENGER_Message
*message,
const struct GNUNET_HashCode *hash,
const struct GNUNET_CRYPTO_PublicKey *key)
{
+ struct GNUNET_MESSENGER_MessageSignature signature;
+
GNUNET_assert ((message) && (hash) && (key));
if (key->type != message->header.signature.type)
return GNUNET_SYSERR;
- struct GNUNET_MESSENGER_MessageSignature signature;
-
signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
signature.purpose.size = htonl (sizeof(signature));
@@ -1127,13 +1182,13 @@ verify_message_by_peer (const struct
GNUNET_MESSENGER_Message *message,
const struct GNUNET_HashCode *hash,
const struct GNUNET_PeerIdentity *identity)
{
+ struct GNUNET_MESSENGER_MessageSignature signature;
+
GNUNET_assert ((message) && (hash) && (identity));
if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
return GNUNET_SYSERR;
- struct GNUNET_MESSENGER_MessageSignature signature;
-
signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE);
signature.purpose.size = htonl (sizeof(signature));
@@ -1150,34 +1205,35 @@ enum GNUNET_GenericReturnValue
encrypt_message (struct GNUNET_MESSENGER_Message *message,
const struct GNUNET_CRYPTO_PublicKey *key)
{
- const uint16_t overhead = GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES;
-
struct GNUNET_CRYPTO_EcdhePublicKey hpke_key;
+ enum GNUNET_GenericReturnValue result;
+ struct GNUNET_MESSENGER_ShortMessage shortened;
+ uint16_t length, padded_length, encoded_length;
+ uint8_t *data;
+
GNUNET_assert ((message) && (key));
if (GNUNET_YES == is_service_message (message))
return GNUNET_NO;
- struct GNUNET_MESSENGER_ShortMessage shortened;
-
fold_short_message (message, &shortened);
- const uint16_t length = get_short_message_size (&shortened, GNUNET_YES);
- const uint16_t padded_length = calc_padded_length (length + overhead);
+ length = get_short_message_size (&shortened, GNUNET_YES);
+ padded_length = calc_padded_length (length + encryption_overhead);
- GNUNET_assert (padded_length >= length + overhead);
+ GNUNET_assert (padded_length >= length + encryption_overhead);
message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE;
message->body.privacy.data = GNUNET_malloc (padded_length);
message->body.privacy.length = padded_length;
GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_hpke_pk_to_x25519 (key,
&hpke_key));
- const uint16_t encoded_length = (padded_length - overhead);
+ encoded_length = (padded_length - encryption_overhead);
- GNUNET_assert (padded_length == encoded_length + overhead);
+ GNUNET_assert (padded_length == encoded_length + encryption_overhead);
- enum GNUNET_GenericReturnValue result = GNUNET_NO;
- uint8_t *data = GNUNET_malloc (encoded_length);
+ result = GNUNET_NO;
+ data = GNUNET_malloc (encoded_length);
encode_short_message (&shortened, encoded_length, (char *) data);
@@ -1210,14 +1266,16 @@ enum GNUNET_GenericReturnValue
decrypt_message (struct GNUNET_MESSENGER_Message *message,
const struct GNUNET_CRYPTO_PrivateKey *key)
{
- const uint16_t overhead = GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES;
-
struct GNUNET_CRYPTO_EcdhePrivateKey hpke_key;
+ enum GNUNET_GenericReturnValue result;
+ uint16_t padded_length, encoded_length;
+ uint8_t *data;
+
GNUNET_assert ((message) && (key));
- const uint16_t padded_length = message->body.privacy.length;
+ padded_length = message->body.privacy.length;
- if (padded_length < overhead)
+ if (padded_length < encryption_overhead)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Message length too short to decrypt!\n");
@@ -1226,12 +1284,12 @@ decrypt_message (struct GNUNET_MESSENGER_Message
*message,
}
GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_hpke_sk_to_x25519 (key,
&hpke_key));
- const uint16_t encoded_length = (padded_length - overhead);
+ encoded_length = (padded_length - encryption_overhead);
- GNUNET_assert (padded_length == encoded_length + overhead);
+ GNUNET_assert (padded_length == encoded_length + encryption_overhead);
- enum GNUNET_GenericReturnValue result = GNUNET_NO;
- uint8_t *data = GNUNET_malloc (encoded_length);
+ result = GNUNET_NO;
+ data = GNUNET_malloc (encoded_length);
if (GNUNET_OK !=
GNUNET_CRYPTO_hpke_open_oneshot (&hpke_key,
@@ -1248,20 +1306,21 @@ decrypt_message (struct GNUNET_MESSENGER_Message
*message,
goto cleanup;
}
- struct GNUNET_MESSENGER_ShortMessage shortened;
-
- if (GNUNET_YES != decode_short_message (&shortened,
- encoded_length,
- (char*) data))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Decoding decrypted message failed!\n");
+ struct GNUNET_MESSENGER_ShortMessage shortened;
+ if (GNUNET_YES != decode_short_message (&shortened,
+ encoded_length,
+ (char*) data))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Decoding decrypted message failed!\n");
- goto cleanup;
- }
+ goto cleanup;
+ }
- unfold_short_message (&shortened, message);
- result = GNUNET_YES;
+ unfold_short_message (&shortened, message);
+ result = GNUNET_YES;
+ }
cleanup:
GNUNET_free (data);
@@ -1273,13 +1332,14 @@ struct GNUNET_MESSENGER_Message*
transcribe_message (const struct GNUNET_MESSENGER_Message *message,
const struct GNUNET_CRYPTO_PublicKey *key)
{
+ struct GNUNET_MESSENGER_Message *transcript;
+
GNUNET_assert ((message) && (key));
if (GNUNET_YES == is_service_message (message))
return NULL;
- struct GNUNET_MESSENGER_Message *transcript = create_message (
- GNUNET_MESSENGER_KIND_TRANSCRIPT);
+ transcript = create_message (GNUNET_MESSENGER_KIND_TRANSCRIPT);
if (! transcript)
{
@@ -1290,18 +1350,20 @@ transcribe_message (const struct
GNUNET_MESSENGER_Message *message,
GNUNET_memcpy (&(transcript->body.transcript.key), key,
sizeof(transcript->body.transcript.key));
- struct GNUNET_MESSENGER_ShortMessage shortened;
+ {
+ struct GNUNET_MESSENGER_ShortMessage shortened;
+ uint16_t data_length;
- fold_short_message (message, &shortened);
+ fold_short_message (message, &shortened);
- const uint16_t data_length = get_short_message_size (
- &shortened, GNUNET_YES);
+ data_length = get_short_message_size (&shortened, GNUNET_YES);
- transcript->body.transcript.data = GNUNET_malloc (data_length);
- transcript->body.transcript.length = data_length;
+ transcript->body.transcript.data = GNUNET_malloc (data_length);
+ transcript->body.transcript.length = data_length;
- encode_short_message (&shortened, data_length,
- transcript->body.transcript.data);
+ encode_short_message (&shortened, data_length,
+ transcript->body.transcript.data);
+ }
return transcript;
}
@@ -1310,14 +1372,16 @@ transcribe_message (const struct
GNUNET_MESSENGER_Message *message,
enum GNUNET_GenericReturnValue
read_transcript_message (struct GNUNET_MESSENGER_Message *message)
{
+ uint16_t data_length;
+ struct GNUNET_MESSENGER_ShortMessage shortened;
+
GNUNET_assert (message);
if (GNUNET_MESSENGER_KIND_TRANSCRIPT != message->header.kind)
return GNUNET_NO;
- const uint16_t data_length = message->body.transcript.length;
+ data_length = message->body.transcript.length;
- struct GNUNET_MESSENGER_ShortMessage shortened;
if (GNUNET_YES != decode_short_message (&shortened,
data_length,
message->body.transcript.data))
@@ -1340,31 +1404,29 @@ pack_message (struct GNUNET_MESSENGER_Message *message,
enum GNUNET_MESSENGER_PackMode mode,
const void *cls)
{
+ struct GNUNET_MessageHeader *header;
+ uint16_t length, padded_length;
+ struct GNUNET_MQ_Envelope *env;
+ char *buffer;
+
GNUNET_assert (message);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Packing message kind=%u and sender: %s\n",
message->header.kind, GNUNET_sh2s
(&(message->header.sender_id)));
- struct GNUNET_MessageHeader *header;
-
- const uint16_t length = get_message_size (message, GNUNET_YES);
- const uint16_t padded_length = calc_padded_length (length);
-
- struct GNUNET_MQ_Envelope *env;
- char *buffer;
+ length = get_message_size (message, GNUNET_YES);
+ padded_length = calc_padded_length (length);
if (GNUNET_MESSENGER_PACK_MODE_ENVELOPE == mode)
{
env = GNUNET_MQ_msg_extra (header, padded_length,
GNUNET_MESSAGE_TYPE_CADET_CLI);
-
buffer = (char*) &(header[1]);
}
else
{
env = NULL;
-
buffer = GNUNET_malloc (padded_length);
}
diff --git a/src/service/messenger/messenger_api_message_control.c
b/src/service/messenger/messenger_api_message_control.c
index 350528ed2..a1ae3698a 100644
--- a/src/service/messenger/messenger_api_message_control.c
+++ b/src/service/messenger/messenger_api_message_control.c
@@ -37,10 +37,10 @@
struct GNUNET_MESSENGER_MessageControl*
create_message_control (struct GNUNET_MESSENGER_Room *room)
{
- GNUNET_assert (room);
-
struct GNUNET_MESSENGER_MessageControl *control;
+ GNUNET_assert (room);
+
control = GNUNET_new (struct GNUNET_MESSENGER_MessageControl);
control->room = room;
@@ -60,9 +60,9 @@ destroy_message_control (struct
GNUNET_MESSENGER_MessageControl *control)
{
GNUNET_assert (control);
- struct GNUNET_MESSENGER_MessageControlQueue *queue;
while (control->head)
{
+ struct GNUNET_MESSENGER_MessageControlQueue *queue;
queue = control->head;
if (queue->task)
@@ -89,16 +89,16 @@ enqueue_message_control (struct
GNUNET_MESSENGER_MessageControl *control,
const struct GNUNET_MESSENGER_Message *message,
enum GNUNET_MESSENGER_MessageFlags flags)
{
+ struct GNUNET_CONTAINER_MultiShortmap *map;
+ struct GNUNET_MESSENGER_MessageControlQueue *queue;
+
GNUNET_assert ((control) && (sender) && (context) && (hash) && (message));
- struct GNUNET_CONTAINER_MultiShortmap *map;
if (GNUNET_YES == is_peer_message (message))
map = control->peer_messages;
else
map = control->member_messages;
- struct GNUNET_MESSENGER_MessageControlQueue *queue;
-
queue = GNUNET_new (struct GNUNET_MESSENGER_MessageControlQueue);
queue->control = control;
@@ -141,21 +141,29 @@ handle_message_control (struct
GNUNET_MESSENGER_MessageControl *control,
static void
task_message_control (void *cls)
{
+ struct GNUNET_MESSENGER_MessageControlQueue *queue;
+ struct GNUNET_MESSENGER_MessageControl *control;
+ struct GNUNET_MESSENGER_Contact *contact;
+ struct GNUNET_CONTAINER_MultiShortmap *map;
+
GNUNET_assert (cls);
- struct GNUNET_MESSENGER_MessageControlQueue *queue = cls;
- struct GNUNET_MESSENGER_MessageControl *control = queue->control;
+ queue = cls;
+ control = queue->control;
queue->task = NULL;
- struct GNUNET_MESSENGER_Handle *handle = get_room_handle (control->room);
- struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
- handle);
+ {
+ struct GNUNET_MESSENGER_Handle *handle;
+ struct GNUNET_MESSENGER_ContactStore *store;
- struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw (
- store, &(queue->context), &(queue->sender));
+ handle = get_room_handle (control->room);
+ store = get_handle_contact_store (handle);
+
+ contact = get_store_contact_raw (
+ store, &(queue->context), &(queue->sender));
+ }
- struct GNUNET_CONTAINER_MultiShortmap *map;
if (GNUNET_YES == is_peer_message (queue->message))
map = control->peer_messages;
else
@@ -184,9 +192,11 @@ iterate_message_control (void *cls,
const struct GNUNET_ShortHashCode *key,
void *value)
{
- GNUNET_assert ((key) && (value));
+ struct GNUNET_MESSENGER_MessageControlQueue *queue;
- struct GNUNET_MESSENGER_MessageControlQueue *queue = value;
+ GNUNET_assert ((key) && (value));
+
+ queue = value;
if (queue->task)
return GNUNET_YES;
@@ -204,14 +214,21 @@ process_message_control (struct
GNUNET_MESSENGER_MessageControl *control,
const struct GNUNET_MESSENGER_Message *message,
enum GNUNET_MESSENGER_MessageFlags flags)
{
+ struct GNUNET_MESSENGER_Contact *contact;
+ struct GNUNET_CONTAINER_MultiShortmap *map;
+ const struct GNUNET_ShortHashCode *id;
+
GNUNET_assert ((control) && (sender) && (context) && (hash) && (message));
- struct GNUNET_MESSENGER_Handle *handle = get_room_handle (control->room);
- struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
- handle);
+ {
+ struct GNUNET_MESSENGER_Handle *handle;
+ struct GNUNET_MESSENGER_ContactStore *store;
+
+ handle = get_room_handle (control->room);
+ store = get_handle_contact_store (handle);
- struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw (
- store, context, sender);
+ contact = get_store_contact_raw (store, context, sender);
+ }
if ((! contact) &&
(GNUNET_MESSENGER_KIND_JOIN != message->header.kind) &&
@@ -220,8 +237,8 @@ process_message_control (struct
GNUNET_MESSENGER_MessageControl *control,
else
handle_message_control (control, contact, hash, message, flags);
- struct GNUNET_CONTAINER_MultiShortmap *map = NULL;
- const struct GNUNET_ShortHashCode *id = &(message->header.sender_id);
+ map = NULL;
+ id = &(message->header.sender_id);
if (GNUNET_YES == is_peer_message (message))
map = control->peer_messages;
diff --git a/src/service/messenger/messenger_api_message_kind.c
b/src/service/messenger/messenger_api_message_kind.c
index 9def26409..3006376d5 100644
--- a/src/service/messenger/messenger_api_message_kind.c
+++ b/src/service/messenger/messenger_api_message_kind.c
@@ -30,11 +30,12 @@
struct GNUNET_MESSENGER_Message*
create_message_join (const struct GNUNET_CRYPTO_PrivateKey *key)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! key)
return NULL;
- struct GNUNET_MESSENGER_Message *message = create_message (
- GNUNET_MESSENGER_KIND_JOIN);
+ message = create_message (GNUNET_MESSENGER_KIND_JOIN);
if (! message)
return NULL;
@@ -54,11 +55,12 @@ create_message_leave ()
struct GNUNET_MESSENGER_Message*
create_message_name (const char *name)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! name)
return NULL;
- struct GNUNET_MESSENGER_Message *message = create_message (
- GNUNET_MESSENGER_KIND_NAME);
+ message = create_message (GNUNET_MESSENGER_KIND_NAME);
if (! message)
return NULL;
@@ -71,11 +73,12 @@ create_message_name (const char *name)
struct GNUNET_MESSENGER_Message*
create_message_key (const struct GNUNET_CRYPTO_PrivateKey *key)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! key)
return NULL;
- struct GNUNET_MESSENGER_Message *message = create_message (
- GNUNET_MESSENGER_KIND_KEY);
+ message = create_message (GNUNET_MESSENGER_KIND_KEY);
if (! message)
return NULL;
@@ -88,18 +91,18 @@ create_message_key (const struct GNUNET_CRYPTO_PrivateKey
*key)
struct GNUNET_MESSENGER_Message*
create_message_id (const struct GNUNET_ShortHashCode *unique_id)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! unique_id)
return NULL;
- struct GNUNET_MESSENGER_Message *message = create_message (
- GNUNET_MESSENGER_KIND_ID);
+ message = create_message (GNUNET_MESSENGER_KIND_ID);
if (! message)
return NULL;
- GNUNET_memcpy (&(message->body.id.id), unique_id, sizeof(struct
-
GNUNET_ShortHashCode)
- );
+ GNUNET_memcpy (&(message->body.id.id), unique_id,
+ sizeof(struct GNUNET_ShortHashCode));
return message;
}
@@ -108,17 +111,20 @@ create_message_id (const struct GNUNET_ShortHashCode
*unique_id)
struct GNUNET_MESSENGER_Message*
create_message_request (const struct GNUNET_HashCode *hash)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! hash)
return NULL;
- struct GNUNET_HashCode zero;
- memset (&zero, 0, sizeof(zero));
+ {
+ struct GNUNET_HashCode zero;
+ memset (&zero, 0, sizeof(zero));
- if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero))
- return NULL;
+ if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero))
+ return NULL;
+ }
- struct GNUNET_MESSENGER_Message *message = create_message (
- GNUNET_MESSENGER_KIND_REQUEST);
+ message = create_message (GNUNET_MESSENGER_KIND_REQUEST);
if (! message)
return NULL;
@@ -134,11 +140,12 @@ struct GNUNET_MESSENGER_Message*
create_message_delete (const struct GNUNET_HashCode *hash,
const struct GNUNET_TIME_Relative delay)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! hash)
return NULL;
- struct GNUNET_MESSENGER_Message *message = create_message (
- GNUNET_MESSENGER_KIND_DELETE);
+ message = create_message (GNUNET_MESSENGER_KIND_DELETE);
if (! message)
return NULL;
@@ -156,11 +163,12 @@ create_message_subscribe (const struct
GNUNET_ShortHashCode *discourse,
const struct GNUNET_TIME_Relative time,
uint32_t flags)
{
+ struct GNUNET_MESSENGER_Message *message;
+
if (! discourse)
return NULL;
- struct GNUNET_MESSENGER_Message *message = create_message (
- GNUNET_MESSENGER_KIND_SUBSCRIBE);
+ message = create_message (GNUNET_MESSENGER_KIND_SUBSCRIBE);
if (! message)
return NULL;
diff --git a/src/service/messenger/messenger_api_queue_messages.c
b/src/service/messenger/messenger_api_queue_messages.c
index 9a87f62a7..f26da0363 100644
--- a/src/service/messenger/messenger_api_queue_messages.c
+++ b/src/service/messenger/messenger_api_queue_messages.c
@@ -45,7 +45,8 @@ clear_queue_messages (struct GNUNET_MESSENGER_QueueMessages
*messages)
while (messages->head)
{
- struct GNUNET_MESSENGER_QueueMessage *element = messages->head;
+ struct GNUNET_MESSENGER_QueueMessage *element;
+ element = messages->head;
GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element);
@@ -69,15 +70,16 @@ enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages
*messages,
struct GNUNET_MESSENGER_Message *message,
struct GNUNET_MESSENGER_Message *transcript)
{
- GNUNET_assert ((messages) && (sender) && (message));
+ struct GNUNET_MESSENGER_QueueMessage *element;
+ enum GNUNET_MESSENGER_MessageKind kind;
- struct GNUNET_MESSENGER_QueueMessage *element = GNUNET_new (struct
-
GNUNET_MESSENGER_QueueMessage);
+ GNUNET_assert ((messages) && (sender) && (message));
+ element = GNUNET_new (struct GNUNET_MESSENGER_QueueMessage);
if (! element)
return;
- const enum GNUNET_MESSENGER_MessageKind kind = message->header.kind;
+ kind = message->header.kind;
element->message = message;
element->transcript = transcript;
@@ -97,8 +99,9 @@ enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages
*messages,
GNUNET_CONTAINER_DLL_insert (messages->head, messages->tail, element);
else if (GNUNET_MESSENGER_KIND_SUBSCRIBE == kind)
{
- struct GNUNET_MESSENGER_QueueMessage *other = messages->head;
+ struct GNUNET_MESSENGER_QueueMessage *other;
+ other = messages->head;
while (other)
{
if (GNUNET_MESSENGER_KIND_TALK == other->message->header.kind)
@@ -119,10 +122,12 @@ dequeue_from_messages (struct
GNUNET_MESSENGER_QueueMessages *messages,
struct GNUNET_CRYPTO_PrivateKey *sender,
struct GNUNET_MESSENGER_Message **transcript)
{
- GNUNET_assert (messages);
+ struct GNUNET_MESSENGER_QueueMessage *element;
+ struct GNUNET_MESSENGER_Message *message;
- struct GNUNET_MESSENGER_QueueMessage *element = messages->head;
+ GNUNET_assert (messages);
+ element = messages->head;
if (! element)
{
if (transcript)
@@ -131,7 +136,7 @@ dequeue_from_messages (struct
GNUNET_MESSENGER_QueueMessages *messages,
return NULL;
}
- struct GNUNET_MESSENGER_Message *message = element->message;
+ message = element->message;
if (transcript)
*transcript = element->transcript;
diff --git a/src/service/messenger/messenger_api_room.c
b/src/service/messenger/messenger_api_room.c
index e83c9d7d3..4f02dafd3 100644
--- a/src/service/messenger/messenger_api_room.c
+++ b/src/service/messenger/messenger_api_room.c
@@ -40,12 +40,13 @@ struct GNUNET_MESSENGER_Room*
create_room (struct GNUNET_MESSENGER_Handle *handle,
const struct GNUNET_HashCode *key)
{
- GNUNET_assert ((handle) && (key));
+ struct GNUNET_MESSENGER_Room *room;
- struct GNUNET_MESSENGER_Room *room = GNUNET_new (struct
- GNUNET_MESSENGER_Room);
+ GNUNET_assert ((handle) && (key));
+ room = GNUNET_new (struct GNUNET_MESSENGER_Room);
room->handle = handle;
+
GNUNET_memcpy (&(room->key), key, sizeof(*key));
memset (&(room->last_message), 0, sizeof(room->last_message));
@@ -78,11 +79,14 @@ iterate_destroy_message (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- struct GNUNET_MESSENGER_RoomMessageEntry *entry = value;
+ struct GNUNET_MESSENGER_RoomMessageEntry *entry;
+
+ GNUNET_assert (value);
+
+ entry = value;
destroy_message (entry->message);
GNUNET_free (entry);
-
return GNUNET_YES;
}
@@ -92,7 +96,12 @@ iterate_destroy_link (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- struct GNUNET_HashCode *hash = value;
+ struct GNUNET_HashCode *hash;
+
+ GNUNET_assert (value);
+
+ hash = value;
+
GNUNET_free (hash);
return GNUNET_YES;
}
@@ -103,7 +112,11 @@ iterate_destroy_subscription (void *cls,
const struct GNUNET_ShortHashCode *key,
void *value)
{
- struct GNUNET_MESSENGER_RoomSubscription *subscription = value;
+ struct GNUNET_MESSENGER_RoomSubscription *subscription;
+
+ GNUNET_assert (value);
+
+ subscription = value;
if (subscription->task)
GNUNET_SCHEDULER_cancel (subscription->task);
@@ -226,11 +239,11 @@ const struct GNUNET_MESSENGER_Message*
get_room_message (const struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash)
{
+ struct GNUNET_MESSENGER_RoomMessageEntry *entry;
+
GNUNET_assert ((room) && (hash));
- struct GNUNET_MESSENGER_RoomMessageEntry *entry =
- GNUNET_CONTAINER_multihashmap_get (
- room->messages, hash);
+ entry = GNUNET_CONTAINER_multihashmap_get (room->messages, hash);
if ((! entry) || (GNUNET_YES != entry->completed))
return NULL;
@@ -243,11 +256,11 @@ struct GNUNET_MESSENGER_Contact*
get_room_sender (const struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash)
{
+ struct GNUNET_MESSENGER_RoomMessageEntry *entry;
+
GNUNET_assert ((room) && (hash));
- struct GNUNET_MESSENGER_RoomMessageEntry *entry =
- GNUNET_CONTAINER_multihashmap_get (
- room->messages, hash);
+ entry = GNUNET_CONTAINER_multihashmap_get (room->messages, hash);
if ((! entry) || (GNUNET_YES != entry->completed))
return NULL;
@@ -260,11 +273,11 @@ struct GNUNET_MESSENGER_Contact*
get_room_recipient (const struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash)
{
+ struct GNUNET_MESSENGER_RoomMessageEntry *entry;
+
GNUNET_assert ((room) && (hash));
- struct GNUNET_MESSENGER_RoomMessageEntry *entry =
- GNUNET_CONTAINER_multihashmap_get (
- room->messages, hash);
+ entry = GNUNET_CONTAINER_multihashmap_get (room->messages, hash);
if ((! entry) || (GNUNET_YES != entry->completed))
return NULL;
@@ -277,16 +290,16 @@ void
callback_room_message (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash)
{
- GNUNET_assert ((room) && (hash));
+ struct GNUNET_MESSENGER_Handle *handle;
+ struct GNUNET_MESSENGER_RoomMessageEntry *entry;
- struct GNUNET_MESSENGER_Handle *handle = room->handle;
+ GNUNET_assert ((room) && (hash));
+ handle = room->handle;
if (! handle)
return;
- struct GNUNET_MESSENGER_RoomMessageEntry *entry;
entry = GNUNET_CONTAINER_multihashmap_get (room->messages, hash);
-
if (! entry)
return;
@@ -318,10 +331,11 @@ handle_join_message (struct GNUNET_MESSENGER_Room *room,
if (! entry->sender)
{
- struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
- room->handle);
+ struct GNUNET_MESSENGER_ContactStore *store;
struct GNUNET_HashCode context;
+ store = get_handle_contact_store (room->handle);
+
get_context_from_member (&(room->key), &(entry->message->header.sender_id),
&context);
@@ -336,7 +350,6 @@ handle_join_message (struct GNUNET_MESSENGER_Room *room,
.sender_id),
entry->sender,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)))
-
increase_contact_rc (entry->sender);
}
@@ -370,11 +383,13 @@ handle_name_message (struct GNUNET_MESSENGER_Room *room,
if (GNUNET_MESSENGER_FLAG_SENT & entry->flags)
{
+ const char *handle_name;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Set rule for using handle name in room: %s\n",
GNUNET_h2s (&(room->key)));
- const char *handle_name = get_handle_name (room->handle);
+ handle_name = get_handle_name (room->handle);
if ((handle_name) && (0 == strcmp (handle_name,
entry->message->body.name.name)))
@@ -393,17 +408,18 @@ handle_key_message (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash,
struct GNUNET_MESSENGER_RoomMessageEntry *entry)
{
+ struct GNUNET_HashCode context;
+ struct GNUNET_MESSENGER_ContactStore *store;
+
GNUNET_assert ((room) && (hash) && (entry));
if (! entry->sender)
return;
- struct GNUNET_HashCode context;
get_context_from_member (&(room->key), &(entry->message->header.sender_id),
&context);
- struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
- room->handle);
+ store = get_handle_contact_store (room->handle);
update_store_contact (store, entry->sender, &context, &context,
&(entry->message->body.key.key));
@@ -415,6 +431,9 @@ handle_id_message (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash,
struct GNUNET_MESSENGER_RoomMessageEntry *entry)
{
+ struct GNUNET_HashCode context, next_context;
+ struct GNUNET_MESSENGER_ContactStore *store;
+
GNUNET_assert ((room) && (hash) && (entry));
if (GNUNET_MESSENGER_FLAG_SENT & entry->flags)
@@ -433,14 +452,12 @@ handle_id_message (struct GNUNET_MESSENGER_Room *room,
return;
- struct GNUNET_HashCode context, next_context;
get_context_from_member (&(room->key), &(entry->message->header.sender_id),
&context);
get_context_from_member (&(room->key), &(entry->message->body.id.id),
&next_context);
- struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
- room->handle);
+ store = get_handle_contact_store (room->handle);
update_store_contact (store, entry->sender, &context, &next_context,
get_contact_key (entry->sender));
@@ -452,13 +469,14 @@ handle_miss_message (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash,
struct GNUNET_MESSENGER_RoomMessageEntry *entry)
{
+ struct GNUNET_MESSENGER_ListTunnel *match;
+
GNUNET_assert ((room) && (hash) && (entry));
if (0 == (GNUNET_MESSENGER_FLAG_SENT & entry->flags))
return;
- struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels (
- &(room->entries), &(entry->message->body.miss.peer), NULL);
+ match = find_list_tunnels (&(room->entries),
&(entry->message->body.miss.peer), NULL);
if (match)
remove_from_list_tunnels (&(room->entries), match);
@@ -470,10 +488,11 @@ handle_private_message (struct GNUNET_MESSENGER_Room
*room,
const struct GNUNET_HashCode *hash,
struct GNUNET_MESSENGER_RoomMessageEntry *entry)
{
+ struct GNUNET_MESSENGER_Message *private_message;
+
GNUNET_assert ((room) && (hash) && (entry));
- struct GNUNET_MESSENGER_Message *private_message = copy_message (
- entry->message);
+ private_message = copy_message (entry->message);
if (! private_message)
return;
@@ -511,10 +530,12 @@ handle_delete_message (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash,
struct GNUNET_MESSENGER_RoomMessageEntry *entry)
{
+ const struct GNUNET_HashCode *target_hash;
+ struct GNUNET_MESSENGER_RoomMessageEntry *target;
+
GNUNET_assert ((room) && (hash) && (entry));
- const struct GNUNET_HashCode *target_hash =
- &(entry->message->body.deletion.hash);
+ target_hash = &(entry->message->body.deletion.hash);
if (get_handle_contact (room->handle, &(room->key)) == entry->sender)
{
@@ -532,9 +553,7 @@ handle_delete_message (struct GNUNET_MESSENGER_Room *room,
link_room_deletion (room, target_hash, delay, delete_message_in_room);
}
- struct GNUNET_MESSENGER_RoomMessageEntry *target =
- GNUNET_CONTAINER_multihashmap_get (room->messages, target_hash);
-
+ target = GNUNET_CONTAINER_multihashmap_get (room->messages, target_hash);
if (! target)
return;
@@ -560,19 +579,18 @@ handle_transcript_message (struct GNUNET_MESSENGER_Room
*room,
const struct GNUNET_HashCode *hash,
struct GNUNET_MESSENGER_RoomMessageEntry *entry)
{
+ const struct GNUNET_HashCode *original_hash;
+ struct GNUNET_MESSENGER_RoomMessageEntry *original;
+ struct GNUNET_MESSENGER_Message *original_message;
+
GNUNET_assert ((room) && (hash) && (entry));
if (get_handle_contact (room->handle, &(room->key)) != entry->sender)
return;
- const struct GNUNET_HashCode *original_hash =
- &(entry->message->body.transcript.hash);
- struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store (
- room->handle);
+ original_hash = &(entry->message->body.transcript.hash);
- struct GNUNET_MESSENGER_RoomMessageEntry *original =
- GNUNET_CONTAINER_multihashmap_get (room->messages, original_hash);
- struct GNUNET_MESSENGER_Message *original_message;
+ original = GNUNET_CONTAINER_multihashmap_get (room->messages, original_hash);
if (original)
goto read_transcript;
@@ -610,10 +628,15 @@ read_transcript:
return;
}
- original->recipient = get_store_contact (store,
- NULL,
-
&(entry->message->body.transcript.key
- ));
+ {
+ struct GNUNET_MESSENGER_ContactStore *store;
+
+ store = get_handle_contact_store (room->handle);
+ original->recipient = get_store_contact (store,
+ NULL,
+
&(entry->message->body.transcript.key
+ ));
+ }
if (original->message)
{
@@ -689,9 +712,10 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash,
enum GNUNET_MESSENGER_MessageFlags flags)
{
+ struct GNUNET_MESSENGER_RoomMessageEntry *entry;
+
GNUNET_assert ((room) && (message) && (hash));
- struct GNUNET_MESSENGER_RoomMessageEntry *entry;
entry = GNUNET_CONTAINER_multihashmap_get (room->messages, hash);
if (entry)
@@ -759,8 +783,13 @@ iterate_local_members (void *cls,
const struct GNUNET_ShortHashCode *key,
void *value)
{
- struct GNUNET_MESSENGER_MemberCall *call = cls;
- struct GNUNET_MESSENGER_Contact *contact = value;
+ struct GNUNET_MESSENGER_MemberCall *call;
+ struct GNUNET_MESSENGER_Contact *contact;
+
+ GNUNET_assert ((cls) && (value));
+
+ call = cls;
+ contact = value;
return call->callback (call->cls, call->room, contact);
}
@@ -771,13 +800,13 @@ iterate_room_members (struct GNUNET_MESSENGER_Room *room,
GNUNET_MESSENGER_MemberCallback callback,
void *cls)
{
+ struct GNUNET_MESSENGER_MemberCall call;
+
GNUNET_assert (room);
if (! callback)
return GNUNET_CONTAINER_multishortmap_iterate (room->members, NULL, NULL);
- struct GNUNET_MESSENGER_MemberCall call;
-
call.room = room;
call.callback = callback;
call.cls = cls;
@@ -801,8 +830,13 @@ iterate_find_member (void *cls,
const struct GNUNET_ShortHashCode *key,
void *value)
{
- struct GNUNET_MESSENGER_MemberFind *find = cls;
- struct GNUNET_MESSENGER_Contact *contact = value;
+ struct GNUNET_MESSENGER_MemberFind *find;
+ struct GNUNET_MESSENGER_Contact *contact;
+
+ GNUNET_assert ((cls) && (value));
+
+ find = cls;
+ contact = value;
if (contact == find->contact)
{
@@ -818,10 +852,10 @@ enum GNUNET_GenericReturnValue
find_room_member (const struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_MESSENGER_Contact *contact)
{
- GNUNET_assert (room);
-
struct GNUNET_MESSENGER_MemberFind find;
+ GNUNET_assert (room);
+
find.contact = contact;
find.result = GNUNET_NO;
@@ -837,8 +871,13 @@ find_linked_hash (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- const struct GNUNET_HashCode **result = cls;
- struct GNUNET_HashCode *hash = value;
+ const struct GNUNET_HashCode **result;
+ struct GNUNET_HashCode *hash;
+
+ GNUNET_assert ((cls) && (value));
+
+ result = cls;
+ hash = value;
if (0 == GNUNET_CRYPTO_hash_cmp (hash, *result))
{
@@ -855,18 +894,19 @@ link_room_message (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_HashCode *hash,
const struct GNUNET_HashCode *other)
{
+ const struct GNUNET_HashCode **result;
+ struct GNUNET_HashCode *value;
+
GNUNET_assert ((room) && (hash) && (other));
- const struct GNUNET_HashCode **result = &other;
+ result = &other;
GNUNET_CONTAINER_multihashmap_get_multiple (room->links, hash,
find_linked_hash, result);
if (! *result)
return;
- struct GNUNET_HashCode *value = GNUNET_memdup (other, sizeof(struct
-
GNUNET_HashCode))
- ;
+ value = GNUNET_memdup (other, sizeof(struct GNUNET_HashCode));
if (! value)
return;
@@ -890,8 +930,13 @@ clear_linked_hash (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- struct GNUNET_HashCode **linked = cls;
- struct GNUNET_HashCode *hash = value;
+ struct GNUNET_HashCode **linked;
+ struct GNUNET_HashCode *hash;
+
+ GNUNET_assert ((cls) && (value));
+
+ linked = cls;
+ hash = value;
if (0 != GNUNET_CRYPTO_hash_cmp (*linked, hash))
return GNUNET_YES;
@@ -906,14 +951,19 @@ delete_linked_hash (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- struct GNUNET_MESSENGER_RoomLinkDeletionInfo *info = cls;
- struct GNUNET_HashCode *hash = value;
-
+ struct GNUNET_MESSENGER_RoomLinkDeletionInfo *info;
+ struct GNUNET_HashCode *hash;
struct GNUNET_HashCode key_value;
- GNUNET_memcpy (&key_value, key, sizeof (key_value));
+ struct GNUNET_HashCode *linked;
+
+ GNUNET_assert ((cls) && (key) && (value));
- struct GNUNET_HashCode *linked = &key_value;
+ info = cls;
+ hash = value;
+
+ GNUNET_memcpy (&key_value, key, sizeof (key_value));
+ linked = &key_value;
GNUNET_CONTAINER_multihashmap_get_multiple (info->room->links, hash,
clear_linked_hash, &linked);
@@ -936,9 +986,10 @@ link_room_deletion (struct GNUNET_MESSENGER_Room *room,
const struct GNUNET_TIME_Relative delay,
GNUNET_MESSENGER_RoomLinkDeletion deletion)
{
+ struct GNUNET_MESSENGER_RoomLinkDeletionInfo info;
+
GNUNET_assert ((room) && (hash));
- struct GNUNET_MESSENGER_RoomLinkDeletionInfo info;
info.room = room;
info.delay = delay;
info.deletion = deletion;
diff --git a/src/service/messenger/messenger_api_util.c
b/src/service/messenger/messenger_api_util.c
index 1d38f87a1..2c89b0e76 100644
--- a/src/service/messenger/messenger_api_util.c
+++ b/src/service/messenger/messenger_api_util.c
@@ -31,7 +31,9 @@
static void
callback_close_channel (void *cls)
{
- struct GNUNET_CADET_Channel *channel = cls;
+ struct GNUNET_CADET_Channel *channel;
+
+ channel = cls;
if (channel)
GNUNET_CADET_channel_destroy (channel);
@@ -53,10 +55,11 @@ enum GNUNET_GenericReturnValue
generate_free_member_id (struct GNUNET_ShortHashCode *id,
const struct GNUNET_CONTAINER_MultiShortmap *members)
{
+ size_t counter;
+
GNUNET_assert (id);
- size_t counter = 1 + (members ? GNUNET_CONTAINER_multishortmap_size (
- members) : 0);
+ counter = 1 + (members ? GNUNET_CONTAINER_multishortmap_size (members) : 0);
do
{
@@ -81,7 +84,8 @@ generate_free_member_id (struct GNUNET_ShortHashCode *id,
const struct GNUNET_CRYPTO_PrivateKey*
get_anonymous_private_key ()
{
- const struct GNUNET_IDENTITY_Ego *ego = GNUNET_IDENTITY_ego_get_anonymous ();
+ const struct GNUNET_IDENTITY_Ego *ego;
+ ego = GNUNET_IDENTITY_ego_get_anonymous ();
return GNUNET_IDENTITY_ego_get_private_key (ego);
}
@@ -106,8 +110,10 @@ void
convert_messenger_key_to_port (const struct GNUNET_HashCode *key,
struct GNUNET_HashCode *port)
{
- static uint32_t version_value = 0;
static struct GNUNET_HashCode version;
+ static uint32_t version_value = 0;
+
+ GNUNET_assert ((key) && (port));
if (! version_value)
{
@@ -125,5 +131,7 @@ void
convert_peer_identity_to_id (const struct GNUNET_PeerIdentity *identity,
struct GNUNET_ShortHashCode *id)
{
+ GNUNET_assert ((identity) && (id));
+
GNUNET_memcpy (id, identity, sizeof(struct GNUNET_ShortHashCode));
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: MESSENGER: adjust code in client side of service to reduce warnings,
gnunet <=