gnunet_chat_context_intern.c (4250B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2021--2024 GNUnet e.V. 4 5 GNUnet is free software: you can redistribute it and/or modify it 6 under the terms of the GNU Affero General Public License as published 7 by the Free Software Foundation, either version 3 of the License, 8 or (at your option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 /* 21 * @author Tobias Frisch 22 * @file gnunet_chat_context_intern.c 23 */ 24 25 #include "gnunet_chat_discourse.h" 26 #include "gnunet_chat_invitation.h" 27 #include "gnunet_chat_message.h" 28 29 #include "internal/gnunet_chat_tagging.h" 30 31 #include <gnunet/gnunet_common.h> 32 #include <gnunet/gnunet_error_codes.h> 33 #include <gnunet/gnunet_messenger_service.h> 34 35 #define GNUNET_UNUSED __attribute__ ((unused)) 36 37 enum GNUNET_GenericReturnValue 38 it_destroy_context_timestamps (GNUNET_UNUSED void *cls, 39 GNUNET_UNUSED const struct GNUNET_ShortHashCode *key, 40 void *value) 41 { 42 GNUNET_assert(value); 43 44 struct GNUNET_TIME_Absolute *time = value; 45 GNUNET_free(time); 46 return GNUNET_YES; 47 } 48 49 enum GNUNET_GenericReturnValue 50 it_destroy_context_messages (GNUNET_UNUSED void *cls, 51 GNUNET_UNUSED const struct GNUNET_HashCode *key, 52 void *value) 53 { 54 GNUNET_assert(value); 55 56 struct GNUNET_CHAT_Message *message = value; 57 message_destroy(message); 58 return GNUNET_YES; 59 } 60 61 enum GNUNET_GenericReturnValue 62 it_destroy_context_taggings (GNUNET_UNUSED void *cls, 63 GNUNET_UNUSED const struct GNUNET_HashCode *key, 64 void *value) 65 { 66 GNUNET_assert(value); 67 68 struct GNUNET_CHAT_InternalTagging *tagging = value; 69 internal_tagging_destroy(tagging); 70 return GNUNET_YES; 71 } 72 73 enum GNUNET_GenericReturnValue 74 it_destroy_context_invites (void *cls, 75 GNUNET_UNUSED const struct GNUNET_HashCode *key, 76 void *value) 77 { 78 GNUNET_assert((cls) && (value)); 79 80 struct GNUNET_CHAT_Context *context = cls; 81 struct GNUNET_CHAT_Invitation *invitation = value; 82 83 struct GNUNET_CHAT_Handle *handle = context->handle; 84 85 GNUNET_CONTAINER_multihashmap_remove( 86 handle->invitations, &(invitation->key.hash), invitation); 87 88 invitation_destroy(invitation); 89 return GNUNET_YES; 90 } 91 92 enum GNUNET_GenericReturnValue 93 it_destroy_context_discourses (GNUNET_UNUSED void *cls, 94 GNUNET_UNUSED const struct GNUNET_ShortHashCode *key, 95 void *value) 96 { 97 GNUNET_assert(value); 98 99 struct GNUNET_CHAT_Discourse *discourse = value; 100 discourse_destroy(discourse); 101 return GNUNET_YES; 102 } 103 104 enum GNUNET_GenericReturnValue 105 it_iterate_context_requests (void *cls, 106 const struct GNUNET_HashCode *key, 107 GNUNET_UNUSED void *value) 108 { 109 struct GNUNET_CHAT_Context *context = cls; 110 111 GNUNET_assert((context) && (context->room) && (key)); 112 113 GNUNET_MESSENGER_get_message(context->room, key); 114 115 return GNUNET_YES; 116 } 117 118 void 119 cb_context_request_messages (void *cls) 120 { 121 struct GNUNET_CHAT_Context *context = cls; 122 123 GNUNET_assert(context); 124 125 context->request_task = NULL; 126 127 if ((!(context->room)) || (GNUNET_YES == context->deleted)) 128 return; 129 130 GNUNET_CONTAINER_multihashmap_iterate( 131 context->requests, 132 it_iterate_context_requests, 133 context 134 ); 135 136 GNUNET_CONTAINER_multihashmap_clear(context->requests); 137 } 138 139 void 140 cont_context_write_records (void *cls, 141 enum GNUNET_ErrorCode ec) 142 { 143 struct GNUNET_CHAT_Context *context = cls; 144 145 GNUNET_assert(context); 146 147 context->query = NULL; 148 149 if (GNUNET_EC_NONE != ec) 150 handle_send_internal_message( 151 context->handle, 152 NULL, 153 context, 154 GNUNET_CHAT_FLAG_WARNING, 155 GNUNET_ErrorCode_get_hint(ec), 156 GNUNET_YES 157 ); 158 }