Mercurial > pidgin.yaz
annotate plugins/raw.c @ 11246:df67c09ade6e
[gaim-migrate @ 13415]
Fix another one of those gaim_request handler bugs.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 13 Aug 2005 00:49:50 +0000 |
parents | 50224ac8184d |
children | bb0d7b719af2 |
rev | line source |
---|---|
10884 | 1 #define GAIM_PLUGINS |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
2 #include "conversation.h" |
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
3 #include "debug.h" |
2495 | 4 #include "prpl.h" |
9954 | 5 #include "version.h" |
9821 | 6 |
7 #include "gtkgaim.h" | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
8 #include "gtkplugin.h" |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
9 #include "gtkutils.h" |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
10 |
2495 | 11 #ifdef MAX |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
12 # undef MAX |
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
13 # undef MIN |
2495 | 14 #endif |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
15 |
2824
2c39e70dd07c
[gaim-migrate @ 2837]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2495
diff
changeset
|
16 #include "protocols/jabber/jabber.h" |
10884 | 17 #undef GAIM_PLUGINS |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
18 #include "protocols/msn/session.h" |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
19 |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
20 #define RAW_PLUGIN_ID "gtk-raw" |
2495 | 21 |
22 static GtkWidget *window = NULL; | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
23 static GaimAccount *account = NULL; |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
24 static GaimPlugin *my_plugin = NULL; |
2495 | 25 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
26 static int |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
27 window_closed_cb() |
2495 | 28 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
29 gaim_plugin_unload(my_plugin); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
30 |
2495 | 31 return FALSE; |
32 } | |
33 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
34 static void |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
35 text_sent_cb(GtkEntry *entry) |
2495 | 36 { |
4655 | 37 const char *txt; |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
38 GaimConnection *gc; |
9460 | 39 const char *prpl_id; |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
40 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
41 if (account == NULL) |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
42 return; |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
43 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
44 gc = gaim_account_get_connection(account); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
45 |
2495 | 46 txt = gtk_entry_get_text(entry); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
47 |
9460 | 48 prpl_id = gaim_account_get_protocol_id(account); |
49 | |
50 gaim_debug_misc("raw", "prpl_id = %s\n", prpl_id); | |
51 | |
52 if (strcmp(prpl_id, "prpl-toc") == 0) { | |
53 int *a = (int *)gc->proto_data; | |
54 unsigned short seqno = htons(a[1]++ & 0xffff); | |
55 unsigned short len = htons(strlen(txt) + 1); | |
56 write(*a, "*\002", 2); | |
57 write(*a, &seqno, 2); | |
58 write(*a, &len, 2); | |
59 write(*a, txt, ntohs(len)); | |
60 gaim_debug(GAIM_DEBUG_MISC, "raw", "TOC C: %s\n", txt); | |
61 | |
62 } else if (strcmp(prpl_id, "prpl-msn") == 0) { | |
63 MsnSession *session = gc->proto_data; | |
64 char buf[strlen(txt) + 3]; | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
65 |
9460 | 66 g_snprintf(buf, sizeof(buf), "%s\r\n", txt); |
67 msn_servconn_write(session->notification->servconn, buf, strlen(buf)); | |
68 | |
69 } else if (strcmp(prpl_id, "prpl-irc") == 0) { | |
70 write(*(int *)gc->proto_data, txt, strlen(txt)); | |
71 write(*(int *)gc->proto_data, "\r\n", 2); | |
72 gaim_debug(GAIM_DEBUG_MISC, "raw", "IRC C: %s\n", txt); | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
73 |
9460 | 74 } else if (strcmp(prpl_id, "prpl-jabber") == 0) { |
75 jabber_send_raw((JabberStream *)gc->proto_data, txt, -1); | |
76 } else { | |
77 gaim_debug_error("raw", "Unknown protocol ID %s\n", prpl_id); | |
2495 | 78 } |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
79 |
2495 | 80 gtk_entry_set_text(entry, ""); |
81 } | |
82 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
83 static void |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
84 account_changed_cb(GtkWidget *dropdown, GaimAccount *new_account, |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
85 void *user_data) |
2495 | 86 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
87 account = new_account; |
2495 | 88 } |
89 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
90 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
91 plugin_load(GaimPlugin *plugin) |
2495 | 92 { |
93 GtkWidget *hbox; | |
94 GtkWidget *entry; | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
95 GtkWidget *dropdown; |
2495 | 96 |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10884
diff
changeset
|
97 gaim_debug_register_category("raw"); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10884
diff
changeset
|
98 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
99 /* Setup the window. */ |
2495 | 100 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
6389
c05c02b6bfc8
[gaim-migrate @ 6894]
Christian Hammond <chipx86@chipx86.com>
parents:
6388
diff
changeset
|
101 gtk_container_set_border_width(GTK_CONTAINER(window), 6); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
102 |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
103 g_signal_connect(G_OBJECT(window), "delete_event", |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
104 G_CALLBACK(window_closed_cb), NULL); |
2495 | 105 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
106 /* Main hbox */ |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
107 hbox = gtk_hbox_new(FALSE, 6); |
2495 | 108 gtk_container_add(GTK_CONTAINER(window), hbox); |
109 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
110 /* Account drop-down menu. */ |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
111 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
6647
ed89cd0c675e
[gaim-migrate @ 7172]
Christian Hammond <chipx86@chipx86.com>
parents:
6390
diff
changeset
|
112 G_CALLBACK(account_changed_cb), NULL, NULL); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
113 |
6390
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
114 if (gaim_connections_get_all()) |
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
115 account = (GaimAccount *)gaim_connections_get_all()->data; |
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
116 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
117 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
2495 | 118 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
119 /* Entry box */ |
2495 | 120 entry = gtk_entry_new(); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
121 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
122 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
123 g_signal_connect(G_OBJECT(entry), "activate", |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
124 G_CALLBACK(text_sent_cb), NULL); |
2495 | 125 |
126 gtk_widget_show_all(window); | |
127 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
128 return TRUE; |
2495 | 129 } |
130 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
131 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
132 plugin_unload(GaimPlugin *plugin) |
2495 | 133 { |
134 if (window) | |
135 gtk_widget_destroy(window); | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
136 |
2495 | 137 window = NULL; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
138 |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10884
diff
changeset
|
139 gaim_debug_register_category("raw"); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10884
diff
changeset
|
140 |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
141 return TRUE; |
2495 | 142 } |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
143 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
144 static GaimPluginInfo info = |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
145 { |
9954 | 146 GAIM_PLUGIN_MAGIC, |
147 GAIM_MAJOR_VERSION, | |
148 GAIM_MINOR_VERSION, | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
149 GAIM_PLUGIN_STANDARD, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
150 GAIM_GTK_PLUGIN_TYPE, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
151 0, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
152 NULL, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
153 GAIM_PRIORITY_DEFAULT, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
154 RAW_PLUGIN_ID, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
155 N_("Raw"), |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
156 VERSION, |
5424 | 157 N_("Lets you send raw input to text-based protocols."), |
158 N_("Lets you send raw input to text-based protocols (Jabber, MSN, IRC, " | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
159 "TOC). Hit 'Enter' in the entry box to send. Watch the debug window."), |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
160 "Eric Warmenhoven <eric@warmenhoven.org>", |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6063
diff
changeset
|
161 GAIM_WEBSITE, |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
162 plugin_load, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
163 plugin_unload, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
164 NULL, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
165 NULL, |
8993 | 166 NULL, |
167 NULL, | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
168 NULL |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
169 }; |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
170 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
171 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5424
diff
changeset
|
172 init_plugin(GaimPlugin *plugin) |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
173 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
174 my_plugin = plugin; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
175 } |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
176 |
6063 | 177 GAIM_INIT_PLUGIN(raw, init_plugin, info) |