yong-purple_ruby 0.4.0 → 0.4.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.
data/Manifest.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  ext/extconf.rb
2
2
  ext/purple_ruby.c
3
3
  ext/reconnect.c
4
+ ext/account.c
4
5
  examples/purplegw_example.rb
5
6
  Manifest.txt
6
7
  History.txt
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.4.0') do |p|
6
+ Hoe.new('purple_ruby', '0.4.1') do |p|
7
7
  p.author = 'yong'
8
8
  p.email = 'yong@intridea.com'
9
9
  p.url = 'http://www.intridea.com'
@@ -52,11 +52,15 @@ class PurpleGWExample
52
52
  end
53
53
 
54
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}"
55
+ PurpleRuby.watch_new_buddy do |acc, remote_user, message|
56
+ puts "new buddy: #{acc.username} #{remote_user} #{message}"
57
57
  true #'true': accept; 'false': deny
58
58
  end
59
59
 
60
+ PurpleRuby.watch_notify_message do |type, title, primary, secondary|
61
+ puts "notification: #{type}, #{title}, #{primary}, #{secondary}"
62
+ end
63
+
60
64
  #listen a tcp port, parse incoming data and send it out.
61
65
  #We assume the incoming data is in the following format (separated by comma):
62
66
  #<protocol>,<user>,<message>
data/ext/account.c ADDED
@@ -0,0 +1,163 @@
1
+ /*
2
+ * adopted from finch's gntaccount.c
3
+ */
4
+
5
+ /* finch
6
+ *
7
+ * Finch is the legal property of its developers, whose names are too numerous
8
+ * to list here. Please refer to the COPYRIGHT file distributed with this
9
+ * source distribution.
10
+ *
11
+ * This program is free software; you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation; either version 2 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * This program is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program; if not, write to the Free Software
23
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
24
+ */
25
+
26
+ #include <libpurple/account.h>
27
+ #include <libpurple/conversation.h>
28
+ #include <libpurple/core.h>
29
+ #include <libpurple/debug.h>
30
+ #include <libpurple/cipher.h>
31
+ #include <libpurple/eventloop.h>
32
+ #include <libpurple/ft.h>
33
+ #include <libpurple/log.h>
34
+ #include <libpurple/notify.h>
35
+ #include <libpurple/prefs.h>
36
+ #include <libpurple/prpl.h>
37
+ #include <libpurple/pounce.h>
38
+ #include <libpurple/request.h>
39
+ #include <libpurple/savedstatuses.h>
40
+ #include <libpurple/sound.h>
41
+ #include <libpurple/status.h>
42
+ #include <libpurple/util.h>
43
+ #include <libpurple/whiteboard.h>
44
+ #include <libpurple/network.h>
45
+
46
+ #include <ruby.h>
47
+
48
+ extern ID CALL;
49
+ extern VALUE cAccount;
50
+ extern VALUE new_buddy_handler;
51
+
52
+ static char *
53
+ make_info(PurpleAccount *account, PurpleConnection *gc, const char *remote_user,
54
+ const char *id, const char *alias, const char *msg)
55
+ {
56
+ if (msg != NULL && *msg == '\0')
57
+ msg = NULL;
58
+
59
+ return g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%s"),
60
+ remote_user,
61
+ (alias != NULL ? " (" : ""),
62
+ (alias != NULL ? alias : ""),
63
+ (alias != NULL ? ")" : ""),
64
+ (id != NULL
65
+ ? id
66
+ : (purple_connection_get_display_name(gc) != NULL
67
+ ? purple_connection_get_display_name(gc)
68
+ : purple_account_get_username(account))),
69
+ (msg != NULL ? ": " : "."),
70
+ (msg != NULL ? msg : ""));
71
+ }
72
+
73
+ static void
74
+ notify_added(PurpleAccount *account, const char *remote_user,
75
+ const char *id, const char *alias,
76
+ const char *msg)
77
+ {
78
+ char *buffer;
79
+ PurpleConnection *gc;
80
+
81
+ gc = purple_account_get_connection(account);
82
+
83
+ buffer = make_info(account, gc, remote_user, id, alias, msg);
84
+
85
+ purple_notify_info(NULL, NULL, buffer, NULL);
86
+
87
+ g_free(buffer);
88
+ }
89
+
90
+ static void
91
+ request_add(PurpleAccount *account, const char *remote_user,
92
+ const char *id, const char *alias,
93
+ const char *message)
94
+ {
95
+ if (new_buddy_handler != Qnil) {
96
+ VALUE *args = g_new(VALUE, 3);
97
+ args[0] = Data_Wrap_Struct(cAccount, NULL, NULL, account);
98
+ args[1] = rb_str_new2(NULL == remote_user ? "" : remote_user);
99
+ args[2] = rb_str_new2(NULL == message ? "" : message);
100
+ VALUE v = rb_funcall2((VALUE)new_buddy_handler, CALL, 3, args);
101
+
102
+ if (v != Qnil && v != Qfalse) {
103
+ PurpleConnection *gc = purple_account_get_connection(account);
104
+ if (g_list_find(purple_connections_get_all(), gc))
105
+ {
106
+ purple_blist_request_add_buddy(account, remote_user,
107
+ NULL, alias);
108
+ }
109
+ }
110
+
111
+ g_free(args);
112
+ }
113
+ }
114
+
115
+ static void *request_authorize(PurpleAccount *account,
116
+ const char *remote_user,
117
+ const char *id,
118
+ const char *alias,
119
+ const char *message,
120
+ gboolean on_list,
121
+ PurpleAccountRequestAuthorizationCb auth_cb,
122
+ PurpleAccountRequestAuthorizationCb deny_cb,
123
+ void *user_data)
124
+ {
125
+ if (new_buddy_handler != Qnil) {
126
+ VALUE *args = g_new(VALUE, 3);
127
+ args[0] = Data_Wrap_Struct(cAccount, NULL, NULL, account);
128
+ args[1] = rb_str_new2(NULL == remote_user ? "" : remote_user);
129
+ args[2] = rb_str_new2(NULL == message ? "" : message);
130
+ VALUE v = rb_funcall2((VALUE)new_buddy_handler, CALL, 3, args);
131
+
132
+ if (v != Qnil && v != Qfalse) {
133
+ auth_cb(user_data);
134
+ purple_blist_request_add_buddy(account, remote_user, NULL, alias);
135
+ } else {
136
+ deny_cb(user_data);
137
+ }
138
+
139
+ g_free(args);
140
+ }
141
+
142
+ return NULL;
143
+ }
144
+
145
+ static void
146
+ request_close(void *uihandle)
147
+ {
148
+ purple_request_close(PURPLE_REQUEST_ACTION, uihandle);
149
+ }
150
+
151
+ PurpleAccountUiOps account_ops =
152
+ {
153
+ notify_added,
154
+ NULL,
155
+ request_add,
156
+ request_authorize,
157
+ request_close,
158
+ NULL,
159
+ NULL,
160
+ NULL,
161
+ NULL
162
+ };
163
+
data/ext/purple_ruby.c CHANGED
@@ -120,7 +120,7 @@ static PurpleEventLoopUiOps glib_eventloops =
120
120
  };
121
121
 
122
122
  static VALUE cPurpleRuby;
123
- static VALUE cAccount;
123
+ VALUE cAccount;
124
124
  const char* UI_ID = "purplegw";
125
125
  static GMainLoop *main_loop = NULL;
126
126
  static VALUE im_handler = Qnil;
@@ -128,10 +128,11 @@ 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
+ VALUE new_buddy_handler = Qnil;
132
132
  static GHashTable* data_hash_table = NULL;
133
133
  static GHashTable* fd_hash_table = NULL;
134
- static ID CALL;
134
+ ID CALL;
135
+ extern PurpleAccountUiOps account_ops;
135
136
 
136
137
  extern void
137
138
  finch_connection_report_disconnect(PurpleConnection *gc, PurpleConnectionError reason,
@@ -179,36 +180,6 @@ static void write_conv(PurpleConversation *conv, const char *who, const char *al
179
180
  }
180
181
  }
181
182
 
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
-
212
183
  static PurpleConversationUiOps conv_uiops =
213
184
  {
214
185
  NULL, /* create_conversation */
@@ -247,19 +218,6 @@ static PurpleConnectionUiOps connection_ops =
247
218
  NULL
248
219
  };
249
220
 
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
-
263
221
  static void* notify_message(PurpleNotifyMsgType type,
264
222
  const char *title,
265
223
  const char *primary,
@@ -416,11 +374,11 @@ static VALUE watch_request(VALUE self)
416
374
  return request_handler;
417
375
  }
418
376
 
419
- static VALUE watch_authorize(VALUE self)
377
+ static VALUE watch_new_buddy(VALUE self)
420
378
  {
421
379
  purple_accounts_set_ui_ops(&account_ops);
422
- authorize_handler = rb_block_proc();
423
- return authorize_handler;
380
+ new_buddy_handler = rb_block_proc();
381
+ return new_buddy_handler;
424
382
  }
425
383
 
426
384
  static void signed_on(PurpleConnection* connection)
@@ -717,7 +675,7 @@ void Init_purple_ruby()
717
675
  rb_define_singleton_method(cPurpleRuby, "watch_incoming_im", watch_incoming_im, 0);
718
676
  rb_define_singleton_method(cPurpleRuby, "watch_notify_message", watch_notify_message, 0);
719
677
  rb_define_singleton_method(cPurpleRuby, "watch_request", watch_request, 0);
720
- rb_define_singleton_method(cPurpleRuby, "watch_authorize", watch_authorize, 0);
678
+ rb_define_singleton_method(cPurpleRuby, "watch_new_buddy", watch_new_buddy, 0);
721
679
  rb_define_singleton_method(cPurpleRuby, "watch_incoming_ipc", watch_incoming_ipc, 2);
722
680
  rb_define_singleton_method(cPurpleRuby, "login", login, 3);
723
681
  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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yong
@@ -36,6 +36,7 @@ files:
36
36
  - ext/extconf.rb
37
37
  - ext/purple_ruby.c
38
38
  - ext/reconnect.c
39
+ - ext/account.c
39
40
  - examples/purplegw_example.rb
40
41
  - Manifest.txt
41
42
  - History.txt