commit ea62f25fccb6c10d5f4a32a8d259116c51d94ee3
parent d1a6ac474d731b74ea1b191a76471b698687a278
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Thu, 22 Jul 2021 21:02:33 +0200
Added user pointers to structs and some new kinds for messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
10 files changed, 202 insertions(+), 6 deletions(-)
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
@@ -41,17 +41,37 @@ enum GNUNET_CHAT_MessageKind
/**
* TODO
*/
- GNUNET_CHAT_KIND_TEXT = 1, /**< GNUNET_CHAT_KIND_TEXT */
+ GNUNET_CHAT_KIND_JOIN = 1, /**< GNUNET_CHAT_KIND_JOIN */
/**
* TODO
*/
- GNUNET_CHAT_KIND_FILE = 2, /**< GNUNET_CHAT_KIND_FILE */
+ GNUNET_CHAT_KIND_LEAVE = 2, /**< GNUNET_CHAT_KIND_LEAVE */
/**
* TODO
*/
- GNUNET_CHAT_KIND_INVITATION = 3, /**< GNUNET_CHAT_KIND_INVITATION */
+ GNUNET_CHAT_KIND_CONTACT = 3, /**< GNUNET_CHAT_KIND_CONTACT */
+
+ /**
+ * TODO
+ */
+ GNUNET_CHAT_KIND_INVITATION = 4, /**< GNUNET_CHAT_KIND_INVITATION */
+
+ /**
+ * TODO
+ */
+ GNUNET_CHAT_KIND_TEXT = 5, /**< GNUNET_CHAT_KIND_TEXT */
+
+ /**
+ * TODO
+ */
+ GNUNET_CHAT_KIND_FILE = 6, /**< GNUNET_CHAT_KIND_FILE */
+
+ /**
+ * TODO
+ */
+ GNUNET_CHAT_KIND_DELETION = 7, /**< GNUNET_CHAT_KIND_DELETION */
/**
* TODO
@@ -338,6 +358,26 @@ GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact);
/**
* TODO
*
+ * @param contact
+ * @param user_pointer
+ * @return
+ */
+void
+GNUNET_CHAT_contact_set_user_pointer (struct GNUNET_CHAT_Contact *contact,
+ void *user_pointer);
+
+/**
+ * TODO
+ *
+ * @param contact
+ * @return
+ */
+void*
+GNUNET_CHAT_contact_get_user_pointer (struct GNUNET_CHAT_Contact *contact);
+
+/**
+ * TODO
+ *
* @param group
* @return
*/
@@ -352,7 +392,7 @@ GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group);
*/
void
GNUNET_CHAT_group_set_name (struct GNUNET_CHAT_Group *group,
- const char *name);
+ const char *name);
/**
* TODO
@@ -367,6 +407,24 @@ GNUNET_CHAT_group_get_name (const struct GNUNET_CHAT_Group *group);
* TODO
*
* @param group
+ * @param user_pointer
+ */
+void
+GNUNET_CHAT_group_set_user_pointer (struct GNUNET_CHAT_Group *group,
+ void *user_pointer);
+
+/**
+ * TODO
+ *
+ * @param group
+ */
+void*
+GNUNET_CHAT_group_get_user_pointer (struct GNUNET_CHAT_Group *group);
+
+/**
+ * TODO
+ *
+ * @param group
* @param contact
*/
void
@@ -399,6 +457,24 @@ GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group);
* TODO
*
* @param context
+ * @param user_pointer
+ */
+void
+GNUNET_CHAT_context_set_user_pointer (struct GNUNET_CHAT_Context *context,
+ void *user_pointer);
+
+/**
+ * TODO
+ *
+ * @param context
+ */
+void*
+GNUNET_CHAT_context_get_user_pointer (const struct GNUNET_CHAT_Context *context);
+
+/**
+ * TODO
+ *
+ * @param context
* @param text
* @return
*/
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -37,6 +37,8 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle,
contact->member = member;
+ contact->user_pointer = NULL;
+
return contact;
}
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
@@ -39,6 +39,8 @@ struct GNUNET_CHAT_Contact
struct GNUNET_CHAT_Context *context;
const struct GNUNET_MESSENGER_Contact *member;
+
+ void *user_pointer;
};
struct GNUNET_CHAT_Contact*
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
@@ -43,6 +43,8 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle,
context->room = room;
+ context->user_pointer = NULL;
+
return context;
}
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h
@@ -52,6 +52,8 @@ struct GNUNET_CHAT_Context
struct GNUNET_CONTAINER_MultiHashMap *files;
struct GNUNET_MESSENGER_Room *room;
+
+ void *user_pointer;
};
struct GNUNET_CHAT_Context*
diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c
@@ -40,6 +40,8 @@ group_create_from_context (struct GNUNET_CHAT_Handle *handle,
group->announcement = NULL;
group->search = NULL;
+ group->user_pointer = NULL;
+
return group;
}
diff --git a/src/gnunet_chat_group.h b/src/gnunet_chat_group.h
@@ -42,6 +42,8 @@ struct GNUNET_CHAT_Group
struct GNUNET_REGEX_Announcement *announcement;
struct GNUNET_REGEX_Search *search;
+
+ void *user_pointer;
};
struct GNUNET_CHAT_Group*
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -77,6 +77,8 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
on_handle_message, handle
);
+ handle->user_pointer = NULL;
+
return handle;
}
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
@@ -56,6 +56,8 @@ struct GNUNET_CHAT_Handle
struct GNUNET_ARM_Handle *arm;
struct GNUNET_FS_Handle *fs;
struct GNUNET_MESSENGER_Handle *messenger;
+
+ void *user_pointer;
};
struct GNUNET_CHAT_Handle*
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -55,6 +55,7 @@ GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
);
}
+
void
GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
{
@@ -64,6 +65,7 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
handle_destroy(handle);
}
+
int
GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle)
{
@@ -73,6 +75,7 @@ GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle)
return GNUNET_MESSENGER_update(handle->messenger);
}
+
int
GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle,
const char *name)
@@ -86,6 +89,7 @@ GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle,
return GNUNET_MESSENGER_set_name(handle->messenger, name);
}
+
const char*
GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle)
{
@@ -95,6 +99,7 @@ GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle)
return GNUNET_MESSENGER_get_name(handle->messenger);
}
+
const struct GNUNET_IDENTITY_PublicKey*
GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle)
{
@@ -104,6 +109,28 @@ GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle)
return GNUNET_MESSENGER_get_key(handle->messenger);
}
+
+void
+GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle,
+ void *user_pointer)
+{
+ if (!handle)
+ return;
+
+ handle->user_pointer = user_pointer;
+}
+
+
+void*
+GNUNET_CHAT_get_user_pointer (const struct GNUNET_CHAT_Handle *handle)
+{
+ if (!handle)
+ return NULL;
+
+ return handle->user_pointer;
+}
+
+
int
GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
GNUNET_CHAT_ContactCallback callback,
@@ -122,6 +149,7 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
);
}
+
struct GNUNET_CHAT_Group *
GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle,
const char* topic)
@@ -174,6 +202,7 @@ destroy_context:
return NULL;
}
+
int
GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
GNUNET_CHAT_GroupCallback callback,
@@ -192,6 +221,7 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
);
}
+
int
GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact)
{
@@ -220,6 +250,7 @@ GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact)
return GNUNET_OK;
}
+
void
GNUNET_CHAT_contact_set_name (struct GNUNET_CHAT_Contact *contact,
const char *name)
@@ -264,6 +295,27 @@ GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact)
}
+void
+GNUNET_CHAT_contact_set_user_pointer (struct GNUNET_CHAT_Contact *contact,
+ void *user_pointer)
+{
+ if (!contact)
+ return;
+
+ contact->user_pointer = user_pointer;
+}
+
+
+void*
+GNUNET_CHAT_contact_get_user_pointer (struct GNUNET_CHAT_Contact *contact)
+{
+ if (!contact)
+ return NULL;
+
+ return contact->user_pointer;
+}
+
+
int
GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group)
{
@@ -312,6 +364,27 @@ GNUNET_CHAT_group_get_name (const struct GNUNET_CHAT_Group *group)
void
+GNUNET_CHAT_group_set_user_pointer (struct GNUNET_CHAT_Group *group,
+ void *user_pointer)
+{
+ if (!group)
+ return;
+
+ group->user_pointer = user_pointer;
+}
+
+
+void*
+GNUNET_CHAT_group_get_user_pointer (struct GNUNET_CHAT_Group *group)
+{
+ if (!group)
+ return NULL;
+
+ return group->user_pointer;
+}
+
+
+void
GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group,
struct GNUNET_CHAT_Contact *contact)
{
@@ -362,6 +435,27 @@ GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group)
}
+void
+GNUNET_CHAT_context_set_user_pointer (struct GNUNET_CHAT_Context *context,
+ void *user_pointer)
+{
+ if (!context)
+ return;
+
+ context->user_pointer = user_pointer;
+}
+
+
+void*
+GNUNET_CHAT_context_get_user_pointer (const struct GNUNET_CHAT_Context *context)
+{
+ if (!context)
+ return NULL;
+
+ return context->user_pointer;
+}
+
+
int
GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
const char *text)
@@ -521,12 +615,22 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message)
switch (message->msg->header.kind)
{
+ case GNUNET_MESSENGER_KIND_JOIN:
+ return GNUNET_CHAT_KIND_JOIN;
+ case GNUNET_MESSENGER_KIND_LEAVE:
+ return GNUNET_CHAT_KIND_LEAVE;
+ case GNUNET_MESSENGER_KIND_NAME:
+ case GNUNET_MESSENGER_KIND_KEY:
+ case GNUNET_MESSENGER_KIND_ID:
+ return GNUNET_CHAT_KIND_CONTACT;
case GNUNET_MESSENGER_KIND_INVITE:
return GNUNET_CHAT_KIND_INVITATION;
case GNUNET_MESSENGER_KIND_TEXT:
return GNUNET_CHAT_KIND_TEXT;
case GNUNET_MESSENGER_KIND_FILE:
return GNUNET_CHAT_KIND_FILE;
+ case GNUNET_MESSENGER_KIND_DELETE:
+ return GNUNET_CHAT_KIND_DELETION;
default:
return GNUNET_CHAT_KIND_UNKNOWN;
}
@@ -633,8 +737,8 @@ GNUNET_CHAT_message_delete (const struct GNUNET_CHAT_Message *message,
struct GNUNET_MESSENGER_Message msg;
msg.header.kind = GNUNET_MESSENGER_KIND_DELETE;
- GNUNET_memcpy(&(msg.body.delete.hash), &(message->hash), sizeof(message->hash));
- msg.body.delete.delay = GNUNET_TIME_relative_hton(delay);
+ GNUNET_memcpy(&(msg.body.deletion.hash), &(message->hash), sizeof(message->hash));
+ msg.body.deletion.delay = GNUNET_TIME_relative_hton(delay);
GNUNET_MESSENGER_send_message(message->context->room, &msg, NULL);
return GNUNET_OK;