Wed, 19 Sep 2007 22:55:19 +0000
You can actually receive Google Talk voice calls with crappy UI now
| 15225 | 1 | /** |
| 15884 | 2 | * Purple is the legal property of its developers, whose names are too numerous |
| 15225 | 3 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 4 | * source distribution. | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | */ | |
| 20 | ||
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
21 | #include <farsight/farsight-transport.h> |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
22 | |
| 15225 | 23 | #include "internal.h" |
| 24 | #include "debug.h" | |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
25 | #include "mediamanager.h" |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
26 | #include "util.h" |
| 15265 | 27 | #include "privacy.h" |
| 28 | ||
| 29 | #include "buddy.h" | |
| 15225 | 30 | #include "google.h" |
| 31 | #include "jabber.h" | |
| 15265 | 32 | #include "presence.h" |
| 15225 | 33 | #include "iq.h" |
| 34 | ||
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
35 | typedef struct { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
36 | char *id; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
37 | char *initiator; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
38 | } GoogleSessionId; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
39 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
40 | typedef enum { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
41 | UNINIT, |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
42 | SENT_INITIATE, |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
43 | RECEIVED_INITIATE, |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
44 | IN_PRORESS, |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
45 | TERMINATED |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
46 | } GoogleSessionState; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
47 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
48 | typedef struct { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
49 | GoogleSessionId id; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
50 | GoogleSessionState state; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
51 | PurpleMedia *media; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
52 | FarsightStream *stream; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
53 | JabberStream *js; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
54 | char *remote_jid; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
55 | } GoogleSession; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
56 | |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
57 | GHashTable *sessions = NULL; |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
58 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
59 | static guint |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
60 | google_session_id_hash(gconstpointer key) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
61 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
62 | GoogleSessionId *id = (GoogleSessionId*)key; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
63 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
64 | guint id_hash = g_str_hash(id->id); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
65 | guint init_hash = g_str_hash(id->initiator); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
66 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
67 | return 23 * id_hash + init_hash; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
68 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
69 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
70 | static gboolean |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
71 | google_session_id_equal(gconstpointer a, gconstpointer b) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
72 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
73 | GoogleSessionId *c = (GoogleSessionId*)a; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
74 | GoogleSessionId *d = (GoogleSessionId*)b; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
75 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
76 | return !strcmp(c->id, d->id) && !strcmp(c->initiator, d->initiator); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
77 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
78 | |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
79 | static void |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
80 | google_session_destroy(GoogleSession *session) |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
81 | { |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
82 | g_hash_table_remove(sessions, &(session->id)); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
83 | g_free(session->id.id); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
84 | g_free(session->id.initiator); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
85 | g_free(session->remote_jid); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
86 | g_object_unref(session->media); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
87 | g_object_unref(session->stream); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
88 | g_free(session); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
89 | } |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
90 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
91 | static xmlnode * |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
92 | google_session_create_xmlnode(GoogleSession *session, const char *type) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
93 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
94 | xmlnode *node = xmlnode_new("session"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
95 | xmlnode_set_namespace(node, "http://www.google.com/session"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
96 | xmlnode_set_attrib(node, "id", session->id.id); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
97 | xmlnode_set_attrib(node, "initiator", session->id.initiator); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
98 | xmlnode_set_attrib(node, "type", type); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
99 | return node; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
100 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
101 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
102 | static void |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
103 | google_session_send_accept(GoogleSession *session) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
104 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
105 | xmlnode *sess, *desc, *payload; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
106 | GList *codecs = farsight_stream_get_codec_intersection(session->stream); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
107 | JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
108 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
109 | xmlnode_set_attrib(iq->node, "to", session->remote_jid); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
110 | sess = google_session_create_xmlnode(session, "accept"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
111 | xmlnode_insert_child(iq->node, sess); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
112 | desc = xmlnode_new_child(sess, "description"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
113 | xmlnode_set_namespace(desc, "http://www.google.com/session/phone"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
114 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
115 | for (;codecs; codecs = codecs->next) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
116 | FarsightCodec *codec = (FarsightCodec*)codecs->data; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
117 | char id[8], clockrate[10]; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
118 | payload = xmlnode_new_child(desc, "payload-type"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
119 | g_snprintf(id, sizeof(id), "%d", codec->id); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
120 | g_snprintf(clockrate, sizeof(clockrate), "%d", codec->clock_rate); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
121 | xmlnode_set_attrib(payload, "name", codec->encoding_name); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
122 | xmlnode_set_attrib(payload, "id", id); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
123 | xmlnode_set_attrib(payload, "clockrate", clockrate); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
124 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
125 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
126 | jabber_iq_send(iq); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
127 | farsight_stream_start(session->stream); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
128 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
129 | |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
130 | static void |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
131 | google_session_send_terminate(GoogleSession *session) |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
132 | { |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
133 | xmlnode *sess; |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
134 | GList *codecs = farsight_stream_get_codec_intersection(session->stream); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
135 | JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
136 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
137 | xmlnode_set_attrib(iq->node, "to", session->remote_jid); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
138 | sess = google_session_create_xmlnode(session, "terminate"); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
139 | xmlnode_insert_child(iq->node, sess); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
140 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
141 | jabber_iq_send(iq); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
142 | farsight_stream_stop(session->stream); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
143 | google_session_destroy(session); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
144 | } |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
145 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
146 | static void |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
147 | google_session_send_reject(GoogleSession *session) |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
148 | { |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
149 | xmlnode *sess; |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
150 | GList *codecs = farsight_stream_get_codec_intersection(session->stream); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
151 | JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
152 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
153 | xmlnode_set_attrib(iq->node, "to", session->remote_jid); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
154 | sess = google_session_create_xmlnode(session, "reject"); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
155 | xmlnode_insert_child(iq->node, sess); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
156 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
157 | jabber_iq_send(iq); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
158 | farsight_stream_stop(session->stream); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
159 | google_session_destroy(session); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
160 | } |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
161 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
162 | |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
163 | static void |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
164 | google_session_candidates_prepared (FarsightStream *stream, gchar *candidate_id, GoogleSession *session) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
165 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
166 | JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
167 | GList *candidates = farsight_stream_get_native_candidate_list(stream); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
168 | FarsightTransportInfo *transport; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
169 | xmlnode *sess; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
170 | xmlnode *candidate; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
171 | sess = google_session_create_xmlnode(session, "candidates"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
172 | xmlnode_insert_child(iq->node, sess); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
173 | xmlnode_set_attrib(iq->node, "to", session->remote_jid); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
174 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
175 | for (;candidates;candidates = candidates->next) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
176 | transport = (FarsightTransportInfo*)(candidates->data); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
177 | char port[8]; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
178 | char pref[8]; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
179 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
180 | if (!strcmp(transport->ip, "127.0.0.1")) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
181 | continue; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
182 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
183 | candidate = xmlnode_new("candidate"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
184 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
185 | g_snprintf(port, sizeof(port), "%d", transport->port); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
186 | g_snprintf(pref, sizeof(pref), "%f", transport->preference); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
187 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
188 | xmlnode_set_attrib(candidate, "address", transport->ip); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
189 | xmlnode_set_attrib(candidate, "port", port); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
190 | xmlnode_set_attrib(candidate, "name", "rtp"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
191 | xmlnode_set_attrib(candidate, "username", transport->username); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
192 | xmlnode_set_attrib(candidate, "password", transport->password); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
193 | xmlnode_set_attrib(candidate, "preference", pref); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
194 | xmlnode_set_attrib(candidate, "protocol", transport->proto == FARSIGHT_NETWORK_PROTOCOL_UDP ? "udp" : "tcp"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
195 | xmlnode_set_attrib(candidate, "type", transport->type == FARSIGHT_CANDIDATE_TYPE_LOCAL ? "local" : |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
196 | transport->type == FARSIGHT_CANDIDATE_TYPE_DERIVED ? "stun" : |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
197 | transport->type == FARSIGHT_CANDIDATE_TYPE_RELAY ? "relay" : NULL); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
198 | xmlnode_set_attrib(candidate, "generation", "0"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
199 | xmlnode_set_attrib(candidate, "network", "0"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
200 | xmlnode_insert_child(sess, candidate); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
201 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
202 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
203 | jabber_iq_send(iq); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
204 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
205 | |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
206 | static void |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
207 | google_session_handle_initiate(JabberStream *js, GoogleSession *session, xmlnode *packet, xmlnode *sess) |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
208 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
209 | PurpleMedia *media; |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
210 | JabberIq *result; |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
211 | FarsightSession *fs; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
212 | GList *codecs = NULL; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
213 | xmlnode *desc_element, *codec_element; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
214 | FarsightCodec *codec; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
215 | const char *id, *encoding_name, *clock_rate; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
216 | int res; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
217 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
218 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
219 | if (session->state != UNINIT) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
220 | purple_debug_error("jabber", "Received initiate for active session.\n"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
221 | return FALSE; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
222 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
223 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
224 | fs = farsight_session_factory_make("rtp"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
225 | if (!fs) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
226 | purple_debug_error("jabber", "Farsight's rtp plugin not installed"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
227 | return FALSE; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
228 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
229 | session->stream = farsight_session_create_stream(fs, FARSIGHT_MEDIA_TYPE_AUDIO, FARSIGHT_STREAM_DIRECTION_BOTH); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
230 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
231 | g_object_set(G_OBJECT(session->stream), "transmitter", "libjingle", NULL); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
232 | |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
233 | desc_element = xmlnode_get_child(sess, "description"); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
234 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
235 | for (codec_element = xmlnode_get_child(desc_element, "payload-type"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
236 | codec_element; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
237 | codec_element = xmlnode_get_next_twin(codec_element)) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
238 | encoding_name = xmlnode_get_attrib(codec_element, "name"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
239 | id = xmlnode_get_attrib(codec_element, "id"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
240 | clock_rate = xmlnode_get_attrib(codec_element, "clockrate"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
241 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
242 | codec = g_new0(FarsightCodec, 1); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
243 | farsight_codec_init(codec, atoi(id), encoding_name, FARSIGHT_MEDIA_TYPE_AUDIO, clock_rate ? atoi(clock_rate) : 0); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
244 | codecs = g_list_append(codecs, codec); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
245 | } |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
246 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
247 | session->media = media = purple_media_manager_create_media(purple_media_manager_get(), js->gc, session->remote_jid, session->stream, NULL); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
248 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
249 | g_signal_connect_swapped(G_OBJECT(media), "accepted", G_CALLBACK(google_session_send_accept), session); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
250 | g_signal_connect_swapped(G_OBJECT(media), "reject", G_CALLBACK(google_session_send_reject), session); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
251 | g_signal_connect_swapped(G_OBJECT(media), "hangup", G_CALLBACK(google_session_send_terminate), session); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
252 | |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
253 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
254 | GstElement *e = purple_media_get_audio_src(media); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
255 | farsight_stream_set_source(session->stream, e); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
256 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
257 | e = purple_media_get_audio_sink(media); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
258 | farsight_stream_set_sink(session->stream, e); |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
259 | |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
260 | farsight_stream_prepare_transports(session->stream); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
261 | res = farsight_stream_set_remote_codecs(session->stream, codecs); |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
262 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
263 | purple_media_ready(media); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
264 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
265 | farsight_codec_list_destroy(codecs); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
266 | g_signal_connect(G_OBJECT(session->stream), "new-native-candidate", G_CALLBACK(google_session_candidates_prepared), session); |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
267 | result = jabber_iq_new(js, JABBER_IQ_RESULT); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
268 | jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id")); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
269 | xmlnode_set_attrib(result->node, "to", session->remote_jid); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
270 | jabber_iq_send(result); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
271 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
272 | |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
273 | static void |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
274 | google_session_handle_candidates(JabberStream *js, GoogleSession *session, xmlnode *packet, xmlnode *sess) |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
275 | { |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
276 | JabberIq *result; |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
277 | GList *list = NULL; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
278 | xmlnode *cand; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
279 | static int name = 0; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
280 | char n[4]; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
281 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
282 | for (cand = xmlnode_get_child(sess, "candidate"); cand; cand = xmlnode_get_next_twin(cand)) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
283 | FarsightTransportInfo *info = g_new0(FarsightTransportInfo, 1); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
284 | g_snprintf(n, sizeof(n), "S%d", name++); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
285 | info->ip = xmlnode_get_attrib(cand, "address"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
286 | info->port = atoi(xmlnode_get_attrib(cand, "port")); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
287 | info->proto = !strcmp(xmlnode_get_attrib(cand, "protocol"),"udp") ? FARSIGHT_NETWORK_PROTOCOL_UDP : FARSIGHT_NETWORK_PROTOCOL_TCP; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
288 | info->preference = atof(xmlnode_get_attrib(cand, "preference")); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
289 | info->type = !strcmp(xmlnode_get_attrib(cand, "type"), "local") ? FARSIGHT_CANDIDATE_TYPE_LOCAL : |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
290 | !strcmp(xmlnode_get_attrib(cand, "type"), "stun") ? FARSIGHT_CANDIDATE_TYPE_DERIVED : |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
291 | !strcmp(xmlnode_get_attrib(cand, "type"), "relay") ? FARSIGHT_CANDIDATE_TYPE_RELAY : FARSIGHT_CANDIDATE_TYPE_LOCAL; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
292 | info->candidate_id = n; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
293 | info->username = xmlnode_get_attrib(cand, "username"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
294 | info->password = xmlnode_get_attrib(cand, "password"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
295 | list = g_list_append(list, info); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
296 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
297 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
298 | farsight_stream_add_remote_candidate(session->stream, list); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
299 | g_list_foreach(list, g_free, NULL); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
300 | g_list_free(list); |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
301 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
302 | result = jabber_iq_new(js, JABBER_IQ_RESULT); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
303 | jabber_iq_set_id(result, xmlnode_get_attrib(packet, "id")); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
304 | xmlnode_set_attrib(result->node, "to", session->remote_jid); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
305 | jabber_iq_send(result); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
306 | } |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
307 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
308 | static void |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
309 | google_session_handle_reject(JabberStream *js, GoogleSession *session, xmlnode *packet, xmlnode *sess) |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
310 | { |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
311 | farsight_stream_stop(session->stream); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
312 | purple_media_got_hangup(session->media); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
313 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
314 | google_session_destroy(session); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
315 | } |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
316 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
317 | static void |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
318 | google_session_handle_terminate(JabberStream *js, GoogleSession *session, xmlnode *packet, xmlnode *sess) |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
319 | { |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
320 | farsight_stream_stop(session->stream); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
321 | purple_media_got_hangup(session->media); |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
322 | |
|
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
323 | google_session_destroy(session); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
324 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
325 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
326 | static void |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
327 | google_session_parse_iq(JabberStream *js, GoogleSession *session, xmlnode *packet) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
328 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
329 | xmlnode *sess = xmlnode_get_child(packet, "session"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
330 | const char *type = xmlnode_get_attrib(sess, "type"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
331 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
332 | if (!strcmp(type, "initiate")) { |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
333 | google_session_handle_initiate(js, session, packet, sess); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
334 | } else if (!strcmp(type, "accept")) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
335 | } else if (!strcmp(type, "reject")) { |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
336 | google_session_handle_reject(js, session, packet, sess); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
337 | } else if (!strcmp(type, "terminate")) { |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
338 | google_session_handle_terminate(js, session, packet, sess); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
339 | } else if (!strcmp(type, "candidates")) { |
|
19885
593613a22e57
You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents:
19882
diff
changeset
|
340 | google_session_handle_candidates(js, session, packet, sess); |
|
19882
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
341 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
342 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
343 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
344 | void |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
345 | jabber_google_session_parse(JabberStream *js, xmlnode *packet) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
346 | { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
347 | GoogleSession *session; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
348 | GoogleSessionId id; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
349 | JabberIq *result; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
350 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
351 | xmlnode *session_node; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
352 | xmlnode *desc_node; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
353 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
354 | if (strcmp(xmlnode_get_attrib(packet, "type"), "set")) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
355 | return; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
356 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
357 | session_node = xmlnode_get_child(packet, "session"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
358 | if (!session_node) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
359 | return; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
360 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
361 | id.id = xmlnode_get_attrib(session_node, "id"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
362 | if (!id.id) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
363 | return; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
364 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
365 | id.initiator = xmlnode_get_attrib(session_node, "initiator"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
366 | if (!id.initiator) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
367 | return; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
368 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
369 | if (sessions == NULL) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
370 | sessions = g_hash_table_new(google_session_id_hash, google_session_id_equal); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
371 | session = (GoogleSession*)g_hash_table_lookup(sessions, &id); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
372 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
373 | if (session) { |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
374 | google_session_parse_iq(js, session, packet); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
375 | return; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
376 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
377 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
378 | /* If the session doesn't exist, this has to be an initiate message */ |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
379 | if (strcmp(xmlnode_get_attrib(session_node, "type"), "initiate")) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
380 | return; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
381 | desc_node = xmlnode_get_child(session_node, "description"); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
382 | if (!desc_node) |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
383 | return; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
384 | session = g_new0(GoogleSession, 1); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
385 | session->id.id = g_strdup(id.id); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
386 | session->id.initiator = g_strdup(id.initiator); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
387 | session->state = UNINIT; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
388 | session->js = js; |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
389 | session->remote_jid = g_strdup(session->id.initiator); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
390 | g_hash_table_insert(sessions, &(session->id), session); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
391 | |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
392 | google_session_parse_iq(js, session, packet); |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
393 | } |
|
d8c2a2fc1fbf
Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents:
19046
diff
changeset
|
394 | |
| 18233 | 395 | static void |
| 15225 | 396 | jabber_gmail_parse(JabberStream *js, xmlnode *packet, gpointer nul) |
| 397 | { | |
| 398 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 399 | xmlnode *child; | |
| 400 | xmlnode *message, *sender_node, *subject_node; | |
| 18739 | 401 | const char *from, *to, *url, *tid; |
| 402 | char *subject; | |
| 15225 | 403 | const char *in_str; |
| 404 | char *to_name; | |
| 405 | int i, count = 1, returned_count; | |
| 18233 | 406 | |
| 18739 | 407 | const char **tos, **froms, **urls; |
| 408 | char **subjects; | |
| 18233 | 409 | |
| 15225 | 410 | if (strcmp(type, "result")) |
| 411 | return; | |
| 18233 | 412 | |
| 15225 | 413 | child = xmlnode_get_child(packet, "mailbox"); |
| 414 | if (!child) | |
| 415 | return; | |
| 416 | ||
| 417 | in_str = xmlnode_get_attrib(child, "total-matched"); | |
| 18233 | 418 | if (in_str && *in_str) |
| 15225 | 419 | count = atoi(in_str); |
| 18233 | 420 | |
| 421 | if (count == 0) | |
| 15225 | 422 | return; |
| 423 | ||
| 424 | message = xmlnode_get_child(child, "mail-thread-info"); | |
| 18233 | 425 | |
| 15225 | 426 | /* Loop once to see how many messages were returned so we can allocate arrays |
| 427 | * accordingly */ | |
| 18233 | 428 | if (!message) |
| 15225 | 429 | return; |
| 430 | for (returned_count = 0; message; returned_count++, message=xmlnode_get_next_twin(message)); | |
| 18233 | 431 | |
| 15225 | 432 | froms = g_new0(const char* , returned_count); |
| 433 | tos = g_new0(const char* , returned_count); | |
| 18739 | 434 | subjects = g_new0(char* , returned_count); |
| 15225 | 435 | urls = g_new0(const char* , returned_count); |
| 18233 | 436 | |
| 15225 | 437 | to = xmlnode_get_attrib(packet, "to"); |
| 438 | to_name = jabber_get_bare_jid(to); | |
| 439 | url = xmlnode_get_attrib(child, "url"); | |
| 440 | if (!url || !*url) | |
| 441 | url = "http://www.gmail.com"; | |
| 18233 | 442 | |
| 15225 | 443 | message= xmlnode_get_child(child, "mail-thread-info"); |
| 444 | for (i=0; message; message = xmlnode_get_next_twin(message), i++) { | |
| 445 | subject_node = xmlnode_get_child(message, "subject"); | |
| 446 | sender_node = xmlnode_get_child(message, "senders"); | |
| 447 | sender_node = xmlnode_get_child(sender_node, "sender"); | |
| 448 | ||
| 18233 | 449 | while (sender_node && (!xmlnode_get_attrib(sender_node, "unread") || |
| 15225 | 450 | !strcmp(xmlnode_get_attrib(sender_node, "unread"),"0"))) |
| 451 | sender_node = xmlnode_get_next_twin(sender_node); | |
| 18233 | 452 | |
| 15225 | 453 | if (!sender_node) { |
| 454 | i--; | |
| 455 | continue; | |
| 456 | } | |
| 18233 | 457 | |
| 15225 | 458 | from = xmlnode_get_attrib(sender_node, "name"); |
| 459 | if (!from || !*from) | |
| 460 | from = xmlnode_get_attrib(sender_node, "address"); | |
| 461 | subject = xmlnode_get_data(subject_node); | |
| 462 | /* | |
| 463 | * url = xmlnode_get_attrib(message, "url"); | |
| 464 | */ | |
| 465 | tos[i] = (to_name != NULL ? to_name : ""); | |
| 466 | froms[i] = (from != NULL ? from : ""); | |
| 18739 | 467 | subjects[i] = (subject != NULL ? subject : g_strdup("")); |
| 15225 | 468 | urls[i] = (url != NULL ? url : ""); |
| 18233 | 469 | |
| 15225 | 470 | tid = xmlnode_get_attrib(message, "tid"); |
| 18233 | 471 | if (tid && |
| 15225 | 472 | (js->gmail_last_tid == NULL || strcmp(tid, js->gmail_last_tid) > 0)) { |
| 473 | g_free(js->gmail_last_tid); | |
| 474 | js->gmail_last_tid = g_strdup(tid); | |
| 475 | } | |
| 476 | } | |
| 477 | ||
| 18233 | 478 | if (i>0) |
|
18740
1b1f72624316
Only display the "detailed" email notifications for gtalk if we really have all the details to show. Fixes #1813.
Daniel Atallah <datallah@pidgin.im>
parents:
18739
diff
changeset
|
479 | purple_notify_emails(js->gc, count, count == i, (const char**) subjects, froms, tos, |
| 18233 | 480 | urls, NULL, NULL); |
| 15261 | 481 | |
| 15225 | 482 | g_free(to_name); |
| 483 | g_free(tos); | |
| 484 | g_free(froms); | |
|
19046
4c4a79e7e21c
Fix a stupid crash (that I introduced) that occurs when parsing gmail notifications. Fixes #2323
Daniel Atallah <datallah@pidgin.im>
parents:
18740
diff
changeset
|
485 | for (; i > 0; i--) |
|
4c4a79e7e21c
Fix a stupid crash (that I introduced) that occurs when parsing gmail notifications. Fixes #2323
Daniel Atallah <datallah@pidgin.im>
parents:
18740
diff
changeset
|
486 | g_free(subjects[i - 1]); |
| 15225 | 487 | g_free(subjects); |
| 488 | g_free(urls); | |
| 489 | ||
| 490 | in_str = xmlnode_get_attrib(child, "result-time"); | |
| 491 | if (in_str && *in_str) { | |
| 492 | g_free(js->gmail_last_time); | |
| 493 | js->gmail_last_time = g_strdup(in_str); | |
| 494 | } | |
| 495 | } | |
| 496 | ||
| 18233 | 497 | void |
| 498 | jabber_gmail_poke(JabberStream *js, xmlnode *packet) | |
| 15225 | 499 | { |
| 500 | const char *type; | |
| 501 | xmlnode *query; | |
| 502 | JabberIq *iq; | |
| 18233 | 503 | |
| 15225 | 504 | /* bail if the user isn't interested */ |
| 15884 | 505 | if (!purple_account_get_check_mail(js->gc->account)) |
| 15225 | 506 | return; |
| 507 | ||
| 508 | type = xmlnode_get_attrib(packet, "type"); | |
| 18233 | 509 | |
| 15225 | 510 | |
| 511 | /* Is this an initial incoming mail notification? If so, send a request for more info */ | |
| 512 | if (strcmp(type, "set") || !xmlnode_get_child(packet, "new-mail")) | |
| 513 | return; | |
| 514 | ||
| 15884 | 515 | purple_debug(PURPLE_DEBUG_MISC, "jabber", |
| 15225 | 516 | "Got new mail notification. Sending request for more info\n"); |
| 517 | ||
| 518 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "google:mail:notify"); | |
| 519 | jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); | |
| 520 | query = xmlnode_get_child(iq->node, "query"); | |
| 521 | ||
| 522 | if (js->gmail_last_time) | |
| 523 | xmlnode_set_attrib(query, "newer-than-time", js->gmail_last_time); | |
| 524 | if (js->gmail_last_tid) | |
| 525 | xmlnode_set_attrib(query, "newer-than-tid", js->gmail_last_tid); | |
| 526 | ||
| 527 | jabber_iq_send(iq); | |
| 528 | return; | |
| 529 | } | |
| 530 | ||
| 531 | void jabber_gmail_init(JabberStream *js) { | |
| 532 | JabberIq *iq; | |
| 533 | ||
| 18233 | 534 | if (!purple_account_get_check_mail(js->gc->account)) |
| 15225 | 535 | return; |
| 536 | ||
| 537 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "google:mail:notify"); | |
| 538 | jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); | |
| 539 | jabber_iq_send(iq); | |
| 540 | } | |
| 15265 | 541 | |
| 542 | void jabber_google_roster_init(JabberStream *js) | |
| 543 | { | |
| 544 | JabberIq *iq; | |
| 545 | xmlnode *query; | |
| 546 | ||
| 547 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster"); | |
| 548 | query = xmlnode_get_child(iq->node, "query"); | |
| 18233 | 549 | |
| 15265 | 550 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); |
| 551 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 552 | ||
| 553 | jabber_iq_send(iq); | |
| 554 | } | |
| 555 | ||
| 556 | void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item) | |
| 557 | { | |
| 15884 | 558 | PurpleAccount *account = purple_connection_get_account(js->gc); |
| 15265 | 559 | GSList *list = account->deny; |
| 560 | const char *jid = xmlnode_get_attrib(item, "jid"); | |
| 561 | char *jid_norm = g_strdup(jabber_normalize(account, jid)); | |
| 562 | ||
| 563 | while (list) { | |
| 564 | if (!strcmp(jid_norm, (char*)list->data)) { | |
| 565 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 566 | xmlnode_set_attrib(item, "gr:t", "B"); | |
| 567 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 568 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 569 | return; | |
| 570 | } | |
| 571 | list = list->next; | |
| 572 | } | |
| 573 | ||
| 18739 | 574 | g_free(jid_norm); |
| 575 | ||
| 15265 | 576 | } |
| 577 | ||
|
15530
9355a1be068e
Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
578 | gboolean jabber_google_roster_incoming(JabberStream *js, xmlnode *item) |
| 15265 | 579 | { |
| 15884 | 580 | PurpleAccount *account = purple_connection_get_account(js->gc); |
| 15265 | 581 | GSList *list = account->deny; |
| 582 | const char *jid = xmlnode_get_attrib(item, "jid"); | |
| 583 | gboolean on_block_list = FALSE; | |
| 584 | ||
| 585 | char *jid_norm = g_strdup(jabber_normalize(account, jid)); | |
| 586 | ||
| 587 | const char *grt = xmlnode_get_attrib_with_namespace(item, "t", "google:roster"); | |
|
17148
db0801f13aa8
If Google Talk tells you a roster item as a none subscription, we probably don't ever want to show it. Fixes #1189
Sean Egan <seanegan@pidgin.im>
parents:
16988
diff
changeset
|
588 | const char *subscription = xmlnode_get_attrib(item, "subscription"); |
| 18233 | 589 | |
| 17327 | 590 | if (!subscription || !strcmp(subscription, "none")) { |
|
17148
db0801f13aa8
If Google Talk tells you a roster item as a none subscription, we probably don't ever want to show it. Fixes #1189
Sean Egan <seanegan@pidgin.im>
parents:
16988
diff
changeset
|
591 | /* The Google Talk servers will automatically add people from your Gmail address book |
|
db0801f13aa8
If Google Talk tells you a roster item as a none subscription, we probably don't ever want to show it. Fixes #1189
Sean Egan <seanegan@pidgin.im>
parents:
16988
diff
changeset
|
592 | * with subscription=none. If we see someone with subscription=none, ignore them. |
|
db0801f13aa8
If Google Talk tells you a roster item as a none subscription, we probably don't ever want to show it. Fixes #1189
Sean Egan <seanegan@pidgin.im>
parents:
16988
diff
changeset
|
593 | */ |
|
db0801f13aa8
If Google Talk tells you a roster item as a none subscription, we probably don't ever want to show it. Fixes #1189
Sean Egan <seanegan@pidgin.im>
parents:
16988
diff
changeset
|
594 | return FALSE; |
|
db0801f13aa8
If Google Talk tells you a roster item as a none subscription, we probably don't ever want to show it. Fixes #1189
Sean Egan <seanegan@pidgin.im>
parents:
16988
diff
changeset
|
595 | } |
| 18233 | 596 | |
| 15265 | 597 | while (list) { |
| 598 | if (!strcmp(jid_norm, (char*)list->data)) { | |
| 599 | on_block_list = TRUE; | |
| 600 | break; | |
| 601 | } | |
| 602 | list = list->next; | |
| 603 | } | |
| 18233 | 604 | |
|
15530
9355a1be068e
Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
605 | if (grt && (*grt == 'H' || *grt == 'h')) { |
| 15884 | 606 | PurpleBuddy *buddy = purple_find_buddy(account, jid_norm); |
| 607 | purple_blist_remove_buddy(buddy); | |
| 18739 | 608 | g_free(jid_norm); |
|
15530
9355a1be068e
Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
609 | return FALSE; |
|
9355a1be068e
Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
610 | } |
| 18233 | 611 | |
| 15265 | 612 | if (!on_block_list && (grt && (*grt == 'B' || *grt == 'b'))) { |
| 15884 | 613 | purple_debug_info("jabber", "Blocking %s\n", jid_norm); |
| 614 | purple_privacy_deny_add(account, jid_norm, TRUE); | |
| 15265 | 615 | } else if (on_block_list && (!grt || (*grt != 'B' && *grt != 'b' ))){ |
| 15884 | 616 | purple_debug_info("jabber", "Unblocking %s\n", jid_norm); |
| 617 | purple_privacy_deny_remove(account, jid_norm, TRUE); | |
| 15265 | 618 | } |
| 18739 | 619 | |
| 620 | g_free(jid_norm); | |
|
15530
9355a1be068e
Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
621 | return TRUE; |
| 15265 | 622 | } |
| 623 | ||
| 18233 | 624 | void jabber_google_roster_add_deny(PurpleConnection *gc, const char *who) |
| 15265 | 625 | { |
| 626 | JabberStream *js; | |
| 627 | GSList *buddies; | |
| 628 | JabberIq *iq; | |
| 629 | xmlnode *query; | |
| 630 | xmlnode *item; | |
| 631 | xmlnode *group; | |
| 15884 | 632 | PurpleBuddy *b; |
| 15265 | 633 | JabberBuddy *jb; |
| 634 | ||
| 635 | js = (JabberStream*)(gc->proto_data); | |
| 18233 | 636 | |
| 15265 | 637 | if (!js || !js->server_caps & JABBER_CAP_GOOGLE_ROSTER) |
| 638 | return; | |
| 639 | ||
| 640 | jb = jabber_buddy_find(js, who, TRUE); | |
| 641 | ||
| 15884 | 642 | buddies = purple_find_buddies(js->gc->account, who); |
| 15265 | 643 | if(!buddies) |
| 644 | return; | |
| 18233 | 645 | |
| 15265 | 646 | b = buddies->data; |
| 647 | ||
| 648 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 18233 | 649 | |
| 15265 | 650 | query = xmlnode_get_child(iq->node, "query"); |
| 651 | item = xmlnode_new_child(query, "item"); | |
| 652 | ||
| 653 | while(buddies) { | |
| 15884 | 654 | PurpleGroup *g; |
| 15265 | 655 | |
| 656 | b = buddies->data; | |
| 15884 | 657 | g = purple_buddy_get_group(b); |
| 15265 | 658 | |
| 659 | group = xmlnode_new_child(item, "group"); | |
| 660 | xmlnode_insert_data(group, g->name, -1); | |
| 18233 | 661 | |
| 15265 | 662 | buddies = buddies->next; |
| 663 | } | |
| 664 | ||
| 665 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 666 | ||
| 667 | query = xmlnode_get_child(iq->node, "query"); | |
| 668 | item = xmlnode_new_child(query, "item"); | |
| 669 | ||
| 670 | xmlnode_set_attrib(item, "jid", who); | |
| 671 | xmlnode_set_attrib(item, "name", b->alias ? b->alias : ""); | |
| 672 | xmlnode_set_attrib(item, "gr:t", "B"); | |
| 673 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 674 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 675 | ||
| 676 | jabber_iq_send(iq); | |
| 677 | ||
| 678 | /* Synthesize a sign-off */ | |
| 679 | if (jb) { | |
| 680 | JabberBuddyResource *jbr; | |
| 681 | GList *l = jb->resources; | |
| 682 | while (l) { | |
| 683 | jbr = l->data; | |
|
15346
ef48613b5b9b
[gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents:
15265
diff
changeset
|
684 | if (jbr && jbr->name) |
|
ef48613b5b9b
[gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents:
15265
diff
changeset
|
685 | { |
| 15884 | 686 | purple_debug(PURPLE_DEBUG_MISC, "jabber", "Removing resource %s\n", jbr->name); |
|
15346
ef48613b5b9b
[gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents:
15265
diff
changeset
|
687 | jabber_buddy_remove_resource(jb, jbr->name); |
|
ef48613b5b9b
[gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents:
15265
diff
changeset
|
688 | } |
| 15265 | 689 | l = l->next; |
| 690 | } | |
| 691 | } | |
| 15884 | 692 | purple_prpl_got_user_status(purple_connection_get_account(gc), who, "offline", NULL); |
| 15265 | 693 | } |
| 694 | ||
| 15884 | 695 | void jabber_google_roster_rem_deny(PurpleConnection *gc, const char *who) |
| 15265 | 696 | { |
| 697 | JabberStream *js; | |
| 698 | GSList *buddies; | |
| 699 | JabberIq *iq; | |
| 700 | xmlnode *query; | |
| 701 | xmlnode *item; | |
| 702 | xmlnode *group; | |
| 15884 | 703 | PurpleBuddy *b; |
| 15265 | 704 | |
| 705 | g_return_if_fail(gc != NULL); | |
| 706 | g_return_if_fail(who != NULL); | |
| 18233 | 707 | |
| 15265 | 708 | js = (JabberStream*)(gc->proto_data); |
| 18233 | 709 | |
| 15265 | 710 | if (!js || !js->server_caps & JABBER_CAP_GOOGLE_ROSTER) |
| 711 | return; | |
| 18233 | 712 | |
| 15884 | 713 | buddies = purple_find_buddies(js->gc->account, who); |
| 15265 | 714 | if(!buddies) |
| 715 | return; | |
| 18233 | 716 | |
| 15265 | 717 | b = buddies->data; |
| 718 | ||
| 719 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 18233 | 720 | |
| 15265 | 721 | query = xmlnode_get_child(iq->node, "query"); |
| 722 | item = xmlnode_new_child(query, "item"); | |
| 723 | ||
| 724 | while(buddies) { | |
| 15884 | 725 | PurpleGroup *g; |
| 15265 | 726 | |
| 727 | b = buddies->data; | |
| 15884 | 728 | g = purple_buddy_get_group(b); |
| 15265 | 729 | |
| 730 | group = xmlnode_new_child(item, "group"); | |
| 731 | xmlnode_insert_data(group, g->name, -1); | |
| 18233 | 732 | |
| 15265 | 733 | buddies = buddies->next; |
| 734 | } | |
| 735 | ||
| 736 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster"); | |
| 737 | ||
| 738 | query = xmlnode_get_child(iq->node, "query"); | |
| 739 | item = xmlnode_new_child(query, "item"); | |
| 740 | ||
| 741 | xmlnode_set_attrib(item, "jid", who); | |
| 742 | xmlnode_set_attrib(item, "name", b->alias ? b->alias : ""); | |
| 743 | xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); | |
| 744 | xmlnode_set_attrib(query, "gr:ext", "2"); | |
| 745 | ||
| 746 | jabber_iq_send(iq); | |
| 747 | ||
| 748 | /* See if he's online */ | |
| 749 | jabber_presence_subscription_set(js, who, "probe"); | |
| 750 | } | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
751 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
752 | /* This does two passes on the string. The first pass goes through |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
753 | * and determine if all the structured text is properly balanced, and |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
754 | * how many instances of each there is. The second pass goes and converts |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
755 | * everything to HTML, depending on what's figured out by the first pass. |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
756 | * It will short circuit once it knows it has no more replacements to make |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
757 | */ |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
758 | char *jabber_google_format_to_html(const char *text) |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
759 | { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
760 | const char *p; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
761 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
762 | /* The start of the screen may be consdiered a space for this purpose */ |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
763 | gboolean preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
764 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
765 | gboolean in_bold = FALSE, in_italic = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
766 | gboolean in_tag = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
767 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
768 | gint bold_count = 0, italic_count = 0; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
769 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
770 | GString *str; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
771 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
772 | for (p = text; *p != '\0'; p = g_utf8_next_char(p)) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
773 | gunichar c = g_utf8_get_char(p); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
774 | if (c == '*' && !in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
775 | if (in_bold && (g_unichar_isspace(*(p+1)) || |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
776 | *(p+1) == '\0' || |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
777 | *(p+1) == '<')) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
778 | bold_count++; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
779 | in_bold = FALSE; |
|
16988
1aaf51bf0f23
Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
780 | } else if (preceding_space && !in_bold && !g_unichar_isspace(*(p+1))) { |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
781 | bold_count++; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
782 | in_bold = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
783 | } |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
784 | preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
785 | } else if (c == '_' && !in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
786 | if (in_italic && (g_unichar_isspace(*(p+1)) || |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
787 | *(p+1) == '\0' || |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
788 | *(p+1) == '<')) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
789 | italic_count++; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
790 | in_italic = FALSE; |
|
16988
1aaf51bf0f23
Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
791 | } else if (preceding_space && !in_italic && !g_unichar_isspace(*(p+1))) { |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
792 | italic_count++; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
793 | in_italic = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
794 | } |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
795 | preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
796 | } else if (c == '<' && !in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
797 | in_tag = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
798 | } else if (c == '>' && in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
799 | in_tag = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
800 | } else if (!in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
801 | if (g_unichar_isspace(c)) |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
802 | preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
803 | else |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
804 | preceding_space = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
805 | } |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
806 | } |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
807 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
808 | str = g_string_new(NULL); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
809 | in_bold = in_italic = in_tag = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
810 | preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
811 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
812 | for (p = text; *p != '\0'; p = g_utf8_next_char(p)) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
813 | gunichar c = g_utf8_get_char(p); |
| 18233 | 814 | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
815 | if (bold_count < 2 && italic_count < 2 && !in_bold && !in_italic) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
816 | g_string_append(str, p); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
817 | return g_string_free(str, FALSE); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
818 | } |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
819 | |
| 18233 | 820 | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
821 | if (c == '*' && !in_tag) { |
| 18233 | 822 | if (in_bold && |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
823 | (g_unichar_isspace(*(p+1))||*(p+1)=='<')) { /* This is safe in UTF-8 */ |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
824 | str = g_string_append(str, "</b>"); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
825 | in_bold = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
826 | bold_count--; |
|
16988
1aaf51bf0f23
Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
827 | } else if (preceding_space && bold_count > 1 && !g_unichar_isspace(*(p+1))) { |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
828 | str = g_string_append(str, "<b>"); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
829 | bold_count--; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
830 | in_bold = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
831 | } else { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
832 | str = g_string_append_unichar(str, c); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
833 | } |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
834 | preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
835 | } else if (c == '_' && !in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
836 | if (in_italic && |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
837 | (g_unichar_isspace(*(p+1))||*(p+1)=='<')) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
838 | str = g_string_append(str, "</i>"); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
839 | italic_count--; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
840 | in_italic = FALSE; |
|
16988
1aaf51bf0f23
Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents:
15884
diff
changeset
|
841 | } else if (preceding_space && italic_count > 1 && !g_unichar_isspace(*(p+1))) { |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
842 | str = g_string_append(str, "<i>"); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
843 | italic_count--; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
844 | in_italic = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
845 | } else { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
846 | str = g_string_append_unichar(str, c); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
847 | } |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
848 | preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
849 | } else if (c == '<' && !in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
850 | str = g_string_append_unichar(str, c); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
851 | in_tag = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
852 | } else if (c == '>' && in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
853 | str = g_string_append_unichar(str, c); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
854 | in_tag = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
855 | } else if (!in_tag) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
856 | str = g_string_append_unichar(str, c); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
857 | if (g_unichar_isspace(c)) |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
858 | preceding_space = TRUE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
859 | else |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
860 | preceding_space = FALSE; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
861 | } else { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
862 | str = g_string_append_unichar(str, c); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
863 | } |
| 18233 | 864 | } |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
865 | return g_string_free(str, FALSE); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15530
diff
changeset
|
866 | } |