yong-purple_ruby 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/ext/reconnect.c +166 -0
- metadata +3 -2
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
data/ext/reconnect.c
ADDED
@@ -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
|
+
}
|
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.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yong
|
@@ -35,12 +35,13 @@ extra_rdoc_files:
|
|
35
35
|
files:
|
36
36
|
- ext/extconf.rb
|
37
37
|
- ext/purple_ruby.c
|
38
|
+
- ext/reconnect.c
|
38
39
|
- examples/purplegw_example.rb
|
39
40
|
- Manifest.txt
|
40
41
|
- History.txt
|
41
42
|
- README.txt
|
42
43
|
- Rakefile
|
43
|
-
has_rdoc:
|
44
|
+
has_rdoc: false
|
44
45
|
homepage: http://www.intridea.com
|
45
46
|
post_install_message:
|
46
47
|
rdoc_options:
|