tox 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,147 +1,201 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # tox.rb - Ruby interface for libtoxcore
5
- # Copyright (C) 2015-2017 Braiden Vasco
6
- #
7
- # This program is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation, either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
-
20
4
  require 'mkmf'
21
5
 
22
6
  def cflags(s)
23
7
  $CFLAGS += " #{s} "
24
8
  end
25
9
 
26
- cflags '-std=c99'
10
+ def have_library!(*args)
11
+ exit 1 unless have_library(*args)
12
+ end
13
+
14
+ def have_header!(*args)
15
+ exit 1 unless have_header(*args)
16
+ end
17
+
18
+ def have_struct_member!(*args)
19
+ exit 1 unless have_struct_member(*args, 'tox/tox.h')
20
+ end
21
+
22
+ def have_func!(*args)
23
+ exit 1 unless have_func(*args, 'tox/tox.h')
24
+ end
25
+
26
+ def have_macro!(*args)
27
+ exit 1 unless have_macro(*args, 'tox/tox.h')
28
+ end
29
+
30
+ def have_type!(*args)
31
+ exit 1 unless have_type(*args, 'tox/tox.h')
32
+ end
33
+
34
+ def have_const!(*args)
35
+ exit 1 unless have_const(*args, 'tox/tox.h')
36
+ end
37
+
38
+ cflags '-std=c11'
27
39
  cflags '-Wall'
28
40
  cflags '-Wextra'
41
+ cflags '-Wno-declaration-after-statement'
42
+
43
+ have_library! 'toxcore'
44
+
45
+ have_header! 'ruby.h'
46
+ have_header! 'time.h'
47
+ have_header! 'tox/tox.h'
48
+
49
+ have_struct_member! 'struct timespec', 'tv_sec'
50
+ have_struct_member! 'struct timespec', 'tv_nsec'
51
+
52
+ have_func! 'free'
53
+ have_func! 'memset'
54
+ have_func! 'sprintf'
55
+ have_func! 'nanosleep'
56
+
57
+ have_macro! 'TOX_VERSION_IS_API_COMPATIBLE'
58
+ have_macro! 'TOX_VERSION_IS_ABI_COMPATIBLE'
59
+
60
+ have_type! 'TOX_ERR_OPTIONS_NEW'
61
+ have_type! 'TOX_ERR_NEW'
62
+ have_type! 'TOX_ERR_BOOTSTRAP'
63
+ have_type! 'TOX_ERR_SET_INFO'
64
+ have_type! 'TOX_ERR_FRIEND_ADD'
65
+ have_type! 'TOX_ERR_FRIEND_GET_PUBLIC_KEY'
66
+ have_type! 'TOX_ERR_FRIEND_QUERY'
67
+ have_type! 'TOX_ERR_FRIEND_SEND_MESSAGE'
68
+ have_type! 'TOX_SAVEDATA_TYPE'
69
+ have_type! 'TOX_MESSAGE_TYPE'
70
+ have_type! 'TOX_USER_STATUS'
71
+ have_type! 'TOX_CONNECTION'
72
+ have_type! 'tox_friend_request_cb'
73
+ have_type! 'tox_friend_message_cb'
74
+ have_type! 'tox_friend_name_cb'
75
+ have_type! 'tox_friend_status_message_cb'
76
+ have_type! 'tox_friend_status_cb'
77
+
78
+ have_struct_member! 'struct Tox_Options', 'savedata_type'
79
+ have_struct_member! 'struct Tox_Options', 'savedata_length'
80
+ have_struct_member! 'struct Tox_Options', 'savedata_data'
81
+
82
+ have_const! 'TOX_VERSION_MAJOR'
83
+ have_const! 'TOX_VERSION_MINOR'
84
+ have_const! 'TOX_VERSION_PATCH'
85
+ have_const! 'TOX_HASH_LENGTH'
86
+ have_const! 'TOX_SAVEDATA_TYPE_NONE'
87
+ have_const! 'TOX_SAVEDATA_TYPE_TOX_SAVE'
88
+ have_const! 'TOX_ERR_OPTIONS_NEW_OK'
89
+ have_const! 'TOX_ERR_OPTIONS_NEW_MALLOC'
90
+ have_const! 'TOX_ERR_NEW_OK'
91
+ have_const! 'TOX_ERR_NEW_NULL'
92
+ have_const! 'TOX_ERR_NEW_MALLOC'
93
+ have_const! 'TOX_ERR_NEW_PORT_ALLOC'
94
+ have_const! 'TOX_ERR_NEW_PROXY_BAD_TYPE'
95
+ have_const! 'TOX_ERR_NEW_PROXY_BAD_HOST'
96
+ have_const! 'TOX_ERR_NEW_PROXY_BAD_PORT'
97
+ have_const! 'TOX_ERR_NEW_PROXY_NOT_FOUND'
98
+ have_const! 'TOX_ERR_NEW_LOAD_ENCRYPTED'
99
+ have_const! 'TOX_ERR_NEW_LOAD_BAD_FORMAT'
100
+ have_const! 'TOX_ADDRESS_SIZE'
101
+ have_const! 'TOX_PUBLIC_KEY_SIZE'
102
+ have_const! 'TOX_ERR_BOOTSTRAP_OK'
103
+ have_const! 'TOX_ERR_BOOTSTRAP_NULL'
104
+ have_const! 'TOX_ERR_BOOTSTRAP_BAD_HOST'
105
+ have_const! 'TOX_ERR_BOOTSTRAP_BAD_PORT'
106
+ have_const! 'TOX_ERR_SET_INFO_OK'
107
+ have_const! 'TOX_ERR_SET_INFO_NULL'
108
+ have_const! 'TOX_ERR_SET_INFO_TOO_LONG'
109
+ have_const! 'TOX_ERR_FRIEND_ADD_OK'
110
+ have_const! 'TOX_ERR_FRIEND_ADD_NULL'
111
+ have_const! 'TOX_ERR_FRIEND_ADD_TOO_LONG'
112
+ have_const! 'TOX_ERR_FRIEND_ADD_NO_MESSAGE'
113
+ have_const! 'TOX_ERR_FRIEND_ADD_OWN_KEY'
114
+ have_const! 'TOX_ERR_FRIEND_ADD_ALREADY_SENT'
115
+ have_const! 'TOX_ERR_FRIEND_ADD_BAD_CHECKSUM'
116
+ have_const! 'TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM'
117
+ have_const! 'TOX_ERR_FRIEND_ADD_MALLOC'
118
+ have_const! 'TOX_MESSAGE_TYPE_NORMAL'
119
+ have_const! 'TOX_MESSAGE_TYPE_ACTION'
120
+ have_const! 'TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK'
121
+ have_const! 'TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND'
122
+ have_const! 'TOX_ERR_FRIEND_QUERY_OK'
123
+ have_const! 'TOX_ERR_FRIEND_QUERY_NULL'
124
+ have_const! 'TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND'
125
+ have_const! 'TOX_USER_STATUS_NONE'
126
+ have_const! 'TOX_USER_STATUS_AWAY'
127
+ have_const! 'TOX_USER_STATUS_BUSY'
128
+ have_const! 'TOX_ERR_FRIEND_SEND_MESSAGE_OK'
129
+ have_const! 'TOX_ERR_FRIEND_SEND_MESSAGE_NULL'
130
+ have_const! 'TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND'
131
+ have_const! 'TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED'
132
+ have_const! 'TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ'
133
+ have_const! 'TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG'
134
+ have_const! 'TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY'
135
+ have_const! 'TOX_CONNECTION_NONE'
136
+ have_const! 'TOX_CONNECTION_TCP'
137
+ have_const! 'TOX_CONNECTION_UDP'
29
138
 
30
- have_library 'toxcore' and
31
-
32
- have_header 'ruby.h' and
33
- have_header 'time.h' and
34
- have_header 'tox/tox.h' and
35
-
36
- have_struct_member 'struct timespec', 'tv_sec' and
37
- have_struct_member 'struct timespec', 'tv_nsec' and
38
-
39
- have_func 'free' and
40
- have_func 'memset' and
41
- have_func 'sprintf' and
42
- have_func 'nanosleep' and
43
-
44
- have_macro 'TOX_VERSION_IS_API_COMPATIBLE', 'tox/tox.h' and
45
- have_macro 'TOX_VERSION_IS_ABI_COMPATIBLE', 'tox/tox.h' and
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_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
60
-
61
- have_struct_member 'struct Tox_Options', 'savedata_type', 'tox/tox.h' and
62
- have_struct_member 'struct Tox_Options', 'savedata_length', 'tox/tox.h' and
63
- have_struct_member 'struct Tox_Options', 'savedata_data', 'tox/tox.h' and
64
-
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
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
111
- have_func 'tox_version_is_compatible', 'tox/tox.h' and
112
- have_func 'tox_hash', 'tox/tox.h' and
113
- have_func 'tox_new', 'tox/tox.h' and
114
- have_func 'tox_options_default', 'tox/tox.h' and
115
- have_func 'tox_get_savedata_size', 'tox/tox.h' and
116
- have_func 'tox_get_savedata', 'tox/tox.h' and
117
- have_func 'tox_self_get_address', 'tox/tox.h' and
118
- have_func 'tox_self_get_public_key', 'tox/tox.h' and
119
- have_func 'tox_kill', 'tox/tox.h' and
120
- have_func 'tox_bootstrap', 'tox/tox.h' and
121
- have_func 'tox_iteration_interval', 'tox/tox.h' and
122
- have_func 'tox_iterate', 'tox/tox.h' and
123
- have_func 'tox_friend_add_norequest', 'tox/tox.h' and
124
- have_func 'tox_friend_send_message', 'tox/tox.h' and
125
- have_func 'tox_callback_friend_request', 'tox/tox.h' and
126
- have_func 'tox_callback_friend_message', 'tox/tox.h' and
127
- have_func 'tox_self_get_name_size', 'tox/tox.h' and
128
- have_func 'tox_self_get_name', 'tox/tox.h' and
129
- have_func 'tox_self_set_name', 'tox/tox.h' and
130
- have_func 'tox_self_get_status_message_size', 'tox/tox.h' and
131
- have_func 'tox_self_get_status_message', 'tox/tox.h' and
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
139
+ have_func! 'tox_version_major'
140
+ have_func! 'tox_version_minor'
141
+ have_func! 'tox_version_patch'
142
+ have_func! 'tox_version_is_compatible'
143
+ have_func! 'tox_hash'
144
+ have_func! 'tox_new'
145
+ have_func! 'tox_options_default'
146
+ have_func! 'tox_options_get_ipv6_enabled'
147
+ have_func! 'tox_options_set_ipv6_enabled'
148
+ have_func! 'tox_options_get_udp_enabled'
149
+ have_func! 'tox_options_set_udp_enabled'
150
+ have_func! 'tox_options_get_local_discovery_enabled'
151
+ have_func! 'tox_options_set_local_discovery_enabled'
152
+ have_func! 'tox_options_get_proxy_type'
153
+ have_func! 'tox_options_set_proxy_type'
154
+ have_func! 'tox_options_get_proxy_host'
155
+ have_func! 'tox_options_set_proxy_host'
156
+ have_func! 'tox_options_get_proxy_port'
157
+ have_func! 'tox_options_set_proxy_port'
158
+ have_func! 'tox_options_get_start_port'
159
+ have_func! 'tox_options_set_start_port'
160
+ have_func! 'tox_options_get_end_port'
161
+ have_func! 'tox_options_set_end_port'
162
+ have_func! 'tox_options_get_tcp_port'
163
+ have_func! 'tox_options_set_tcp_port'
164
+ have_func! 'tox_get_savedata_size'
165
+ have_func! 'tox_get_savedata'
166
+ have_func! 'tox_self_get_address'
167
+ have_func! 'tox_self_get_nospam'
168
+ have_func! 'tox_self_set_nospam'
169
+ have_func! 'tox_self_get_public_key'
170
+ have_func! 'tox_self_get_udp_port'
171
+ have_func! 'tox_self_get_tcp_port'
172
+ have_func! 'tox_kill'
173
+ have_func! 'tox_bootstrap'
174
+ have_func! 'tox_add_tcp_relay'
175
+ have_func! 'tox_iteration_interval'
176
+ have_func! 'tox_iterate'
177
+ have_func! 'tox_friend_add_norequest'
178
+ have_func! 'tox_friend_send_message'
179
+ have_func! 'tox_callback_friend_request'
180
+ have_func! 'tox_callback_friend_message'
181
+ have_func! 'tox_self_get_name_size'
182
+ have_func! 'tox_self_get_name'
183
+ have_func! 'tox_self_set_name'
184
+ have_func! 'tox_self_get_status_message_size'
185
+ have_func! 'tox_self_get_status_message'
186
+ have_func! 'tox_self_set_status_message'
187
+ have_func! 'tox_self_get_status'
188
+ have_func! 'tox_self_set_status'
189
+ have_func! 'tox_self_get_friend_list_size'
190
+ have_func! 'tox_self_get_friend_list'
191
+ have_func! 'tox_friend_exists'
192
+ have_func! 'tox_friend_get_public_key'
193
+ have_func! 'tox_friend_get_name_size'
194
+ have_func! 'tox_friend_get_name'
195
+ have_func! 'tox_friend_get_status_message'
196
+ have_func! 'tox_friend_get_status'
197
+ have_func! 'tox_callback_friend_name'
198
+ have_func! 'tox_callback_friend_status_message'
199
+ have_func! 'tox_callback_friend_status'
146
200
 
147
201
  create_makefile 'tox/tox' or exit 1
@@ -1,21 +1,3 @@
1
- /*
2
- * tox.rb - Ruby interface for libtoxcore
3
- * Copyright (C) 2015-2017 Braiden Vasco
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
1
  #include "tox.h"
20
2
 
21
3
  // Public methods
@@ -55,9 +37,7 @@ VALUE mTox_cFriend_exist_QUESTION(const VALUE self)
55
37
  const VALUE client = rb_iv_get(self, "@client");
56
38
  const VALUE number = rb_iv_get(self, "@number");
57
39
 
58
- mTox_cClient_CDATA *client_cdata;
59
-
60
- Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
40
+ CDATA(client, mTox_cClient_CDATA, client_cdata)
61
41
 
62
42
  const bool result = tox_friend_exists(client_cdata->tox, NUM2LONG(number));
63
43
 
@@ -75,18 +55,16 @@ VALUE mTox_cFriend_public_key(const VALUE self)
75
55
  const VALUE client = rb_iv_get(self, "@client");
76
56
  const VALUE number = rb_iv_get(self, "@number");
77
57
 
78
- mTox_cClient_CDATA *client_cdata;
58
+ CDATA(client, mTox_cClient_CDATA, client_cdata);
79
59
 
80
- Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
81
-
82
- uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
60
+ uint8_t public_key_data[TOX_PUBLIC_KEY_SIZE];
83
61
 
84
62
  TOX_ERR_FRIEND_GET_PUBLIC_KEY error;
85
63
 
86
64
  const bool result = tox_friend_get_public_key(
87
65
  client_cdata->tox,
88
66
  NUM2LONG(number),
89
- public_key,
67
+ public_key_data,
90
68
  &error
91
69
  );
92
70
 
@@ -94,24 +72,26 @@ VALUE mTox_cFriend_public_key(const VALUE self)
94
72
  case TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK:
95
73
  break;
96
74
  case TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND:
97
- rb_raise(
75
+ RAISE_FUNC_ERROR(
76
+ "tox_friend_get_public_key",
98
77
  mTox_cFriend_eNotFoundError,
99
- "tox_friend_get_public_key() failed with TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND"
78
+ "TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND"
100
79
  );
101
80
  default:
102
- rb_raise(mTox_eUnknownSecurityError, "tox_friend_get_public_key() failed");
81
+ RAISE_FUNC_ERROR_DEFAULT("tox_friend_get_public_key");
103
82
  }
104
83
 
105
84
  if (result != true) {
106
- rb_raise(mTox_eUnknownSecurityError, "tox_friend_get_public_key() failed");
85
+ RAISE_FUNC_RESULT("tox_friend_get_public_key");
107
86
  }
108
87
 
109
- return rb_funcall(
110
- mTox_cPublicKey,
111
- rb_intern("new"),
112
- 1,
113
- rb_str_new(public_key, TOX_PUBLIC_KEY_SIZE)
114
- );
88
+ const VALUE public_key_value =
89
+ rb_str_new(public_key_data, TOX_PUBLIC_KEY_SIZE);
90
+
91
+ const VALUE public_key = rb_funcall(mTox_cPublicKey, rb_intern("new"), 1,
92
+ public_key_value);
93
+
94
+ return public_key;
115
95
  }
116
96
 
117
97
  // Tox::Friend#send_message
@@ -122,9 +102,7 @@ VALUE mTox_cFriend_send_message(const VALUE self, const VALUE text)
122
102
  const VALUE client = rb_iv_get(self, "@client");
123
103
  const VALUE number = rb_iv_get(self, "@number");
124
104
 
125
- mTox_cClient_CDATA *client_cdata;
126
-
127
- Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
105
+ CDATA(client, mTox_cClient_CDATA, client_cdata);
128
106
 
129
107
  TOX_ERR_FRIEND_ADD error;
130
108
 
@@ -132,7 +110,7 @@ VALUE mTox_cFriend_send_message(const VALUE self, const VALUE text)
132
110
  client_cdata->tox,
133
111
  NUM2LONG(number),
134
112
  TOX_MESSAGE_TYPE_NORMAL,
135
- (uint8_t*)RSTRING_PTR(text),
113
+ RSTRING_PTR(text),
136
114
  RSTRING_LEN(text),
137
115
  &error
138
116
  ));
@@ -141,46 +119,49 @@ VALUE mTox_cFriend_send_message(const VALUE self, const VALUE text)
141
119
  case TOX_ERR_FRIEND_SEND_MESSAGE_OK:
142
120
  break;
143
121
  case TOX_ERR_FRIEND_SEND_MESSAGE_NULL:
144
- rb_raise(
122
+ RAISE_FUNC_ERROR(
123
+ "tox_friend_send_message",
145
124
  mTox_eNullError,
146
- "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_NULL"
125
+ "TOX_ERR_FRIEND_SEND_MESSAGE_NULL"
147
126
  );
148
127
  case TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND:
149
- rb_raise(
128
+ RAISE_FUNC_ERROR(
129
+ "tox_friend_send_message",
150
130
  mTox_cFriend_eNotFoundError,
151
- "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND"
131
+ "TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND"
152
132
  );
153
133
  case TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED:
154
- rb_raise(
134
+ RAISE_FUNC_ERROR(
135
+ "tox_friend_send_message",
155
136
  mTox_cFriend_eNotConnectedError,
156
- "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED"
137
+ "TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED"
157
138
  );
158
139
  case TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ:
159
- rb_raise(
140
+ RAISE_FUNC_ERROR(
141
+ "tox_friend_send_message",
160
142
  mTox_mOutMessage_eSendQueueAllocError,
161
- "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ"
143
+ "TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ"
162
144
  );
163
145
  case TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG:
164
- rb_raise(
146
+ RAISE_FUNC_ERROR(
147
+ "tox_friend_send_message",
165
148
  mTox_mOutMessage_eTooLongError,
166
- "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG"
149
+ "TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG"
167
150
  );
168
151
  case TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY:
169
- rb_raise(
152
+ RAISE_FUNC_ERROR(
153
+ "tox_friend_send_message",
170
154
  mTox_mOutMessage_eEmptyError,
171
- "tox_friend_send_message() failed with TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY"
155
+ "TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY"
172
156
  );
173
157
  default:
174
- rb_raise(mTox_eUnknownError, "tox_friend_send_message() failed");
158
+ RAISE_FUNC_ERROR_DEFAULT("tox_friend_send_message");
175
159
  }
176
160
 
177
- return rb_funcall(
178
- mTox_cFriend_cOutMessage,
179
- rb_intern("new"),
180
- 2,
181
- self,
182
- result
183
- );
161
+ const VALUE friend_out_message =
162
+ rb_funcall(mTox_cOutFriendMessage, rb_intern("new"), 2,
163
+ self,
164
+ result);
184
165
  }
185
166
 
186
167
  // Tox::Friend#name
@@ -189,13 +170,11 @@ VALUE mTox_cFriend_name(const VALUE self)
189
170
  const VALUE client = rb_iv_get(self, "@client");
190
171
  const VALUE number = rb_iv_get(self, "@number");
191
172
 
192
- mTox_cClient_CDATA *client_cdata;
193
-
194
- Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
173
+ CDATA(client, mTox_cClient_CDATA, client_cdata);
195
174
 
196
175
  TOX_ERR_FRIEND_QUERY error;
197
176
 
198
- const size_t name_size = tox_friend_get_name_size(
177
+ const size_t name_size_data = tox_friend_get_name_size(
199
178
  client_cdata->tox,
200
179
  NUM2LONG(number),
201
180
  &error
@@ -205,25 +184,27 @@ VALUE mTox_cFriend_name(const VALUE self)
205
184
  case TOX_ERR_FRIEND_QUERY_OK:
206
185
  break;
207
186
  case TOX_ERR_FRIEND_QUERY_NULL:
208
- rb_raise(
187
+ RAISE_FUNC_ERROR(
188
+ "tox_friend_get_name_size",
209
189
  mTox_eNullError,
210
- "tox_friend_get_name_size() failed with TOX_ERR_FRIEND_QUERY_NULL"
190
+ "TOX_ERR_FRIEND_QUERY_NULL"
211
191
  );
212
192
  case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
213
- rb_raise(
193
+ RAISE_FUNC_ERROR(
194
+ "tox_friend_get_name_size",
214
195
  mTox_cFriend_eNotFoundError,
215
- "tox_friend_get_name_size() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
196
+ "TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
216
197
  );
217
198
  default:
218
- rb_raise(mTox_eUnknownError, "tox_friend_get_name_size() failed");
199
+ RAISE_FUNC_ERROR_DEFAULT("tox_friend_get_name_size");
219
200
  }
220
201
 
221
- char name[name_size];
202
+ char name_data[name_size_data];
222
203
 
223
204
  const bool result = tox_friend_get_name(
224
205
  client_cdata->tox,
225
206
  NUM2LONG(number),
226
- name,
207
+ name_data,
227
208
  &error
228
209
  );
229
210
 
@@ -231,24 +212,28 @@ VALUE mTox_cFriend_name(const VALUE self)
231
212
  case TOX_ERR_FRIEND_QUERY_OK:
232
213
  break;
233
214
  case TOX_ERR_FRIEND_QUERY_NULL:
234
- rb_raise(
215
+ RAISE_FUNC_ERROR(
216
+ "tox_friend_get_name",
235
217
  mTox_eNullError,
236
- "tox_friend_get_name() failed with TOX_ERR_FRIEND_QUERY_NULL"
218
+ "TOX_ERR_FRIEND_QUERY_NULL"
237
219
  );
238
220
  case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
239
- rb_raise(
221
+ RAISE_FUNC_ERROR(
222
+ "tox_friend_get_name",
240
223
  mTox_cFriend_eNotFoundError,
241
- "tox_friend_get_name() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
224
+ "TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
242
225
  );
243
226
  default:
244
- rb_raise(mTox_eUnknownError, "tox_friend_get_name() failed");
227
+ RAISE_FUNC_ERROR_DEFAULT("tox_friend_get_name");
245
228
  }
246
229
 
247
230
  if (result != true) {
248
- rb_raise(mTox_eUnknownError, "tox_friend_get_name() failed");
231
+ RAISE_FUNC_RESULT("tox_friend_get_name");
249
232
  }
250
233
 
251
- return rb_str_new(name, name_size);
234
+ const VALUE name = rb_str_new(name_data, name_size_data);
235
+
236
+ return name;
252
237
  }
253
238
 
254
239
  // Tox::Friend#status
@@ -257,9 +242,7 @@ VALUE mTox_cFriend_status(const VALUE self)
257
242
  const VALUE client = rb_iv_get(self, "@client");
258
243
  const VALUE number = rb_iv_get(self, "@number");
259
244
 
260
- mTox_cClient_CDATA *client_cdata;
261
-
262
- Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
245
+ CDATA(client, mTox_cClient_CDATA, client_cdata);
263
246
 
264
247
  TOX_ERR_FRIEND_QUERY error;
265
248
 
@@ -273,17 +256,19 @@ VALUE mTox_cFriend_status(const VALUE self)
273
256
  case TOX_ERR_FRIEND_QUERY_OK:
274
257
  break;
275
258
  case TOX_ERR_FRIEND_QUERY_NULL:
276
- rb_raise(
259
+ RAISE_FUNC_ERROR(
260
+ "tox_friend_get_status",
277
261
  mTox_eNullError,
278
- "tox_friend_get_status() failed with TOX_ERR_FRIEND_QUERY_NULL"
262
+ "TOX_ERR_FRIEND_QUERY_NULL"
279
263
  );
280
264
  case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
281
- rb_raise(
265
+ RAISE_FUNC_ERROR(
266
+ "tox_friend_get_status",
282
267
  mTox_cFriend_eNotFoundError,
283
- "tox_friend_get_status() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
268
+ "TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
284
269
  );
285
270
  default:
286
- rb_raise(mTox_eUnknownError, "tox_friend_get_name() failed");
271
+ RAISE_FUNC_ERROR_DEFAULT("tox_friend_get_name");
287
272
  }
288
273
 
289
274
  switch (result) {
@@ -294,7 +279,7 @@ VALUE mTox_cFriend_status(const VALUE self)
294
279
  case TOX_USER_STATUS_BUSY:
295
280
  return mTox_mUserStatus_BUSY;
296
281
  default:
297
- rb_raise(rb_eNotImpError, "Tox::Client#status has unknown value");
282
+ RAISE_ENUM("TOX_USER_STATUS");
298
283
  }
299
284
  }
300
285
 
@@ -304,13 +289,11 @@ VALUE mTox_cFriend_status_message(const VALUE self)
304
289
  const VALUE client = rb_iv_get(self, "@client");
305
290
  const VALUE number = rb_iv_get(self, "@number");
306
291
 
307
- mTox_cClient_CDATA *client_cdata;
308
-
309
- Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
292
+ CDATA(client, mTox_cClient_CDATA, client_cdata);
310
293
 
311
294
  TOX_ERR_FRIEND_QUERY error;
312
295
 
313
- const size_t status_message_size = tox_friend_get_status_message_size(
296
+ const size_t status_message_size_data = tox_friend_get_status_message_size(
314
297
  client_cdata->tox,
315
298
  NUM2LONG(number),
316
299
  &error
@@ -320,25 +303,27 @@ VALUE mTox_cFriend_status_message(const VALUE self)
320
303
  case TOX_ERR_FRIEND_QUERY_OK:
321
304
  break;
322
305
  case TOX_ERR_FRIEND_QUERY_NULL:
323
- rb_raise(
306
+ RAISE_FUNC_ERROR(
307
+ "tox_friend_get_status_message_size",
324
308
  mTox_eNullError,
325
- "tox_friend_get_status_message_size() failed with TOX_ERR_FRIEND_QUERY_NULL"
309
+ "TOX_ERR_FRIEND_QUERY_NULL"
326
310
  );
327
311
  case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
328
- rb_raise(
312
+ RAISE_FUNC_ERROR(
313
+ "tox_friend_get_status_message_size",
329
314
  mTox_cFriend_eNotFoundError,
330
- "tox_friend_get_status_message_size() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
315
+ "TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
331
316
  );
332
317
  default:
333
- rb_raise(mTox_eUnknownError, "tox_friend_get_status_message_size() failed");
318
+ RAISE_FUNC_ERROR_DEFAULT("tox_friend_get_status_message_size");
334
319
  }
335
320
 
336
- char status_message[status_message_size];
321
+ char status_message_data[status_message_size_data];
337
322
 
338
323
  const bool result = tox_friend_get_status_message(
339
324
  client_cdata->tox,
340
325
  NUM2LONG(number),
341
- status_message,
326
+ status_message_data,
342
327
  &error
343
328
  );
344
329
 
@@ -346,22 +331,27 @@ VALUE mTox_cFriend_status_message(const VALUE self)
346
331
  case TOX_ERR_FRIEND_QUERY_OK:
347
332
  break;
348
333
  case TOX_ERR_FRIEND_QUERY_NULL:
349
- rb_raise(
334
+ RAISE_FUNC_ERROR(
335
+ "tox_friend_get_status_message",
350
336
  mTox_eNullError,
351
- "tox_friend_get_status_message() failed with TOX_ERR_FRIEND_QUERY_NULL"
337
+ "TOX_ERR_FRIEND_QUERY_NULL"
352
338
  );
353
339
  case TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND:
354
- rb_raise(
340
+ RAISE_FUNC_ERROR(
341
+ "tox_friend_get_status_message",
355
342
  mTox_cFriend_eNotFoundError,
356
- "tox_friend_get_status_message() failed with TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
343
+ "TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND"
357
344
  );
358
345
  default:
359
- rb_raise(mTox_eUnknownError, "tox_friend_get_status_message() failed");
346
+ RAISE_FUNC_ERROR_DEFAULT("tox_friend_get_status_message");
360
347
  }
361
348
 
362
349
  if (result != true) {
363
- rb_raise(mTox_eUnknownError, "tox_friend_get_status_message() failed");
350
+ RAISE_FUNC_RESULT("tox_friend_get_status_message");
364
351
  }
365
352
 
366
- return rb_str_new(status_message, status_message_size);
353
+ const VALUE status_message =
354
+ rb_str_new(status_message_data, status_message_size_data);
355
+
356
+ return status_message;
367
357
  }