gnunet_chat_context.h (5523B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2021--2025 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.h 23 */ 24 25 #ifndef GNUNET_CHAT_CONTEXT_H_ 26 #define GNUNET_CHAT_CONTEXT_H_ 27 28 #include <gnunet/gnunet_common.h> 29 #include <gnunet/gnunet_gnsrecord_lib.h> 30 #include <gnunet/gnunet_messenger_service.h> 31 #include <gnunet/gnunet_util_lib.h> 32 #include <stdint.h> 33 34 #include "gnunet_chat_util.h" 35 36 struct GNUNET_CHAT_Handle; 37 struct GNUNET_CHAT_Message; 38 39 struct GNUNET_CHAT_Context 40 { 41 struct GNUNET_CHAT_Handle *handle; 42 43 union GNUNET_MESSENGER_RoomKey key; 44 enum GNUNET_CHAT_ContextType type; 45 uint32_t flags; 46 char *nick; 47 char *topic; 48 int deleted; 49 50 struct GNUNET_SCHEDULER_Task *request_task; 51 52 struct GNUNET_CONTAINER_MultiShortmap *timestamps; 53 struct GNUNET_CONTAINER_MultiHashMap *dependencies; 54 struct GNUNET_CONTAINER_MultiHashMap *messages; 55 struct GNUNET_CONTAINER_MultiHashMap *requests; 56 struct GNUNET_CONTAINER_MultiHashMap *taggings; 57 struct GNUNET_CONTAINER_MultiHashMap *invites; 58 struct GNUNET_CONTAINER_MultiHashMap *files; 59 struct GNUNET_CONTAINER_MultiShortmap *discourses; 60 61 struct GNUNET_MESSENGER_Room *room; 62 const struct GNUNET_MESSENGER_Contact *contact; 63 64 void *user_pointer; 65 66 struct GNUNET_CONTAINER_MultiShortmap *member_pointers; 67 68 struct GNUNET_NAMESTORE_QueueEntry *query; 69 }; 70 71 /** 72 * Creates a chat context from a messenger <i>room</i> 73 * with a selected chat <i>handle</i>. 74 * 75 * @param[in,out] handle Chat handle 76 * @param[in,out] room Messenger room 77 * @return New chat context 78 */ 79 struct GNUNET_CHAT_Context* 80 context_create_from_room (struct GNUNET_CHAT_Handle *handle, 81 struct GNUNET_MESSENGER_Room *room); 82 83 /** 84 * Creates a chat context from a messenger <i>contact</i> 85 * with a selected chat <i>handle</i>. 86 * 87 * @param[in,out] handle Chat handle 88 * @param[in] contact Messenger contact 89 * @return New chat context 90 */ 91 struct GNUNET_CHAT_Context* 92 context_create_from_contact (struct GNUNET_CHAT_Handle *handle, 93 const struct GNUNET_MESSENGER_Contact *contact); 94 95 /** 96 * Destroys a chat <i>context</i> and frees its memory. 97 * 98 * @param[in,out] context Chat context 99 */ 100 void 101 context_destroy (struct GNUNET_CHAT_Context* context); 102 103 /** 104 * Request a message from a chat <i>context</i> with a 105 * given <i>hash</i>. 106 * 107 * @param[in,out] context Chat context 108 * @param[in] hash Message hash 109 */ 110 void 111 context_request_message (struct GNUNET_CHAT_Context* context, 112 const struct GNUNET_HashCode *hash); 113 114 /** 115 * Updates a message with a given <i>hash</i> inside a 116 * given chat <i>context</i>. 117 * 118 * @param[in,out] context Chat context 119 * @param[in] hash Message hash 120 */ 121 void 122 context_update_message (struct GNUNET_CHAT_Context* context, 123 const struct GNUNET_HashCode *hash); 124 125 /** 126 * Updates the connected messenger <i>room</i> of a 127 * selected chat <i>context</i>. 128 * 129 * @param[in,out] context Chat context 130 * @param[in,out] room Messenger room 131 * @param[in] record Write changes to records 132 */ 133 void 134 context_update_room (struct GNUNET_CHAT_Context *context, 135 struct GNUNET_MESSENGER_Room *room, 136 enum GNUNET_GenericReturnValue record); 137 138 /** 139 * Updates the <i>nick</i> of a selected chat <i>context</i>. 140 * 141 * @param[in,out] context Chat context 142 * @param[in] nick Nick name 143 */ 144 void 145 context_update_nick (struct GNUNET_CHAT_Context *context, 146 const char *nick); 147 148 /** 149 * Deletes linked content from a given chat <i>context</i> 150 * of a specific chat <i>message</i>. 151 * 152 * @param[in,out] context Chat context 153 * @param[in] message Chat message 154 */ 155 void 156 context_delete_message (struct GNUNET_CHAT_Context *context, 157 const struct GNUNET_CHAT_Message *message); 158 159 /** 160 * Reads the <i>data</i> of records under a given <i>label</i> 161 * and updates the chat <i>context</i> with it. 162 * 163 * @param[in,out] context Chat context 164 * @param[in] label Label 165 * @param[in] count Count of data 166 * @param[in] data Records data 167 */ 168 void 169 context_read_records (struct GNUNET_CHAT_Context *context, 170 const char *label, 171 unsigned int count, 172 const struct GNUNET_GNSRECORD_Data *data); 173 174 /** 175 * Writes the data from a selected chat <i>context</i> into 176 * the namestore as private records. 177 * 178 * @param[in,out] context Chat context 179 */ 180 void 181 context_write_records (struct GNUNET_CHAT_Context *context); 182 183 /** 184 * Removes the data from a selected chat <i>context</i> from 185 * the namestore and closes its room optionally. 186 * 187 * @param[in,out] context Chat context 188 * @param[in] exit Closing its room 189 */ 190 void 191 context_delete (struct GNUNET_CHAT_Context *context, 192 enum GNUNET_GenericReturnValue exit); 193 194 #endif /* GNUNET_CHAT_CONTEXT_H_ */