2 * Purple - Send raw data across the connections of some protocols.
4 * Pidgin 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
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #include "conversation.h"
32 #include "gtk3compat.h"
33 #include "gtkplugin.h"
36 #include "protocols/jabber/jabber.h"
37 #include "protocols/msn/session.h"
44 #define RAW_PLUGIN_ID "gtk-raw"
46 static GtkWidget
*window
= NULL
;
47 static PurpleAccount
*account
= NULL
;
48 static PurplePlugin
*my_plugin
= NULL
;
53 purple_plugin_unload(my_plugin
, NULL
);
59 text_sent_cb(GtkEntry
*entry
)
63 const char *protocol_id
;
68 gc
= purple_account_get_connection(account
);
70 txt
= gtk_entry_get_text(entry
);
72 protocol_id
= purple_account_get_protocol_id(account
);
74 purple_debug_misc("raw", "protocol_id = %s\n", protocol_id
);
76 if (strcmp(protocol_id
, "prpl-toc") == 0) {
77 int *a
= (int *)purple_connection_get_protocol_data(gc
);
78 unsigned short seqno
= htons(a
[1]++ & 0xffff);
79 unsigned short len
= htons(strlen(txt
) + 1);
80 write(*a
, "*\002", 2);
83 write(*a
, txt
, ntohs(len
));
84 purple_debug(PURPLE_DEBUG_MISC
, "raw", "TOC C: %s\n", txt
);
86 } else if (strcmp(protocol_id
, "prpl-msn") == 0) {
87 MsnSession
*session
= purple_connection_get_protocol_data(gc
);
88 char buf
[strlen(txt
) + 3];
90 g_snprintf(buf
, sizeof(buf
), "%s\r\n", txt
);
91 msn_servconn_write(session
->notification
->servconn
, buf
, strlen(buf
));
93 } else if (strcmp(protocol_id
, "prpl-irc") == 0) {
94 write(*(int *)purple_connection_get_protocol_data(gc
), txt
, strlen(txt
));
95 write(*(int *)purple_connection_get_protocol_data(gc
), "\r\n", 2);
96 purple_debug(PURPLE_DEBUG_MISC
, "raw", "IRC C: %s\n", txt
);
98 } else if (strcmp(protocol_id
, "prpl-jabber") == 0) {
99 jabber_send_raw((JabberStream
*)purple_connection_get_protocol_data(gc
), txt
, -1);
102 purple_debug_error("raw", "Unknown protocol ID %s\n", protocol_id
);
105 gtk_entry_set_text(entry
, "");
109 account_changed_cb(GtkWidget
*dropdown
, PurpleAccount
*new_account
,
112 account
= new_account
;
115 static PidginPluginInfo
*
116 plugin_query(GError
**error
)
118 const gchar
* const authors
[] = {
119 "Eric Warmenhoven <eric@warmenhoven.org>",
123 return pidgin_plugin_info_new(
126 "version", DISPLAY_VERSION
,
127 "category", N_("Protocol utility"),
128 "summary", N_("Lets you send raw input to text-based protocols."),
129 "description", N_("Lets you send raw input to text-based protocols "
130 "(XMPP, MSN, IRC, TOC). Hit 'Enter' in the entry "
131 "box to send. Watch the debug window."),
133 "website", PURPLE_WEBSITE
,
134 "abi-version", PURPLE_ABI_VERSION
,
140 plugin_load(PurplePlugin
*plugin
, GError
**error
)
148 /* Setup the window. */
149 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
150 gtk_container_set_border_width(GTK_CONTAINER(window
), 6);
152 g_signal_connect(G_OBJECT(window
), "delete_event",
153 G_CALLBACK(window_closed_cb
), NULL
);
156 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 6);
157 gtk_container_add(GTK_CONTAINER(window
), hbox
);
159 /* Account drop-down menu. */
160 dropdown
= pidgin_account_option_menu_new(NULL
, FALSE
,
161 G_CALLBACK(account_changed_cb
), NULL
, NULL
);
163 if (purple_connections_get_all())
164 account
= (PurpleAccount
*)purple_connections_get_all()->data
;
166 gtk_box_pack_start(GTK_BOX(hbox
), dropdown
, FALSE
, FALSE
, 0);
169 entry
= gtk_entry_new();
170 gtk_box_pack_start(GTK_BOX(hbox
), entry
, FALSE
, FALSE
, 0);
172 g_signal_connect(G_OBJECT(entry
), "activate",
173 G_CALLBACK(text_sent_cb
), NULL
);
175 gtk_widget_show_all(window
);
181 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
184 gtk_widget_destroy(window
);
192 PURPLE_PLUGIN_INIT(raw
, plugin_query
, plugin_load
, plugin_unload
);