Mercurial > pidgin.yaz
annotate plugins/raw.c @ 19753:88b0c434259a
[gaim-migrate @ 16733]
change the BL process method
continue to debug
This is an in progress version,continue to add support for send Yahoo Message
committed by Ma Yuan <mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Sun, 13 Aug 2006 06:09:48 +0000 |
parents | 440d9354b67f |
children |
rev | line source |
---|---|
12019 | 1 /* |
12020 | 2 * Gaim - Send raw data across the connections of some protocols. |
12019 | 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 | |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
27 #include "conversation.h" |
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
28 #include "debug.h" |
2495 | 29 #include "prpl.h" |
9954 | 30 #include "version.h" |
9821 | 31 |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
32 #include "gtkplugin.h" |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
33 #include "gtkutils.h" |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
34 |
12020 | 35 #include "protocols/jabber/jabber.h" |
36 #include "protocols/msn/session.h" | |
37 | |
2495 | 38 #ifdef MAX |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
39 # undef MAX |
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
40 # undef MIN |
2495 | 41 #endif |
6387
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
42 |
b9c9f4d6f5d8
[gaim-migrate @ 6892]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
43 #define RAW_PLUGIN_ID "gtk-raw" |
2495 | 44 |
45 static GtkWidget *window = NULL; | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
46 static GaimAccount *account = NULL; |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
47 static GaimPlugin *my_plugin = NULL; |
2495 | 48 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
49 static int |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
50 window_closed_cb() |
2495 | 51 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
52 gaim_plugin_unload(my_plugin); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
53 |
2495 | 54 return FALSE; |
55 } | |
56 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
57 static void |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
58 text_sent_cb(GtkEntry *entry) |
2495 | 59 { |
4655 | 60 const char *txt; |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
61 GaimConnection *gc; |
9460 | 62 const char *prpl_id; |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
63 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
64 if (account == NULL) |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
65 return; |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
66 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
67 gc = gaim_account_get_connection(account); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
68 |
2495 | 69 txt = gtk_entry_get_text(entry); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
70 |
9460 | 71 prpl_id = gaim_account_get_protocol_id(account); |
12019 | 72 |
9460 | 73 gaim_debug_misc("raw", "prpl_id = %s\n", prpl_id); |
12019 | 74 |
9460 | 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); | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
84 |
12020 | 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 | |
9460 | 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); | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
96 |
12020 | 97 } else if (strcmp(prpl_id, "prpl-jabber") == 0) { |
98 jabber_send_raw((JabberStream *)gc->proto_data, txt, -1); | |
99 | |
9460 | 100 } else { |
101 gaim_debug_error("raw", "Unknown protocol ID %s\n", prpl_id); | |
2495 | 102 } |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
103 |
2495 | 104 gtk_entry_set_text(entry, ""); |
105 } | |
106 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
107 static void |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
108 account_changed_cb(GtkWidget *dropdown, GaimAccount *new_account, |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
109 void *user_data) |
2495 | 110 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
111 account = new_account; |
2495 | 112 } |
113 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
114 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
115 plugin_load(GaimPlugin *plugin) |
2495 | 116 { |
117 GtkWidget *hbox; | |
118 GtkWidget *entry; | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
119 GtkWidget *dropdown; |
2495 | 120 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
121 /* Setup the window. */ |
2495 | 122 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
6389
c05c02b6bfc8
[gaim-migrate @ 6894]
Christian Hammond <chipx86@chipx86.com>
parents:
6388
diff
changeset
|
123 gtk_container_set_border_width(GTK_CONTAINER(window), 6); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
124 |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
125 g_signal_connect(G_OBJECT(window), "delete_event", |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
126 G_CALLBACK(window_closed_cb), NULL); |
2495 | 127 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
128 /* Main hbox */ |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
129 hbox = gtk_hbox_new(FALSE, 6); |
2495 | 130 gtk_container_add(GTK_CONTAINER(window), hbox); |
131 | |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
132 /* Account drop-down menu. */ |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
133 dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, |
6647
ed89cd0c675e
[gaim-migrate @ 7172]
Christian Hammond <chipx86@chipx86.com>
parents:
6390
diff
changeset
|
134 G_CALLBACK(account_changed_cb), NULL, NULL); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
135 |
6390
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
136 if (gaim_connections_get_all()) |
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
137 account = (GaimAccount *)gaim_connections_get_all()->data; |
7788dd90cfe7
[gaim-migrate @ 6895]
Christian Hammond <chipx86@chipx86.com>
parents:
6389
diff
changeset
|
138 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
139 gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); |
2495 | 140 |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
141 /* Entry box */ |
2495 | 142 entry = gtk_entry_new(); |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
143 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
144 |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
145 g_signal_connect(G_OBJECT(entry), "activate", |
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
146 G_CALLBACK(text_sent_cb), NULL); |
2495 | 147 |
148 gtk_widget_show_all(window); | |
149 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
150 return TRUE; |
2495 | 151 } |
152 | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
153 static gboolean |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
154 plugin_unload(GaimPlugin *plugin) |
2495 | 155 { |
156 if (window) | |
157 gtk_widget_destroy(window); | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
158 |
2495 | 159 window = NULL; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
160 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
161 return TRUE; |
2495 | 162 } |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
163 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
164 static GaimPluginInfo info = |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
165 { |
9954 | 166 GAIM_PLUGIN_MAGIC, |
167 GAIM_MAJOR_VERSION, | |
168 GAIM_MINOR_VERSION, | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
169 GAIM_PLUGIN_STANDARD, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
170 GAIM_GTK_PLUGIN_TYPE, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
171 0, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
172 NULL, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
173 GAIM_PRIORITY_DEFAULT, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
174 RAW_PLUGIN_ID, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
175 N_("Raw"), |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
176 VERSION, |
5424 | 177 N_("Lets you send raw input to text-based protocols."), |
12020 | 178 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
|
179 "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
|
180 "Eric Warmenhoven <eric@warmenhoven.org>", |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6063
diff
changeset
|
181 GAIM_WEBSITE, |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
182 plugin_load, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
183 plugin_unload, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
184 NULL, |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
185 NULL, |
8993 | 186 NULL, |
187 NULL, | |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
188 NULL |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
189 }; |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
190 |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
191 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5424
diff
changeset
|
192 init_plugin(GaimPlugin *plugin) |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
193 { |
6388
9e49daffac97
[gaim-migrate @ 6893]
Christian Hammond <chipx86@chipx86.com>
parents:
6387
diff
changeset
|
194 my_plugin = plugin; |
5320
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
195 } |
9445d59d9db8
[gaim-migrate @ 5692]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
196 |
6063 | 197 GAIM_INIT_PLUGIN(raw, init_plugin, info) |