gnunet_chat_tagging.h (3475B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 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_tagging.h 23 */ 24 25 #ifndef GNUNET_CHAT_INTERNAL_TAGGING_H_ 26 #define GNUNET_CHAT_INTERNAL_TAGGING_H_ 27 28 #include <gnunet/gnunet_common.h> 29 #include <gnunet/gnunet_util_lib.h> 30 31 struct GNUNET_CHAT_Message; 32 33 struct GNUNET_CHAT_InternalTagging 34 { 35 struct GNUNET_CONTAINER_MultiHashMap *tags; 36 }; 37 38 typedef enum GNUNET_GenericReturnValue 39 (*GNUNET_CHAT_TaggingCallback) (void *cls, 40 struct GNUNET_CHAT_Message *message); 41 42 /** 43 * Creates a tagging structure to manage different tag messages 44 * mapped by its custom tag value. 45 * 46 * @return New chat tagging 47 */ 48 struct GNUNET_CHAT_InternalTagging* 49 internal_tagging_create (); 50 51 /** 52 * Destroys a <i>tagging</i> structure to manage different tag 53 * messages mapped by its custom tag value. 54 * 55 * @param[out] tagging Chat tagging 56 */ 57 void 58 internal_tagging_destroy (struct GNUNET_CHAT_InternalTagging *tagging); 59 60 /** 61 * Adds a tag <i>message</i> to a selected <i>tagging</i> 62 * structure for later iterations. 63 * 64 * @param[in,out] tagging Chat tagging 65 * @param[in,out] message Tag message 66 * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR 67 */ 68 enum GNUNET_GenericReturnValue 69 internal_tagging_add (struct GNUNET_CHAT_InternalTagging *tagging, 70 struct GNUNET_CHAT_Message *message); 71 72 /** 73 * Removes a tag <i>message</i> from a selected <i>tagging</i> 74 * structure. 75 * 76 * @param[in,out] tagging Chat tagging 77 * @param[in] message Tag message 78 * @return #GNUNET_YES on success, #GNUNET_SYSERR on failure and 79 * otherwise #GNUNET_NO 80 */ 81 enum GNUNET_GenericReturnValue 82 internal_tagging_remove (struct GNUNET_CHAT_InternalTagging *tagging, 83 const struct GNUNET_CHAT_Message *message); 84 85 /** 86 * Iterates through a selected <i>tagging</i> structure forwarding 87 * tag messages with a specific <i>tag</i> to a custom callback with 88 * its closure. 89 * 90 * If <i>ignore_tag</i> is set to #GNUNET_YES all tag messages of the 91 * <i>tagging</i> structure will be iterated, otherwise only with matching 92 * tag value. 93 * 94 * @param[in] tagging Chat tagging 95 * @param[in] ignore_tag Flag to set tag filtering of the iteration 96 * @param[in] tag Tag value for filtering the iteration 97 * @param[in] cb Callback for iteration 98 * @param[in,out] cls Closure for iteration 99 * @return Amount of tags iterated or #GNUNET_SYSERR on error 100 */ 101 int 102 internal_tagging_iterate (const struct GNUNET_CHAT_InternalTagging *tagging, 103 enum GNUNET_GenericReturnValue ignore_tag, 104 const char *tag, 105 GNUNET_CHAT_TaggingCallback cb, 106 void *cls); 107 108 #endif /* GNUNET_CHAT_INTERNAL_TAGGING_H_ */