[gaim-migrate @ 4639]
[pidgin-git.git] / plugins / autorecon.c
blob0e905560799e804ef949361e77eddf1ff663f684
1 #include "config.h"
3 #ifndef GAIM_PLUGINS
4 #define GAIM_PLUGINS
5 #endif
7 #include "gaim.h"
8 #include "prpl.h"
10 #ifdef _WIN32
11 #include "win32dep.h"
12 #endif
14 #define INITIAL 8000
15 #define MAXTIME 1024000
17 static GHashTable *hash = NULL;
19 static guint tim = 0;
21 static gboolean do_signon(gpointer data) {
22 struct aim_user *u = data;
23 if (g_slist_index(aim_users, u) < 0)
24 return FALSE;
25 serv_login(u);
26 tim = 0;
27 return FALSE;
30 static void reconnect(struct gaim_connection *gc, void *m) {
31 if (!gc->wants_to_die) {
32 int del;
33 del = (int)g_hash_table_lookup(hash, gc->user);
34 if (!del)
35 del = INITIAL;
36 else
37 del = MAX(2 * del, MAXTIME);
38 tim = g_timeout_add(del, do_signon, gc->user);
39 g_hash_table_insert(hash, gc->user, (gpointer)del);
40 } else {
41 g_hash_table_remove(hash, gc->user);
46 * EXPORTED FUNCTIONS
49 struct gaim_plugin_description desc;
50 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() {
51 desc.api_version = PLUGIN_API_VERSION;
52 desc.name = g_strdup("Autoreconnect");
53 desc.version = g_strdup(VERSION);
54 desc.description = g_strdup(_("When you are kicked offline, this reconnects you."));
55 desc.authors = g_strdup("Eric Warmenhoven &lt;eric@warmenhoven.org>");
56 desc.url = g_strdup(WEBSITE);
57 return &desc;
60 G_MODULE_EXPORT char *name() {
61 return _("Auto Reconnect");
64 G_MODULE_EXPORT char *description() {
65 return _("When you are kicked offline, this reconnects you.");
68 G_MODULE_EXPORT char *gaim_plugin_init(GModule *handle) {
69 hash = g_hash_table_new(g_int_hash, g_int_equal);
71 gaim_signal_connect(handle, event_signoff, reconnect, NULL);
73 return NULL;
76 G_MODULE_EXPORT void gaim_plugin_remove() {
77 if (tim)
78 g_source_remove(tim);
79 g_hash_table_destroy(hash);
80 hash = NULL;
81 tim = 0;