dcu-purple_ruby 0.7.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.
@@ -0,0 +1,166 @@
1
+ /*
2
+ * adopted from finch's gntconn.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
+ extern const char* UI_ID;
47
+
48
+ #define INITIAL_RECON_DELAY_MIN 8000
49
+ #define INITIAL_RECON_DELAY_MAX 60000
50
+
51
+ #define MAX_RECON_DELAY 600000
52
+
53
+ typedef struct {
54
+ int delay;
55
+ guint timeout;
56
+ } FinchAutoRecon;
57
+
58
+ /**
59
+ * Contains accounts that are auto-reconnecting.
60
+ * The key is a pointer to the PurpleAccount and the
61
+ * value is a pointer to a FinchAutoRecon.
62
+ */
63
+ static GHashTable *hash = NULL;
64
+
65
+ static void
66
+ free_auto_recon(gpointer data)
67
+ {
68
+ FinchAutoRecon *info = data;
69
+
70
+ if (info->timeout != 0)
71
+ g_source_remove(info->timeout);
72
+
73
+ g_free(info);
74
+ }
75
+
76
+ static gboolean
77
+ do_signon(gpointer data)
78
+ {
79
+ PurpleAccount *account = data;
80
+ FinchAutoRecon *info;
81
+ PurpleStatus *status;
82
+
83
+ purple_debug_info("autorecon", "do_signon called\n");
84
+ g_return_val_if_fail(account != NULL, FALSE);
85
+ info = g_hash_table_lookup(hash, account);
86
+
87
+ if (info)
88
+ info->timeout = 0;
89
+
90
+ status = purple_account_get_active_status(account);
91
+ if (purple_status_is_online(status))
92
+ {
93
+ purple_debug_info("autorecon", "calling purple_account_connect\n");
94
+ purple_account_connect(account);
95
+ purple_debug_info("autorecon", "done calling purple_account_connect\n");
96
+ }
97
+
98
+ return FALSE;
99
+ }
100
+
101
+ static gboolean
102
+ enable_account(gpointer data)
103
+ {
104
+ PurpleAccount *account = data;
105
+ FinchAutoRecon *info;
106
+
107
+ purple_debug_info("autorecon", "enable_account called\n");
108
+ g_return_val_if_fail(account != NULL, FALSE);
109
+ info = g_hash_table_lookup(hash, account);
110
+
111
+ if (info)
112
+ info->timeout = 0;
113
+
114
+ purple_account_set_enabled(account, UI_ID, TRUE);
115
+
116
+ return FALSE;
117
+ }
118
+
119
+ void
120
+ finch_connection_report_disconnect(PurpleConnection *gc, PurpleConnectionError reason,
121
+ const char *text)
122
+ {
123
+ PurpleAccount *account = purple_connection_get_account(gc);
124
+ FinchAutoRecon *info = g_hash_table_lookup(hash, account);
125
+
126
+ if (info == NULL) {
127
+ info = g_new0(FinchAutoRecon, 1);
128
+ g_hash_table_insert(hash, account, info);
129
+ info->delay = g_random_int_range(INITIAL_RECON_DELAY_MIN, INITIAL_RECON_DELAY_MAX);
130
+ } else {
131
+ info->delay = MIN(2 * info->delay, MAX_RECON_DELAY);
132
+ if (info->timeout != 0)
133
+ g_source_remove(info->timeout);
134
+ }
135
+
136
+ if (!purple_connection_error_is_fatal(reason)) {
137
+ info->timeout = g_timeout_add(info->delay, do_signon, account);
138
+ } else {
139
+ info->timeout = g_timeout_add(info->delay, enable_account, account);
140
+ }
141
+ }
142
+
143
+ static void
144
+ account_removed_cb(PurpleAccount *account, gpointer user_data)
145
+ {
146
+ g_hash_table_remove(hash, account);
147
+ }
148
+
149
+ static void *
150
+ finch_connection_get_handle(void)
151
+ {
152
+ static int handle;
153
+
154
+ return &handle;
155
+ }
156
+
157
+ void finch_connections_init()
158
+ {
159
+ hash = g_hash_table_new_full(
160
+ g_direct_hash, g_direct_equal,
161
+ NULL, free_auto_recon);
162
+
163
+ purple_signal_connect(purple_accounts_get_handle(), "account-removed",
164
+ finch_connection_get_handle(),
165
+ PURPLE_CALLBACK(account_removed_cb), NULL);
166
+ }
@@ -0,0 +1,70 @@
1
+ require File.join(File.dirname(__FILE__), %w{.. ext purple_ruby_ext})
2
+
3
+ Purple = PurpleRuby
4
+
5
+ Purple::Account.class_eval do
6
+ class AccountOptions
7
+ include Enumerable
8
+
9
+ def initialize(acc)
10
+ @acc = acc
11
+ end
12
+
13
+ def each
14
+ @acc.protocol.default_options.each{|k,v|
15
+ yield(k, self[k, v])
16
+ }
17
+ end
18
+
19
+ def []=(name, value)
20
+ opt = default_value(name)
21
+ case opt
22
+ when Integer
23
+ @acc.set_int_setting(name, value)
24
+ when true, false
25
+ @acc.set_bool_setting(name, value)
26
+ when String
27
+ @acc.set_string_setting(name, value)
28
+ else
29
+ raise "Unrecognized options type #{opt.class}, expected Integer, Boolean or String"
30
+ end
31
+ end
32
+
33
+ def [](name, default=nil)
34
+ opt = default || default_value(opt)
35
+ case opt
36
+ when Integer
37
+ @acc.get_int_setting(name, opt)
38
+ when true, false
39
+ @acc.get_bool_setting(name, opt)
40
+ when String
41
+ @acc.get_string_setting(name, opt)
42
+ end
43
+ end
44
+
45
+ def default_value(name)
46
+ opt = @acc.protocol.default_options[name.to_s]
47
+ unless opt
48
+ raise "Unknown option #{name}, expected one of: #{@acc.protocol.default_options.keys.join(', ')}"
49
+ end
50
+
51
+ opt
52
+ end
53
+
54
+ def inspect
55
+ inject("<#AccountOptions: "){|a, (k,v)|
56
+ a << "#{k}=#{v.inspect}, "
57
+ } << "account=#{@acc.inspect}>"
58
+ end
59
+ end
60
+
61
+ def options
62
+ @options ||= AccountOptions.new(self)
63
+ end
64
+
65
+ def protocol
66
+ id = self.protocol_id
67
+ Purple.list_protocols.find{|p| p.id == id }
68
+ end
69
+
70
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcu-purple_ruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
+ platform: ruby
11
+ authors:
12
+ - Xue Yong Zhi
13
+ - Pradeep Elankumaran
14
+ - Davide D'Agostino
15
+ - Pavel Valodzka
16
+ - Greg Hazel
17
+ autorequire:
18
+ bindir: bin
19
+ cert_chain: []
20
+
21
+ date: 2010-04-02 00:00:00 -05:00
22
+ default_executable:
23
+ dependencies: []
24
+
25
+ description: A ruby gem to write server that sends and recives IM messages
26
+ email: krawek@gmail.com
27
+ executables: []
28
+
29
+ extensions:
30
+ - ext/extconf.rb
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .gitignore
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.rdoc
39
+ - Rakefile
40
+ - examples/purplegw_example.rb
41
+ - ext/account.c
42
+ - ext/extconf.rb
43
+ - ext/purple_ruby.c
44
+ - ext/reconnect.c
45
+ - lib/purple_ruby.rb
46
+ - LICENSE
47
+ has_rdoc: true
48
+ homepage: http://github.com/dcu/purple_ruby
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: A ruby gem to write server that sends and recives IM messages
77
+ test_files:
78
+ - examples/purplegw_example.rb