Mercurial > pidgin
annotate plugins/gaim-remote/remote.c @ 9993:bdec08a8fc5b
[gaim-migrate @ 10906]
Remove away.c and away.h
And get rid of some code in server.c that I'm pretty sure doesn't
do anything
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Thu, 09 Sep 2004 03:36:35 +0000 |
| parents | 499a71d5d20f |
| children | 33431f91e4a8 |
| 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" |
| 9943 | 39 #include "version.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
40 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
41 /* XXX */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
42 #include "gtkconv.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
43 #include "gtkplugin.h" |
| 5859 | 44 #include "gaim.h" |
| 9608 | 45 #include "prefs.h" |
| 5859 | 46 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
47 #include <gaim-remote/remote.h> |
| 5859 | 48 |
|
5873
a18e88c4dace
[gaim-migrate @ 6305]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
49 #define REMOTE_PLUGIN_ID "gtk-remote" |
| 5859 | 50 |
| 51 struct UI { | |
| 52 GIOChannel *channel; | |
| 53 guint inpa; | |
| 54 }; | |
| 55 | |
| 56 #ifndef _WIN32 | |
| 57 static gint UI_fd = -1; | |
| 6107 | 58 static guint watcher = 0; |
| 5859 | 59 #endif |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
60 static int gaim_session = 0; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
61 static GSList *uis = NULL; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
62 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
63 /* AIM URI's ARE FUN :-D */ |
|
5884
d188b000e892
[gaim-migrate @ 6316]
Christian Hammond <chipx86@chipx86.com>
parents:
5873
diff
changeset
|
64 static const char * |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
65 gaim_remote_handle_uri(const char *uri) |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
66 { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
67 const char *username; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
68 GString *str; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
69 GList *conn; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
70 GaimConnection *gc = NULL; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
71 GaimAccount *account; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
72 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
73 gaim_debug(GAIM_DEBUG_INFO, "gaim_remote_handle_uri", "Handling URI: %s\n", uri); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
74 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
75 /* 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
|
76 AIM account connected. */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
77 for (conn = gaim_connections_get_all(); conn != NULL; conn = conn->next) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
78 gc = conn->data; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
79 account = gaim_connection_get_account(gc); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
80 username = gaim_account_get_username(account); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
81 |
| 9460 | 82 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
|
83 username != NULL && isalpha(*username)) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
84 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
85 break; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
86 } |
|
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 if (gc == NULL) |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
90 return _("Not connected to AIM"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
91 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
92 /* aim:goim?screenname=screenname&message=message */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
93 if (!g_ascii_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
94 char *who, *what; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
95 GaimConversation *c; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
96 uri = uri + strlen("aim:goim?"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
97 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
98 if (!(who = strstr(uri, "screenname="))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
99 return _("No screenname given."); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
100 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
101 /* spaces are encoded as +'s */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
102 who = who + strlen("screenname="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
103 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
104 while (*who && (*who != '&')) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
105 g_string_append_c(str, *who == '+' ? ' ' : *who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
106 who++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
107 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
108 who = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
109 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
110 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
111 what = strstr(uri, "message="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
112 if (what) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
113 what = what + strlen("message="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
114 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
115 while (*what && (*what != '&' || !g_ascii_strncasecmp(what, "&", 5))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
116 g_string_append_c(str, *what == '+' ? ' ' : *what); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
117 what++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
118 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
119 what = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
120 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
121 } |
|
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 c = gaim_conversation_new(GAIM_CONV_IM, gc->account, who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
124 g_free(who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
125 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
126 if (what) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
127 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(c); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
128 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
129 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
130 g_free(what); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
131 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
132 } else if (!g_ascii_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
133 char *who, *group; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
134 uri = uri + strlen("aim:addbuddy?"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
135 /* spaces are encoded as +'s */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
136 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
137 if (!(who = strstr(uri, "screenname="))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
138 return _("No screenname given."); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
139 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
140 who = who + strlen("screenname="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
141 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
142 while (*who && (*who != '&')) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
143 g_string_append_c(str, *who == '+' ? ' ' : *who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
144 who++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
145 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
146 who = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
147 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
148 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
149 group = strstr(uri, "group="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
150 if (group) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
151 group = group + strlen("group="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
152 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
153 while (*group && (*group != '&' || !g_ascii_strncasecmp(group, "&", 5))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
154 g_string_append_c(str, *group == '+' ? ' ' : *group); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
155 group++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
156 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
157 group = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
158 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
159 } |
|
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 gaim_debug(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
|
162 gaim_blist_request_add_buddy(gc->account, who, group, NULL); |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
163 g_free(who); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
164 if (group) |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
165 g_free(group); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
166 } else if (!g_ascii_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
167 char *room; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
168 GHashTable *components; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
169 int exch = 5; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
170 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
171 uri = uri + strlen("aim:gochat?"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
172 /* spaces are encoded as +'s */ |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
173 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
174 if (!(room = strstr(uri, "roomname="))) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
175 return _("No roomname given."); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
176 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
177 room = room + strlen("roomname="); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
178 str = g_string_new(NULL); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
179 while (*room && (*room != '&')) { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
180 g_string_append_c(str, *room == '+' ? ' ' : *room); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
181 room++; |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
182 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
183 room = g_strdup(str->str); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
184 g_string_free(str, TRUE); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
185 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
|
186 g_free); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
187 g_hash_table_replace(components, g_strdup("room"), room); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
188 g_hash_table_replace(components, g_strdup("exchange"), |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
189 g_strdup_printf("%d", exch)); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
190 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
191 serv_join_chat(gc, components); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
192 g_hash_table_destroy(components); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
193 } else { |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
194 return _("Invalid AIM URI"); |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
195 } |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
196 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
197 |
|
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; | |
| 307 switch (subtype) { | |
| 308 case CUI_META_LIST: | |
| 309 break; | |
| 310 case CUI_META_QUIT: | |
| 311 while (uis) { | |
| 312 ui = uis->data; | |
| 313 uis = g_slist_remove(uis, ui); | |
| 314 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 315 g_source_remove(ui->inpa); | |
| 316 g_free(ui); | |
| 317 } | |
| 7646 | 318 g_timeout_add(0, gaim_core_quit_cb, NULL); |
| 5859 | 319 break; |
| 320 case CUI_META_DETACH: | |
| 321 uis = g_slist_remove(uis, ui); | |
| 322 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 323 g_source_remove(ui->inpa); | |
| 324 g_free(ui); | |
| 325 break; | |
| 326 case CUI_META_PING: | |
| 327 p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_ACK); | |
| 328 gaim_remote_session_send_packet(g_io_channel_unix_get_fd(ui->channel), | |
| 329 p); | |
| 330 gaim_remote_packet_free(p); | |
| 331 break; | |
| 332 default: | |
| 333 gaim_debug(GAIM_DEBUG_WARNING, "cui", | |
| 334 "Unhandled meta subtype %d\n", subtype); | |
| 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: | |
| 365 gaim_debug(GAIM_DEBUG_WARNING, "cui", | |
| 366 "Unhandled plugin subtype %d\n", subtype); | |
| 367 break; | |
| 368 } | |
| 369 #endif | |
| 370 } | |
| 371 | |
| 372 static void | |
| 6063 | 373 user_handler(struct UI *ui, guchar subtype, gchar *data) |
| 5859 | 374 { |
| 375 guint id; | |
| 376 GaimAccount *account; | |
| 377 | |
| 378 switch (subtype) { | |
| 379 /* | |
| 380 case CUI_USER_LIST: | |
| 381 break; | |
| 382 case CUI_USER_ADD: | |
| 383 break; | |
| 384 case CUI_USER_REMOVE: | |
| 385 break; | |
| 386 case CUI_USER_MODIFY: | |
| 387 break; | |
| 388 */ | |
| 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) | |
| 6036 | 395 gaim_account_connect(account); |
| 5859 | 396 /* don't need to do anything here because the UI will get updates from other handlers */ |
| 397 break; | |
| 9962 | 398 #if 0 /* STATUS */ |
| 9608 | 399 case CUI_USER_AWAY: |
| 400 { | |
| 401 GSList* l; | |
| 402 const char* default_away_name = gaim_prefs_get_string("/core/away/default_message"); | |
| 403 | |
| 404 for(l = away_messages; l; l = l->next) { | |
| 405 if(!strcmp(default_away_name, ((struct away_message *)l->data)->name)) { | |
| 406 do_away_message(NULL, l->data); | |
| 407 break; | |
| 408 } | |
| 409 } | |
| 410 } | |
| 411 break; | |
| 412 case CUI_USER_BACK: | |
| 413 do_im_back(NULL, NULL); | |
| 414 break; | |
| 9962 | 415 #endif /* STATUS */ |
| 5859 | 416 default: |
| 417 gaim_debug(GAIM_DEBUG_WARNING, "cui", | |
| 418 "Unhandled user subtype %d\n", subtype); | |
| 419 break; | |
| 420 } | |
| 421 } | |
| 422 | |
| 423 static void | |
| 6063 | 424 message_handler(struct UI *ui, guchar subtype, gchar *data) |
| 5859 | 425 { |
| 426 switch (subtype) { | |
| 427 case CUI_MESSAGE_LIST: | |
| 428 break; | |
| 429 case CUI_MESSAGE_SEND: | |
| 430 if (!data) | |
| 431 return; | |
| 432 { | |
| 433 guint id; | |
| 434 GaimConnection *gc; | |
| 435 guint len; | |
| 436 char *who, *msg; | |
| 437 gint flags; | |
| 438 int pos = 0; | |
| 439 | |
| 440 memcpy(&id, data + pos, sizeof(id)); | |
| 441 pos += sizeof(id); | |
| 442 gc = g_list_nth_data(gaim_connections_get_all(), id); | |
| 443 if (!gc) | |
| 444 return; | |
| 445 | |
| 446 memcpy(&len, data + pos, sizeof(len)); | |
| 447 pos += sizeof(len); | |
| 448 who = g_strndup(data + pos, len + 1); | |
| 449 pos += len; | |
| 450 | |
| 451 memcpy(&len, data + pos, sizeof(len)); | |
| 452 pos += sizeof(len); | |
| 453 msg = g_strndup(data + pos, len + 1); | |
| 454 pos += len; | |
| 455 | |
| 456 memcpy(&flags, data + pos, sizeof(flags)); | |
| 6982 | 457 serv_send_im(gc, who, msg, flags); |
| 5859 | 458 |
| 459 g_free(who); | |
| 460 g_free(msg); | |
| 461 } | |
| 462 break; | |
| 463 case CUI_MESSAGE_RECV: | |
| 464 break; | |
| 465 default: | |
| 466 gaim_debug(GAIM_DEBUG_WARNING, "cui", | |
| 467 "Unhandled message subtype %d\n", subtype); | |
| 468 break; | |
| 469 } | |
| 470 } | |
| 471 | |
| 472 static gint | |
| 6063 | 473 gaim_recv(GIOChannel *source, gchar *buf, gint len) |
| 5859 | 474 { |
| 475 gint total = 0; | |
| 6063 | 476 guint cur; |
| 5859 | 477 |
| 478 GError *error = NULL; | |
| 479 | |
| 480 while (total < len) { | |
| 7386 | 481 if (g_io_channel_read_chars(source, buf + total, len - total, (gsize *) &cur, &error) != G_IO_STATUS_NORMAL) { |
| 5859 | 482 if (error) |
| 483 g_error_free(error); | |
| 484 return -1; | |
| 485 } | |
| 486 if (cur == 0) | |
| 487 return total; | |
| 488 total += cur; | |
| 489 } | |
| 490 | |
| 491 return total; | |
| 492 } | |
| 493 | |
| 494 static void | |
| 6063 | 495 remote_handler(struct UI *ui, guchar subtype, gchar *data, int len) |
| 5859 | 496 { |
| 497 const char *resp; | |
| 498 char *send; | |
| 499 switch (subtype) { | |
| 500 case CUI_REMOTE_CONNECTIONS: | |
| 501 break; | |
| 502 case CUI_REMOTE_URI: | |
| 503 send = g_malloc(len + 1); | |
| 504 memcpy(send, data, len); | |
| 505 send[len] = 0; | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
506 resp = gaim_remote_handle_uri(send); |
| 5859 | 507 g_free(send); |
| 508 /* report error */ | |
| 509 break; | |
| 510 default: | |
| 511 gaim_debug(GAIM_DEBUG_WARNING, "cui", | |
| 512 "Unhandled remote subtype %d\n", subtype); | |
| 513 break; | |
| 514 } | |
| 515 } | |
| 516 | |
| 517 static gboolean | |
| 518 UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) | |
| 519 { | |
| 520 struct UI *ui = data; | |
| 521 | |
| 6063 | 522 gchar type; |
| 523 gchar subtype; | |
| 7631 | 524 gint len; |
| 5859 | 525 |
| 526 GError *error = NULL; | |
| 527 | |
| 6063 | 528 gchar *in; |
| 5859 | 529 |
| 530 /* no byte order worries! this'll change if we go to TCP */ | |
| 531 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) { | |
| 532 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); | |
| 533 uis = g_slist_remove(uis, ui); | |
| 534 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 535 if(error) { | |
| 536 g_error_free(error); | |
| 537 error = NULL; | |
| 538 } | |
| 539 g_source_remove(ui->inpa); | |
| 540 g_free(ui); | |
| 541 return FALSE; | |
| 542 } | |
| 543 | |
| 544 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) { | |
| 545 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); | |
| 546 uis = g_slist_remove(uis, ui); | |
| 547 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 548 if(error) { | |
| 549 g_error_free(error); | |
| 550 error = NULL; | |
| 551 } | |
| 552 g_source_remove(ui->inpa); | |
| 553 g_free(ui); | |
| 554 return FALSE; | |
| 555 } | |
| 556 | |
| 6063 | 557 if (gaim_recv(source, (gchar *)&len, sizeof(len)) != sizeof(len)) { |
| 5859 | 558 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); |
| 559 uis = g_slist_remove(uis, ui); | |
| 560 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 561 if(error) { | |
| 562 g_error_free(error); | |
| 563 error = NULL; | |
| 564 } | |
| 565 g_source_remove(ui->inpa); | |
| 566 g_free(ui); | |
| 567 return FALSE; | |
| 568 } | |
| 569 | |
| 570 if (len) { | |
| 6063 | 571 in = g_new0(gchar, len); |
| 5859 | 572 if (gaim_recv(source, in, len) != len) { |
| 573 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n"); | |
| 574 uis = g_slist_remove(uis, ui); | |
| 575 g_io_channel_shutdown(ui->channel, TRUE, &error); | |
| 576 if(error) { | |
| 577 g_error_free(error); | |
| 578 error = NULL; | |
| 579 } | |
| 580 g_source_remove(ui->inpa); | |
| 581 g_free(ui); | |
| 582 return FALSE; | |
| 583 } | |
| 584 } else | |
| 585 in = NULL; | |
| 586 | |
| 587 switch (type) { | |
| 588 case CUI_TYPE_META: | |
| 589 meta_handler(ui, subtype, in); | |
| 590 break; | |
| 591 case CUI_TYPE_PLUGIN: | |
| 592 plugin_handler(ui, subtype, in); | |
| 593 break; | |
| 594 case CUI_TYPE_USER: | |
| 595 user_handler(ui, subtype, in); | |
| 596 break; | |
| 597 /* | |
| 598 case CUI_TYPE_CONN: | |
| 599 conn_handler(ui, subtype, in); | |
| 600 break; | |
| 601 case CUI_TYPE_BUDDY: | |
| 602 buddy_handler(ui, subtype, in); | |
| 603 break; | |
| 604 */ | |
| 605 case CUI_TYPE_MESSAGE: | |
| 606 message_handler(ui, subtype, in); | |
| 607 break; | |
| 608 /* | |
| 609 case CUI_TYPE_CHAT: | |
| 610 chat_handler(ui, subtype, in); | |
| 611 break; | |
| 612 */ | |
| 613 case CUI_TYPE_REMOTE: | |
| 614 remote_handler(ui, subtype, in, len); | |
| 615 break; | |
| 616 default: | |
| 617 gaim_debug(GAIM_DEBUG_WARNING, "cui", | |
| 618 "Unhandled type %d\n", type); | |
| 619 break; | |
| 620 } | |
| 621 | |
| 622 if (in) | |
| 623 g_free(in); | |
| 624 return TRUE; | |
| 625 } | |
| 626 | |
| 627 static gboolean | |
| 628 socket_readable(GIOChannel *source, GIOCondition cond, gpointer data) | |
| 629 { | |
| 630 struct sockaddr_un saddr; | |
| 6063 | 631 guint len = sizeof(saddr); |
| 5859 | 632 gint fd; |
| 633 | |
| 634 struct UI *ui; | |
| 635 | |
| 636 if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1) | |
| 637 return FALSE; | |
| 638 | |
| 639 ui = g_new0(struct UI, 1); | |
| 640 uis = g_slist_append(uis, ui); | |
| 641 | |
| 642 ui->channel = g_io_channel_unix_new(fd); | |
| 643 ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui); | |
| 644 g_io_channel_unref(ui->channel); | |
| 645 | |
| 646 gaim_debug(GAIM_DEBUG_MISC, "cui", "Got one\n"); | |
| 647 return TRUE; | |
| 648 } | |
| 649 | |
| 650 static gint | |
| 8704 | 651 open_socket(char **error) |
| 5859 | 652 { |
| 653 struct sockaddr_un saddr; | |
| 654 gint fd; | |
| 655 | |
| 656 while (gaim_remote_session_exists(gaim_session)) | |
| 657 gaim_session++; | |
| 658 | |
| 659 gaim_debug(GAIM_DEBUG_MISC, "cui", "Session: %d\n", gaim_session); | |
| 660 | |
| 661 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { | |
| 662 mode_t m = umask(0177); | |
| 663 saddr.sun_family = AF_UNIX; | |
| 664 | |
| 665 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", | |
| 666 g_get_tmp_dir(), g_get_user_name(), gaim_session); | |
| 667 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) | |
| 668 listen(fd, 100); | |
| 669 else { | |
| 8704 | 670 *error = g_strdup_printf(_("Failed to assign %s to a socket:\n%s"), |
| 671 saddr.sun_path, strerror(errno)); | |
| 5859 | 672 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
| 673 "Failed to assign %s to a socket (Error: %s)", | |
| 674 saddr.sun_path, strerror(errno)); | |
| 7617 | 675 umask(m); |
| 5859 | 676 return -1; |
| 677 } | |
| 678 umask(m); | |
| 679 } else | |
| 680 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); | |
| 681 return fd; | |
| 682 } | |
| 683 #endif /*! _WIN32*/ | |
| 684 | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
685 static gboolean |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
686 plugin_load(GaimPlugin *plugin) |
| 5859 | 687 { |
| 688 #ifndef _WIN32 | |
| 689 GIOChannel *channel; | |
| 8704 | 690 char *buf; |
| 5859 | 691 |
| 8704 | 692 if ((UI_fd = open_socket(&buf)) < 0) { |
| 693 gaim_notify_error(NULL, NULL, _("Unable to open socket"), buf); | |
| 694 g_free(buf); | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
695 return FALSE; |
| 8704 | 696 } |
| 5859 | 697 |
| 698 channel = g_io_channel_unix_new(UI_fd); | |
| 6107 | 699 watcher = g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); |
| 5859 | 700 g_io_channel_unref(channel); |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
701 |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
702 return TRUE; |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
703 #else |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
704 return FALSE; |
| 5859 | 705 #endif |
| 706 } | |
| 707 | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
708 static gboolean |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
709 plugin_unload(GaimPlugin *plugin) |
| 5859 | 710 { |
| 711 /* don't save prefs after plugins are gone... */ | |
| 712 #ifndef _WIN32 | |
| 713 char buf[1024]; | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
714 |
| 6107 | 715 g_source_remove(watcher); |
| 5859 | 716 close(UI_fd); |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
717 |
| 6063 | 718 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", |
| 5859 | 719 g_get_tmp_dir(), g_get_user_name(), gaim_session); |
| 720 | |
| 721 unlink(buf); | |
| 722 | |
| 723 gaim_debug(GAIM_DEBUG_MISC, "core", "Removed core\n"); | |
| 5954 | 724 |
| 725 return TRUE; | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
726 #else |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
727 return FALSE; |
|
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
728 #endif |
| 5859 | 729 } |
| 730 | |
| 731 static GaimPluginInfo info = | |
| 732 { | |
| 9943 | 733 GAIM_PLUGIN_MAGIC, |
| 734 GAIM_MAJOR_VERSION, | |
| 735 GAIM_MINOR_VERSION, | |
| 5859 | 736 GAIM_PLUGIN_STANDARD, /**< type */ |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
737 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
| 5859 | 738 0, /**< flags */ |
| 739 NULL, /**< dependencies */ | |
| 740 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 741 | |
| 742 REMOTE_PLUGIN_ID, /**< id */ | |
| 743 N_("Remote Control"), /**< name */ | |
| 744 VERSION, /**< version */ | |
| 745 /** summary */ | |
| 746 N_("Provides remote control for gaim applications."), | |
| 747 /** description */ | |
| 748 N_("Gives Gaim the ability to be remote-controlled through third-party " | |
| 749 "applications or through the gaim-remote tool."), | |
|
7782
795b71216887
[gaim-migrate @ 8427]
Christian Hammond <chipx86@chipx86.com>
parents:
7646
diff
changeset
|
750 "Sean Egan <sean.egan@binghamton.edu>", |
|
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6179
diff
changeset
|
751 GAIM_WEBSITE, /**< homepage */ |
| 5859 | 752 |
| 753 plugin_load, /**< load */ | |
| 754 plugin_unload, /**< unload */ | |
| 755 NULL, /**< destroy */ | |
| 756 | |
| 757 NULL, /**< ui_info */ | |
| 8993 | 758 NULL, /**< extra_info */ |
| 759 NULL, | |
| 760 NULL | |
| 5859 | 761 }; |
| 762 | |
| 763 static void | |
| 764 __init_plugin(GaimPlugin *plugin) | |
| 765 { | |
| 766 } | |
| 767 | |
|
6177
73f8f5c0e348
[gaim-migrate @ 6662]
Christian Hammond <chipx86@chipx86.com>
parents:
6107
diff
changeset
|
768 /* This may be horribly wrong. Oh the mayhem! */ |
| 6063 | 769 GAIM_INIT_PLUGIN(remote, __init_plugin, info) |
