libpurple/protocols/jabber/google.c

Sun, 25 May 2008 04:01:44 +0000

author
Michael Ruprecht <maiku@pidgin.im>
date
Sun, 25 May 2008 04:01:44 +0000
branch
soc.2008.vv
changeset 23700
e47be56bdd2b
parent 23697
299bafcd8eb8
child 23704
9b88c9b23aed
permissions
-rw-r--r--

Fix compiling with the --disable-vv switch.

15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
1 /**
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
2 * Purple is the legal property of its developers, whose names are too numerous
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
3 * to list here. Please refer to the COPYRIGHT file distributed with this
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
4 * source distribution.
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
5 *
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
10 *
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
15 *
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19046
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
19 */
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
20
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
22 #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
23 #include "mediamanager.h"
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
24 #include "util.h"
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
25 #include "privacy.h"
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
26
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
27 #include "buddy.h"
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
28 #include "google.h"
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
29 #include "jabber.h"
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
30 #include "presence.h"
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
31 #include "iq.h"
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
32
23700
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
33 #ifdef USE_FARSIGHT
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
34 #include <gst/farsight/fs-conference-iface.h>
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
35
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
36 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
37 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
38 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
39 } 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
40
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 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
42 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
43 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
44 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
45 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
46 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
47 } 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
48
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 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
50 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
51 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
52 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
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_free(session);
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
88 }
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
89
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 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
91 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
92 {
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 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
94 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
95 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
96 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
97 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
98 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
99 }
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 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
102 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
103 {
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 xmlnode *sess, *desc, *payload;
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
105 GList *codecs = purple_media_get_negotiated_audio_codecs(session->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
106 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
107
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 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
109 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
110 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
111 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
112 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
113
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 for (;codecs; codecs = codecs->next) {
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
115 FsCodec *codec = (FsCodec*)codecs->data;
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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 }
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
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
125 fs_codec_list_destroy(codecs);
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
126 jabber_iq_send(iq);
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
127 gst_element_set_state(purple_media_get_audio_pipeline(session->media), GST_STATE_PLAYING);
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
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 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
135
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
136 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
137 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
138 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
139
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
140 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
141 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
142 }
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
143
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
144 static void
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
145 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
146 {
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
147 xmlnode *sess;
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
148 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
149
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
150 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
151 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
152 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
153
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
154 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
155 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
156 }
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
157
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
158
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
159 static void
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
160 google_session_candidates_prepared (PurpleMedia *media, GoogleSession *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
161 {
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
162 JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
163 GList *candidates = purple_media_get_local_audio_candidates(session->media);
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
164 FsCandidate *transport;
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
165 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
166 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
167 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
168 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
169 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
170
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 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
172 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
173 char pref[8];
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
174 transport = (FsCandidate*)(candidates->data);
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
175
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 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
177 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
178
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 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
180
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 g_snprintf(port, sizeof(port), "%d", transport->port);
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
182 g_snprintf(pref, sizeof(pref), "%d", transport->priority);
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
183
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 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
185 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
186 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
187 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
188 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
189 xmlnode_set_attrib(candidate, "preference", pref);
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
190 xmlnode_set_attrib(candidate, "protocol", transport->proto == FS_NETWORK_PROTOCOL_UDP ? "udp" : "tcp");
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
191 xmlnode_set_attrib(candidate, "type", transport->type == FS_CANDIDATE_TYPE_HOST ? "local" :
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
192 transport->type == FS_CANDIDATE_TYPE_PRFLX ? "stun" :
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
193 transport->type == FS_CANDIDATE_TYPE_RELAY ? "relay" : 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
194 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
195 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
196 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
197
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 }
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 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
200 }
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
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
202 static void
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
203 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
204 {
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
205 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
206 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
207 xmlnode *desc_element, *codec_element;
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
208 FsCodec *codec;
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
209 const char *id, *encoding_name, *clock_rate;
22648
e286d795c5f9 Patch from Marcus Lundblad ('mlundblad') to improve audio support in xmpp.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22069
diff changeset
210
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 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
212 purple_debug_error("jabber", "Received initiate for active session.\n");
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
213 return;
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
214 }
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
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
216 session->media = purple_media_manager_create_media(purple_media_manager_get(), js->gc,
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
217 "fsrtpconference", session->remote_jid);
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
218
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
219 /* "rawudp" will need to be changed to "nice" when libnice is finished */
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
220 purple_media_add_stream(session->media, session->remote_jid,
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
221 PURPLE_MEDIA_AUDIO, "rawudp");
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
222
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
223 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
224
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 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
226 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
227 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
228 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
229 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
230 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
231
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
232 codec = fs_codec_new(atoi(id), encoding_name, FS_MEDIA_TYPE_AUDIO,
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
233 clock_rate ? atoi(clock_rate) : 0);
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 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
235 }
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
236
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
237 purple_media_set_remote_audio_codecs(session->media, session->remote_jid, codecs);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
238
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
239 g_signal_connect_swapped(G_OBJECT(session->media), "accepted",
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
240 G_CALLBACK(google_session_send_accept), session);
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
241 g_signal_connect_swapped(G_OBJECT(session->media), "reject",
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
242 G_CALLBACK(google_session_send_reject), session);
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
243 g_signal_connect_swapped(G_OBJECT(session->media), "hangup",
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
244 G_CALLBACK(google_session_send_terminate), session);
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
245 g_signal_connect(G_OBJECT(session->media), "candidates-prepared",
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
246 G_CALLBACK(google_session_candidates_prepared), session);
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
247 purple_media_ready(session->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
248
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
249 fs_codec_list_destroy(codecs);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
250
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
251 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
252 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
253 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
254 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
255 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
256
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
257 static void
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
258 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
259 {
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
260 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
261 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
262 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
263 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
264 char n[4];
22648
e286d795c5f9 Patch from Marcus Lundblad ('mlundblad') to improve audio support in xmpp.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22069
diff changeset
265
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
266 for (cand = xmlnode_get_child(sess, "candidate"); cand; cand = xmlnode_get_next_twin(cand)) {
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
267 FsCandidate *info;
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
268 g_snprintf(n, sizeof(n), "S%d", name++);
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
269 info = fs_candidate_new(n, FS_COMPONENT_RTP, !strcmp(xmlnode_get_attrib(cand, "type"), "local") ?
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
270 FS_CANDIDATE_TYPE_HOST :
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
271 !strcmp(xmlnode_get_attrib(cand, "type"), "stun") ?
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
272 FS_CANDIDATE_TYPE_PRFLX :
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
273 !strcmp(xmlnode_get_attrib(cand, "type"), "relay") ?
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
274 FS_CANDIDATE_TYPE_RELAY : FS_CANDIDATE_TYPE_HOST,
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
275 !strcmp(xmlnode_get_attrib(cand, "protocol"),"udp") ?
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
276 FS_NETWORK_PROTOCOL_UDP : FS_NETWORK_PROTOCOL_TCP,
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
277 xmlnode_get_attrib(cand, "address"), atoi(xmlnode_get_attrib(cand, "port")));
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
278
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
279 info->username = g_strdup(xmlnode_get_attrib(cand, "username"));
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
280 info->password = g_strdup(xmlnode_get_attrib(cand, "password"));
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
281
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
282 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
283 }
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
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
285 purple_media_add_remote_audio_candidates(session->media, session->remote_jid, list);
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
286 fs_candidate_list_destroy(list);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
287
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
288 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
289 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
290 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
291 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
292 }
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
293
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
294 static void
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
295 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
296 {
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
297 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
298
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
299 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
300 }
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 static void
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
303 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
304 {
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
305 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
306
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
307 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
308 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
309
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
310 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
311 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
312 {
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
313 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
314 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
315
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
316 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
317 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
318 } 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
319 } 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
320 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
321 } 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
322 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
323 } 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
324 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
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 }
23700
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
327 #endif /* USE_FARSIGHT */
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
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 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
330 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
331 {
23700
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
332 #ifdef USE_FARSIGHT
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
333 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
334 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
335
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
336 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
337 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
338
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 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
340 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
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 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
343 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
344 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
345
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
346 id.id = (gchar*)xmlnode_get_attrib(session_node, "id");
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
347 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
348 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
349
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
350 id.initiator = (gchar*)xmlnode_get_attrib(session_node, "initiator");
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
351 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
352 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
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 (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
355 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
356 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
357
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) {
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 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
360 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
361 }
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
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 /* 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
364 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
365 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
366 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
367 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
368 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
369 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
370 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
371 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
372 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
373 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
374 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
375 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
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 google_session_parse_iq(js, session, packet);
23700
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
378 #else
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
379 /* TODO: send proper error response */
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
380 #endif /* USE_FARSIGHT */
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
381 }
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
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
383 static void
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
384 jabber_gmail_parse(JabberStream *js, xmlnode *packet, gpointer nul)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
385 {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
386 const char *type = xmlnode_get_attrib(packet, "type");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
387 xmlnode *child;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
388 xmlnode *message, *sender_node, *subject_node;
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
389 const char *from, *to, *url, *tid;
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
390 char *subject;
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
391 const char *in_str;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
392 char *to_name;
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
393 char *default_tos[1];
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
394
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
395 int i, count = 1, returned_count;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
396
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
397 const char **tos, **froms, **urls;
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
398 char **subjects;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
399
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
400 if (strcmp(type, "result"))
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
401 return;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
402
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
403 child = xmlnode_get_child(packet, "mailbox");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
404 if (!child)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
405 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
406
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
407 in_str = xmlnode_get_attrib(child, "total-matched");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
408 if (in_str && *in_str)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
409 count = atoi(in_str);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
410
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
411 /* If Gmail doesn't tell us who the mail is to, let's use our JID */
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
412 to = xmlnode_get_attrib(packet, "to");
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
413 default_tos[0] = jabber_get_bare_jid(to);
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
414
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
415 message = xmlnode_get_child(child, "mail-thread-info");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
416
20114
96e715e155e0 applied changes from 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
Richard Laager <rlaager@pidgin.im>
parents: 20107
diff changeset
417 if (count == 0 || !message) {
20186
25fce12345fe Don't display mail notifications for 0 new emails in Google Talk
Evan Schoenberg <evands@pidgin.im>
parents: 20114
diff changeset
418 if (count > 0)
25fce12345fe Don't display mail notifications for 0 new emails in Google Talk
Evan Schoenberg <evands@pidgin.im>
parents: 20114
diff changeset
419 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, (const char**) default_tos, NULL, NULL, NULL);
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
420 g_free(default_tos[0]);
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
421 return;
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
422 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
423
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
424 /* Loop once to see how many messages were returned so we can allocate arrays
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
425 * accordingly */
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
426 for (returned_count = 0; message; returned_count++, message=xmlnode_get_next_twin(message));
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
427
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
428 froms = g_new0(const char* , returned_count);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
429 tos = g_new0(const char* , returned_count);
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
430 subjects = g_new0(char* , returned_count);
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
431 urls = g_new0(const char* , returned_count);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
432
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
433 to = xmlnode_get_attrib(packet, "to");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
434 to_name = jabber_get_bare_jid(to);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
435 url = xmlnode_get_attrib(child, "url");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
436 if (!url || !*url)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
437 url = "http://www.gmail.com";
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
438
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
439 message= xmlnode_get_child(child, "mail-thread-info");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
440 for (i=0; message; message = xmlnode_get_next_twin(message), i++) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
441 subject_node = xmlnode_get_child(message, "subject");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
442 sender_node = xmlnode_get_child(message, "senders");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
443 sender_node = xmlnode_get_child(sender_node, "sender");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
444
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
445 while (sender_node && (!xmlnode_get_attrib(sender_node, "unread") ||
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
446 !strcmp(xmlnode_get_attrib(sender_node, "unread"),"0")))
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
447 sender_node = xmlnode_get_next_twin(sender_node);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
448
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
449 if (!sender_node) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
450 i--;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
451 continue;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
452 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
453
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
454 from = xmlnode_get_attrib(sender_node, "name");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
455 if (!from || !*from)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
456 from = xmlnode_get_attrib(sender_node, "address");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
457 subject = xmlnode_get_data(subject_node);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
458 /*
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
459 * url = xmlnode_get_attrib(message, "url");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
460 */
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
461 tos[i] = (to_name != NULL ? to_name : "");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
462 froms[i] = (from != NULL ? from : "");
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
463 subjects[i] = (subject != NULL ? subject : g_strdup(""));
20225
684334efdc19 applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents: 20209
diff changeset
464 urls[i] = url;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
465
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
466 tid = xmlnode_get_attrib(message, "tid");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
467 if (tid &&
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
468 (js->gmail_last_tid == NULL || strcmp(tid, js->gmail_last_tid) > 0)) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
469 g_free(js->gmail_last_tid);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
470 js->gmail_last_tid = g_strdup(tid);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
471 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
472 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
473
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
474 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
475 purple_notify_emails(js->gc, count, count == i, (const char**) subjects, froms, tos,
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
476 urls, NULL, NULL);
20114
96e715e155e0 applied changes from 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
Richard Laager <rlaager@pidgin.im>
parents: 20107
diff changeset
477 else
20107
c2fafb2681d1 applied changes from 606266f42c25624ce35e54483778d855641806be
Richard Laager <rlaager@pidgin.im>
parents: 20097
diff changeset
478 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, (const char**) default_tos, NULL, NULL, NULL);
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
479
15261
109ac4fcc3e7 [gaim-migrate @ 17989]
Sean Egan <seanegan@pidgin.im>
parents: 15225
diff changeset
480
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
481 g_free(to_name);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
482 g_free(tos);
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
483 g_free(default_tos[0]);
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
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
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
487 g_free(subjects);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
488 g_free(urls);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
489
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
490 in_str = xmlnode_get_attrib(child, "result-time");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
491 if (in_str && *in_str) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
492 g_free(js->gmail_last_time);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
493 js->gmail_last_time = g_strdup(in_str);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
494 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
495 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
496
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
497 void
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
498 jabber_gmail_poke(JabberStream *js, xmlnode *packet)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
499 {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
500 const char *type;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
501 xmlnode *query;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
502 JabberIq *iq;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
503
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
504 /* bail if the user isn't interested */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
505 if (!purple_account_get_check_mail(js->gc->account))
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
506 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
507
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
508 type = xmlnode_get_attrib(packet, "type");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
509
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
510
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
511 /* Is this an initial incoming mail notification? If so, send a request for more info */
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
512 if (strcmp(type, "set") || !xmlnode_get_child(packet, "new-mail"))
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
513 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
514
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
515 purple_debug(PURPLE_DEBUG_MISC, "jabber",
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
516 "Got new mail notification. Sending request for more info\n");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
517
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
518 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "google:mail:notify");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
519 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
520 query = xmlnode_get_child(iq->node, "query");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
521
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
522 if (js->gmail_last_time)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
523 xmlnode_set_attrib(query, "newer-than-time", js->gmail_last_time);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
524 if (js->gmail_last_tid)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
525 xmlnode_set_attrib(query, "newer-than-tid", js->gmail_last_tid);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
526
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
527 jabber_iq_send(iq);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
528 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
529 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
530
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
531 void jabber_gmail_init(JabberStream *js) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
532 JabberIq *iq;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
533
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
534 if (!purple_account_get_check_mail(js->gc->account))
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
535 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
536
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
537 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "google:mail:notify");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
538 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
539 jabber_iq_send(iq);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
540 }
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
541
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
542 void jabber_google_roster_init(JabberStream *js)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
543 {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
544 JabberIq *iq;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
545 xmlnode *query;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
546
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
547 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
548 query = xmlnode_get_child(iq->node, "query");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
549
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
550 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
551 xmlnode_set_attrib(query, "gr:ext", "2");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
552
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
553 jabber_iq_send(iq);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
554 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
555
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
556 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
557 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
558 PurpleAccount *account = purple_connection_get_account(js->gc);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
559 GSList *list = account->deny;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
560 const char *jid = xmlnode_get_attrib(item, "jid");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
561 char *jid_norm = g_strdup(jabber_normalize(account, jid));
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
562
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
563 while (list) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
564 if (!strcmp(jid_norm, (char*)list->data)) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
565 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
566 xmlnode_set_attrib(item, "gr:t", "B");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
567 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
568 xmlnode_set_attrib(query, "gr:ext", "2");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
569 return;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
570 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
571 list = list->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
572 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
573
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
574 g_free(jid_norm);
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
575
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
576 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
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
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
579 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
580 PurpleAccount *account = purple_connection_get_account(js->gc);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
581 GSList *list = account->deny;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
582 const char *jid = xmlnode_get_attrib(item, "jid");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
583 gboolean on_block_list = FALSE;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
584
20209
c1bbdde1f373 applied changes from 6b5f1f48667171fe73de619dd8f80cacd231a2e2
Luke Schierer <lschiere@pidgin.im>
parents: 20186
diff changeset
585 char *jid_norm;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
586
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
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
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
589
17327
c0ba0055387a This should be better
Sean Egan <seanegan@pidgin.im>
parents: 17322
diff changeset
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
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
596
20209
c1bbdde1f373 applied changes from 6b5f1f48667171fe73de619dd8f80cacd231a2e2
Luke Schierer <lschiere@pidgin.im>
parents: 20186
diff changeset
597 jid_norm = g_strdup(jabber_normalize(account, jid));
c1bbdde1f373 applied changes from 6b5f1f48667171fe73de619dd8f80cacd231a2e2
Luke Schierer <lschiere@pidgin.im>
parents: 20186
diff changeset
598
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
599 while (list) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
600 if (!strcmp(jid_norm, (char*)list->data)) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
601 on_block_list = TRUE;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
602 break;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
603 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
604 list = list->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
605 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
606
15530
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
607 if (grt && (*grt == 'H' || *grt == 'h')) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
608 PurpleBuddy *buddy = purple_find_buddy(account, jid_norm);
20114
96e715e155e0 applied changes from 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
Richard Laager <rlaager@pidgin.im>
parents: 20107
diff changeset
609 if (buddy)
96e715e155e0 applied changes from 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
Richard Laager <rlaager@pidgin.im>
parents: 20107
diff changeset
610 purple_blist_remove_buddy(buddy);
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
611 g_free(jid_norm);
15530
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
612 return FALSE;
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
613 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
614
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
615 if (!on_block_list && (grt && (*grt == 'B' || *grt == 'b'))) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
616 purple_debug_info("jabber", "Blocking %s\n", jid_norm);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
617 purple_privacy_deny_add(account, jid_norm, TRUE);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
618 } else if (on_block_list && (!grt || (*grt != 'B' && *grt != 'b' ))){
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
619 purple_debug_info("jabber", "Unblocking %s\n", jid_norm);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
620 purple_privacy_deny_remove(account, jid_norm, TRUE);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
621 }
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
622
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
623 g_free(jid_norm);
15530
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
624 return TRUE;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
625 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
626
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
627 void jabber_google_roster_add_deny(PurpleConnection *gc, const char *who)
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
628 {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
629 JabberStream *js;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
630 GSList *buddies;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
631 JabberIq *iq;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
632 xmlnode *query;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
633 xmlnode *item;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
634 xmlnode *group;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
635 PurpleBuddy *b;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
636 JabberBuddy *jb;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
637
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
638 js = (JabberStream*)(gc->proto_data);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
639
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
640 if (!js || !js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
641 return;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
642
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
643 jb = jabber_buddy_find(js, who, TRUE);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
644
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
645 buddies = purple_find_buddies(js->gc->account, who);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
646 if(!buddies)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
647 return;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
648
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
649 b = buddies->data;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
650
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
651 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
652
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
653 query = xmlnode_get_child(iq->node, "query");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
654 item = xmlnode_new_child(query, "item");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
655
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
656 while(buddies) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
657 PurpleGroup *g;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
658
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
659 b = buddies->data;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
660 g = purple_buddy_get_group(b);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
661
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
662 group = xmlnode_new_child(item, "group");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
663 xmlnode_insert_data(group, g->name, -1);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
664
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
665 buddies = buddies->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
666 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
667
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
668 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
669
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
670 query = xmlnode_get_child(iq->node, "query");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
671 item = xmlnode_new_child(query, "item");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
672
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
673 xmlnode_set_attrib(item, "jid", who);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
674 xmlnode_set_attrib(item, "name", b->alias ? b->alias : "");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
675 xmlnode_set_attrib(item, "gr:t", "B");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
676 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
677 xmlnode_set_attrib(query, "gr:ext", "2");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
678
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
679 jabber_iq_send(iq);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
680
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
681 /* Synthesize a sign-off */
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
682 if (jb) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
683 JabberBuddyResource *jbr;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
684 GList *l = jb->resources;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
685 while (l) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
686 jbr = l->data;
15346
ef48613b5b9b [gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents: 15265
diff changeset
687 if (jbr && jbr->name)
ef48613b5b9b [gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents: 15265
diff changeset
688 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
689 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
690 jabber_buddy_remove_resource(jb, jbr->name);
ef48613b5b9b [gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents: 15265
diff changeset
691 }
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
692 l = l->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
693 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
694 }
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
695 purple_prpl_got_user_status(purple_connection_get_account(gc), who, "offline", NULL);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
696 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
697
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
698 void jabber_google_roster_rem_deny(PurpleConnection *gc, const char *who)
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
699 {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
700 JabberStream *js;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
701 GSList *buddies;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
702 JabberIq *iq;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
703 xmlnode *query;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
704 xmlnode *item;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
705 xmlnode *group;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
706 PurpleBuddy *b;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
707
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
708 g_return_if_fail(gc != NULL);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
709 g_return_if_fail(who != NULL);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
710
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
711 js = (JabberStream*)(gc->proto_data);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
712
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
713 if (!js || !js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
714 return;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
715
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
716 buddies = purple_find_buddies(js->gc->account, who);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
717 if(!buddies)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
718 return;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
719
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
720 b = buddies->data;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
721
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
722 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
723
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
724 query = xmlnode_get_child(iq->node, "query");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
725 item = xmlnode_new_child(query, "item");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
726
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
727 while(buddies) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
728 PurpleGroup *g;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
729
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
730 b = buddies->data;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
731 g = purple_buddy_get_group(b);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
732
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
733 group = xmlnode_new_child(item, "group");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
734 xmlnode_insert_data(group, g->name, -1);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
735
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
736 buddies = buddies->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
737 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
738
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
739 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
740
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
741 query = xmlnode_get_child(iq->node, "query");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
742 item = xmlnode_new_child(query, "item");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
743
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
744 xmlnode_set_attrib(item, "jid", who);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
745 xmlnode_set_attrib(item, "name", b->alias ? b->alias : "");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
746 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
747 xmlnode_set_attrib(query, "gr:ext", "2");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
748
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
749 jabber_iq_send(iq);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
750
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
751 /* See if he's online */
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
752 jabber_presence_subscription_set(js, who, "probe");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
753 }
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
754
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
755 /* 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
756 * 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
757 * 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
758 * 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
759 * 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
760 */
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
761 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
762 {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
763 const char *p;
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 /* 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
766 gboolean preceding_space = TRUE;
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 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
769 gboolean in_tag = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
770
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
771 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
772
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
773 GString *str;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
774
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
775 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
776 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
777 if (c == '*' && !in_tag) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
778 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
779 *(p+1) == '\0' ||
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
780 *(p+1) == '<')) {
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 = FALSE;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
783 } 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
784 bold_count++;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
785 in_bold = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
786 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
787 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
788 } 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
789 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
790 *(p+1) == '\0' ||
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
791 *(p+1) == '<')) {
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 = FALSE;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
794 } 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
795 italic_count++;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
796 in_italic = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
797 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
798 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
799 } 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
800 in_tag = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
801 } 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
802 in_tag = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
803 } else if (!in_tag) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
804 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
805 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
806 else
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
807 preceding_space = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
808 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
809 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
810
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
811 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
812 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
813 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
814
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
815 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
816 gunichar c = g_utf8_get_char(p);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
817
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
818 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
819 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
820 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
821 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
822
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
823
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
824 if (c == '*' && !in_tag) {
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
825 if (in_bold &&
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
826 (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
827 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
828 in_bold = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
829 bold_count--;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
830 } 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
831 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
832 bold_count--;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
833 in_bold = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
834 } else {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
835 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
836 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
837 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
838 } 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
839 if (in_italic &&
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
840 (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
841 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
842 italic_count--;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
843 in_italic = FALSE;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
844 } 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
845 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
846 italic_count--;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
847 in_italic = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
848 } else {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
849 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
850 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
851 preceding_space = 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 = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
855 } 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
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 in_tag = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
858 } else if (!in_tag) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
859 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
860 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
861 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
862 else
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
863 preceding_space = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
864 } else {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
865 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
866 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
867 }
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
868 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
869 }
21195
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
870
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
871 void jabber_google_presence_incoming(JabberStream *js, const char *user, JabberBuddyResource *jbr)
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
872 {
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
873 if (!js->googletalk)
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
874 return;
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
875 if (jbr->status && !strncmp(jbr->status, "♫ ", strlen("♫ "))) {
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
876 purple_prpl_got_user_status(js->gc->account, user, "tune",
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
877 PURPLE_TUNE_TITLE, jbr->status + strlen("♫ "), NULL);
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
878 jbr->status = NULL;
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
879 } else {
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
880 purple_prpl_got_user_status_deactive(js->gc->account, user, "tune");
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
881 }
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
882 }
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
883
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
884 char *jabber_google_presence_outgoing(PurpleStatus *tune)
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
885 {
21714
5956ea2cb4af don't set the current tune title if it's NULL
Ka-Hing Cheung <khc@pidgin.im>
parents: 21204
diff changeset
886 const char *attr = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
5956ea2cb4af don't set the current tune title if it's NULL
Ka-Hing Cheung <khc@pidgin.im>
parents: 21204
diff changeset
887 return attr ? g_strdup_printf("♫ %s", attr) : g_strdup("");
21195
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
888 }

mercurial