Mercurial > pidgin
annotate plugins/gaim-remote/remote.c @ 10401:3e4ecbdf8d0a
[gaim-migrate @ 11638]
Stuff compiles again, if that's what you wanted stuff to do. It works a bit
too. I fixed one crash in oscar, only to reveal another that I didnn't fix
(tooltips).
Most protocols still need updating to actually log in in the specified state,
TCL needs some love for gaim_account_connect, perl probably does too but that
needs more love anyway. The reconnect plugin could be more intelligent too, as
could gaim-remote.
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Tue, 21 Dec 2004 01:48:30 +0000 |
| parents | b4b9dabdd7c7 |
| children | f7b32dd67bdf |
| rev | line source |
|---|---|
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6179
diff
changeset
|
1 /** |
| 5859 | 2 * Remote control plugin for Gaim |
| 3 * | |
| 4 * Copyright (C) 2003 Christian Hammond. | |
| 5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 6 * | |
| 7 * This program is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU General Public License as | |
| 9 * published by the Free Software Foundation; either version 2 of the | |
| 10 * License, or (at your option) any later version. | |
| 11 * | |
| 12 * This program is distributed in the hope that it will be useful, but | |
| 13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU General Public License | |
| 18 * along with this program; if not, write to the Free Software | |
| 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
| 20 * 02111-1307, USA. | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
21 * |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
22 * @todo Make this a core plugin! |
| 5859 | 23 */ |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
24 #include "internal.h" |
| 9791 | 25 #include "gtkgaim.h" |
| 5859 | 26 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
27 #ifndef _WIN32 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
28 # include <sys/un.h> |
| 5859 | 29 #endif |
| 30 | |
| 31 #include <signal.h> | |
| 32 #include <getopt.h> | |
| 33 | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
34 #include "conversation.h" |
|
6179
16e384bb7fbf
[gaim-migrate @ 6664]
Christian Hammond <chipx86@chipx86.com>
parents:
6177
diff
changeset
|
35 #include "core.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
36 #include "debug.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
37 #include "prpl.h" |
| 8704 | 38 #include "notify.h" |
| 10005 | 39 #include "util.h" |
| 9943 | 40 #include "version.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
41 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
42 /* XXX */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
43 #include "gtkconv.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
44 #include "gtkplugin.h" |
| 5859 | 45 #include "gaim.h" |
| 9608 | 46 #include "prefs.h" |
| 5859 | 47 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
48 #include <gaim-remote/remote.h> |
| 5859 | 49 |
|
5873
a18e88c4dace
[gaim-migrate @ 6305]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
50 #define REMOTE_PLUGIN_ID "gtk-remote" |
| 5859 | 51 |
| 52 struct UI { | |
| 53 GIOChannel *channel; | |
| 54 guint inpa; | |
| 55 }; | |
| 56 | |
| 57 #ifndef _WIN32 | |
| 58 static gint UI_fd = -1; | |
| 6107 | 59 static guint watcher = 0; |
| 5859 | 60 #endif |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
61 static int gaim_session = 0; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
62 static GSList *uis = NULL; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
63 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
64 /* AIM URI's ARE FUN :-D */ |
|
5884
d188b000e892
[gaim-migrate @ 6316]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
65 static const char * |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
66 gaim_remote_handle_uri(const char *uri) |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
67 { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
68 const char *username; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
69 GString *str; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
70 GList *conn; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
71 GaimConnection *gc = NULL; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
72 GaimAccount *account; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
73 |
| 10003 | 74 gaim_debug_info("gaim_remote_handle_uri", "Handling URI: %s\n", uri); |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
75 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
76 /* Well, we'd better check to make sure we have at least one |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
77 AIM account connected. */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
78 for (conn = gaim_connections_get_all(); conn != NULL; conn = conn->next) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
79 gc = conn->data; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
80 account = gaim_connection_get_account(gc); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
81 username = gaim_account_get_username(account); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
82 |
| 9460 | 83 if (strcmp(gaim_account_get_protocol_id(account), "prpl-oscar") == 0 && |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
84 username != NULL && isalpha(*username)) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
85 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
86 break; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
87 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
88 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
89 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
90 if (gc == NULL) |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
91 return _("Not connected to AIM"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
92 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
93 /* aim:goim?screenname=screenname&message=message */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
94 if (!g_ascii_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
95 char *who, *what; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
96 GaimConversation *c; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
97 uri = uri + strlen("aim:goim?"); |
| 10395 | 98 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
99 if (!(who = strstr(uri, "screenname="))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
100 return _("No screenname given."); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
101 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
102 /* spaces are encoded as +'s */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
103 who = who + strlen("screenname="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
104 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
105 while (*who && (*who != '&')) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
106 g_string_append_c(str, *who == '+' ? ' ' : *who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
107 who++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
108 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
109 who = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
110 g_string_free(str, TRUE); |
| 10395 | 111 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
112 what = strstr(uri, "message="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
113 if (what) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
114 what = what + strlen("message="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
115 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
116 while (*what && (*what != '&' || !g_ascii_strncasecmp(what, "&", 5))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
117 g_string_append_c(str, *what == '+' ? ' ' : *what); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
118 what++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
119 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
120 what = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
121 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
122 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
123 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
124 c = gaim_conversation_new(GAIM_CONV_IM, gc->account, who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
125 g_free(who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
126 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
127 if (what) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
128 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(c); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
129 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
130 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
131 g_free(what); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
132 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
133 } else if (!g_ascii_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
134 char *who, *group; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
135 uri = uri + strlen("aim:addbuddy?"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
136 /* spaces are encoded as +'s */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
137 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
138 if (!(who = strstr(uri, "screenname="))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
139 return _("No screenname given."); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
140 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
141 who = who + strlen("screenname="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
142 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
143 while (*who && (*who != '&')) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
144 g_string_append_c(str, *who == '+' ? ' ' : *who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
145 who++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
146 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
147 who = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
148 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
149 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
150 group = strstr(uri, "group="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
151 if (group) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
152 group = group + strlen("group="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
153 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
154 while (*group && (*group != '&' || !g_ascii_strncasecmp(group, "&", 5))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
155 g_string_append_c(str, *group == '+' ? ' ' : *group); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
156 group++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
157 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
158 group = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
159 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
160 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
161 |
| 10003 | 162 gaim_debug_misc("gaim_remote_handle_uri", "who: %s\n", who); |
|
7100
abdc55ffadba
[gaim-migrate @ 7665]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
163 gaim_blist_request_add_buddy(gc->account, who, group, NULL); |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
164 g_free(who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
165 if (group) |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
166 g_free(group); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
167 } else if (!g_ascii_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
168 char *room; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
169 GHashTable *components; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
170 int exch = 5; |
| 10395 | 171 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
172 uri = uri + strlen("aim:gochat?"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
173 /* spaces are encoded as +'s */ |
| 10395 | 174 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
175 if (!(room = strstr(uri, "roomname="))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
176 return _("No roomname given."); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
177 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
178 room = room + strlen("roomname="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
179 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
180 while (*room && (*room != '&')) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
181 g_string_append_c(str, *room == '+' ? ' ' : *room); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
182 room++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
183 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
184 room = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
185 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
186 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
187 g_free); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
188 g_hash_table_replace(components, g_strdup("room"), room); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
189 g_hash_table_replace(components, g_strdup("exchange"), |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
190 g_strdup_printf("%d", exch)); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
191 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
192 serv_join_chat(gc, components); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
193 g_hash_table_destroy(components); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
194 } else { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
195 return _("Invalid AIM URI"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
196 } |
| 10395 | 197 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
198 return NULL; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
199 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
200 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
201 |
| 5859 | 202 |
| 203 #if 0 | |
| 204 static guchar * | |
| 205 UI_build(guint32 *len, guchar type, guchar subtype, va_list args) | |
| 206 { | |
| 207 guchar *buffer; | |
| 208 guint32 pos; | |
| 209 int size; | |
| 210 void *data; | |
| 211 | |
| 212 *len = sizeof(guchar) * 2 + 4; | |
| 213 buffer = g_malloc(*len); | |
| 214 pos = 0; | |
| 215 | |
| 216 memcpy(buffer + pos, &type, sizeof(type)); pos += sizeof(type); | |
| 217 memcpy(buffer + pos, &subtype, sizeof(subtype)); pos += sizeof(subtype); | |
| 218 | |
| 219 /* we come back and do size last */ | |
| 220 pos += 4; | |
| 221 | |
| 222 size = va_arg(args, int); | |
| 223 while (size != -1) { | |
| 224 *len += size; | |
| 225 buffer = g_realloc(buffer, *len); | |
| 226 | |
| 227 data = va_arg(args, void *); | |
| 228 memcpy(buffer + pos, data, size); | |
| 229 pos += size; | |
| 230 | |
| 231 size = va_arg(args, int); | |
| 232 } | |
| 233 | |
| 234 pos -= sizeof(guchar) * 2 + 4; | |
| 235 | |
| 236 /* now we do size */ | |
| 237 memcpy(buffer + sizeof(guchar) * 2, &pos, 4); | |
| 238 | |
| 239 return buffer; | |
| 240 } | |
| 241 | |
| 242 static gint | |
| 243 UI_write(struct UI *ui, guchar *data, gint len) | |
| 244 { | |
| 245 GError *error = NULL; | |
| 246 gint sent; | |
| 247 /* we'll let the write silently fail because the read will pick it up as dead */ | |
| 248 g_io_channel_write_chars(ui->channel, data, len, &sent, &error); | |
| 249 if (error) | |
| 250 g_error_free(error); | |
| 251 return sent; | |
| 252 } | |
| 253 | |
| 254 static void | |
| 255 UI_build_write(struct UI *ui, guchar type, guchar subtype, ...) | |
| 256 { | |
| 257 va_list ap; | |
| 258 gchar *data; | |
| 259 guint32 len; | |
| 260 | |
| 261 va_start(ap, subtype); | |
| 262 data = UI_build(&len, type, subtype, ap); | |
| 263 va_end(ap); | |
| 264 | |
| 265 UI_write(ui, data, len); | |
| 266 | |
| 267 g_free(data); | |
| 268 } | |
| 269 | |
| 270 static void | |
| 271 UI_broadcast(guchar *data, gint len) | |
| 272 { | |
| 273 GSList *u = uis; | |
| 274 while (u) { | |
| 275 struct UI *ui = u->data; | |
| 276 UI_write(ui, data, len); | |
| 277 u = u->next; | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 static void | |
| 282 UI_build_broadcast(guchar type, guchar subtype, ...) | |
| 283 { | |
| 284 va_list ap; | |
| 285 gchar *data; | |
| 286 guint32 len; | |
| 287 | |
| 288 if (!uis) | |
| 289 return; | |
| 290 | |
| 291 va_start(ap, subtype); | |
| 292 data = UI_build(&len, type, subtype, ap); | |
| 293 va_end(ap); | |
| 294 | |
| 295 UI_broadcast(data, len); | |
| 296 | |
| 297 g_free(data); | |
| 298 } | |
| 299 #endif | |
| 300 | |
| 301 #ifndef _WIN32 | |
| 302 static void | |
| 6063 | 303 meta_handler(struct UI *ui, guchar subtype, gchar *data) |
| 5859 | 304 { |
| 305 GaimRemotePacket *p; | |
| 306 GError *error = NULL; | |
| 10395 | 307 |
| 5859 | 308 switch (subtype) { |
| 309 case CUI_META_LIST: | |
| 310 break; | |
| 311 case CUI_META_QUIT: | |
| 312 while (uis) { | |
| 313 ui = uis->data; | |
| 314 uis = g_slist_remove(uis, ui); | |
| 315 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 316 g_source_remove(ui->inpa); | |
| 317 g_free(ui); | |
| 318 } | |
| 7646 | 319 g_timeout_add(0, gaim_core_quit_cb, NULL); |
| 5859 | 320 break; |
| 321 case CUI_META_DETACH: | |
| 322 uis = g_slist_remove(uis, ui); | |
| 323 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 324 g_source_remove(ui->inpa); | |
| 325 g_free(ui); | |
| 326 break; | |
| 327 case CUI_META_PING: | |
| 328 p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_ACK); | |
| 329 gaim_remote_session_send_packet(g_io_channel_unix_get_fd(ui->channel), | |
| 330 p); | |
| 331 gaim_remote_packet_free(p); | |
| 332 break; | |
| 333 default: | |
| 10003 | 334 gaim_debug_warning("cui", "Unhandled meta subtype %d\n", subtype); |
| 5859 | 335 break; |
| 336 } | |
| 337 | |
| 338 if(error) | |
| 339 g_error_free(error); | |
| 340 } | |
| 341 | |
| 342 static void | |
| 6063 | 343 plugin_handler(struct UI *ui, guchar subtype, gpointer data) |
| 5859 | 344 { |
| 345 #ifdef GAIM_PLUGINS | |
| 346 guint id; | |
| 347 GaimPlugin *p; | |
| 348 | |
| 349 switch (subtype) { | |
| 350 /* | |
| 351 case CUI_PLUGIN_LIST: | |
| 352 break; | |
| 353 */ | |
| 354 case CUI_PLUGIN_LOAD: | |
| 355 gaim_plugin_load(gaim_plugin_probe(data)); | |
| 356 break; | |
| 357 case CUI_PLUGIN_UNLOAD: | |
| 358 memcpy(&id, data, sizeof(id)); | |
| 359 p = g_list_nth_data(gaim_plugins_get_loaded(), id); | |
| 360 if (p) { | |
| 361 gaim_plugin_unload(p); | |
| 362 } | |
| 363 break; | |
| 364 default: | |
| 10003 | 365 gaim_debug_warning("cui", "Unhandled plugin subtype %d\n", subtype); |
| 5859 | 366 break; |
| 367 } | |
| 368 #endif | |
| 369 } | |
| 370 | |
| 371 static void | |
| 6063 | 372 user_handler(struct UI *ui, guchar subtype, gchar *data) |
| 5859 | 373 { |
| 374 guint id; | |
| 375 GaimAccount *account; | |
| 376 | |
| 377 switch (subtype) { | |
| 10005 | 378 /* |
| 5859 | 379 case CUI_USER_LIST: |
| 380 break; | |
| 381 case CUI_USER_ADD: | |
| 382 break; | |
| 383 case CUI_USER_REMOVE: | |
| 384 break; | |
| 385 case CUI_USER_MODIFY: | |
| 386 break; | |
| 10005 | 387 */ |
| 388 | |
| 5859 | 389 case CUI_USER_SIGNON: |
| 390 if (!data) | |
| 391 return; | |
| 392 memcpy(&id, data, sizeof(id)); | |
| 393 account = g_list_nth_data(gaim_accounts_get_all(), id); | |
| 394 if (account) | |
| 10401 | 395 /* XXX: someone might want to extend this to allow connecting with a different status */ |
| 396 gaim_account_connect(account, gaim_account_get_status(account, "online")); | |
| 5859 | 397 /* don't need to do anything here because the UI will get updates from other handlers */ |
| 398 break; | |
| 10005 | 399 |
| 9962 | 400 #if 0 /* STATUS */ |
| 10005 | 401 case CUI_USER_AWAY: |
| 402 { | |
| 403 GSList* l; | |
| 404 const char* default_away_name = gaim_prefs_get_string("/core/away/default_message"); | |
| 9608 | 405 |
| 10005 | 406 for (l = away_messages; l; l = l->next) { |
| 407 if (!strcmp(default_away_name, ((struct away_message *)l->data)->name)) { | |
| 408 do_away_message(NULL, l->data); | |
| 409 break; | |
| 410 } | |
| 411 } | |
| 412 } | |
| 413 break; | |
| 414 | |
| 415 case CUI_USER_BACK: | |
| 416 do_im_back(NULL, NULL); | |
| 417 break; | |
| 418 | |
| 9962 | 419 #endif /* STATUS */ |
| 10395 | 420 |
| 421 case CUI_USER_LOGOUT: | |
| 422 gaim_connections_disconnect_all(); | |
| 423 break; | |
| 424 | |
| 5859 | 425 default: |
| 10003 | 426 gaim_debug_warning("cui", "Unhandled user subtype %d\n", subtype); |
| 5859 | 427 break; |
| 428 } | |
| 429 } | |
| 430 | |
| 431 static void | |
| 6063 | 432 message_handler(struct UI *ui, guchar subtype, gchar *data) |
| 5859 | 433 { |
| 434 switch (subtype) { | |
| 435 case CUI_MESSAGE_LIST: | |
| 436 break; | |
| 437 case CUI_MESSAGE_SEND: | |
| 438 if (!data) | |
| 439 return; | |
| 440 { | |
| 441 guint id; | |
| 442 GaimConnection *gc; | |
| 443 guint len; | |
| 444 char *who, *msg; | |
| 445 gint flags; | |
| 446 int pos = 0; | |
| 447 | |
| 448 memcpy(&id, data + pos, sizeof(id)); | |
| 449 pos += sizeof(id); | |
| 450 gc = g_list_nth_data(gaim_connections_get_all(), id); | |
| 451 if (!gc) | |
| 452 return; | |
| 453 | |
| 454 memcpy(&len, data + pos, sizeof(len)); | |
| 455 pos += sizeof(len); | |
| 456 who = g_strndup(data + pos, len + 1); | |
| 457 pos += len; | |
| 458 | |
| 459 memcpy(&len, data + pos, sizeof(len)); | |
| 460 pos += sizeof(len); | |
| 461 msg = g_strndup(data + pos, len + 1); | |
| 462 pos += len; | |
| 463 | |
| 464 memcpy(&flags, data + pos, sizeof(flags)); | |
| 6982 | 465 serv_send_im(gc, who, msg, flags); |
| 5859 | 466 |
| 467 g_free(who); | |
| 468 g_free(msg); | |
| 469 } | |
| 470 break; | |
| 471 case CUI_MESSAGE_RECV: | |
| 472 break; | |
| 473 default: | |
| 10003 | 474 gaim_debug_warning("cui", "Unhandled message subtype %d\n", subtype); |
| 5859 | 475 break; |
| 476 } | |
| 477 } | |
| 478 | |
| 479 static gint | |
| 6063 | 480 gaim_recv(GIOChannel *source, gchar *buf, gint len) |
| 5859 | 481 { |
| 482 gint total = 0; | |
| 10124 | 483 gsize cur; |
| 5859 | 484 |
| 485 GError *error = NULL; | |
| 486 | |
| 487 while (total < len) { | |
| 10124 | 488 if (g_io_channel_read_chars(source, buf + total, len - total, &cur, &error) != G_IO_STATUS_NORMAL) { |
| 5859 | 489 if (error) |
| 490 g_error_free(error); | |
| 491 return -1; | |
| 492 } | |
| 493 if (cur == 0) | |
| 494 return total; | |
| 495 total += cur; | |
| 496 } | |
| 497 | |
| 498 return total; | |
| 499 } | |
| 500 | |
| 501 static void | |
| 6063 | 502 remote_handler(struct UI *ui, guchar subtype, gchar *data, int len) |
| 5859 | 503 { |
| 504 const char *resp; | |
| 505 char *send; | |
| 10003 | 506 GList *c = gaim_connections_get_all(); |
| 10012 | 507 GaimConnection *gc = NULL; |
| 10003 | 508 GaimAccount *account; |
| 509 | |
| 5859 | 510 switch (subtype) { |
| 511 case CUI_REMOTE_CONNECTIONS: | |
| 512 break; | |
| 10003 | 513 case CUI_REMOTE_SEND: |
| 514 if (!data) | |
| 515 return; | |
| 516 { | |
| 517 GaimConversation *conv; | |
| 10005 | 518 guint tlen, len, len2, quiet; |
| 10003 | 519 char *who, *msg; |
| 520 char *tmp, *from, *proto; | |
| 521 int pos = 0; | |
| 522 | |
| 523 gaim_debug_info("cui", "Got `gaim-remote send` packet\n",data); | |
| 524 gaim_debug_info("cui", "g-r>%s;\n",data); | |
| 525 | |
| 526 tmp = g_strndup(data + pos, 4); | |
| 10005 | 527 tlen = atoi(tmp); |
| 528 pos += 4; | |
| 10003 | 529 |
| 10005 | 530 who = g_strndup(data+pos, tlen); |
| 531 pos += tlen; | |
| 10003 | 532 |
| 533 tmp = g_strndup(data + pos, 4); | |
| 10005 | 534 tlen = atoi(tmp); len=tlen; /* length for 'from' compare */ |
| 535 pos += 4; | |
| 10003 | 536 |
| 10005 | 537 from = g_strndup(data+pos, tlen); |
| 538 pos += tlen; | |
| 10003 | 539 |
| 540 tmp = g_strndup(data + pos, 4); | |
| 10005 | 541 tlen = atoi(tmp); len2=tlen; /* length for 'proto' compare */ |
| 542 pos += 4; | |
| 543 | |
| 544 proto = g_strndup(data+pos, tlen); | |
| 545 pos += tlen; | |
| 10003 | 546 |
| 547 tmp = g_strndup(data + pos, 4); | |
| 10005 | 548 tlen = atoi(tmp); |
| 549 pos += 4; | |
| 10003 | 550 |
| 10005 | 551 msg = g_strndup(data+pos, tlen); |
| 552 pos += tlen; | |
| 10003 | 553 |
| 554 tmp = g_strndup(data + pos, 1); | |
| 10005 | 555 quiet = atoi(tmp); /* quiet flag - not in use yet */ |
| 10003 | 556 |
| 10005 | 557 /* find acct */ |
| 10003 | 558 while (c) { |
| 559 gc = c->data; | |
| 560 account=gaim_connection_get_account(gc); | |
| 561 if ((!gaim_utf8_strcasecmp(from, gaim_account_get_username(account))) && (!g_ascii_strncasecmp(proto, gaim_account_get_protocol_id(account), len2)) ) | |
| 562 break; | |
| 563 c = c->next; | |
| 564 } | |
| 565 if (!gc) | |
| 566 return; | |
| 10005 | 567 /* end acct find */ |
| 10003 | 568 |
| 10005 | 569 /* gaim_debug_info("cui", "g-r>To: %s; From: %s; Protocol: %s; Message: %s; Quiet: %d\n",who,from,proto,msg,quiet); */ |
| 10003 | 570 conv = gaim_conversation_new(GAIM_CONV_IM, gaim_connection_get_account(gc), who); |
| 571 gaim_conv_im_send(GAIM_CONV_IM(conv), msg); | |
| 572 | |
| 10005 | 573 /* likely to be used for quiet: |
| 10003 | 574 serv_send_im(gc, who, msg, -1, 0); |
| 575 */ | |
| 10005 | 576 |
| 10003 | 577 g_free(who); |
| 578 g_free(msg); | |
| 579 g_free(from); | |
| 580 g_free(tmp); | |
| 581 } | |
| 582 break; | |
| 583 | |
| 5859 | 584 case CUI_REMOTE_URI: |
| 585 send = g_malloc(len + 1); | |
| 586 memcpy(send, data, len); | |
| 587 send[len] = 0; | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
588 resp = gaim_remote_handle_uri(send); |
| 5859 | 589 g_free(send); |
| 590 /* report error */ | |
| 591 break; | |
| 10005 | 592 |
| 5859 | 593 default: |
| 10003 | 594 gaim_debug_warning("cui", "Unhandled remote subtype %d\n", subtype); |
| 5859 | 595 break; |
| 596 } | |
| 597 } | |
| 598 | |
| 599 static gboolean | |
| 600 UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) | |
| 601 { | |
| 602 struct UI *ui = data; | |
| 6063 | 603 gchar type; |
| 604 gchar subtype; | |
| 7631 | 605 gint len; |
| 5859 | 606 GError *error = NULL; |
| 6063 | 607 gchar *in; |
| 5859 | 608 |
| 609 /* no byte order worries! this'll change if we go to TCP */ | |
| 610 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) { | |
| 10003 | 611 gaim_debug_error("cui", "UI has abandoned us!\n"); |
| 5859 | 612 uis = g_slist_remove(uis, ui); |
| 613 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 614 if(error) { | |
| 615 g_error_free(error); | |
| 616 error = NULL; | |
| 617 } | |
| 618 g_source_remove(ui->inpa); | |
| 619 g_free(ui); | |
| 620 return FALSE; | |
| 621 } | |
| 622 | |
| 623 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) { | |
| 10003 | 624 gaim_debug_error("cui", "UI has abandoned us!\n"); |
| 5859 | 625 uis = g_slist_remove(uis, ui); |
| 626 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 627 if(error) { | |
| 628 g_error_free(error); | |
| 629 error = NULL; | |
| 630 } | |
| 631 g_source_remove(ui->inpa); | |
| 632 g_free(ui); | |
| 633 return FALSE; | |
| 634 } | |
| 635 | |
| 6063 | 636 if (gaim_recv(source, (gchar *)&len, sizeof(len)) != sizeof(len)) { |
| 10003 | 637 gaim_debug_error("cui", "UI has abandoned us!\n"); |
| 5859 | 638 uis = g_slist_remove(uis, ui); |
| 639 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 640 if(error) { | |
| 641 g_error_free(error); | |
| 642 error = NULL; | |
| 643 } | |
| 644 g_source_remove(ui->inpa); | |
| 645 g_free(ui); | |
| 646 return FALSE; | |
| 647 } | |
| 648 | |
| 649 if (len) { | |
| 6063 | 650 in = g_new0(gchar, len); |
| 5859 | 651 if (gaim_recv(source, in, len) != len) { |
| 10003 | 652 gaim_debug_error("cui", "UI has abandoned us!\n"); |
| 5859 | 653 uis = g_slist_remove(uis, ui); |
| 654 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 655 if(error) { | |
| 656 g_error_free(error); | |
| 657 error = NULL; | |
| 658 } | |
| 659 g_source_remove(ui->inpa); | |
| 660 g_free(ui); | |
| 661 return FALSE; | |
| 662 } | |
| 663 } else | |
| 664 in = NULL; | |
| 665 | |
| 666 switch (type) { | |
| 667 case CUI_TYPE_META: | |
| 668 meta_handler(ui, subtype, in); | |
| 669 break; | |
| 670 case CUI_TYPE_PLUGIN: | |
| 671 plugin_handler(ui, subtype, in); | |
| 672 break; | |
| 673 case CUI_TYPE_USER: | |
| 674 user_handler(ui, subtype, in); | |
| 675 break; | |
| 676 /* | |
| 677 case CUI_TYPE_CONN: | |
| 678 conn_handler(ui, subtype, in); | |
| 679 break; | |
| 680 case CUI_TYPE_BUDDY: | |
| 681 buddy_handler(ui, subtype, in); | |
| 682 break; | |
| 683 */ | |
| 684 case CUI_TYPE_MESSAGE: | |
| 685 message_handler(ui, subtype, in); | |
| 686 break; | |
| 687 /* | |
| 688 case CUI_TYPE_CHAT: | |
| 689 chat_handler(ui, subtype, in); | |
| 690 break; | |
| 10395 | 691 */ |
| 10005 | 692 case CUI_TYPE_REMOTE: |
| 5859 | 693 remote_handler(ui, subtype, in, len); |
| 10395 | 694 break; |
| 10005 | 695 default: |
| 10003 | 696 gaim_debug_warning("cui", "Unhandled type %d\n", type); |
| 5859 | 697 break; |
| 698 } | |
| 699 | |
| 700 if (in) | |
| 701 g_free(in); | |
| 702 return TRUE; | |
| 703 } | |
| 704 | |
| 705 static gboolean | |
| 706 socket_readable(GIOChannel *source, GIOCondition cond, gpointer data) | |
| 707 { | |
| 708 struct sockaddr_un saddr; | |
| 6063 | 709 guint len = sizeof(saddr); |
| 5859 | 710 gint fd; |
| 711 | |
| 712 struct UI *ui; | |
| 713 | |
| 714 if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1) | |
| 715 return FALSE; | |
| 716 | |
| 717 ui = g_new0(struct UI, 1); | |
| 718 uis = g_slist_append(uis, ui); | |
| 719 | |
| 720 ui->channel = g_io_channel_unix_new(fd); | |
| 721 ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui); | |
| 722 g_io_channel_unref(ui->channel); | |
| 723 | |
| 10003 | 724 gaim_debug_misc("cui", "Got one\n"); |
| 5859 | 725 return TRUE; |
| 726 } | |
| 727 | |
| 728 static gint | |
| 8704 | 729 open_socket(char **error) |
| 5859 | 730 { |
| 731 struct sockaddr_un saddr; | |
| 732 gint fd; | |
| 10395 | 733 |
| 5859 | 734 while (gaim_remote_session_exists(gaim_session)) |
| 735 gaim_session++; | |
| 10395 | 736 |
| 10003 | 737 gaim_debug_misc("cui", "Session: %d\n", gaim_session); |
| 10395 | 738 |
| 5859 | 739 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { |
| 740 mode_t m = umask(0177); | |
| 741 saddr.sun_family = AF_UNIX; | |
| 742 | |
| 743 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", | |
| 744 g_get_tmp_dir(), g_get_user_name(), gaim_session); | |
| 745 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) | |
| 746 listen(fd, 100); | |
| 747 else { | |
| 8704 | 748 *error = g_strdup_printf(_("Failed to assign %s to a socket:\n%s"), |
| 749 saddr.sun_path, strerror(errno)); | |
| 5859 | 750 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
| 10395 | 751 "Failed to assign %s to a socket (Error: %s)", |
| 5859 | 752 saddr.sun_path, strerror(errno)); |
| 7617 | 753 umask(m); |
| 5859 | 754 return -1; |
| 755 } | |
| 756 umask(m); | |
| 757 } else | |
| 758 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); | |
| 759 return fd; | |
| 760 } | |
| 761 #endif /*! _WIN32*/ | |
| 762 | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
763 static gboolean |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
764 plugin_load(GaimPlugin *plugin) |
| 5859 | 765 { |
| 766 #ifndef _WIN32 | |
| 767 GIOChannel *channel; | |
| 10344 | 768 char *buf = NULL; |
| 5859 | 769 |
| 8704 | 770 if ((UI_fd = open_socket(&buf)) < 0) { |
| 771 gaim_notify_error(NULL, NULL, _("Unable to open socket"), buf); | |
| 772 g_free(buf); | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
773 return FALSE; |
| 8704 | 774 } |
| 5859 | 775 |
| 776 channel = g_io_channel_unix_new(UI_fd); | |
| 6107 | 777 watcher = g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); |
| 5859 | 778 g_io_channel_unref(channel); |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
779 |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
780 return TRUE; |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
781 #else |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
782 return FALSE; |
| 5859 | 783 #endif |
| 784 } | |
| 785 | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
786 static gboolean |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
787 plugin_unload(GaimPlugin *plugin) |
| 5859 | 788 { |
| 789 /* don't save prefs after plugins are gone... */ | |
| 790 #ifndef _WIN32 | |
| 791 char buf[1024]; | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
792 |
| 6107 | 793 g_source_remove(watcher); |
| 5859 | 794 close(UI_fd); |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
795 |
| 6063 | 796 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", |
| 5859 | 797 g_get_tmp_dir(), g_get_user_name(), gaim_session); |
| 798 | |
| 799 unlink(buf); | |
| 800 | |
| 10003 | 801 gaim_debug_misc("core", "Removed core\n"); |
| 5954 | 802 |
| 803 return TRUE; | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
804 #else |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
805 return FALSE; |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
806 #endif |
| 5859 | 807 } |
| 808 | |
| 809 static GaimPluginInfo info = | |
| 810 { | |
| 9943 | 811 GAIM_PLUGIN_MAGIC, |
| 812 GAIM_MAJOR_VERSION, | |
| 813 GAIM_MINOR_VERSION, | |
| 5859 | 814 GAIM_PLUGIN_STANDARD, /**< type */ |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
815 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
| 5859 | 816 0, /**< flags */ |
| 817 NULL, /**< dependencies */ | |
| 818 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 819 | |
| 820 REMOTE_PLUGIN_ID, /**< id */ | |
| 821 N_("Remote Control"), /**< name */ | |
| 822 VERSION, /**< version */ | |
| 823 /** summary */ | |
| 824 N_("Provides remote control for gaim applications."), | |
| 825 /** description */ | |
| 826 N_("Gives Gaim the ability to be remote-controlled through third-party " | |
| 827 "applications or through the gaim-remote tool."), | |
|
7782
795b71216887
[gaim-migrate @ 8427]
Christian Hammond <chipx86@chipx86.com>
parents:
7646
diff
changeset
|
828 "Sean Egan <sean.egan@binghamton.edu>", |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6179
diff
changeset
|
829 GAIM_WEBSITE, /**< homepage */ |
| 5859 | 830 |
| 831 plugin_load, /**< load */ | |
| 832 plugin_unload, /**< unload */ | |
| 833 NULL, /**< destroy */ | |
| 834 | |
| 835 NULL, /**< ui_info */ | |
| 8993 | 836 NULL, /**< extra_info */ |
| 837 NULL, | |
| 838 NULL | |
| 5859 | 839 }; |
| 840 | |
| 841 static void | |
| 10005 | 842 _init_plugin(GaimPlugin *plugin) |
| 5859 | 843 { |
| 844 } | |
| 845 | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
846 /* This may be horribly wrong. Oh the mayhem! */ |
| 10005 | 847 GAIM_INIT_PLUGIN(remote, _init_plugin, info) |
