yong-purple_ruby 0.2.1 → 0.3.0
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.
- data/Rakefile +1 -1
- data/examples/purplegw_example.rb +5 -4
- data/ext/purple_ruby.c +41 -18
- metadata +1 -1
data/Rakefile
CHANGED
@@ -41,7 +41,8 @@ class PurpleGWExample
|
|
41
41
|
end
|
42
42
|
|
43
43
|
PurpleRuby.watch_connection_error do |acc, type, description|
|
44
|
-
|
44
|
+
puts "connection_error: #{acc.username} #{type} #{description}"
|
45
|
+
true #'true': auto-reconnect; 'false': do nothing
|
45
46
|
end
|
46
47
|
|
47
48
|
#request can be: 'SSL Certificate Verification' etc
|
@@ -51,11 +52,11 @@ class PurpleGWExample
|
|
51
52
|
end
|
52
53
|
|
53
54
|
#listen a tcp port, parse incoming data and send it out.
|
54
|
-
#We assume the incoming data is in the following format:
|
55
|
-
#<protocol
|
55
|
+
#We assume the incoming data is in the following format (separated by comma):
|
56
|
+
#<protocol>,<user>,<message>
|
56
57
|
PurpleRuby.watch_incoming_ipc(SERVER_IP, SERVER_PORT) do |data|
|
57
58
|
protocol, user, message = data.split(",").collect{|x| x.chomp.strip}
|
58
|
-
puts "send: #{protocol}
|
59
|
+
puts "send: #{protocol},#{user},#{message}"
|
59
60
|
puts accounts[protocol].send_im(user, message)
|
60
61
|
end
|
61
62
|
|
data/ext/purple_ruby.c
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
* Author: yong@intridea.com
|
3
|
+
*
|
4
|
+
* This program is free software; you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU General Public License as published by
|
6
|
+
* the Free Software Foundation; either version 2 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU General Public License
|
15
|
+
* along with this program; if not, write to the Free Software
|
16
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
17
|
+
*
|
18
|
+
*/
|
19
|
+
|
1
20
|
#include <libpurple/account.h>
|
2
21
|
#include <libpurple/conversation.h>
|
3
22
|
#include <libpurple/core.h>
|
@@ -102,7 +121,7 @@ static PurpleEventLoopUiOps glib_eventloops =
|
|
102
121
|
|
103
122
|
static VALUE cPurpleRuby;
|
104
123
|
static VALUE cAccount;
|
105
|
-
|
124
|
+
const char* UI_ID = "purplegw";
|
106
125
|
static GMainLoop *main_loop = NULL;
|
107
126
|
static VALUE im_handler = Qnil;
|
108
127
|
static VALUE signed_on_handler = Qnil;
|
@@ -113,17 +132,25 @@ static GHashTable* data_hash_table = NULL;
|
|
113
132
|
static GHashTable* fd_hash_table = NULL;
|
114
133
|
static ID CALL;
|
115
134
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
135
|
+
extern void
|
136
|
+
finch_connection_report_disconnect(PurpleConnection *gc, PurpleConnectionError reason,
|
137
|
+
const char *text);
|
138
|
+
|
139
|
+
extern void finch_connections_init();
|
140
|
+
|
141
|
+
void report_disconnect(PurpleConnection *gc, PurpleConnectionError reason, const char *text)
|
120
142
|
{
|
121
143
|
if (Qnil != connection_error_handler) {
|
122
144
|
VALUE *args = g_new(VALUE, 3);
|
123
|
-
args[0] = Data_Wrap_Struct(cAccount, NULL, NULL, purple_connection_get_account(
|
124
|
-
args[1] = INT2FIX(
|
125
|
-
args[2] = rb_str_new2(
|
126
|
-
rb_funcall2((VALUE)connection_error_handler, CALL, 3, args);
|
145
|
+
args[0] = Data_Wrap_Struct(cAccount, NULL, NULL, purple_connection_get_account(gc));
|
146
|
+
args[1] = INT2FIX(reason);
|
147
|
+
args[2] = rb_str_new2(text);
|
148
|
+
VALUE v = rb_funcall2((VALUE)connection_error_handler, CALL, 3, args);
|
149
|
+
|
150
|
+
if (v != Qnil && v != Qfalse) {
|
151
|
+
finch_connection_report_disconnect(gc, reason, text);
|
152
|
+
}
|
153
|
+
|
127
154
|
g_free(args);
|
128
155
|
}
|
129
156
|
}
|
@@ -139,7 +166,7 @@ static void write_conv(PurpleConversation *conv, const char *who, const char *al
|
|
139
166
|
* In that case, libpurple will notify user with two regular im message.
|
140
167
|
* The first message is an error message, the second one is the original message that failed to send.
|
141
168
|
*/
|
142
|
-
|
169
|
+
report_disconnect(purple_account_get_connection(account), PURPLE_CONNECTION_ERROR_NETWORK_ERROR, message);
|
143
170
|
} else {
|
144
171
|
VALUE *args = g_new(VALUE, 3);
|
145
172
|
args[0] = rb_str_new2(purple_account_get_username(account));
|
@@ -174,11 +201,6 @@ static PurpleConversationUiOps conv_uiops =
|
|
174
201
|
NULL
|
175
202
|
};
|
176
203
|
|
177
|
-
static void report_disconnect_reason(PurpleConnection *gc, PurpleConnectionError reason, const char *text)
|
178
|
-
{
|
179
|
-
connection_error(gc, reason, text, NULL);
|
180
|
-
}
|
181
|
-
|
182
204
|
static PurpleConnectionUiOps connection_ops =
|
183
205
|
{
|
184
206
|
NULL, /* connect_progress */
|
@@ -188,7 +210,7 @@ static PurpleConnectionUiOps connection_ops =
|
|
188
210
|
NULL,
|
189
211
|
NULL, /* network_connected */
|
190
212
|
NULL, /* network_disconnected */
|
191
|
-
|
213
|
+
report_disconnect,
|
192
214
|
NULL,
|
193
215
|
NULL,
|
194
216
|
NULL
|
@@ -368,12 +390,13 @@ static VALUE watch_signed_on_event(VALUE self)
|
|
368
390
|
|
369
391
|
static VALUE watch_connection_error(VALUE self)
|
370
392
|
{
|
393
|
+
finch_connections_init();
|
371
394
|
purple_connections_set_ui_ops(&connection_ops);
|
372
395
|
|
373
396
|
connection_error_handler = rb_block_proc();
|
374
|
-
int handle;
|
397
|
+
/*int handle;
|
375
398
|
purple_signal_connect(purple_connections_get_handle(), "connection-error", &handle,
|
376
|
-
PURPLE_CALLBACK(connection_error), NULL)
|
399
|
+
PURPLE_CALLBACK(connection_error), NULL);*/
|
377
400
|
return connection_error_handler;
|
378
401
|
}
|
379
402
|
|