tox 0.0.1

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.
@@ -0,0 +1,29 @@
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
+ #include <ruby.h>
20
+
21
+ #include <tox/tox.h>
22
+
23
+ void mTox_cClient_INIT();
24
+
25
+ extern VALUE mTox_cClient;
26
+
27
+ typedef struct {
28
+ Tox *tox;
29
+ } mTox_cClient_CDATA;
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
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
+ require 'mkmf'
21
+
22
+ def cflags(s)
23
+ $CFLAGS += " #{s} "
24
+ end
25
+
26
+ cflags '-std=c99'
27
+ cflags '-Wall'
28
+ cflags '-Wextra'
29
+
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_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
53
+
54
+ have_struct_member 'struct Tox_Options', 'savedata_type', 'tox/tox.h' and
55
+ have_struct_member 'struct Tox_Options', 'savedata_length', 'tox/tox.h' and
56
+ have_struct_member 'struct Tox_Options', 'savedata_data', 'tox/tox.h' and
57
+
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
68
+
69
+ have_func 'tox_version_is_compatible', 'tox/tox.h' and
70
+ have_func 'tox_new', 'tox/tox.h' and
71
+ have_func 'tox_options_default', 'tox/tox.h' and
72
+ have_func 'tox_get_savedata_size', 'tox/tox.h' and
73
+ have_func 'tox_get_savedata', 'tox/tox.h' and
74
+ have_func 'tox_self_get_address', 'tox/tox.h' and
75
+ have_func 'tox_kill', 'tox/tox.h' and
76
+ have_func 'tox_bootstrap', 'tox/tox.h' and
77
+ have_func 'tox_iteration_interval', 'tox/tox.h' and
78
+ have_func 'tox_iterate', 'tox/tox.h' and
79
+ have_func 'tox_friend_add_norequest', 'tox/tox.h' and
80
+ have_func 'tox_friend_send_message', 'tox/tox.h' and
81
+ have_func 'tox_callback_friend_request', 'tox/tox.h' and
82
+ have_func 'tox_callback_friend_message', 'tox/tox.h' and
83
+ have_func 'tox_self_get_name_size', 'tox/tox.h' and
84
+ have_func 'tox_self_get_name', 'tox/tox.h' and
85
+ have_func 'tox_self_set_name', 'tox/tox.h' and
86
+ have_func 'tox_self_get_status_message_size', 'tox/tox.h' and
87
+ have_func 'tox_self_get_status_message', 'tox/tox.h' and
88
+ have_func 'tox_self_set_status_message', 'tox/tox.h' and
89
+
90
+ create_makefile 'tox/tox' or exit 1
@@ -0,0 +1,81 @@
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
+ #include "friend.h"
20
+ #include "tox.h"
21
+ #include "client.h"
22
+
23
+ // Instance
24
+ VALUE mTox_cFriend;
25
+
26
+ // Public methods
27
+
28
+ static VALUE mTox_cFriend_send_message(VALUE self, VALUE text);
29
+
30
+ /*************************************************************
31
+ * Initialization
32
+ *************************************************************/
33
+
34
+ void mTox_cFriend_INIT()
35
+ {
36
+ // Instance
37
+ mTox_cFriend = rb_define_class_under(mTox, "Friend", rb_cObject);
38
+
39
+ // Public methods
40
+
41
+ rb_define_method(mTox_cFriend, "send_message", mTox_cFriend_send_message, 1);
42
+ }
43
+
44
+ /*************************************************************
45
+ * Public methods
46
+ *************************************************************/
47
+
48
+ // Tox::Friend#send_message
49
+ VALUE mTox_cFriend_send_message(const VALUE self, const VALUE text)
50
+ {
51
+ Check_Type(text, T_STRING);
52
+
53
+ const VALUE client = rb_iv_get(self, "@client");
54
+ const VALUE number = rb_iv_get(self, "@number");
55
+
56
+ mTox_cClient_CDATA *client_cdata;
57
+
58
+ Data_Get_Struct(client, mTox_cClient_CDATA, client_cdata);
59
+
60
+ TOX_ERR_FRIEND_ADD error;
61
+
62
+ const result = tox_friend_send_message(
63
+ client_cdata->tox,
64
+ NUM2LONG(number),
65
+ TOX_MESSAGE_TYPE_NORMAL,
66
+ (uint8_t*)RSTRING_PTR(text),
67
+ RSTRING_LEN(text),
68
+ &error
69
+ );
70
+
71
+ switch (error) {
72
+ case TOX_ERR_FRIEND_SEND_MESSAGE_OK:
73
+ break;
74
+ case TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ:
75
+ rb_raise(rb_eNoMemError, "tox_friend_send_message() returned TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ");
76
+ default:
77
+ rb_raise(rb_eRuntimeError, "tox_friend_send_message() failed");
78
+ }
79
+
80
+ return LONG2FIX(result);
81
+ }
@@ -0,0 +1,25 @@
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
+ #include <ruby.h>
20
+
21
+ #include <tox/tox.h>
22
+
23
+ void mTox_cFriend_INIT();
24
+
25
+ extern VALUE mTox_cFriend;
@@ -0,0 +1,33 @@
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
+ #include "tox.h"
20
+ #include "node.h"
21
+
22
+ // Instance
23
+ VALUE mTox_cNode;
24
+
25
+ /*************************************************************
26
+ * Initialization
27
+ *************************************************************/
28
+
29
+ void mTox_cNode_INIT()
30
+ {
31
+ // Instance
32
+ mTox_cNode = rb_define_class_under(mTox, "Node", rb_cObject);
33
+ }
@@ -0,0 +1,25 @@
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
+ #include <ruby.h>
20
+
21
+ #include <tox/tox.h>
22
+
23
+ void mTox_cNode_INIT();
24
+
25
+ extern VALUE mTox_cNode;
@@ -0,0 +1,112 @@
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
+ #include "tox.h"
20
+ #include "options.h"
21
+
22
+ // Instance
23
+ VALUE mTox_cOptions;
24
+
25
+ // Memory management
26
+ static VALUE mTox_cOptions_alloc(VALUE klass);
27
+ static void mTox_cOptions_free(void *free_cdata);
28
+
29
+ // Public methods
30
+
31
+ static VALUE mTox_cOptions_savedata(VALUE self);
32
+ static VALUE mTox_cOptions_savedata_EQUALS(VALUE self, VALUE savedata);
33
+
34
+ /*************************************************************
35
+ * Initialization
36
+ *************************************************************/
37
+
38
+ void mTox_cOptions_INIT()
39
+ {
40
+ // Instance
41
+ mTox_cOptions = rb_define_class_under(mTox, "Options", rb_cObject);
42
+
43
+ // Memory management
44
+ rb_define_alloc_func(mTox_cOptions, mTox_cOptions_alloc);
45
+
46
+ // Public methods
47
+ rb_define_method(mTox_cOptions, "savedata", mTox_cOptions_savedata, 0);
48
+ rb_define_method(mTox_cOptions, "savedata=", mTox_cOptions_savedata_EQUALS, 1);
49
+ }
50
+
51
+ /*************************************************************
52
+ * Memory management
53
+ *************************************************************/
54
+
55
+ VALUE mTox_cOptions_alloc(const VALUE klass)
56
+ {
57
+ mTox_cOptions_CDATA *alloc_cdata = ALLOC(mTox_cOptions_CDATA);
58
+
59
+ tox_options_default(alloc_cdata);
60
+
61
+ return Data_Wrap_Struct(klass, NULL, mTox_cOptions_free, alloc_cdata);
62
+ }
63
+
64
+ void mTox_cOptions_free(void *const free_cdata)
65
+ {
66
+ free(free_cdata);
67
+ }
68
+
69
+ /*************************************************************
70
+ * Public methods
71
+ *************************************************************/
72
+
73
+ // Tox::Options#savedata
74
+ VALUE mTox_cOptions_savedata(const VALUE self)
75
+ {
76
+ mTox_cOptions_CDATA *self_cdata;
77
+
78
+ Data_Get_Struct(self, mTox_cOptions_CDATA, self_cdata);
79
+
80
+ switch (self_cdata->savedata_type) {
81
+ case TOX_SAVEDATA_TYPE_NONE:
82
+ return Qnil;
83
+ case TOX_SAVEDATA_TYPE_TOX_SAVE:
84
+ return rb_str_new(self_cdata->savedata_data, self_cdata->savedata_length);
85
+ default:
86
+ rb_raise(rb_eNotImpError, "Tox::Options#savedata has unknown type");
87
+ }
88
+ }
89
+
90
+ // Tox::Options#savedata=
91
+ VALUE mTox_cOptions_savedata_EQUALS(const VALUE self, const VALUE savedata)
92
+ {
93
+ mTox_cOptions_CDATA *self_cdata;
94
+
95
+ Data_Get_Struct(self, mTox_cOptions_CDATA, self_cdata);
96
+
97
+ if (Qnil == savedata) {
98
+ self_cdata->savedata_type = TOX_SAVEDATA_TYPE_NONE;
99
+ self_cdata->savedata_data = NULL;
100
+ self_cdata->savedata_length = 0;
101
+
102
+ return Qnil;
103
+ }
104
+
105
+ Check_Type(savedata, T_STRING);
106
+
107
+ self_cdata->savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE;
108
+ self_cdata->savedata_data = (uint8_t*)RSTRING_PTR(savedata);
109
+ self_cdata->savedata_length = RSTRING_LEN(savedata);
110
+
111
+ return savedata;
112
+ }
@@ -0,0 +1,27 @@
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
+ #include <ruby.h>
20
+
21
+ #include <tox/tox.h>
22
+
23
+ void mTox_cOptions_INIT();
24
+
25
+ extern VALUE mTox_cOptions;
26
+
27
+ typedef struct Tox_Options mTox_cOptions_CDATA;
@@ -0,0 +1,49 @@
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
+ #include "tox.h"
20
+ #include "options.h"
21
+ #include "node.h"
22
+ #include "client.h"
23
+ #include "friend.h"
24
+
25
+ #if !(TOX_VERSION_IS_API_COMPATIBLE(0, 1, 9))
26
+ #error "Tox API version is not compatible"
27
+ #endif
28
+
29
+ // Instance
30
+ VALUE mTox;
31
+
32
+ /*************************************************************
33
+ * Initialization
34
+ *************************************************************/
35
+
36
+ void Init_tox()
37
+ {
38
+ if (!TOX_VERSION_IS_ABI_COMPATIBLE()) {
39
+ rb_raise(rb_eLoadError, "incompatible Tox ABI version");
40
+ }
41
+
42
+ // Instance
43
+ mTox = rb_define_module("Tox");
44
+
45
+ mTox_cOptions_INIT();
46
+ mTox_cNode_INIT();
47
+ mTox_cClient_INIT();
48
+ mTox_cFriend_INIT();
49
+ }