gnunet_chat_message.h (4406B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2021--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_message.h 23 */ 24 25 #ifndef GNUNET_CHAT_MESSAGE_H_ 26 #define GNUNET_CHAT_MESSAGE_H_ 27 28 #include <gnunet/gnunet_common.h> 29 #include <gnunet/gnunet_messenger_service.h> 30 #include <gnunet/gnunet_util_lib.h> 31 32 struct GNUNET_CHAT_Context; 33 struct GNUNET_CHAT_Message; 34 35 struct GNUNET_CHAT_MessageList 36 { 37 struct GNUNET_CHAT_Message *message; 38 39 struct GNUNET_CHAT_MessageList *prev; 40 struct GNUNET_CHAT_MessageList *next; 41 }; 42 43 enum GNUNET_CHAT_MessageFlag 44 { 45 GNUNET_CHAT_FLAG_NONE = 0, 46 GNUNET_CHAT_FLAG_WARNING = 1, 47 GNUNET_CHAT_FLAG_REFRESH = 2, 48 GNUNET_CHAT_FLAG_LOGIN = 3, 49 GNUNET_CHAT_FLAG_LOGOUT = 4, 50 GNUNET_CHAT_FLAG_CREATE_ACCOUNT = 5, 51 GNUNET_CHAT_FLAG_DELETE_ACCOUNT = 6, 52 GNUNET_CHAT_FLAG_UPDATE_ACCOUNT = 7, 53 GNUNET_CHAT_FLAG_UPDATE_CONTEXT = 8, 54 GNUNET_CHAT_FLAG_ATTRIBUTES = 9, 55 GNUNET_CHAT_FLAG_SHARE_ATTRIBUTES = 10 56 }; 57 58 struct GNUNET_CHAT_Message 59 { 60 struct GNUNET_CHAT_Account *account; 61 62 struct GNUNET_CHAT_Context *context; 63 struct GNUNET_SCHEDULER_Task *task; 64 65 char *warning_buffer; 66 67 union { 68 const struct GNUNET_MESSENGER_Message *msg; 69 const char *warning; 70 const char *attr; 71 }; 72 73 struct GNUNET_HashCode hash; 74 enum GNUNET_MESSENGER_MessageFlags flags; 75 enum GNUNET_CHAT_MessageFlag flag; 76 77 void *user_pointer; 78 }; 79 80 /** 81 * Creates a chat message representing an actual message 82 * from the messenger service in a given chat <i>context</i> 83 * with a valid <i>hash</i> and message <i>flags</i> 84 * 85 * @param[in,out] context Chat context 86 * @param[in] hash Message hash 87 * @param[in] flags Message flags 88 * @param[in] msg Messenger message 89 * @return New chat message 90 */ 91 struct GNUNET_CHAT_Message* 92 message_create_from_msg (struct GNUNET_CHAT_Context *context, 93 const struct GNUNET_HashCode *hash, 94 enum GNUNET_MESSENGER_MessageFlags flags, 95 const struct GNUNET_MESSENGER_Message *msg); 96 97 /** 98 * Creates an internal chat message with an optional chat 99 * <i>account</i> or <i>context</i>, a custom <i>flag</i> 100 * and an optional <i>warning</i> text. 101 * 102 * @param[in,out] account Chat account or NULL 103 * @param[in,out] context Chat context or NULL 104 * @param[in] flag Chat message flag 105 * @param[in] warning Warning text 106 * @param[in] async_warning Async flag to buffer warning text 107 * @return New internal chat message 108 */ 109 struct GNUNET_CHAT_Message* 110 message_create_internally (struct GNUNET_CHAT_Account *account, 111 struct GNUNET_CHAT_Context *context, 112 enum GNUNET_CHAT_MessageFlag flag, 113 const char *warning, 114 enum GNUNET_GenericReturnValue async_warning); 115 116 /** 117 * Returns whether a chat <i>message</i> contains an actual 118 * message from the messenger service. 119 * 120 * @param[in] message Chat message 121 * @return #GNUNET_YES if it contains message content, #GNUNET_NO otherwise 122 */ 123 enum GNUNET_GenericReturnValue 124 message_has_msg (const struct GNUNET_CHAT_Message* message); 125 126 /** 127 * Updates a chat message representing an actual message 128 * from the messenger service. 129 * 130 * @param[in,out] message Chat message 131 * @param[in] flags Message flags 132 * @param[in] msg Messenger message 133 */ 134 void 135 message_update_msg (struct GNUNET_CHAT_Message* message, 136 enum GNUNET_MESSENGER_MessageFlags flags, 137 const struct GNUNET_MESSENGER_Message *msg); 138 139 /** 140 * Destroys a chat <i>message</i> and frees its memory. 141 * 142 * @param[in,out] message Chat message 143 */ 144 void 145 message_destroy (struct GNUNET_CHAT_Message* message); 146 147 #endif /* GNUNET_CHAT_MESSAGE_H_ */