libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

gnunet_chat_context_intern.c (4319B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2021--2024, 2026 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_context.h"
     26 #include "gnunet_chat_discourse.h"
     27 #include "gnunet_chat_handle.h"
     28 #include "gnunet_chat_invitation.h"
     29 #include "gnunet_chat_message.h"
     30 
     31 #include "internal/gnunet_chat_tagging.h"
     32 
     33 #include <gnunet/gnunet_common.h>
     34 #include <gnunet/gnunet_error_codes.h>
     35 #include <gnunet/gnunet_messenger_service.h>
     36 
     37 #define GNUNET_UNUSED __attribute__ ((unused))
     38 
     39 enum GNUNET_GenericReturnValue
     40 it_destroy_context_timestamps (GNUNET_UNUSED void *cls,
     41                                GNUNET_UNUSED const struct GNUNET_ShortHashCode *key,
     42                                void *value)
     43 {
     44   GNUNET_assert(value);
     45 
     46   struct GNUNET_TIME_Absolute *time = value;
     47   GNUNET_free(time);
     48   return GNUNET_YES;
     49 }
     50 
     51 enum GNUNET_GenericReturnValue
     52 it_destroy_context_messages (GNUNET_UNUSED void *cls,
     53                              GNUNET_UNUSED const struct GNUNET_HashCode *key,
     54                              void *value)
     55 {
     56   GNUNET_assert(value);
     57 
     58   struct GNUNET_CHAT_Message *message = value;
     59   message_destroy(message);
     60   return GNUNET_YES;
     61 }
     62 
     63 enum GNUNET_GenericReturnValue
     64 it_destroy_context_taggings (GNUNET_UNUSED void *cls,
     65                              GNUNET_UNUSED const struct GNUNET_HashCode *key,
     66                              void *value)
     67 {
     68   GNUNET_assert(value);
     69 
     70   struct GNUNET_CHAT_InternalTagging *tagging = value;
     71   internal_tagging_destroy(tagging);
     72   return GNUNET_YES;
     73 }
     74 
     75 enum GNUNET_GenericReturnValue
     76 it_destroy_context_invites (void *cls,
     77                             GNUNET_UNUSED const struct GNUNET_HashCode *key,
     78                             void *value)
     79 {
     80   GNUNET_assert((cls) && (value));
     81 
     82   struct GNUNET_CHAT_Context *context = cls;
     83   struct GNUNET_CHAT_Invitation *invitation = value;
     84 
     85   struct GNUNET_CHAT_Handle *handle = context->handle;
     86 
     87   GNUNET_CONTAINER_multihashmap_remove(
     88     handle->invitations, &(invitation->key.hash), invitation);
     89 
     90   invitation_destroy(invitation);
     91   return GNUNET_YES;
     92 }
     93 
     94 enum GNUNET_GenericReturnValue
     95 it_destroy_context_discourses (GNUNET_UNUSED void *cls,
     96                                GNUNET_UNUSED const struct GNUNET_ShortHashCode *key,
     97                                void *value)
     98 {
     99   GNUNET_assert(value);
    100 
    101   struct GNUNET_CHAT_Discourse *discourse = value;
    102   discourse_destroy(discourse);
    103   return GNUNET_YES;
    104 }
    105 
    106 enum GNUNET_GenericReturnValue
    107 it_iterate_context_requests (void *cls,
    108                              const struct GNUNET_HashCode *key,
    109                              GNUNET_UNUSED void *value)
    110 {
    111   struct GNUNET_CHAT_Context *context = cls;
    112 
    113   GNUNET_assert((context) && (context->room) && (key));
    114 
    115   GNUNET_MESSENGER_get_message(context->room, key);
    116 
    117   return GNUNET_YES;
    118 }
    119 
    120 void
    121 cb_context_request_messages (void *cls)
    122 {
    123   struct GNUNET_CHAT_Context *context = cls;
    124 
    125   GNUNET_assert(context);
    126 
    127   context->request_task = NULL;
    128 
    129   if ((!(context->room)) || (GNUNET_YES == context->deleted))
    130     return;
    131 
    132   GNUNET_CONTAINER_multihashmap_iterate(
    133     context->requests,
    134     it_iterate_context_requests,
    135     context
    136   );
    137 
    138   GNUNET_CONTAINER_multihashmap_clear(context->requests);
    139 }
    140 
    141 void
    142 cont_context_write_records (void *cls,
    143 			                      enum GNUNET_ErrorCode ec)
    144 {
    145   struct GNUNET_CHAT_Context *context = cls;
    146 
    147   GNUNET_assert(context);
    148 
    149   context->query = NULL;
    150 
    151   if (GNUNET_EC_NONE != ec)
    152     handle_send_internal_message(
    153       context->handle,
    154       NULL,
    155       context,
    156       GNUNET_CHAT_FLAG_WARNING,
    157       GNUNET_ErrorCode_get_hint(ec),
    158       GNUNET_YES
    159     );
    160 }