Mercurial > pidgin
comparison src/gaim-remote.c @ 10086:6cd2b467e303
[gaim-migrate @ 11097]
Add a --session option to gaim-remote to allow manipulating multiple Gaim
instances
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 10 Oct 2004 16:47:56 +0000 |
parents | c892b6dbc341 |
children | 1a91e814e9d8 |
comparison
equal
deleted
inserted
replaced
10085:9c174a7f9afc | 10086:6cd2b467e303 |
---|---|
41 static struct option longopts[] = { | 41 static struct option longopts[] = { |
42 {"message", required_argument, NULL, 'm'}, | 42 {"message", required_argument, NULL, 'm'}, |
43 {"to", required_argument, NULL, 't'}, | 43 {"to", required_argument, NULL, 't'}, |
44 {"protocol",required_argument, NULL, 'p'}, | 44 {"protocol",required_argument, NULL, 'p'}, |
45 {"from", required_argument, NULL, 'f'}, | 45 {"from", required_argument, NULL, 'f'}, |
46 {"session", required_argument, NULL, 's'}, | |
46 {"quiet", no_argument, NULL, 'q'}, | 47 {"quiet", no_argument, NULL, 'q'}, |
47 {"help", no_argument, NULL, 'h'}, | 48 {"help", no_argument, NULL, 'h'}, |
48 {0,0,0,0} | 49 {0,0,0,0} |
49 }; | 50 }; |
50 | 51 |
51 struct remoteopts { | 52 struct remoteopts { |
52 char *command; | 53 char *command; |
53 char *uri; | 54 char *uri; |
54 gboolean help, quiet; | 55 gboolean help, quiet; |
55 char *message, *to, *from, *protocol; | 56 char *message, *to, *from, *protocol, *session; |
56 /*int protocol;*/ | 57 /*int protocol;*/ |
57 }; | 58 }; |
58 struct remoteopts opts; | 59 struct remoteopts opts; |
59 | 60 |
60 /* | 61 /* |
110 " OPTIONS:\n" | 111 " OPTIONS:\n" |
111 " -m, --message=MESG Message to send or show in conversation window\n" | 112 " -m, --message=MESG Message to send or show in conversation window\n" |
112 " -t, --to=SCREENNAME Select a target for command\n" | 113 " -t, --to=SCREENNAME Select a target for command\n" |
113 " -p, --protocol=PROTO Specify protocol to use\n" | 114 " -p, --protocol=PROTO Specify protocol to use\n" |
114 " -f, --from=SCREENNAME Specify screen name to use\n" | 115 " -f, --from=SCREENNAME Specify screen name to use\n" |
116 " -s, --session=SESSION Specify which Gaim session to use\n" | |
115 " -h, --help [command] Show help for command\n"), name); | 117 " -h, --help [command] Show help for command\n"), name); |
116 | 118 |
117 message(text, 1); | 119 message(text, 1); |
118 g_free(text); | 120 g_free(text); |
119 | 121 |
126 int i; | 128 int i; |
127 | 129 |
128 memset(&opts, 0, sizeof(opts)); | 130 memset(&opts, 0, sizeof(opts)); |
129 /*opts.protocol = -1;*/ | 131 /*opts.protocol = -1;*/ |
130 | 132 |
131 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) { | 133 while ((i=getopt_long(argc, argv, "m:t:p:f:s:qh", longopts, NULL)) != -1) { |
132 switch (i) { | 134 switch (i) { |
133 case 'm': | 135 case 'm': |
134 opts.message = optarg; | 136 opts.message = optarg; |
135 break; | 137 break; |
136 case 't': | 138 case 't': |
140 opts.protocol = optarg; | 142 opts.protocol = optarg; |
141 break; | 143 break; |
142 case 'f': | 144 case 'f': |
143 opts.from = optarg; | 145 opts.from = optarg; |
144 break; | 146 break; |
147 case 's': | |
148 opts.session = optarg; | |
149 break; | |
145 case 'q': | 150 case 'q': |
146 opts.quiet = TRUE; | 151 opts.quiet = TRUE; |
147 break; | 152 break; |
148 case 'h': | 153 case 'h': |
149 opts.help = TRUE; | 154 opts.help = TRUE; |
150 break; | 155 break; |
151 } | 156 } |
152 } | 157 } |
153 | 158 |
154 /* We must have non getopt'ed argument-- the command */ | 159 /* We must have non getopt'ed argument-- the command */ |
155 if (optind < argc) | 160 if (optind < argc) |
156 opts.command = g_strdup(argv[optind++]); | 161 opts.command = g_strdup(argv[optind++]); |
157 else | 162 else |
158 return 1; | 163 return 1; |
170 } else if (optind == argc) | 175 } else if (optind == argc) |
171 return 0; | 176 return 0; |
172 else | 177 else |
173 return 1; | 178 return 1; |
174 | 179 |
175 return 0; | 180 return 0; |
181 } | |
182 | |
183 static int | |
184 open_session() { | |
185 int fd = 0, session = 0; | |
186 char *msg; | |
187 | |
188 if (opts.session != NULL) | |
189 session = atoi(opts.session); | |
190 | |
191 fd = gaim_remote_session_connect(session); | |
192 if (fd < 0) { | |
193 msg = g_strdup_printf(_("Gaim not running (on session %d)\nIs the \"Remote Control\" plugin loaded?\n"), session); | |
194 message(msg, 2); | |
195 g_free(msg); | |
196 return -1; | |
197 } | |
198 | |
199 return fd; | |
176 } | 200 } |
177 | 201 |
178 static int | 202 static int |
179 send_generic_command(guchar type, guchar subtype) { | 203 send_generic_command(guchar type, guchar subtype) { |
180 int fd = 0; | 204 int fd = 0; |
181 GaimRemotePacket *p = NULL; | 205 GaimRemotePacket *p = NULL; |
182 | 206 |
183 fd = gaim_remote_session_connect(0); | 207 fd = open_session(); |
184 if (fd < 0) { | 208 if (fd < 0) { |
185 message(_("Gaim not running (on session 0)\nIs the \"Remote Control\" plugin loaded?\n"), 2); | |
186 return 1; | 209 return 1; |
187 } | 210 } |
188 p = gaim_remote_packet_new(type, subtype); | 211 p = gaim_remote_packet_new(type, subtype); |
189 gaim_remote_session_send_packet(fd, p); | 212 gaim_remote_session_send_packet(fd, p); |
190 close(fd); | 213 close(fd); |
196 static int | 219 static int |
197 send_command_uri() { | 220 send_command_uri() { |
198 int fd = 0; | 221 int fd = 0; |
199 GaimRemotePacket *p = NULL; | 222 GaimRemotePacket *p = NULL; |
200 | 223 |
201 fd = gaim_remote_session_connect(0); | 224 fd = open_session(); |
202 if (fd < 0) { | 225 if (fd < 0) { |
203 message(_("Gaim not running (on session 0)\nIs the \"Remote Control\" plugin loaded?\n"), 2); | |
204 return 1; | 226 return 1; |
205 } | 227 } |
206 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI); | 228 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI); |
207 gaim_remote_packet_append_string(p, opts.uri); | 229 gaim_remote_packet_append_string(p, opts.uri); |
208 gaim_remote_session_send_packet(fd, p); | 230 gaim_remote_session_send_packet(fd, p); |
216 send_command_send() { | 238 send_command_send() { |
217 int fd = 0; | 239 int fd = 0; |
218 GaimRemotePacket *p = NULL; | 240 GaimRemotePacket *p = NULL; |
219 char temp[10003]; /* TODO: Future implementation should send packets instead */ | 241 char temp[10003]; /* TODO: Future implementation should send packets instead */ |
220 | 242 |
221 fd = gaim_remote_session_connect(0); | 243 fd = open_session(); |
222 if (fd < 0) { | 244 if (fd < 0) { |
223 message(_("Gaim not running (on session 0)\nIs the \"Remote Control\" plugin loaded?\n"), 2); | |
224 return 1; | 245 return 1; |
225 } | 246 } |
226 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_SEND); | 247 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_SEND); |
227 | 248 |
228 /* | 249 /* |