comparison src/core.c @ 3478:3da42b64304e

[gaim-migrate @ 3532] This isn't complete--but it's cool. gaim-remote is now built and installed. Eventually it will do lots of cool stuff--right now it just handles aim:// URI's. Try it out... when connected to OSCAR run: gaim-remote uri "aim://goim?screenname=seanegn&message=Good+job+Sean" Also, I made it so that if you're already running a Gaim session, and start a new one, it won't auto-login and disconnect all your accounts from the first instance. Useful if you accidentally hit the wrong button or something. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 30 Aug 2002 16:09:22 +0000
parents 1e12a24b7f27
children 6c32036050cf
comparison
equal deleted inserted replaced
3477:db5dd21aa345 3478:3da42b64304e
36 #include <getopt.h> 36 #include <getopt.h>
37 #include <stdarg.h> 37 #include <stdarg.h>
38 #include <string.h> 38 #include <string.h>
39 39
40 #include "gaim.h" 40 #include "gaim.h"
41 #include "gaim-socket.h"
41 42
42 static gint UI_fd = -1; 43 static gint UI_fd = -1;
44 int gaim_session = 0;
43 GSList *uis = NULL; 45 GSList *uis = NULL;
44 46
45 static guchar *UI_build(guint32 *len, guchar type, guchar subtype, va_list args) 47 static guchar *UI_build(guint32 *len, guchar type, guchar subtype, va_list args)
46 { 48 {
47 guchar *buffer; 49 guchar *buffer;
130 g_free(data); 132 g_free(data);
131 } 133 }
132 134
133 static void meta_handler(struct UI *ui, guchar subtype, guchar *data) 135 static void meta_handler(struct UI *ui, guchar subtype, guchar *data)
134 { 136 {
137 struct gaim_cui_packet *p;
135 switch (subtype) { 138 switch (subtype) {
136 case CUI_META_LIST: 139 case CUI_META_LIST:
137 break; 140 break;
138 case CUI_META_QUIT: 141 case CUI_META_QUIT:
139 while (uis) { 142 while (uis) {
148 case CUI_META_DETACH: 151 case CUI_META_DETACH:
149 uis = g_slist_remove(uis, ui); 152 uis = g_slist_remove(uis, ui);
150 g_io_channel_close(ui->channel); 153 g_io_channel_close(ui->channel);
151 g_source_remove(ui->inpa); 154 g_source_remove(ui->inpa);
152 g_free(ui); 155 g_free(ui);
156 break;
157 case CUI_META_PING:
158 p = cui_packet_new(CUI_TYPE_META, CUI_META_ACK);
159 cui_send_packet(g_io_channel_unix_get_fd(ui->channel), p);
160 cui_packet_free(p);
153 break; 161 break;
154 default: 162 default:
155 debug_printf("unhandled meta subtype %d\n", subtype); 163 debug_printf("unhandled meta subtype %d\n", subtype);
156 break; 164 break;
157 } 165 }
287 } 295 }
288 296
289 return total; 297 return total;
290 } 298 }
291 299
300 static void remote_handler(struct UI *ui, guchar subtype, guchar *data, int len)
301 {
302 const char *resp;
303 char *send;
304 switch (subtype) {
305 case CUI_REMOTE_CONNECTIONS:
306 break;
307 case CUI_REMOTE_URI:
308 send = g_malloc(len + 1);
309 memcpy(send, data, len);
310 send[len] = 0;
311 resp = handle_uri(send);
312 g_free(send);
313 /* report error */
314 break;
315 default:
316 debug_printf("Unhandled remote subtype %d\n", subtype);
317 break;
318 }
319 }
320
292 static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) 321 static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data)
293 { 322 {
294 struct UI *ui = data; 323 struct UI *ui = data;
295 324
296 guchar type; 325 guchar type;
363 break; 392 break;
364 /* 393 /*
365 case CUI_TYPE_CHAT: 394 case CUI_TYPE_CHAT:
366 chat_handler(ui, subtype, in); 395 chat_handler(ui, subtype, in);
367 break; 396 break;
368 */ 397 */
369 default: 398 case CUI_TYPE_REMOTE:
399 remote_handler(ui, subtype, in, len);
400 break;
401 default:
370 debug_printf("unhandled type %d\n", type); 402 debug_printf("unhandled type %d\n", type);
371 break; 403 break;
372 } 404 }
373 405
374 if (in) 406 if (in)
400 432
401 static gint open_socket() 433 static gint open_socket()
402 { 434 {
403 struct sockaddr_un saddr; 435 struct sockaddr_un saddr;
404 gint fd; 436 gint fd;
405 437
438 while (gaim_session_exists(gaim_session))
439 gaim_session++;
440
441 debug_printf("session: %d\n", gaim_session);
442
406 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { 443 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) {
407 mode_t m = umask(0177); 444 mode_t m = umask(0177);
408 saddr.sun_family = AF_UNIX; 445 saddr.sun_family = AF_UNIX;
409 g_snprintf(saddr.sun_path, 108, "%s/gaim_%s.%d", 446 g_snprintf(saddr.sun_path, 108, "%s/gaim_%s.%d",
410 g_get_tmp_dir(), g_get_user_name(), getpid()); 447 g_get_tmp_dir(), g_get_user_name(), gaim_session);
411 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) 448 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1)
412 listen(fd, 100); 449 listen(fd, 100);
413 else { 450 else {
414 g_log(NULL, G_LOG_LEVEL_CRITICAL, 451 g_log(NULL, G_LOG_LEVEL_CRITICAL,
415 "Failed to assign %s to a socket (Error: %s)", 452 "Failed to assign %s to a socket (Error: %s)",
416 saddr.sun_path, strerror(errno)); 453 saddr.sun_path, strerror(errno));
417 return -1; 454 return -1;
418 } 455 }
419 umask(m); 456 umask(m);
420 } else 457 } else
421 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); 458 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno));
448 485
449 void core_quit() 486 void core_quit()
450 { 487 {
451 char buf[1024]; 488 char buf[1024];
452 close(UI_fd); 489 close(UI_fd);
453 sprintf(buf, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), getpid()); 490 sprintf(buf, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session);
454 unlink(buf); 491 unlink(buf);
455 debug_printf("Removed core\n"); 492 debug_printf("Removed core\n");
456 } 493 }