Mercurial > pidgin.yaz
comparison plugins/filectl.c @ 7658:251e2e434a86
[gaim-migrate @ 8302]
Alex Bennee (trent) made filectl.c compile
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 29 Nov 2003 04:22:35 +0000 |
parents | 083d1e4a9c78 |
children | e4952ba22fc1 |
comparison
equal
deleted
inserted
replaced
7657:2e32c38760b2 | 7658:251e2e434a86 |
---|---|
1 #include "config.h" | 1 /* |
2 #include "gaim.h" | 2 ** Send commands to gaim via ~/.gaim/control |
3 | 3 ** |
4 ** By Eric Warmenhoven <eric@warmenhoven.org> | |
5 ** compile fixes/mini hacks Alex Bennee <alex@bennee.com> | |
6 */ | |
7 | |
8 /* system includes */ | |
4 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
5 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <stdio.h> | |
6 #include <unistd.h> | 12 #include <unistd.h> |
7 #include <sys/types.h> | 13 #include <sys/types.h> |
8 #include <sys/stat.h> | 14 #include <sys/stat.h> |
9 #include <string.h> | 15 #include <string.h> |
10 #include <ctype.h> | 16 #include <ctype.h> |
11 | 17 |
18 /* gaim includes */ | |
19 #include "internal.h" | |
20 | |
21 #include "config.h" | |
22 #include "gaim.h" | |
23 #include "debug.h" | |
24 #include "account.h" | |
25 #include "conversation.h" | |
26 | |
27 | |
28 | |
12 #define FILECTL_PLUGIN_ID "core-filectl" | 29 #define FILECTL_PLUGIN_ID "core-filectl" |
13 static int check; | 30 static int check; |
14 static time_t mtime; | 31 static time_t mtime; |
15 | 32 |
16 static void init_file(); | 33 static void init_file(); |
17 static void check_file(); | 34 static gboolean check_file(); |
18 | 35 |
19 /* parse char * as if were word array */ | 36 /* parse char * as if were word array */ |
20 char *getarg(char *, int, int); | 37 char *getarg(char *, int, int); |
21 | 38 |
22 /* go through file and run any commands */ | 39 /* go through file and run any commands */ |
34 if (buffer[strlen(buffer) - 1] == '\n') | 51 if (buffer[strlen(buffer) - 1] == '\n') |
35 buffer[strlen(buffer) - 1] = 0; | 52 buffer[strlen(buffer) - 1] = 0; |
36 gaim_debug(GAIM_DEBUG_MISC, "filectl", "read: %s\n", buffer); | 53 gaim_debug(GAIM_DEBUG_MISC, "filectl", "read: %s\n", buffer); |
37 command = getarg(buffer, 0, 0); | 54 command = getarg(buffer, 0, 0); |
38 if (!strncasecmp(command, "signon", 6)) { | 55 if (!strncasecmp(command, "signon", 6)) { |
39 struct gaim_account *account = NULL; | 56 GaimAccount *account = NULL; |
40 GSList *accts = gaim_accounts; | 57 GList *accts = gaim_accounts_get_all(); |
41 arg1 = getarg(buffer, 1, 1); | 58 arg1 = getarg(buffer, 1, 1); |
42 if (arg1) { | 59 if (arg1) { |
43 while (accts) { | 60 while (accts) { |
44 struct gaim_account *a = accts->data; | 61 GaimAccount *a = accts->data; |
45 if (!strcmp(a->username, arg1)) { | 62 if (!strcmp(a->username, arg1)) { |
46 account = a; | 63 account = a; |
47 break; | 64 break; |
48 } | 65 } |
49 accts = accts->next; | 66 accts = accts->next; |
51 free(arg1); | 68 free(arg1); |
52 } | 69 } |
53 if (account) /* username found */ | 70 if (account) /* username found */ |
54 gaim_account_connect(account); | 71 gaim_account_connect(account); |
55 } else if (!strncasecmp(command, "signoff", 7)) { | 72 } else if (!strncasecmp(command, "signoff", 7)) { |
56 struct gaim_connection *gc = NULL; | 73 GaimConnection *gc = NULL; |
57 GSList *c = connections; | 74 GList *c = gaim_connections_get_all(); |
58 arg1 = getarg(buffer, 1, 1); | 75 arg1 = getarg(buffer, 1, 1); |
59 while (arg1 && c) { | 76 while (arg1 && c) { |
60 gc = c->data; | 77 gc = c->data; |
61 if (!strcmp(gc->username, arg1)) { | 78 if (!strcmp(gc->account->username, arg1)) { |
62 break; | 79 break; |
63 } | 80 } |
64 gc = NULL; | 81 gc = NULL; |
65 c = c->next; | 82 c = c->next; |
66 } | 83 } |
67 if (gc) | 84 if (gc) |
68 signoff(gc); | 85 gaim_connection_disconnect(gc); |
69 else if (!arg1) | 86 else if (!arg1) |
70 signoff_all(NULL, NULL); | 87 gaim_connections_disconnect_all(); |
71 free(arg1); | 88 free(arg1); |
72 } else if (!strncasecmp(command, "send", 4)) { | 89 } else if (!strncasecmp(command, "send", 4)) { |
73 GaimConversation *c; | 90 GaimConversation *c; |
74 arg1 = getarg(buffer, 1, 0); | 91 arg1 = getarg(buffer, 1, 0); |
75 arg2 = getarg(buffer, 2, 1); | 92 arg2 = getarg(buffer, 2, 1); |
76 c = find_conversation(arg1); | 93 c = gaim_find_conversation(arg1); |
77 if (!c) c = gaim_conversation_new(GAIM_CONV_IM, arg1); | 94 if (c) |
78 write_to_conv(c, arg2, WFLAG_SEND, NULL, time(NULL), -1); | 95 { |
79 serv_send_im(c->gc, arg1, arg2, 0); | 96 /* disable for now |
97 gaim_conversation_write(c, arg2, WFLAG_SEND, NULL, time(NULL), -1); | |
98 serv_send_im(c->gc, arg1, arg2, 0); | |
99 */ | |
100 } | |
80 free(arg1); | 101 free(arg1); |
81 free(arg2); | 102 free(arg2); |
82 } else if (!strncasecmp(command, "away", 4)) { | 103 } else if (!strncasecmp(command, "away", 4)) { |
83 struct away_message a; | |
84 arg1 = getarg(buffer, 1, 1); | 104 arg1 = getarg(buffer, 1, 1); |
85 snprintf(a.message, 2048, "%s", arg1); | 105 serv_set_away_all(arg1); |
86 a.name[0] = 0; | |
87 do_away_message(NULL, &a); | |
88 free(arg1); | 106 free(arg1); |
89 } else if (!strncasecmp(command, "hide", 4)) { | 107 } else if (!strncasecmp(command, "hide", 4)) { |
90 hide_buddy_list(); | 108 //hide_buddy_list(); |
91 } else if (!strncasecmp(command, "unhide", 6)) { | 109 } else if (!strncasecmp(command, "unhide", 6)) { |
92 unhide_buddy_list(); | 110 //unhide_buddy_list(); |
93 } else if (!strncasecmp(command, "back", 4)) { | 111 } else if (!strncasecmp(command, "back", 4)) { |
94 do_im_back(); | 112 //do_im_back(); |
95 } else if (!strncasecmp(command, "quit", 4)) { | 113 } else if (!strncasecmp(command, "quit", 4)) { |
96 gaim_core_quit(); | 114 //gaim_core_quit(); |
97 } | 115 } |
98 free(command); | 116 free(command); |
99 } | 117 } |
100 | 118 |
101 fclose(file); | 119 fclose(file); |
116 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | 134 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) |
117 run_commands(); | 135 run_commands(); |
118 } | 136 } |
119 | 137 |
120 /* check to see if we need to run commands from the file */ | 138 /* check to see if we need to run commands from the file */ |
121 void check_file() { | 139 gboolean check_file() { |
122 /* most of this was taken from Bash v2.04 by the FSF */ | 140 /* most of this was taken from Bash v2.04 by the FSF */ |
123 struct stat finfo; | 141 struct stat finfo; |
124 char file[256]; | 142 char file[256]; |
125 | 143 |
126 sprintf(file, "%s/.gaim/control", getenv("HOME")); | 144 sprintf(file, "%s/.gaim/control", getenv("HOME")); |
127 | 145 |
128 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | 146 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) |
147 { | |
129 if (mtime != finfo.st_mtime) { | 148 if (mtime != finfo.st_mtime) { |
130 gaim_debug(GAIM_DEBUG_INFO, "filectl", | 149 gaim_debug(GAIM_DEBUG_INFO, "filectl", |
131 "control changed, checking\n"); | 150 "control changed, checking\n"); |
132 run_commands(); | 151 run_commands(); |
133 } | 152 } |
153 } | |
154 | |
155 return TRUE; | |
134 } | 156 } |
135 | 157 |
136 char *getarg(char *line, int which, int remain) { | 158 char *getarg(char *line, int which, int remain) { |
137 char *arr; | 159 char *arr; |
138 char *val; | 160 char *val; |
173 | 195 |
174 static gboolean | 196 static gboolean |
175 plugin_load(GaimPlugin *plugin) | 197 plugin_load(GaimPlugin *plugin) |
176 { | 198 { |
177 init_file(); | 199 init_file(); |
178 check = g_timeout_add(5000, check_file, NULL); | 200 check = g_timeout_add(5000, (GSourceFunc) check_file, NULL); |
179 | 201 |
180 return TRUE; | 202 return TRUE; |
181 } | 203 } |
182 | 204 |
183 static gboolean | 205 static gboolean |