From 106d7f2253661aa4504609486174bc396223b067 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 14 Nov 2014 23:08:01 -0500 Subject: [PATCH] add api function to get group title --- toxcore/group.c | 20 ++++++++++++++++++++ toxcore/group.h | 9 +++++++++ toxcore/tox.c | 12 ++++++++++++ toxcore/tox.h | 8 ++++++++ 4 files changed, 49 insertions(+) diff --git a/toxcore/group.c b/toxcore/group.c index cda1944d..826572ae 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1181,6 +1181,26 @@ int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *tit return -1; } +/* Get group title from groupnumber and put it in title. + * title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. + * + * return length of title if success. + * return -1 if failure. + */ +int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title) +{ + Group_c *g = get_group_c(g_c, groupnumber); + + if (!g) + return -1; + + if (g->title_len == 0 || g->title_len > MAX_NAME_LENGTH) + return -1; + + memcpy(title, g->title, g->title_len); + return g->title_len; +} + static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length) { Group_Chats *g_c = m->group_chat_object; diff --git a/toxcore/group.h b/toxcore/group.h index 775f14eb..c4a513b7 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -233,6 +233,15 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac */ int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len); + +/* Get group title from groupnumber and put it in title. + * title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. + * + * return length of title if success. + * return -1 if failure. + */ +int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title); + /* Return the number of peers in the group chat on success. * return -1 on failure */ diff --git a/toxcore/tox.c b/toxcore/tox.c index 8cef64cb..45014e63 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -693,6 +693,18 @@ int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t return group_title_send(m->group_chat_object, groupnumber, title, length); } +/* Get group title from groupnumber and put it in title. + * title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. + * + * return length of title if success. + * return -1 if failure. + */ +int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title) +{ + Messenger *m = tox; + return group_title_get(m->group_chat_object, groupnumber, title); +} + /* Check if the current peernumber corresponds to ours. * * return 1 if the peernumber corresponds to ours. diff --git a/toxcore/tox.h b/toxcore/tox.h index 9d239ef1..0902e166 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -528,6 +528,14 @@ int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint */ int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length); +/* Get group title from groupnumber and put it in title. + * title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. + * + * return length of title if success. + * return -1 if failure. + */ +int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title); + /* Check if the current peernumber corresponds to ours. * * return 1 if the peernumber corresponds to ours.