libpurple/protocols/jabber/google.c

Wed, 19 Sep 2007 22:55:19 +0000

author
Sean Egan <seanegan@pidgin.im>
date
Wed, 19 Sep 2007 22:55:19 +0000
branch
vv
changeset 19885
593613a22e57
parent 19882
d8c2a2fc1fbf
child 22069
841d24b3a2bc
permissions
-rw-r--r--

You can actually receive Google Talk voice calls with crappy UI now

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

mercurial