Mercurial > pidgin
annotate plugins/autorecon.c @ 9967:2f153f8cdf81
[gaim-migrate @ 10877]
(21:12:31) KingAnt: What's up with MSN status stuff?
(21:12:33) KingAnt: I want to compile
(21:12:35) LSchiere: hey mark :-)
(21:12:39) LSchiere: lack of patches
(21:12:48) nosnilmot:
http://nosnilmot.com/patches/gaim-1.0.0cvs-msn-status.patch
(21:12:54) KingAnt: Ha ha
(21:12:57) LSchiere: there we go :-D
(21:12:58) nosnilmot: might be good enough, might not
(21:13:06) KingAnt: I need to ask these kinds of questions more often
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 08 Sep 2004 01:16:14 +0000 |
parents | ff704c905239 |
children | ab5db2c5da79 |
rev | line source |
---|---|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
1 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
2 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
3 #include "connection.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
4 #include "debug.h" |
8774 | 5 #include "pluginpref.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5607
diff
changeset
|
6 #include "prpl.h" |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
7 #include "signals.h" |
9943 | 8 #include "version.h" |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4113
diff
changeset
|
9 |
8774 | 10 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
11 #define AUTORECON_PLUGIN_ID "core-autorecon" |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
12 |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
13 #define INITIAL 8000 |
4590 | 14 #define MAXTIME 2048000 |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
15 |
6113 | 16 typedef struct { |
17 int delay; | |
18 guint timeout; | |
19 } GaimAutoRecon; | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
20 |
6113 | 21 static GHashTable *hash = NULL; |
8774 | 22 |
23 #define AUTORECON_OPT "/plugins/core/autorecon" | |
9930 | 24 #define OPT_HIDE_CONNECTED AUTORECON_OPT "/hide_connected_error" |
25 #define OPT_HIDE_CONNECTING AUTORECON_OPT "/hide_connecting_error" | |
26 #define OPT_RESTORE_STATE AUTORECON_OPT "/restore_state" | |
8774 | 27 |
28 /* storage of original (old_ops) and modified (new_ops) ui ops to allow us to | |
29 intercept calls to report_disconnect */ | |
30 static GaimConnectionUiOps *old_ops = NULL; | |
31 static GaimConnectionUiOps *new_ops = NULL; | |
32 | |
33 | |
34 static void report_disconnect(GaimConnection *gc, const char *text) { | |
35 | |
36 if(old_ops == NULL || old_ops->report_disconnect == NULL) { | |
37 /* there's nothing to call through to, so don't bother | |
38 checking prefs */ | |
39 return; | |
40 | |
41 } else if(gc->state == GAIM_CONNECTED | |
42 && gaim_prefs_get_bool(OPT_HIDE_CONNECTED)) { | |
43 /* this is a connected error, and we're hiding those */ | |
44 gaim_debug(GAIM_DEBUG_INFO, "autorecon", | |
45 "hid disconnect error message\n"); | |
46 return; | |
47 | |
48 } else if(gc->state == GAIM_CONNECTING | |
49 && gaim_prefs_get_bool(OPT_HIDE_CONNECTING)) { | |
50 /* this is a connecting error, and we're hiding those */ | |
51 gaim_debug(GAIM_DEBUG_INFO, "autorecon", | |
52 "hid error message while connecting\n"); | |
53 return; | |
54 } | |
55 | |
56 /* if we haven't returned by now, then let's pass to the real | |
57 function */ | |
58 old_ops->report_disconnect(gc, text); | |
59 } | |
60 | |
61 | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
62 static gboolean do_signon(gpointer data) { |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
63 GaimAccount *account = data; |
6113 | 64 GaimAutoRecon *info; |
65 | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
66 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "do_signon called\n"); |
6113 | 67 g_return_val_if_fail(account != NULL, FALSE); |
68 info = g_hash_table_lookup(hash, account); | |
4494
b5a50a6a13b0
[gaim-migrate @ 4769]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4491
diff
changeset
|
69 |
5607 | 70 if (g_list_index(gaim_accounts_get_all(), account) < 0) |
1817
b367beee6448
[gaim-migrate @ 1827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1404
diff
changeset
|
71 return FALSE; |
6113 | 72 |
7372 | 73 if(info) |
74 info->timeout = 0; | |
75 | |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
76 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "calling gaim_account_connect\n"); |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
77 gaim_account_connect(account); |
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
78 gaim_debug(GAIM_DEBUG_INFO, "autorecon", "done calling gaim_account_connect\n"); |
6113 | 79 |
1817
b367beee6448
[gaim-migrate @ 1827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1404
diff
changeset
|
80 return FALSE; |
1378
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
81 } |
aedeb1218a0a
[gaim-migrate @ 1388]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1165
diff
changeset
|
82 |
8774 | 83 |
5587
1c55b1540e18
[gaim-migrate @ 5991]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
84 static void reconnect(GaimConnection *gc, void *m) { |
6113 | 85 GaimAccount *account; |
86 GaimAutoRecon *info; | |
87 | |
88 g_return_if_fail(gc != NULL); | |
89 account = gaim_connection_get_account(gc); | |
90 info = g_hash_table_lookup(hash, account); | |
91 | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
92 if (!gc->wants_to_die) { |
6113 | 93 if (info == NULL) { |
94 info = g_new0(GaimAutoRecon, 1); | |
95 g_hash_table_insert(hash, account, info); | |
96 info->delay = INITIAL; | |
8249 | 97 } else { |
6113 | 98 info->delay = MIN(2 * info->delay, MAXTIME); |
8250 | 99 if (info->timeout != 0) |
100 g_source_remove(info->timeout); | |
8249 | 101 } |
6113 | 102 info->timeout = g_timeout_add(info->delay, do_signon, account); |
103 } else if (info != NULL) { | |
104 g_hash_table_remove(hash, account); | |
2216
66783ad29e55
[gaim-migrate @ 2226]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1818
diff
changeset
|
105 } |
9546 | 106 } |
8774 | 107 |
6113 | 108 static void |
109 free_auto_recon(gpointer data) | |
110 { | |
111 GaimAutoRecon *info = data; | |
112 | |
113 if (info->timeout != 0) | |
114 g_source_remove(info->timeout); | |
115 | |
116 g_free(info); | |
117 } | |
118 | |
8774 | 119 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
120 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
121 plugin_load(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
122 { |
8774 | 123 |
124 /* this was the suggested way to override a single function of the | |
125 real ui ops. However, there's a mild concern of having more than one | |
126 bit of code making a new ui op call-through copy. If plugins A and B | |
127 both override the ui ops (in that order), B thinks that the | |
128 overridden ui ops A created was the original. If A unloads first, | |
129 and swaps out and frees its overridden version, then B is calling | |
130 through to a free'd ui op. There needs to be a way to "stack up" | |
131 overridden ui ops or something... I have a good idea of how to write | |
132 such a creature if someone wants it done. - siege 2004-04-20 */ | |
133 | |
134 /* get old ops, make a copy with a minor change */ | |
135 old_ops = gaim_connections_get_ui_ops(); | |
136 new_ops = (GaimConnectionUiOps *) g_memdup(old_ops, | |
137 sizeof(GaimConnectionUiOps)); | |
138 new_ops->report_disconnect = report_disconnect; | |
139 gaim_connections_set_ui_ops(new_ops); | |
140 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
141 hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, |
8774 | 142 free_auto_recon); |
3630 | 143 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
144 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", |
8774 | 145 plugin, GAIM_CALLBACK(reconnect), NULL); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
146 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
147 return TRUE; |
3802 | 148 } |
149 | |
8774 | 150 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
151 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
152 plugin_unload(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
153 { |
8243 | 154 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", |
155 plugin, GAIM_CALLBACK(reconnect)); | |
9546 | 156 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
157 g_hash_table_destroy(hash); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
158 hash = NULL; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
159 |
8774 | 160 gaim_connections_set_ui_ops(old_ops); |
161 g_free(new_ops); | |
162 old_ops = new_ops = NULL; | |
163 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
164 return TRUE; |
3630 | 165 } |
166 | |
8774 | 167 |
168 static GaimPluginPrefFrame *get_plugin_pref_frame(GaimPlugin *plugin) { | |
169 GaimPluginPrefFrame *frame = gaim_plugin_pref_frame_new(); | |
170 GaimPluginPref *pref; | |
171 | |
172 pref = gaim_plugin_pref_new_with_label(_("Error Message Suppression")); | |
9549 | 173 gaim_plugin_pref_frame_add(frame, pref); |
8774 | 174 |
175 pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTED, | |
176 _("Hide Disconnect Errors")); | |
177 gaim_plugin_pref_frame_add(frame, pref); | |
178 | |
179 pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTING, | |
180 _("Hide Login Errors")); | |
181 gaim_plugin_pref_frame_add(frame, pref); | |
182 | |
183 return frame; | |
184 } | |
185 | |
186 | |
187 static GaimPluginUiInfo pref_info = { | |
188 get_plugin_pref_frame | |
189 }; | |
190 | |
191 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
192 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
193 { |
9943 | 194 GAIM_PLUGIN_MAGIC, |
195 GAIM_MAJOR_VERSION, | |
196 GAIM_MINOR_VERSION, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
197 GAIM_PLUGIN_STANDARD, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
198 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
199 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
200 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
201 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
202 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
203 AUTORECON_PLUGIN_ID, /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
204 N_("Auto-Reconnect"), /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
205 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
206 /** summary */ |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
207 N_("When you are kicked offline, this reconnects you."), |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
208 /** description */ |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
209 N_("When you are kicked offline, this reconnects you."), |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
210 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */ |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
211 GAIM_WEBSITE, /**< homepage */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
212 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
213 plugin_load, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
214 plugin_unload, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
215 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
216 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
217 NULL, /**< ui_info */ |
8774 | 218 NULL, /**< extra_info */ |
8993 | 219 &pref_info, /**< prefs_info */ |
220 NULL | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
221 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
222 |
8774 | 223 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
224 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
225 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
4590
diff
changeset
|
226 { |
8774 | 227 gaim_prefs_add_none(AUTORECON_OPT); |
228 gaim_prefs_add_bool(OPT_HIDE_CONNECTED, FALSE); | |
229 gaim_prefs_add_bool(OPT_HIDE_CONNECTING, FALSE); | |
9961 | 230 gaim_prefs_remove_bool(OPT_RESTORE_STATE); |
3630 | 231 } |
232 | |
6063 | 233 GAIM_INIT_PLUGIN(autorecon, init_plugin, info) |
8774 | 234 |