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"
35 #include "pidginaccountchooser.h"
37 #include "protocols/jabber/jabber.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 (purple_strequal(protocol_id
, "prpl-toc")protocol_id
) {
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 (purple_strequal(protocol_id
, "prpl-irc")) {
87 write(*(int *)gc
->proto_data
, txt
, strlen(txt
));
88 write(*(int *)gc
->proto_data
, "\r\n", 2);
89 purple_debug(PURPLE_DEBUG_MISC
, "raw", "IRC C: %s\n", txt
);
91 } else if (purple_strequal(protocol_id
, "prpl-jabber")) {
92 jabber_send_raw((JabberStream
*)purple_connection_get_protocol_data(gc
), txt
, -1);
95 purple_debug_error("raw", "Unknown protocol ID %s\n", protocol_id
);
98 gtk_entry_set_text(entry
, "");
102 account_changed_cb(GtkWidget
*chooser
, void *user_data
)
104 account
= pidgin_account_chooser_get_selected(chooser
);
107 static PidginPluginInfo
*
108 plugin_query(GError
**error
)
110 const gchar
* const authors
[] = {
111 "Eric Warmenhoven <eric@warmenhoven.org>",
115 return pidgin_plugin_info_new(
118 "version", DISPLAY_VERSION
,
119 "category", N_("Protocol utility"),
120 "summary", N_("Lets you send raw input to text-based protocols."),
121 "description", N_("Lets you send raw input to text-based protocols "
122 "(XMPP, IRC, TOC). Hit 'Enter' in the entry "
123 "box to send. Watch the debug window."),
125 "website", PURPLE_WEBSITE
,
126 "abi-version", PURPLE_ABI_VERSION
,
132 plugin_load(PurplePlugin
*plugin
, GError
**error
)
140 /* Setup the window. */
141 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
142 gtk_container_set_border_width(GTK_CONTAINER(window
), 6);
144 g_signal_connect(G_OBJECT(window
), "delete_event",
145 G_CALLBACK(window_closed_cb
), NULL
);
148 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 6);
149 gtk_container_add(GTK_CONTAINER(window
), hbox
);
151 /* Account drop-down menu. */
152 dropdown
= pidgin_account_chooser_new(NULL
, FALSE
);
153 g_signal_connect(dropdown
, "changed", G_CALLBACK(account_changed_cb
),
156 if (purple_connections_get_all())
157 account
= (PurpleAccount
*)purple_connections_get_all()->data
;
159 gtk_box_pack_start(GTK_BOX(hbox
), dropdown
, FALSE
, FALSE
, 0);
162 entry
= gtk_entry_new();
163 gtk_box_pack_start(GTK_BOX(hbox
), entry
, FALSE
, FALSE
, 0);
165 g_signal_connect(G_OBJECT(entry
), "activate",
166 G_CALLBACK(text_sent_cb
), NULL
);
168 gtk_widget_show_all(window
);
174 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
177 gtk_widget_destroy(window
);
185 PURPLE_PLUGIN_INIT(raw
, plugin_query
, plugin_load
, plugin_unload
);