Mercurial > pidgin
annotate plugins/filectl.c @ 7011:4375bf2d9020
[gaim-migrate @ 7574]
The user-visible changes? Gaim now shows peep's away messages in their
tooltip for AIM over oscar.
Things to do:
-Make sure this doesn't screw up with huge buddy lists
-Replace %n with your screen name, etc. in the tooltip
-Leave in b, i, u tags in the tooltip
-Fix the 2 8 byte memleaks in locate.c
Client authors that aren't me will want to read the following pretty
closely...
I made some internal libfaim changes. I desire to make libfaim cleaner.
I don't know if this really helps or not. Here's what I've done:
Changed all the SNAC-sending functions in info.c to NOT take a conn
argument. The connection is looked up from the session. I'm trying
to make oscar.c less-aware of connections.
Added aim_locate_finduserinfo() - Use for getting the aim_userinfo_t for the
given screenname.
Added aim_locate_getinfoshort() - Use this to request that the servers send
you profile info, away message, caps, or a combination of the above. It's
like aim_locate_getinfo() but less rate limited.
Renamed aim_bos_reqlocaterights() to aim_locate_reqrights()
Renamed aim_getinfo() to aim_locate_getinfo()
Renamed aim_setdirectoryinfo() to aim_locate_setdirinfo()
Renamed aim_0002_000b() to aim_locate_000b()
Renamed aim_setuserinterests() to aim_locate_setinterests()
Removed aim_userinfo_sn()
Removed aim_userinfo_flags()
Removed aim_userinfo_idle()
Removed aim_userinfo_warnlevel()
Removed aim_userinfo_createtime()
Removed aim_userinfo_membersince()
Removed aim_userinfo_onlinesince()
Removed aim_userinfo_sessionlen()
Removed aim_userinfo_hascap()
Renamed info.c to locate.c
Made locate.c keep a static, linked list of nodes of sn, away message,
available message, user info. This list is maintained by libfaim
automatically. Now clients don't have to keep track of all this stuff
themselves, and users won't have to wait for away message/info retrieval
if the person is in your buddy list. libfaim uses the iChat way of
retrieving stuff, which is not nearly as rate limited as the old way.
I actually have a feeling WinAIM uses the same SNAC now (although I
didn't check), but I like pluggin iChat because it's innovative.
Moved sess->emailinfo to a static variable inside email.c.
Removed evilhack from oscar.c
I think that's about everything...
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 29 Sep 2003 12:30:03 +0000 |
| parents | 083d1e4a9c78 |
| children | 251e2e434a86 |
| rev | line source |
|---|---|
| 3198 | 1 #include "config.h" |
| 106 | 2 #include "gaim.h" |
| 3 | |
| 4 #include <gtk/gtk.h> | |
| 5 #include <stdlib.h> | |
| 6 #include <unistd.h> | |
| 7 #include <sys/types.h> | |
| 8 #include <sys/stat.h> | |
| 9 #include <string.h> | |
| 10 #include <ctype.h> | |
| 11 | |
| 5255 | 12 #define FILECTL_PLUGIN_ID "core-filectl" |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
13 static int check; |
|
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
14 static time_t mtime; |
| 106 | 15 |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
16 static void init_file(); |
|
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
17 static void check_file(); |
| 106 | 18 |
| 19 /* parse char * as if were word array */ | |
| 20 char *getarg(char *, int, int); | |
| 21 | |
| 22 /* go through file and run any commands */ | |
| 23 void run_commands() { | |
| 24 struct stat finfo; | |
| 25 char filename[256]; | |
| 26 char buffer[1024]; | |
| 27 char *command, *arg1, *arg2; | |
| 28 FILE *file; | |
| 29 | |
| 30 sprintf(filename, "%s/.gaim/control", getenv("HOME")); | |
| 31 | |
| 32 file = fopen(filename, "r+"); | |
| 33 while (fgets(buffer, sizeof buffer, file)) { | |
| 34 if (buffer[strlen(buffer) - 1] == '\n') | |
| 35 buffer[strlen(buffer) - 1] = 0; | |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
36 gaim_debug(GAIM_DEBUG_MISC, "filectl", "read: %s\n", buffer); |
| 106 | 37 command = getarg(buffer, 0, 0); |
|
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
38 if (!strncasecmp(command, "signon", 6)) { |
| 4491 | 39 struct gaim_account *account = NULL; |
| 40 GSList *accts = gaim_accounts; | |
|
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
41 arg1 = getarg(buffer, 1, 1); |
|
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
42 if (arg1) { |
| 4491 | 43 while (accts) { |
| 44 struct gaim_account *a = accts->data; | |
| 45 if (!strcmp(a->username, arg1)) { | |
| 46 account = a; | |
|
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
47 break; |
|
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
48 } |
| 4491 | 49 accts = accts->next; |
|
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
50 } |
|
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
51 free(arg1); |
| 106 | 52 } |
| 4491 | 53 if (account) /* username found */ |
| 6036 | 54 gaim_account_connect(account); |
| 106 | 55 } else if (!strncasecmp(command, "signoff", 7)) { |
|
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
576
diff
changeset
|
56 struct gaim_connection *gc = NULL; |
|
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
57 GSList *c = connections; |
|
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
576
diff
changeset
|
58 arg1 = getarg(buffer, 1, 1); |
|
2766
0e082a9e4c32
[gaim-migrate @ 2779]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2765
diff
changeset
|
59 while (arg1 && c) { |
|
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
60 gc = c->data; |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
61 if (!strcmp(gc->username, arg1)) { |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
62 break; |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
63 } |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
64 gc = NULL; |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
65 c = c->next; |
|
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
66 } |
|
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
67 if (gc) |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
68 signoff(gc); |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
69 else if (!arg1) |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
70 signoff_all(NULL, NULL); |
|
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
71 free(arg1); |
| 106 | 72 } else if (!strncasecmp(command, "send", 4)) { |
|
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
73 GaimConversation *c; |
| 106 | 74 arg1 = getarg(buffer, 1, 0); |
| 75 arg2 = getarg(buffer, 2, 1); | |
| 76 c = find_conversation(arg1); | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
77 if (!c) c = gaim_conversation_new(GAIM_CONV_IM, arg1); |
|
2906
538c58b43eff
[gaim-migrate @ 2919]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2766
diff
changeset
|
78 write_to_conv(c, arg2, WFLAG_SEND, NULL, time(NULL), -1); |
| 6982 | 79 serv_send_im(c->gc, arg1, arg2, 0); |
| 106 | 80 free(arg1); |
| 81 free(arg2); | |
| 82 } else if (!strncasecmp(command, "away", 4)) { | |
| 83 struct away_message a; | |
| 84 arg1 = getarg(buffer, 1, 1); | |
| 85 snprintf(a.message, 2048, "%s", arg1); | |
| 86 a.name[0] = 0; | |
| 87 do_away_message(NULL, &a); | |
| 88 free(arg1); | |
| 3198 | 89 } else if (!strncasecmp(command, "hide", 4)) { |
| 90 hide_buddy_list(); | |
| 91 } else if (!strncasecmp(command, "unhide", 6)) { | |
| 92 unhide_buddy_list(); | |
| 106 | 93 } else if (!strncasecmp(command, "back", 4)) { |
| 94 do_im_back(); | |
| 95 } else if (!strncasecmp(command, "quit", 4)) { | |
|
6179
16e384bb7fbf
[gaim-migrate @ 6664]
Christian Hammond <chipx86@chipx86.com>
parents:
6063
diff
changeset
|
96 gaim_core_quit(); |
| 106 | 97 } |
| 98 free(command); | |
| 99 } | |
| 100 | |
| 101 fclose(file); | |
| 102 | |
| 103 if (stat (filename, &finfo) != 0) | |
| 104 return; | |
| 105 mtime = finfo.st_mtime; | |
| 106 } | |
| 107 | |
| 108 /* check to see if the size of the file is > 0. if so, run commands */ | |
| 109 void init_file() { | |
| 110 /* most of this was taken from Bash v2.04 by the FSF */ | |
| 111 struct stat finfo; | |
| 112 char file[256]; | |
| 113 | |
| 114 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
| 115 | |
| 116 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
| 117 run_commands(); | |
| 118 } | |
| 119 | |
| 120 /* check to see if we need to run commands from the file */ | |
| 121 void check_file() { | |
| 122 /* most of this was taken from Bash v2.04 by the FSF */ | |
| 123 struct stat finfo; | |
| 124 char file[256]; | |
| 125 | |
| 126 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
| 127 | |
| 128 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
129 if (mtime != finfo.st_mtime) { |
|
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
130 gaim_debug(GAIM_DEBUG_INFO, "filectl", |
|
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
131 "control changed, checking\n"); |
| 106 | 132 run_commands(); |
|
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
133 } |
| 106 | 134 } |
| 135 | |
| 136 char *getarg(char *line, int which, int remain) { | |
| 137 char *arr; | |
| 138 char *val; | |
| 139 int count = -1; | |
| 140 int i; | |
| 141 int state = 0; | |
| 142 | |
| 143 for (i = 0; i < strlen(line) && count < which; i++) { | |
| 144 switch (state) { | |
| 145 case 0: /* in whitespace, expecting word */ | |
| 146 if (isalnum(line[i])) { | |
| 147 count++; | |
| 148 state = 1; | |
| 149 } | |
| 150 break; | |
| 151 case 1: /* inside word, waiting for whitespace */ | |
| 152 if (isspace(line[i])) { | |
| 153 state = 0; | |
| 154 } | |
| 155 break; | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 arr = strdup(&line[i - 1]); | |
| 160 if (remain) | |
| 161 return arr; | |
| 162 | |
| 163 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); | |
| 164 arr[i] = 0; | |
| 165 val = strdup(arr); | |
| 166 arr[i] = ' '; | |
| 167 free(arr); | |
| 168 return val; | |
| 169 } | |
| 5255 | 170 /* |
| 171 * EXPORTED FUNCTIONS | |
| 172 */ | |
| 173 | |
| 174 static gboolean | |
| 175 plugin_load(GaimPlugin *plugin) | |
| 176 { | |
| 177 init_file(); | |
| 178 check = g_timeout_add(5000, check_file, NULL); | |
| 179 | |
| 180 return TRUE; | |
| 181 } | |
| 182 | |
| 183 static gboolean | |
| 184 plugin_unload(GaimPlugin *plugin) | |
| 185 { | |
| 186 g_source_remove(check); | |
| 187 | |
| 188 return TRUE; | |
| 189 } | |
| 190 | |
| 191 static GaimPluginInfo info = | |
| 192 { | |
| 193 2, /**< api_version */ | |
| 194 GAIM_PLUGIN_STANDARD, /**< type */ | |
| 195 NULL, /**< ui_requirement */ | |
| 196 0, /**< flags */ | |
| 197 NULL, /**< dependencies */ | |
| 198 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 199 | |
| 200 FILECTL_PLUGIN_ID, /**< id */ | |
| 201 N_("Gaim File Control"), /**< name */ | |
| 202 VERSION, /**< version */ | |
| 203 /** summary */ | |
| 204 N_("Allows you to control Gaim by entering commands in a file."), | |
| 205 /** description */ | |
| 206 N_("Allows you to control Gaim by entering commands in a file."), | |
| 207 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */ | |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6179
diff
changeset
|
208 GAIM_WEBSITE, /**< homepage */ |
| 5255 | 209 |
| 210 plugin_load, /**< load */ | |
| 211 plugin_unload, /**< unload */ | |
| 212 NULL, /**< destroy */ | |
| 213 | |
| 214 NULL, /**< ui_info */ | |
| 215 NULL /**< extra_info */ | |
| 216 }; | |
| 217 | |
| 218 static void | |
|
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
219 init_plugin(GaimPlugin *plugin) |
| 5255 | 220 { |
| 221 } | |
| 222 | |
| 6063 | 223 GAIM_INIT_PLUGIN(filectl, init_plugin, info) |
