| |
1 /* |
| |
2 * Gaim - Send raw data across the connections of some protocols. |
| |
3 * |
| |
4 * Gaim is the legal property of its developers, whose names are too numerous |
| |
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
6 * source distribution. |
| |
7 * |
| |
8 * This program is free software; you can redistribute it and/or modify |
| |
9 * it under the terms of the GNU General Public License as published by |
| |
10 * the Free Software Foundation; either version 2 of the License, or |
| |
11 * (at your option) any later version. |
| |
12 * |
| |
13 * This program is distributed in the hope that it will be useful, |
| |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
16 * GNU General Public License for more details. |
| |
17 * |
| |
18 * You should have received a copy of the GNU General Public License |
| |
19 * along with this program; if not, write to the Free Software |
| |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| |
21 * |
| |
22 */ |
| |
23 |
| |
24 #include "internal.h" |
| |
25 #include "gtkgaim.h" |
| |
26 |
| |
27 #include "conversation.h" |
| |
28 #include "debug.h" |
| |
29 #include "prpl.h" |
| |
30 #include "version.h" |
| |
31 |
| |
32 #include "gtkplugin.h" |
| |
33 #include "gtkutils.h" |
| |
34 |
| |
35 #include "protocols/jabber/jabber.h" |
| |
36 #include "protocols/msn/session.h" |
| |
37 |
| |
38 #ifdef MAX |
| |
39 # undef MAX |
| |
40 # undef MIN |
| |
41 #endif |
| |
42 |
| |
43 #define RAW_PLUGIN_ID "gtk-raw" |
| |
44 |
| |
45 static GtkWidget *window = NULL; |
| |
46 static GaimAccount *account = NULL; |
| |
47 static GaimPlugin *my_plugin = NULL; |
| |
48 |
| |
49 static int |
| |
50 window_closed_cb() |
| |
51 { |
| |
52 gaim_plugin_unload(my_plugin); |
| |
53 |
| |
54 return FALSE; |
| |
55 } |
| |
56 |
| |
57 static void |
| |
58 text_sent_cb(GtkEntry *entry) |
| |
59 { |
| |
60 const char *txt; |
| |
61 GaimConnection *gc; |
| |
62 const char *prpl_id; |
| |
63 |
| |
64 if (account == NULL) |
| |
65 return; |
| |
66 |
| |
67 gc = gaim_account_get_connection(account); |
| |
68 |
| |
69 txt = gtk_entry_get_text(entry); |
| |
70 |
| |
71 prpl_id = gaim_account_get_protocol_id(account); |
| |
72 |
| |
73 gaim_debug_misc("raw", "prpl_id = %s\n", prpl_id); |
| |
74 |
| |
75 if (strcmp(prpl_id, "prpl-toc") == 0) { |
| |
76 int *a = (int *)gc->proto_data; |
| |
77 unsigned short seqno = htons(a[1]++ & 0xffff); |
| |
78 unsigned short len = htons(strlen(txt) + 1); |
| |
79 write(*a, "*\002", 2); |
| |
80 write(*a, &seqno, 2); |
| |
81 write(*a, &len, 2); |
| |
82 write(*a, txt, ntohs(len)); |
| |
83 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); |
| |
84 |
| |
85 } else if (strcmp(prpl_id, "prpl-msn") == 0) { |
| |
86 MsnSession *session = gc->proto_data; |
| |
87 char buf[strlen(txt) + 3]; |
| |
88 |
| |
89 g_snprintf(buf, sizeof(buf), "%s\r\n", txt); |
| |
90 msn_servconn_write(session->notification->servconn, buf, strlen(buf)); |
| |
91 |
| |
92 } else if (strcmp(prpl_id, "prpl-irc") == 0) { |
| |
93 write(*(int *)gc->proto_data, txt, strlen(txt)); |
| |
94 write(*(int *)gc->proto_data, "\r\n", 2); |
| |
95 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); |
| |
96 |
| |
97 } else if (strcmp(prpl_id, "prpl-jabber") == 0) { |
| |
98 jabber_send_raw((JabberStream *)gc->proto_data, txt, -1); |
| |
99 |
| |
100 } else { |
| |
101 gaim_debug_error("raw", "Unknown protocol ID %s\n", prpl_id); |
| |
102 } |
| |
103 |
| |
104 gtk_entry_set_text(entry, ""); |
| |
105 } |
| |
106 |
| |
107 static void |
| |
108 account_changed_cb(GtkWidget *dropdown, GaimAccount *new_account, |
| |
109 void *user_data) |
| |
110 { |
| |
111 account = new_account; |
| |
112 } |
| |
113 |
| |
114 static gboolean |
| |
115 plugin_load(GaimPlugin *plugin) |
| |
116 { |
| |
117 GtkWidget *hbox; |
| |
118 GtkWidget *entry; |
| |
119 GtkWidget *dropdown; |
| |
120 |
| |
121 /* Setup the window. */ |
| |
122 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| |
123 gtk_container_set_border_width(GTK_CONTAINER(window), 6); |
| |
124 |
| |
125 g_signal_connect(G_OBJECT(window), "delete_event", |
| |
126 G_CALLBACK(window_closed_cb), NULL); |
| |
127 |
| |
128 /* Main hbox */ |
| |
129 hbox = gtk_hbox_new(FALSE, 6); |
| |
130 gtk_container_add(GTK_CONTAINER(window), hbox); |
| |
131 |
| |
132 /* Account drop-down menu. */ |
| |
133 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
| |
134 G_CALLBACK(account_changed_cb), NULL, NULL); |
| |
135 |
| |
136 if (gaim_connections_get_all()) |
| |
137 account = (GaimAccount *)gaim_connections_get_all()->data; |
| |
138 |
| |
139 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
| |
140 |
| |
141 /* Entry box */ |
| |
142 entry = gtk_entry_new(); |
| |
143 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); |
| |
144 |
| |
145 g_signal_connect(G_OBJECT(entry), "activate", |
| |
146 G_CALLBACK(text_sent_cb), NULL); |
| |
147 |
| |
148 gtk_widget_show_all(window); |
| |
149 |
| |
150 return TRUE; |
| |
151 } |
| |
152 |
| |
153 static gboolean |
| |
154 plugin_unload(GaimPlugin *plugin) |
| |
155 { |
| |
156 if (window) |
| |
157 gtk_widget_destroy(window); |
| |
158 |
| |
159 window = NULL; |
| |
160 |
| |
161 return TRUE; |
| |
162 } |
| |
163 |
| |
164 static GaimPluginInfo info = |
| |
165 { |
| |
166 GAIM_PLUGIN_MAGIC, |
| |
167 GAIM_MAJOR_VERSION, |
| |
168 GAIM_MINOR_VERSION, |
| |
169 GAIM_PLUGIN_STANDARD, |
| |
170 GAIM_GTK_PLUGIN_TYPE, |
| |
171 0, |
| |
172 NULL, |
| |
173 GAIM_PRIORITY_DEFAULT, |
| |
174 RAW_PLUGIN_ID, |
| |
175 N_("Raw"), |
| |
176 VERSION, |
| |
177 N_("Lets you send raw input to text-based protocols."), |
| |
178 N_("Lets you send raw input to text-based protocols (Jabber, MSN, IRC, " |
| |
179 "TOC). Hit 'Enter' in the entry box to send. Watch the debug window."), |
| |
180 "Eric Warmenhoven <eric@warmenhoven.org>", |
| |
181 GAIM_WEBSITE, |
| |
182 plugin_load, |
| |
183 plugin_unload, |
| |
184 NULL, |
| |
185 NULL, |
| |
186 NULL, |
| |
187 NULL, |
| |
188 NULL |
| |
189 }; |
| |
190 |
| |
191 static void |
| |
192 init_plugin(GaimPlugin *plugin) |
| |
193 { |
| |
194 my_plugin = plugin; |
| |
195 } |
| |
196 |
| |
197 GAIM_INIT_PLUGIN(raw, init_plugin, info) |