tox 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,34 +44,78 @@ have_func 'nanosleep' and
44
44
  have_macro 'TOX_VERSION_IS_API_COMPATIBLE', 'tox/tox.h' and
45
45
  have_macro 'TOX_VERSION_IS_ABI_COMPATIBLE', 'tox/tox.h' and
46
46
 
47
- have_type 'TOX_ERR_NEW', 'tox/tox.h' and
48
- have_type 'TOX_ERR_BOOTSTRAP', 'tox/tox.h' and
49
- have_type 'TOX_ERR_SET_INFO', 'tox/tox.h' and
50
- have_type 'TOX_MESSAGE_TYPE', 'tox/tox.h' and
51
- have_type 'tox_friend_request_cb', 'tox/tox.h' and
52
- have_type 'tox_friend_message_cb', 'tox/tox.h' and
47
+ have_type 'TOX_ERR_NEW', 'tox/tox.h' and
48
+ have_type 'TOX_ERR_BOOTSTRAP', 'tox/tox.h' and
49
+ have_type 'TOX_ERR_SET_INFO', 'tox/tox.h' and
50
+ have_type 'TOX_ERR_FRIEND_GET_PUBLIC_KEY', 'tox/tox.h' and
51
+ have_type 'TOX_ERR_FRIEND_QUERY', 'tox/tox.h' and
52
+ have_type 'TOX_ERR_FRIEND_SEND_MESSAGE', 'tox/tox.h' and
53
+ have_type 'TOX_MESSAGE_TYPE', 'tox/tox.h' and
54
+ have_type 'TOX_USER_STATUS', 'tox/tox.h' and
55
+ have_type 'tox_friend_request_cb', 'tox/tox.h' and
56
+ have_type 'tox_friend_message_cb', 'tox/tox.h' and
57
+ have_type 'tox_friend_name_cb', 'tox/tox.h' and
58
+ have_type 'tox_friend_status_message_cb', 'tox/tox.h' and
59
+ have_type 'tox_friend_status_cb', 'tox/tox.h' and
53
60
 
54
61
  have_struct_member 'struct Tox_Options', 'savedata_type', 'tox/tox.h' and
55
62
  have_struct_member 'struct Tox_Options', 'savedata_length', 'tox/tox.h' and
56
63
  have_struct_member 'struct Tox_Options', 'savedata_data', 'tox/tox.h' and
57
64
 
58
- have_const 'TOX_SAVEDATA_TYPE_NONE', 'tox/tox.h' and
59
- have_const 'TOX_SAVEDATA_TYPE_TOX_SAVE', 'tox/tox.h' and
60
- have_const 'TOX_ERR_NEW_OK', 'tox/tox.h' and
61
- have_const 'TOX_ERR_NEW_MALLOC', 'tox/tox.h' and
62
- have_const 'TOX_ERR_NEW_LOAD_BAD_FORMAT', 'tox/tox.h' and
63
- have_const 'TOX_ADDRESS_SIZE', 'tox/tox.h' and
64
- have_const 'TOX_PUBLIC_KEY_SIZE', 'tox/tox.h' and
65
- have_const 'TOX_ERR_BOOTSTRAP_OK', 'tox/tox.h' and
66
- have_const 'TOX_ERR_SET_INFO_OK', 'tox/tox.h' and
67
- have_const 'TOX_MESSAGE_TYPE_NORMAL', 'tox/tox.h' and
65
+ have_const 'TOX_VERSION_MAJOR', 'tox/tox.h' and
66
+ have_const 'TOX_VERSION_MINOR', 'tox/tox.h' and
67
+ have_const 'TOX_VERSION_PATCH', 'tox/tox.h' and
68
+ have_const 'TOX_HASH_LENGTH', 'tox/tox.h' and
69
+ have_const 'TOX_SAVEDATA_TYPE_NONE', 'tox/tox.h' and
70
+ have_const 'TOX_SAVEDATA_TYPE_TOX_SAVE', 'tox/tox.h' and
71
+ have_const 'TOX_ERR_NEW_OK', 'tox/tox.h' and
72
+ have_const 'TOX_ERR_NEW_NULL', 'tox/tox.h' and
73
+ have_const 'TOX_ERR_NEW_MALLOC', 'tox/tox.h' and
74
+ have_const 'TOX_ERR_NEW_PORT_ALLOC', 'tox/tox.h' and
75
+ have_const 'TOX_ERR_NEW_PROXY_BAD_TYPE', 'tox/tox.h' and
76
+ have_const 'TOX_ERR_NEW_PROXY_BAD_HOST', 'tox/tox.h' and
77
+ have_const 'TOX_ERR_NEW_PROXY_BAD_PORT', 'tox/tox.h' and
78
+ have_const 'TOX_ERR_NEW_PROXY_NOT_FOUND', 'tox/tox.h' and
79
+ have_const 'TOX_ERR_NEW_LOAD_ENCRYPTED', 'tox/tox.h' and
80
+ have_const 'TOX_ERR_NEW_LOAD_BAD_FORMAT', 'tox/tox.h' and
81
+ have_const 'TOX_ADDRESS_SIZE', 'tox/tox.h' and
82
+ have_const 'TOX_PUBLIC_KEY_SIZE', 'tox/tox.h' and
83
+ have_const 'TOX_ERR_BOOTSTRAP_OK', 'tox/tox.h' and
84
+ have_const 'TOX_ERR_BOOTSTRAP_NULL', 'tox/tox.h' and
85
+ have_const 'TOX_ERR_BOOTSTRAP_BAD_HOST', 'tox/tox.h' and
86
+ have_const 'TOX_ERR_BOOTSTRAP_BAD_PORT', 'tox/tox.h' and
87
+ have_const 'TOX_ERR_SET_INFO_OK', 'tox/tox.h' and
88
+ have_const 'TOX_ERR_SET_INFO_NULL', 'tox/tox.h' and
89
+ have_const 'TOX_ERR_SET_INFO_TOO_LONG', 'tox/tox.h' and
90
+ have_const 'TOX_MESSAGE_TYPE_NORMAL', 'tox/tox.h' and
91
+ have_const 'TOX_MESSAGE_TYPE_ACTION', 'tox/tox.h' and
92
+ have_const 'TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK', 'tox/tox.h' and
93
+ have_const 'TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND', 'tox/tox.h' and
94
+ have_const 'TOX_ERR_FRIEND_QUERY_OK', 'tox/tox.h' and
95
+ have_const 'TOX_ERR_FRIEND_QUERY_NULL', 'tox/tox.h' and
96
+ have_const 'TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND', 'tox/tox.h' and
97
+ have_const 'TOX_USER_STATUS_NONE', 'tox/tox.h' and
98
+ have_const 'TOX_USER_STATUS_AWAY', 'tox/tox.h' and
99
+ have_const 'TOX_USER_STATUS_BUSY', 'tox/tox.h' and
100
+ have_const 'TOX_ERR_FRIEND_SEND_MESSAGE_OK', 'tox/tox.h' and
101
+ have_const 'TOX_ERR_FRIEND_SEND_MESSAGE_NULL', 'tox/tox.h' and
102
+ have_const 'TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND', 'tox/tox.h' and
103
+ have_const 'TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED', 'tox/tox.h' and
104
+ have_const 'TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ', 'tox/tox.h' and
105
+ have_const 'TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG', 'tox/tox.h' and
106
+ have_const 'TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY', 'tox/tox.h' and
68
107
 
108
+ have_func 'tox_version_major', 'tox/tox.h' and
109
+ have_func 'tox_version_minor', 'tox/tox.h' and
110
+ have_func 'tox_version_patch', 'tox/tox.h' and
69
111
  have_func 'tox_version_is_compatible', 'tox/tox.h' and
112
+ have_func 'tox_hash', 'tox/tox.h' and
70
113
  have_func 'tox_new', 'tox/tox.h' and
71
114
  have_func 'tox_options_default', 'tox/tox.h' and
72
115
  have_func 'tox_get_savedata_size', 'tox/tox.h' and
73
116
  have_func 'tox_get_savedata', 'tox/tox.h' and
74
117
  have_func 'tox_self_get_address', 'tox/tox.h' and
118
+ have_func 'tox_self_get_public_key', 'tox/tox.h' and
75
119
  have_func 'tox_kill', 'tox/tox.h' and
76
120
  have_func 'tox_bootstrap', 'tox/tox.h' and
77
121
  have_func 'tox_iteration_interval', 'tox/tox.h' and
@@ -86,5 +130,18 @@ have_func 'tox_self_set_name', 'tox/tox.h' and
86
130
  have_func 'tox_self_get_status_message_size', 'tox/tox.h' and
87
131
  have_func 'tox_self_get_status_message', 'tox/tox.h' and
88
132
  have_func 'tox_self_set_status_message', 'tox/tox.h' and
133
+ have_func 'tox_self_get_status', 'tox/tox.h' and
134
+ have_func 'tox_self_set_status', 'tox/tox.h' and
135
+ have_func 'tox_self_get_friend_list_size', 'tox/tox.h' and
136
+ have_func 'tox_self_get_friend_list', 'tox/tox.h' and
137
+ have_func 'tox_friend_exists', 'tox/tox.h' and
138
+ have_func 'tox_friend_get_public_key', 'tox/tox.h' and
139
+ have_func 'tox_friend_get_name_size', 'tox/tox.h' and
140
+ have_func 'tox_friend_get_name', 'tox/tox.h' and
141
+ have_func 'tox_friend_get_status_message', 'tox/tox.h' and
142
+ have_func 'tox_friend_get_status', 'tox/tox.h' and
143
+ have_func 'tox_callback_friend_name', 'tox/tox.h' and
144
+ have_func 'tox_callback_friend_status_message', 'tox/tox.h' and
145
+ have_func 'tox_callback_friend_status', 'tox/tox.h' and
89
146
 
90
147
  create_makefile 'tox/tox' or exit 1
@@ -16,16 +16,16 @@
16
16
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
 
19
- #include "friend.h"
20
19
  #include "tox.h"
21
- #include "client.h"
22
-
23
- // Instance
24
- VALUE mTox_cFriend;
25
20
 
26
21
  // Public methods
27
22
 
23
+ static VALUE mTox_cFriend_exist_QUESTION(VALUE self);
24
+ static VALUE mTox_cFriend_public_key(VALUE self);
28
25
  static VALUE mTox_cFriend_send_message(VALUE self, VALUE text);
26
+ static VALUE mTox_cFriend_name(VALUE self);
27
+ static VALUE mTox_cFriend_status(VALUE self);
28
+ static VALUE mTox_cFriend_status_message(VALUE self);
29
29
 
30
30
  /*************************************************************
31
31
  * Initialization
@@ -33,18 +33,87 @@ static VALUE mTox_cFriend_send_message(VALUE self, VALUE text);
33
33
 
34
34
  void mTox_cFriend_INIT()
35
35
  {
36
- // Instance
37
- mTox_cFriend = rb_define_class_under(mTox, "Friend", rb_cObject);
38
-
39
36
  // Public methods
40
37
 
41
- rb_define_method(mTox_cFriend, "send_message", mTox_cFriend_send_message, 1);
38
+ rb_define_method(mTox_cFriend, "exist?", mTox_cFriend_exist_QUESTION, 0);
39
+ rb_define_method(mTox_cFriend, "exists?", mTox_cFriend_exist_QUESTION, 0);
40
+ rb_define_method(mTox_cFriend, "public_key", mTox_cFriend_public_key, 0);
41
+ rb_define_method(mTox_cFriend, "send_message", mTox_cFriend_send_message, 1);
42
+ rb_define_method(mTox_cFriend, "name", mTox_cFriend_name, 0);
43
+ rb_define_method(mTox_cFriend, "status", mTox_cFriend_status, 0);
44
+ rb_define_method(mTox_cFriend, "status_message", mTox_cFriend_status_message, 0);
42
45
  }
43
46
 
44
47
  /*************************************************************
45
48
  * Public methods
46
49
  *************************************************************/
47
50
 
51
+ // Tox::Friend#exist?
52
+ // Tox::Friend#exists?
53
+ VALUE mTox_cFriend_exist_QUESTION(const VALUE self)
54
+ {
55
+ const VALUE client = rb_iv_get(self, "@client");
56
+ const VALUE number = rb_iv_get(self, "@number");
57
+
58
+ mTox_cClient_CDATA *client_cdata;
59
+
60
+ Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
61
+
62
+ const bool result = tox_friend_exists(client_cdata->tox, NUM2LONG(number));
63
+
64
+ if (result) {
65
+ return Qtrue;
66
+ }
67
+ else {
68
+ return Qfalse;
69
+ }
70
+ }
71
+
72
+ // Tox::Friend#public_key
73
+ VALUE mTox_cFriend_public_key(const VALUE self)
74
+ {
75
+ const VALUE client = rb_iv_get(self, "@client");
76
+ const VALUE number = rb_iv_get(self, "@number");
77
+
78
+ mTox_cClient_CDATA *client_cdata;
79
+
80
+ Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
81
+
82
+ uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
83
+
84
+ TOX_ERR_FRIEND_GET_PUBLIC_KEY error;
85
+
86
+ const bool result = tox_friend_get_public_key(
87
+ client_cdata->tox,
88
+ NUM2LONG(number),
89
+ public_key,
90
+ &error
91
+ );
92
+
93
+ switch (error) {
94
+ case TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK:
95
+ break;
96
+ case TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND:
97
+ rb_raise(
98
+ mTox_cFriend_eNotFoundError,
99
+ "tox_friend_get_public_key() failed with TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND"
100
+ );
101
+ default:
102
+ rb_raise(mTox_eUnknownSecurityError, "tox_friend_get_public_key() failed");
103
+ }
104
+
105
+ if (result != true) {
106
+ rb_raise(mTox_eUnknownSecurityError, "tox_friend_get_public_key() failed");
107
+ }
108
+
109
+ return rb_funcall(
110
+ mTox_cPublicKey,
111
+ rb_intern("new"),
112
+ 1,
113
+ rb_str_new(public_key, TOX_PUBLIC_KEY_SIZE)
114
+ );
115
+ }
116
+
48
117
  // Tox::Friend#send_message
49
118
  VALUE mTox_cFriend_send_message(const VALUE self, const VALUE text)
50
119
  {
@@ -59,23 +128,240 @@ VALUE mTox_cFriend_send_message(const VALUE self, const VALUE text)
59
128
 
60
129
  TOX_ERR_FRIEND_ADD error;
61
130
 
62
- const result = tox_friend_send_message(
131
+ const VALUE result = LONG2FIX(tox_friend_send_message(
63
132
  client_cdata->tox,
64
133
  NUM2LONG(number),
65
134
  TOX_MESSAGE_TYPE_NORMAL,
66
135
  (uint8_t*)RSTRING_PTR(text),
67
136
  RSTRING_LEN(text),
68
137
  &error
69
- );
138
+ ));
70
139
 
71
140
  switch (error) {
72
141
  case TOX_ERR_FRIEND_SEND_MESSAGE_OK:
73
142
  break;
143
+ case TOX_ERR_FRIEND_SEND_MESSAGE_NULL:
144
+ rb_raise(
145
+ mTox_eNullError,
146
+ "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_NULL"
147
+ );
148
+ case TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND:
149
+ rb_raise(
150
+ mTox_cFriend_eNotFoundError,
151
+ "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND"
152
+ );
153
+ case TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED:
154
+ rb_raise(
155
+ mTox_cFriend_eNotConnectedError,
156
+ "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED"
157
+ );
74
158
  case TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ:
75
- rb_raise(rb_eNoMemError, "tox_friend_send_message() returned TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ");
159
+ rb_raise(
160
+ mTox_mOutMessage_eSendQueueAllocError,
161
+ "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ"
162
+ );
163
+ case TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG:
164
+ rb_raise(
165
+ mTox_mOutMessage_eTooLongError,
166
+ "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG"
167
+ );
168
+ case TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY:
169
+ rb_raise(
170
+ mTox_mOutMessage_eEmptyError,
171
+ "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY"
172
+ );
76
173
  default:
77
- rb_raise(rb_eRuntimeError, "tox_friend_send_message() failed");
174
+ rb_raise(mTox_eUnknownError, "tox_friend_send_message() failed");
175
+ }
176
+
177
+ return rb_funcall(
178
+ mTox_cFriend_cOutMessage,
179
+ rb_intern("new"),
180
+ 2,
181
+ self,
182
+ result
183
+ );
184
+ }
185
+
186
+ // Tox::Friend#name
187
+ VALUE mTox_cFriend_name(const VALUE self)
188
+ {
189
+ const VALUE client = rb_iv_get(self, "@client");
190
+ const VALUE number = rb_iv_get(self, "@number");
191
+
192
+ mTox_cClient_CDATA *client_cdata;
193
+
194
+ Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
195
+
196
+ TOX_ERR_FRIEND_QUERY error;
197
+
198
+ const size_t name_size = tox_friend_get_name_size(
199
+ client_cdata->tox,
200
+ NUM2LONG(number),
201
+ &error
202
+ );
203
+
204
+ switch (error) {
205
+ case TOX_ERR_FRIEND_QUERY_OK:
206
+ break;
207
+ case TOX_ERR_FRIEND_QUERY_NULL:
208
+ rb_raise(
209
+ mTox_eNullError,
210
+ "tox_friend_get_name_size() failed with TOX_ERR_FRIEND_QUERY_NULL"
211
+ );
212
+ case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
213
+ rb_raise(
214
+ mTox_cFriend_eNotFoundError,
215
+ "tox_friend_get_name_size() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
216
+ );
217
+ default:
218
+ rb_raise(mTox_eUnknownError, "tox_friend_get_name_size() failed");
219
+ }
220
+
221
+ char name[name_size];
222
+
223
+ const bool result = tox_friend_get_name(
224
+ client_cdata->tox,
225
+ NUM2LONG(number),
226
+ name,
227
+ &error
228
+ );
229
+
230
+ switch (error) {
231
+ case TOX_ERR_FRIEND_QUERY_OK:
232
+ break;
233
+ case TOX_ERR_FRIEND_QUERY_NULL:
234
+ rb_raise(
235
+ mTox_eNullError,
236
+ "tox_friend_get_name() failed with TOX_ERR_FRIEND_QUERY_NULL"
237
+ );
238
+ case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
239
+ rb_raise(
240
+ mTox_cFriend_eNotFoundError,
241
+ "tox_friend_get_name() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
242
+ );
243
+ default:
244
+ rb_raise(mTox_eUnknownError, "tox_friend_get_name() failed");
245
+ }
246
+
247
+ if (result != true) {
248
+ rb_raise(mTox_eUnknownError, "tox_friend_get_name() failed");
249
+ }
250
+
251
+ return rb_str_new(name, name_size);
252
+ }
253
+
254
+ // Tox::Friend#status
255
+ VALUE mTox_cFriend_status(const VALUE self)
256
+ {
257
+ const VALUE client = rb_iv_get(self, "@client");
258
+ const VALUE number = rb_iv_get(self, "@number");
259
+
260
+ mTox_cClient_CDATA *client_cdata;
261
+
262
+ Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
263
+
264
+ TOX_ERR_FRIEND_QUERY error;
265
+
266
+ const TOX_USER_STATUS result = tox_friend_get_status(
267
+ client_cdata->tox,
268
+ NUM2LONG(number),
269
+ &error
270
+ );
271
+
272
+ switch (error) {
273
+ case TOX_ERR_FRIEND_QUERY_OK:
274
+ break;
275
+ case TOX_ERR_FRIEND_QUERY_NULL:
276
+ rb_raise(
277
+ mTox_eNullError,
278
+ "tox_friend_get_status() failed with TOX_ERR_FRIEND_QUERY_NULL"
279
+ );
280
+ case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
281
+ rb_raise(
282
+ mTox_cFriend_eNotFoundError,
283
+ "tox_friend_get_status() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
284
+ );
285
+ default:
286
+ rb_raise(mTox_eUnknownError, "tox_friend_get_name() failed");
287
+ }
288
+
289
+ switch (result) {
290
+ case TOX_USER_STATUS_NONE:
291
+ return mTox_mUserStatus_NONE;
292
+ case TOX_USER_STATUS_AWAY:
293
+ return mTox_mUserStatus_AWAY;
294
+ case TOX_USER_STATUS_BUSY:
295
+ return mTox_mUserStatus_BUSY;
296
+ default:
297
+ rb_raise(rb_eNotImpError, "Tox::Client#status has unknown value");
298
+ }
299
+ }
300
+
301
+ // Tox::Friend#status_message
302
+ VALUE mTox_cFriend_status_message(const VALUE self)
303
+ {
304
+ const VALUE client = rb_iv_get(self, "@client");
305
+ const VALUE number = rb_iv_get(self, "@number");
306
+
307
+ mTox_cClient_CDATA *client_cdata;
308
+
309
+ Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
310
+
311
+ TOX_ERR_FRIEND_QUERY error;
312
+
313
+ const size_t status_message_size = tox_friend_get_status_message_size(
314
+ client_cdata->tox,
315
+ NUM2LONG(number),
316
+ &error
317
+ );
318
+
319
+ switch (error) {
320
+ case TOX_ERR_FRIEND_QUERY_OK:
321
+ break;
322
+ case TOX_ERR_FRIEND_QUERY_NULL:
323
+ rb_raise(
324
+ mTox_eNullError,
325
+ "tox_friend_get_status_message_size() failed with TOX_ERR_FRIEND_QUERY_NULL"
326
+ );
327
+ case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
328
+ rb_raise(
329
+ mTox_cFriend_eNotFoundError,
330
+ "tox_friend_get_status_message_size() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
331
+ );
332
+ default:
333
+ rb_raise(mTox_eUnknownError, "tox_friend_get_status_message_size() failed");
334
+ }
335
+
336
+ char status_message[status_message_size];
337
+
338
+ const bool result = tox_friend_get_status_message(
339
+ client_cdata->tox,
340
+ NUM2LONG(number),
341
+ status_message,
342
+ &error
343
+ );
344
+
345
+ switch (error) {
346
+ case TOX_ERR_FRIEND_QUERY_OK:
347
+ break;
348
+ case TOX_ERR_FRIEND_QUERY_NULL:
349
+ rb_raise(
350
+ mTox_eNullError,
351
+ "tox_friend_get_status_message() failed with TOX_ERR_FRIEND_QUERY_NULL"
352
+ );
353
+ case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
354
+ rb_raise(
355
+ mTox_cFriend_eNotFoundError,
356
+ "tox_friend_get_status_message() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
357
+ );
358
+ default:
359
+ rb_raise(mTox_eUnknownError, "tox_friend_get_status_message() failed");
360
+ }
361
+
362
+ if (result != true) {
363
+ rb_raise(mTox_eUnknownError, "tox_friend_get_status_message() failed");
78
364
  }
79
365
 
80
- return LONG2FIX(result);
366
+ return rb_str_new(status_message, status_message_size);
81
367
  }