yong-purple_ruby 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'hoe'
3
3
 
4
4
  EXT = "ext/ruburple_ext.#{Hoe::DLEXT}"
5
5
 
6
- Hoe.new('purple_ruby', '0.2.1') do |p|
6
+ Hoe.new('purple_ruby', '0.3.0') do |p|
7
7
  p.author = 'yong'
8
8
  p.email = 'yong@intridea.com'
9
9
  p.url = 'http://www.intridea.com'
@@ -41,7 +41,8 @@ class PurpleGWExample
41
41
  end
42
42
 
43
43
  PurpleRuby.watch_connection_error do |acc, type, description|
44
- raise "connection_error: #{acc.username} #{type} #{description}"
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> <user> <message>
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}, #{user}, #{message}"
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
- static char* UI_ID = "purplegw";
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
- static void connection_error(PurpleConnection* connection,
117
- PurpleConnectionError type,
118
- const gchar *description,
119
- gpointer unused)
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(connection));
124
- args[1] = INT2FIX(type);
125
- args[2] = rb_str_new2(description);
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
- connection_error(purple_account_get_connection(account), PURPLE_CONNECTION_ERROR_NETWORK_ERROR, message, NULL);
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
- report_disconnect_reason,
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yong-purple_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yong