yong-purple_ruby 0.3.2 → 0.4.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.3.2') do |p|
6
+ Hoe.new('purple_ruby', '0.4.0') do |p|
7
7
  p.author = 'yong'
8
8
  p.email = 'yong@intridea.com'
9
9
  p.url = 'http://www.intridea.com'
@@ -51,6 +51,12 @@ class PurpleGWExample
51
51
  true #'true': accept a request; 'false': ignore a request
52
52
  end
53
53
 
54
+ #request for authorization when someone adds this account to their buddy list
55
+ PurpleRuby.watch_authorize do |acc, remote_user, message|
56
+ puts "authorize request: #{acc.username} #{remote_user} #{message}"
57
+ true #'true': accept; 'false': deny
58
+ end
59
+
54
60
  #listen a tcp port, parse incoming data and send it out.
55
61
  #We assume the incoming data is in the following format (separated by comma):
56
62
  #<protocol>,<user>,<message>
data/ext/purple_ruby.c CHANGED
@@ -128,6 +128,7 @@ static VALUE signed_on_handler = Qnil;
128
128
  static VALUE connection_error_handler = Qnil;
129
129
  static VALUE notify_message_handler = Qnil;
130
130
  static VALUE request_handler = Qnil;
131
+ static VALUE authorize_handler = Qnil;
131
132
  static GHashTable* data_hash_table = NULL;
132
133
  static GHashTable* fd_hash_table = NULL;
133
134
  static ID CALL;
@@ -178,6 +179,36 @@ static void write_conv(PurpleConversation *conv, const char *who, const char *al
178
179
  }
179
180
  }
180
181
 
182
+ static void *request_authorize(PurpleAccount *account,
183
+ const char *remote_user,
184
+ const char *id,
185
+ const char *alias,
186
+ const char *message,
187
+ gboolean on_list,
188
+ PurpleAccountRequestAuthorizationCb auth_cb,
189
+ PurpleAccountRequestAuthorizationCb deny_cb,
190
+ void *user_data)
191
+ {
192
+ if (authorize_handler != Qnil) {
193
+ VALUE *args = g_new(VALUE, 3);
194
+ args[0] = Data_Wrap_Struct(cAccount, NULL, NULL, account);
195
+ args[1] = rb_str_new2(remote_user);
196
+ args[2] = rb_str_new2(message);
197
+ VALUE v = rb_funcall2((VALUE)authorize_handler, CALL, 3, args);
198
+
199
+ if (v != Qnil && v != Qfalse) {
200
+ auth_cb(user_data);
201
+ purple_blist_request_add_buddy(account, remote_user, NULL, alias);
202
+ } else {
203
+ deny_cb(user_data);
204
+ }
205
+
206
+ g_free(args);
207
+ }
208
+
209
+ return NULL;
210
+ }
211
+
181
212
  static PurpleConversationUiOps conv_uiops =
182
213
  {
183
214
  NULL, /* create_conversation */
@@ -216,6 +247,19 @@ static PurpleConnectionUiOps connection_ops =
216
247
  NULL
217
248
  };
218
249
 
250
+ static PurpleAccountUiOps account_ops =
251
+ {
252
+ NULL, /*notify_added*/
253
+ NULL,
254
+ NULL, /*request_add*/
255
+ request_authorize,
256
+ NULL, /*request_close*/
257
+ NULL,
258
+ NULL,
259
+ NULL,
260
+ NULL
261
+ };
262
+
219
263
  static void* notify_message(PurpleNotifyMsgType type,
220
264
  const char *title,
221
265
  const char *primary,
@@ -372,6 +416,13 @@ static VALUE watch_request(VALUE self)
372
416
  return request_handler;
373
417
  }
374
418
 
419
+ static VALUE watch_authorize(VALUE self)
420
+ {
421
+ purple_accounts_set_ui_ops(&account_ops);
422
+ authorize_handler = rb_block_proc();
423
+ return authorize_handler;
424
+ }
425
+
375
426
  static void signed_on(PurpleConnection* connection)
376
427
  {
377
428
  VALUE *args = g_new(VALUE, 1);
@@ -666,6 +717,7 @@ void Init_purple_ruby()
666
717
  rb_define_singleton_method(cPurpleRuby, "watch_incoming_im", watch_incoming_im, 0);
667
718
  rb_define_singleton_method(cPurpleRuby, "watch_notify_message", watch_notify_message, 0);
668
719
  rb_define_singleton_method(cPurpleRuby, "watch_request", watch_request, 0);
720
+ rb_define_singleton_method(cPurpleRuby, "watch_authorize", watch_authorize, 0);
669
721
  rb_define_singleton_method(cPurpleRuby, "watch_incoming_ipc", watch_incoming_ipc, 2);
670
722
  rb_define_singleton_method(cPurpleRuby, "login", login, 3);
671
723
  rb_define_singleton_method(cPurpleRuby, "main_loop_run", main_loop_run, 0);
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.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yong