| 1 #define GAIM_PLUGINS |
|
| 2 #include "gaim.h" |
1 #include "gaim.h" |
| 3 #include "prpl.h" |
2 #include "prpl.h" |
| |
3 #include "gtkplugin.h" |
| 4 #ifdef MAX |
4 #ifdef MAX |
| 5 #undef MAX |
5 #undef MAX |
| 6 #undef MIN |
6 #undef MIN |
| 7 #endif |
7 #endif |
| 8 #include "protocols/jabber/jabber.h" |
8 #include "protocols/jabber/jabber.h" |
| |
9 #include "protocols/msn/session.h" |
| |
10 |
| |
11 #define RAW_PLUGIN_ID "raw" |
| 9 |
12 |
| 10 static GtkWidget *window = NULL; |
13 static GtkWidget *window = NULL; |
| 11 static GtkWidget *optmenu = NULL; |
14 static GtkWidget *optmenu = NULL; |
| 12 static struct gaim_connection *gc = NULL; |
15 static struct gaim_connection *gc = NULL; |
| 13 static GModule *me = NULL; |
16 static GaimPlugin *me = NULL; |
| 14 |
|
| 15 /* this is an evil hack. |
|
| 16 * gc->proto_data for Jabber connections can be cast to a jconn *. |
|
| 17 * gc->proto_data for MSN, TOC, and IRC connections can be cast to an int *. |
|
| 18 */ |
|
| 19 |
|
| 20 struct gaim_plugin_description desc; |
|
| 21 struct gaim_plugin_description *gaim_plugin_desc() { |
|
| 22 desc.api_version = GAIM_PLUGIN_API_VERSION; |
|
| 23 desc.name = g_strdup("Raw Input"); |
|
| 24 desc.version = g_strdup(VERSION); |
|
| 25 desc.description = g_strdup("Lets you send raw input to text-vased protocols (Jabber, MSN, IRC, TOC). Hit 'Enter' in the entry box to send. Watch the debug window."); |
|
| 26 desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); |
|
| 27 desc.url = g_strdup(WEBSITE); |
|
| 28 return &desc; |
|
| 29 } |
|
| 30 |
|
| 31 |
|
| 32 char *name() |
|
| 33 { |
|
| 34 return "Raw"; |
|
| 35 } |
|
| 36 |
|
| 37 char *description() |
|
| 38 { |
|
| 39 return "Lets you send raw XML to Jabber, or raw commands to MSN, IRC, and TOC." |
|
| 40 " Not very useful except for debugging. Hit 'enter' in the entry to send." |
|
| 41 " Watch the debug window."; |
|
| 42 } |
|
| 43 |
17 |
| 44 static int goodbye() |
18 static int goodbye() |
| 45 { |
19 { |
| 46 gaim_plugin_unload_self(me); |
20 gaim_plugin_unload(me); |
| 47 return FALSE; |
21 return FALSE; |
| 48 } |
22 } |
| 49 |
23 |
| 50 static void send_it(GtkEntry *entry) |
24 static void send_it(GtkEntry *entry) |
| 51 { |
25 { |
| 52 const char *txt; |
26 const char *txt; |
| 53 if (!gc) return; |
27 if (!gc) return; |
| 54 txt = gtk_entry_get_text(entry); |
28 txt = gtk_entry_get_text(entry); |
| 55 switch (gc->protocol) { |
29 switch (gc->protocol) { |
| 56 case PROTO_TOC: |
30 case GAIM_PROTO_TOC: |
| 57 { |
31 { |
| 58 int *a = (int *)gc->proto_data; |
32 int *a = (int *)gc->proto_data; |
| 59 unsigned short seqno = htons(a[1]++ & 0xffff); |
33 unsigned short seqno = htons(a[1]++ & 0xffff); |
| 60 unsigned short len = htons(strlen(txt) + 1); |
34 unsigned short len = htons(strlen(txt) + 1); |
| 61 write(*a, "*\002", 2); |
35 write(*a, "*\002", 2); |
| 63 write(*a, &len, 2); |
37 write(*a, &len, 2); |
| 64 write(*a, txt, ntohs(len)); |
38 write(*a, txt, ntohs(len)); |
| 65 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); |
39 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); |
| 66 } |
40 } |
| 67 break; |
41 break; |
| 68 case PROTO_MSN: |
42 case GAIM_PROTO_MSN: |
| 69 write(*(int *)gc->proto_data, txt, strlen(txt)); |
43 { |
| 70 write(*(int *)gc->proto_data, "\r\n", 2); |
44 MsnSession *session = gc->proto_data; |
| 71 gaim_debug(GAIM_DEBUG_MISC, "raw", "MSN C: %s\n", txt); |
45 char buf[strlen(txt) + 3]; |
| |
46 |
| |
47 g_snprintf(buf, sizeof(buf), "%s\r\n", txt); |
| |
48 msn_servconn_write(session->notification_conn, buf, strlen(buf)); |
| |
49 } |
| 72 break; |
50 break; |
| 73 case PROTO_IRC: |
51 case GAIM_PROTO_IRC: |
| 74 write(*(int *)gc->proto_data, txt, strlen(txt)); |
52 write(*(int *)gc->proto_data, txt, strlen(txt)); |
| 75 write(*(int *)gc->proto_data, "\r\n", 2); |
53 write(*(int *)gc->proto_data, "\r\n", 2); |
| 76 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); |
54 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); |
| 77 break; |
55 break; |
| 78 case PROTO_JABBER: |
56 case GAIM_PROTO_JABBER: |
| 79 jab_send_raw(*(jconn *)gc->proto_data, txt); |
57 jab_send_raw(*(jconn *)gc->proto_data, txt); |
| 80 break; |
58 break; |
| 81 } |
59 } |
| 82 gtk_entry_set_text(entry, ""); |
60 gtk_entry_set_text(entry, ""); |
| 83 } |
61 } |
| 101 GtkWidget *opt; |
79 GtkWidget *opt; |
| 102 c = (struct gaim_connection *)g->data; |
80 c = (struct gaim_connection *)g->data; |
| 103 g = g->next; |
81 g = g->next; |
| 104 if (x && c == arg) |
82 if (x && c == arg) |
| 105 continue; |
83 continue; |
| 106 if (c->protocol != PROTO_TOC && c->protocol != PROTO_MSN && |
84 if (c->protocol != GAIM_PROTO_TOC && c->protocol != GAIM_PROTO_MSN && |
| 107 c->protocol != PROTO_IRC && c->protocol != PROTO_JABBER) |
85 c->protocol != GAIM_PROTO_IRC && c->protocol != GAIM_PROTO_JABBER) |
| 108 continue; |
86 continue; |
| 109 if (!gc) |
87 if (!gc) |
| 110 gc = c; |
88 gc = c; |
| 111 g_snprintf(buf, sizeof buf, "%s (%s)", c->username, c->prpl->name); |
89 g_snprintf(buf, sizeof buf, "%s (%s)", c->username, |
| |
90 c->prpl->info->name); |
| 112 opt = gtk_menu_item_new_with_label(buf); |
91 opt = gtk_menu_item_new_with_label(buf); |
| 113 g_signal_connect(G_OBJECT(opt), "activate", G_CALLBACK(set_gc), c); |
92 g_signal_connect(G_OBJECT(opt), "activate", G_CALLBACK(set_gc), c); |
| 114 gtk_widget_show(opt); |
93 gtk_widget_show(opt); |
| 115 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
94 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt); |
| 116 } |
95 } |
| 118 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); |
97 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu)); |
| 119 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); |
98 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); |
| 120 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); |
99 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0); |
| 121 } |
100 } |
| 122 |
101 |
| 123 char *gaim_plugin_init(GModule *h) |
102 static gboolean |
| |
103 plugin_load(GaimPlugin *plugin) |
| 124 { |
104 { |
| 125 GtkWidget *hbox; |
105 GtkWidget *hbox; |
| 126 GtkWidget *entry; |
106 GtkWidget *entry; |
| 127 |
107 |
| 128 me = h; |
108 gaim_signal_connect(plugin, event_signon, redo_optmenu, NULL); |
| 129 |
109 gaim_signal_connect(plugin, event_signoff, redo_optmenu, me); |
| 130 gaim_signal_connect(h, event_signon, redo_optmenu, NULL); |
|
| 131 gaim_signal_connect(h, event_signoff, redo_optmenu, me); |
|
| 132 |
110 |
| 133 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
111 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 134 g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(goodbye), NULL); |
112 g_signal_connect(G_OBJECT(window), "delete_event", |
| |
113 G_CALLBACK(goodbye), NULL); |
| 135 |
114 |
| 136 hbox = gtk_hbox_new(FALSE, 0); |
115 hbox = gtk_hbox_new(FALSE, 0); |
| 137 gtk_container_add(GTK_CONTAINER(window), hbox); |
116 gtk_container_add(GTK_CONTAINER(window), hbox); |
| 138 |
117 |
| 139 optmenu = gtk_option_menu_new(); |
118 optmenu = gtk_option_menu_new(); |
| 145 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); |
124 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); |
| 146 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(send_it), NULL); |
125 g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(send_it), NULL); |
| 147 |
126 |
| 148 gtk_widget_show_all(window); |
127 gtk_widget_show_all(window); |
| 149 |
128 |
| 150 return NULL; |
129 return TRUE; |
| 151 } |
130 } |
| 152 |
131 |
| 153 void gaim_plugin_remove() |
132 static gboolean |
| |
133 plugin_unload(GaimPlugin *plugin) |
| 154 { |
134 { |
| 155 if (window) |
135 if (window) |
| 156 gtk_widget_destroy(window); |
136 gtk_widget_destroy(window); |
| |
137 |
| 157 window = NULL; |
138 window = NULL; |
| 158 me = NULL; |
139 |
| |
140 return TRUE; |
| 159 } |
141 } |
| |
142 |
| |
143 static GaimPluginInfo info = |
| |
144 { |
| |
145 2, |
| |
146 GAIM_PLUGIN_STANDARD, |
| |
147 GAIM_GTK_PLUGIN_TYPE, |
| |
148 0, |
| |
149 NULL, |
| |
150 GAIM_PRIORITY_DEFAULT, |
| |
151 RAW_PLUGIN_ID, |
| |
152 N_("Raw"), |
| |
153 VERSION, |
| |
154 N_("Lets you send raw input to text-vased protocols."), |
| |
155 N_("Lets you send raw input to text-vased protocols (Jabber, MSN, IRC, " |
| |
156 "TOC). Hit 'Enter' in the entry box to send. Watch the debug window."), |
| |
157 "Eric Warmenhoven <eric@warmenhoven.org>", |
| |
158 WEBSITE, |
| |
159 plugin_load, |
| |
160 plugin_unload, |
| |
161 NULL, |
| |
162 NULL, |
| |
163 NULL |
| |
164 }; |
| |
165 |
| |
166 static void |
| |
167 __init_plugin(GaimPlugin *plugin) |
| |
168 { |
| |
169 me = plugin; |
| |
170 } |
| |
171 |
| |
172 GAIM_INIT_PLUGIN(raw, __init_plugin, info); |