diff options
author | irungentoo <irungentoo@gmail.com> | 2015-03-10 18:54:01 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-03-10 18:54:01 -0400 |
commit | 916b6aa7344ed922c3f8da04e7b2d73e2ee65411 (patch) | |
tree | dc5e47d18b205ea8766c7ad90e4f1586f39d994c | |
parent | 8e55d96381cca3b1ca9db18bac715ba2e8a6f558 (diff) |
Added group chat functions to the public api.
Since the functions are not new api like I put them in tox_old.{c,h}
-rw-r--r-- | toxcore/tox.c | 3 | ||||
-rw-r--r-- | toxcore/tox.h | 2 | ||||
-rw-r--r-- | toxcore/tox_old.c | 237 | ||||
-rw-r--r-- | toxcore/tox_old.h | 173 |
4 files changed, 415 insertions, 0 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c index bcb871fc..80cbb71d 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -1075,3 +1075,6 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb | |||
1075 | Messenger *m = tox; | 1075 | Messenger *m = tox; |
1076 | custom_lossless_packet_registerhandler(m, function, user_data); | 1076 | custom_lossless_packet_registerhandler(m, function, user_data); |
1077 | } | 1077 | } |
1078 | |||
1079 | |||
1080 | #include "tox_old.c" | ||
diff --git a/toxcore/tox.h b/toxcore/tox.h index b8cac443..5323c4b6 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -1785,6 +1785,7 @@ void tox_callback_file_receive_chunk(Tox *tox, tox_file_receive_chunk_cb *functi | |||
1785 | * | 1785 | * |
1786 | ******************************************************************************/ | 1786 | ******************************************************************************/ |
1787 | 1787 | ||
1788 | /* See: tox_old.h for now. */ | ||
1788 | 1789 | ||
1789 | /******************************************************************************* | 1790 | /******************************************************************************* |
1790 | * | 1791 | * |
@@ -1940,6 +1941,7 @@ uint16_t tox_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error); | |||
1940 | */ | 1941 | */ |
1941 | uint16_t tox_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error); | 1942 | uint16_t tox_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error); |
1942 | 1943 | ||
1944 | #include "tox_old.h" | ||
1943 | 1945 | ||
1944 | #ifdef __cplusplus | 1946 | #ifdef __cplusplus |
1945 | } | 1947 | } |
diff --git a/toxcore/tox_old.c b/toxcore/tox_old.c new file mode 100644 index 00000000..2a422575 --- /dev/null +++ b/toxcore/tox_old.c | |||
@@ -0,0 +1,237 @@ | |||
1 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ | ||
2 | |||
3 | /* Set the callback for group invites. | ||
4 | * | ||
5 | * Function(Tox *tox, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) | ||
6 | * | ||
7 | * data of length is what needs to be passed to join_groupchat(). | ||
8 | */ | ||
9 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, const uint8_t *, uint16_t, | ||
10 | void *), void *userdata) | ||
11 | { | ||
12 | Messenger *m = tox; | ||
13 | g_callback_group_invite(m->group_chat_object, function, userdata); | ||
14 | } | ||
15 | |||
16 | /* Set the callback for group messages. | ||
17 | * | ||
18 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * message, uint16_t length, void *userdata) | ||
19 | */ | ||
20 | void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *), | ||
21 | void *userdata) | ||
22 | { | ||
23 | Messenger *m = tox; | ||
24 | g_callback_group_message(m->group_chat_object, function, userdata); | ||
25 | } | ||
26 | |||
27 | /* Set the callback for group actions. | ||
28 | * | ||
29 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * action, uint16_t length, void *userdata) | ||
30 | */ | ||
31 | void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *), | ||
32 | void *userdata) | ||
33 | { | ||
34 | Messenger *m = tox; | ||
35 | g_callback_group_action(m->group_chat_object, function, userdata); | ||
36 | } | ||
37 | |||
38 | /* Set callback function for title changes. | ||
39 | * | ||
40 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata) | ||
41 | * if peernumber == -1, then author is unknown (e.g. initial joining the group) | ||
42 | */ | ||
43 | void tox_callback_group_title(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint8_t, | ||
44 | void *), void *userdata) | ||
45 | { | ||
46 | Messenger *m = tox; | ||
47 | g_callback_group_title(m->group_chat_object, function, userdata); | ||
48 | } | ||
49 | |||
50 | /* Set callback function for peer name list changes. | ||
51 | * | ||
52 | * It gets called every time the name list changes(new peer/name, deleted peer) | ||
53 | * Function(Tox *tox, int groupnumber, void *userdata) | ||
54 | */ | ||
55 | void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) | ||
56 | { | ||
57 | Messenger *m = tox; | ||
58 | g_callback_group_namelistchange(m->group_chat_object, function, userdata); | ||
59 | } | ||
60 | |||
61 | /* Creates a new groupchat and puts it in the chats array. | ||
62 | * | ||
63 | * return group number on success. | ||
64 | * return -1 on failure. | ||
65 | */ | ||
66 | int tox_add_groupchat(Tox *tox) | ||
67 | { | ||
68 | Messenger *m = tox; | ||
69 | return add_groupchat(m->group_chat_object, GROUPCHAT_TYPE_TEXT); | ||
70 | } | ||
71 | |||
72 | /* Delete a groupchat from the chats array. | ||
73 | * | ||
74 | * return 0 on success. | ||
75 | * return -1 if failure. | ||
76 | */ | ||
77 | int tox_del_groupchat(Tox *tox, int groupnumber) | ||
78 | { | ||
79 | Messenger *m = tox; | ||
80 | return del_groupchat(m->group_chat_object, groupnumber); | ||
81 | } | ||
82 | |||
83 | /* Copy the name of peernumber who is in groupnumber to name. | ||
84 | * name must be at least MAX_NICK_BYTES long. | ||
85 | * | ||
86 | * return length of name if success | ||
87 | * return -1 if failure | ||
88 | */ | ||
89 | int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name) | ||
90 | { | ||
91 | const Messenger *m = tox; | ||
92 | return group_peername(m->group_chat_object, groupnumber, peernumber, name); | ||
93 | } | ||
94 | |||
95 | /* Copy the public key of peernumber who is in groupnumber to public_key. | ||
96 | * public_key must be crypto_box_PUBLICKEYBYTES long. | ||
97 | * | ||
98 | * returns 0 on success | ||
99 | * returns -1 on failure | ||
100 | */ | ||
101 | int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *public_key) | ||
102 | { | ||
103 | const Messenger *m = tox; | ||
104 | return group_peer_pubkey(m->group_chat_object, groupnumber, peernumber, public_key); | ||
105 | } | ||
106 | |||
107 | /* invite friendnumber to groupnumber | ||
108 | * return 0 on success | ||
109 | * return -1 on failure | ||
110 | */ | ||
111 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) | ||
112 | { | ||
113 | Messenger *m = tox; | ||
114 | return invite_friend(m->group_chat_object, friendnumber, groupnumber); | ||
115 | } | ||
116 | |||
117 | /* Join a group (you need to have been invited first.) using data of length obtained | ||
118 | * in the group invite callback. | ||
119 | * | ||
120 | * returns group number on success | ||
121 | * returns -1 on failure. | ||
122 | */ | ||
123 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) | ||
124 | { | ||
125 | Messenger *m = tox; | ||
126 | return join_groupchat(m->group_chat_object, friendnumber, GROUPCHAT_TYPE_TEXT, data, length); | ||
127 | } | ||
128 | |||
129 | /* send a group message | ||
130 | * return 0 on success | ||
131 | * return -1 on failure | ||
132 | */ | ||
133 | int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length) | ||
134 | { | ||
135 | Messenger *m = tox; | ||
136 | return group_message_send(m->group_chat_object, groupnumber, message, length); | ||
137 | } | ||
138 | |||
139 | /* send a group action | ||
140 | * return 0 on success | ||
141 | * return -1 on failure | ||
142 | */ | ||
143 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) | ||
144 | { | ||
145 | Messenger *m = tox; | ||
146 | return group_action_send(m->group_chat_object, groupnumber, action, length); | ||
147 | } | ||
148 | |||
149 | /* set the group's title, limited to MAX_NAME_LENGTH | ||
150 | * return 0 on success | ||
151 | * return -1 on failure | ||
152 | */ | ||
153 | int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length) | ||
154 | { | ||
155 | Messenger *m = tox; | ||
156 | return group_title_send(m->group_chat_object, groupnumber, title, length); | ||
157 | } | ||
158 | |||
159 | /* Get group title from groupnumber and put it in title. | ||
160 | * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. | ||
161 | * | ||
162 | * return length of copied title if success. | ||
163 | * return -1 if failure. | ||
164 | */ | ||
165 | int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length) | ||
166 | { | ||
167 | Messenger *m = tox; | ||
168 | return group_title_get(m->group_chat_object, groupnumber, title, max_length); | ||
169 | } | ||
170 | |||
171 | /* Check if the current peernumber corresponds to ours. | ||
172 | * | ||
173 | * return 1 if the peernumber corresponds to ours. | ||
174 | * return 0 on failure. | ||
175 | */ | ||
176 | unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber) | ||
177 | { | ||
178 | const Messenger *m = tox; | ||
179 | return group_peernumber_is_ours(m->group_chat_object, groupnumber, peernumber); | ||
180 | } | ||
181 | |||
182 | /* Return the number of peers in the group chat on success. | ||
183 | * return -1 on failure | ||
184 | */ | ||
185 | int tox_group_number_peers(const Tox *tox, int groupnumber) | ||
186 | { | ||
187 | const Messenger *m = tox; | ||
188 | return group_number_peers(m->group_chat_object, groupnumber); | ||
189 | } | ||
190 | |||
191 | /* List all the peers in the group chat. | ||
192 | * | ||
193 | * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array. | ||
194 | * | ||
195 | * Copies the lengths of the names to lengths[length] | ||
196 | * | ||
197 | * returns the number of peers on success. | ||
198 | * | ||
199 | * return -1 on failure. | ||
200 | */ | ||
201 | int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], | ||
202 | uint16_t length) | ||
203 | { | ||
204 | const Messenger *m = tox; | ||
205 | return group_names(m->group_chat_object, groupnumber, names, lengths, length); | ||
206 | } | ||
207 | |||
208 | /* Return the number of chats in the instance m. | ||
209 | * You should use this to determine how much memory to allocate | ||
210 | * for copy_chatlist. */ | ||
211 | uint32_t tox_count_chatlist(const Tox *tox) | ||
212 | { | ||
213 | const Messenger *m = tox; | ||
214 | return count_chatlist(m->group_chat_object); | ||
215 | } | ||
216 | |||
217 | /* Copy a list of valid chat IDs into the array out_list. | ||
218 | * If out_list is NULL, returns 0. | ||
219 | * Otherwise, returns the number of elements copied. | ||
220 | * If the array was too small, the contents | ||
221 | * of out_list will be truncated to list_size. */ | ||
222 | uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size) | ||
223 | { | ||
224 | const Messenger *m = tox; | ||
225 | return copy_chatlist(m->group_chat_object, out_list, list_size); | ||
226 | } | ||
227 | |||
228 | /* return the type of groupchat (TOX_GROUPCHAT_TYPE_) that groupnumber is. | ||
229 | * | ||
230 | * return -1 on failure. | ||
231 | * return type on success. | ||
232 | */ | ||
233 | int tox_group_get_type(const Tox *tox, int groupnumber) | ||
234 | { | ||
235 | const Messenger *m = tox; | ||
236 | return group_get_type(m->group_chat_object, groupnumber); | ||
237 | } | ||
diff --git a/toxcore/tox_old.h b/toxcore/tox_old.h new file mode 100644 index 00000000..a926cdf7 --- /dev/null +++ b/toxcore/tox_old.h | |||
@@ -0,0 +1,173 @@ | |||
1 | /**********GROUP CHAT FUNCTIONS ************/ | ||
2 | |||
3 | /* Group chat types for tox_callback_group_invite function. | ||
4 | * | ||
5 | * TOX_GROUPCHAT_TYPE_TEXT groupchats must be accepted with the tox_join_groupchat() function. | ||
6 | * The function to accept TOX_GROUPCHAT_TYPE_AV is in toxav. | ||
7 | */ | ||
8 | enum { | ||
9 | TOX_GROUPCHAT_TYPE_TEXT, | ||
10 | TOX_GROUPCHAT_TYPE_AV | ||
11 | }; | ||
12 | |||
13 | /* Set the callback for group invites. | ||
14 | * | ||
15 | * Function(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) | ||
16 | * | ||
17 | * data of length is what needs to be passed to join_groupchat(). | ||
18 | * | ||
19 | * for what type means see the enum right above this comment. | ||
20 | */ | ||
21 | void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, const uint8_t *, uint16_t, | ||
22 | void *), void *userdata); | ||
23 | |||
24 | /* Set the callback for group messages. | ||
25 | * | ||
26 | * Function(Tox *tox, int groupnumber, int peernumber, const uint8_t * message, uint16_t length, void *userdata) | ||
27 | */ | ||
28 | void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), | ||
29 | void *userdata); | ||
30 | |||
31 | /* Set the callback for group actions. | ||
32 | * | ||
33 | * Function(Tox *tox, int groupnumber, int peernumber, const uint8_t * action, uint16_t length, void *userdata) | ||
34 | */ | ||
35 | void tox_callback_group_action(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), | ||
36 | void *userdata); | ||
37 | |||
38 | /* Set callback function for title changes. | ||
39 | * | ||
40 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata) | ||
41 | * if peernumber == -1, then author is unknown (e.g. initial joining the group) | ||
42 | */ | ||
43 | void tox_callback_group_title(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint8_t, | ||
44 | void *), void *userdata); | ||
45 | |||
46 | /* Set callback function for peer name list changes. | ||
47 | * | ||
48 | * It gets called every time the name list changes(new peer/name, deleted peer) | ||
49 | * Function(Tox *tox, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) | ||
50 | */ | ||
51 | typedef enum { | ||
52 | TOX_CHAT_CHANGE_PEER_ADD, | ||
53 | TOX_CHAT_CHANGE_PEER_DEL, | ||
54 | TOX_CHAT_CHANGE_PEER_NAME, | ||
55 | } TOX_CHAT_CHANGE; | ||
56 | |||
57 | void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), | ||
58 | void *userdata); | ||
59 | |||
60 | /* Creates a new groupchat and puts it in the chats array. | ||
61 | * | ||
62 | * return group number on success. | ||
63 | * return -1 on failure. | ||
64 | */ | ||
65 | int tox_add_groupchat(Tox *tox); | ||
66 | |||
67 | /* Delete a groupchat from the chats array. | ||
68 | * | ||
69 | * return 0 on success. | ||
70 | * return -1 if failure. | ||
71 | */ | ||
72 | int tox_del_groupchat(Tox *tox, int groupnumber); | ||
73 | |||
74 | /* Copy the name of peernumber who is in groupnumber to name. | ||
75 | * name must be at least TOX_MAX_NAME_LENGTH long. | ||
76 | * | ||
77 | * return length of name if success | ||
78 | * return -1 if failure | ||
79 | */ | ||
80 | int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name); | ||
81 | |||
82 | /* Copy the public key of peernumber who is in groupnumber to public_key. | ||
83 | * public_key must be TOX_PUBLIC_KEY_SIZE long. | ||
84 | * | ||
85 | * returns 0 on success | ||
86 | * returns -1 on failure | ||
87 | */ | ||
88 | int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *public_key); | ||
89 | |||
90 | /* invite friendnumber to groupnumber | ||
91 | * return 0 on success | ||
92 | * return -1 on failure | ||
93 | */ | ||
94 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber); | ||
95 | |||
96 | /* Join a group (you need to have been invited first.) using data of length obtained | ||
97 | * in the group invite callback. | ||
98 | * | ||
99 | * returns group number on success | ||
100 | * returns -1 on failure. | ||
101 | */ | ||
102 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length); | ||
103 | |||
104 | /* send a group message | ||
105 | * return 0 on success | ||
106 | * return -1 on failure | ||
107 | */ | ||
108 | int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length); | ||
109 | |||
110 | /* send a group action | ||
111 | * return 0 on success | ||
112 | * return -1 on failure | ||
113 | */ | ||
114 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length); | ||
115 | |||
116 | /* set the group's title, limited to MAX_NAME_LENGTH | ||
117 | * return 0 on success | ||
118 | * return -1 on failure | ||
119 | */ | ||
120 | int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length); | ||
121 | |||
122 | /* Get group title from groupnumber and put it in title. | ||
123 | * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. | ||
124 | * | ||
125 | * return length of copied title if success. | ||
126 | * return -1 if failure. | ||
127 | */ | ||
128 | int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length); | ||
129 | |||
130 | /* Check if the current peernumber corresponds to ours. | ||
131 | * | ||
132 | * return 1 if the peernumber corresponds to ours. | ||
133 | * return 0 on failure. | ||
134 | */ | ||
135 | unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber); | ||
136 | |||
137 | /* Return the number of peers in the group chat on success. | ||
138 | * return -1 on failure | ||
139 | */ | ||
140 | int tox_group_number_peers(const Tox *tox, int groupnumber); | ||
141 | |||
142 | /* List all the peers in the group chat. | ||
143 | * | ||
144 | * Copies the names of the peers to the name[length][TOX_MAX_NAME_LENGTH] array. | ||
145 | * | ||
146 | * Copies the lengths of the names to lengths[length] | ||
147 | * | ||
148 | * returns the number of peers on success. | ||
149 | * | ||
150 | * return -1 on failure. | ||
151 | */ | ||
152 | int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], | ||
153 | uint16_t length); | ||
154 | |||
155 | /* Return the number of chats in the instance m. | ||
156 | * You should use this to determine how much memory to allocate | ||
157 | * for copy_chatlist. */ | ||
158 | uint32_t tox_count_chatlist(const Tox *tox); | ||
159 | |||
160 | /* Copy a list of valid chat IDs into the array out_list. | ||
161 | * If out_list is NULL, returns 0. | ||
162 | * Otherwise, returns the number of elements copied. | ||
163 | * If the array was too small, the contents | ||
164 | * of out_list will be truncated to list_size. */ | ||
165 | uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size); | ||
166 | |||
167 | /* return the type of groupchat (TOX_GROUPCHAT_TYPE_) that groupnumber is. | ||
168 | * | ||
169 | * return -1 on failure. | ||
170 | * return type on success. | ||
171 | */ | ||
172 | int tox_group_get_type(const Tox *tox, int groupnumber); | ||
173 | |||