gnunet_chat_message.h (4246B)
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_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 union { 66 const struct GNUNET_MESSENGER_Message *msg; 67 const char *warning; 68 const char *attr; 69 }; 70 71 struct GNUNET_HashCode hash; 72 enum GNUNET_MESSENGER_MessageFlags flags; 73 enum GNUNET_CHAT_MessageFlag flag; 74 75 void *user_pointer; 76 }; 77 78 /** 79 * Creates a chat message representing an actual message 80 * from the messenger service in a given chat <i>context</i> 81 * with a valid <i>hash</i> and message <i>flags</i> 82 * 83 * @param[in,out] context Chat context 84 * @param[in] hash Message hash 85 * @param[in] flags Message flags 86 * @param[in] msg Messenger message 87 * @return New chat message 88 */ 89 struct GNUNET_CHAT_Message* 90 message_create_from_msg (struct GNUNET_CHAT_Context *context, 91 const struct GNUNET_HashCode *hash, 92 enum GNUNET_MESSENGER_MessageFlags flags, 93 const struct GNUNET_MESSENGER_Message *msg); 94 95 /** 96 * Creates an internal chat message with an optional chat 97 * <i>account</i> or <i>context</i>, a custom <i>flag</i> 98 * and an optional <i>warning</i> text. 99 * 100 * @param[in,out] account Chat account or NULL 101 * @param[in,out] context Chat context or NULL 102 * @param[in] flag Chat message flag 103 * @param[in] warning Warning text 104 * @return New internal chat message 105 */ 106 struct GNUNET_CHAT_Message* 107 message_create_internally (struct GNUNET_CHAT_Account *account, 108 struct GNUNET_CHAT_Context *context, 109 enum GNUNET_CHAT_MessageFlag flag, 110 const char *warning); 111 112 /** 113 * Returns whether a chat <i>message</i> contains an actual 114 * message from the messenger service. 115 * 116 * @param[in] message Chat message 117 * @return #GNUNET_YES if it contains message content, #GNUNET_NO otherwise 118 */ 119 enum GNUNET_GenericReturnValue 120 message_has_msg (const struct GNUNET_CHAT_Message* message); 121 122 /** 123 * Updates a chat message representing an actual message 124 * from the messenger service. 125 * 126 * @param[in,out] message Chat message 127 * @param[in] flags Message flags 128 * @param[in] msg Messenger message 129 */ 130 void 131 message_update_msg (struct GNUNET_CHAT_Message* message, 132 enum GNUNET_MESSENGER_MessageFlags flags, 133 const struct GNUNET_MESSENGER_Message *msg); 134 135 /** 136 * Destroys a chat <i>message</i> and frees its memory. 137 * 138 * @param[in,out] message Chat message 139 */ 140 void 141 message_destroy (struct GNUNET_CHAT_Message* message); 142 143 #endif /* GNUNET_CHAT_MESSAGE_H_ */