libpurple/protocols/jabber/google.c

Sat, 05 Dec 2009 22:48:34 +0000

author
Paul Aurich <darkrain42@pidgin.im>
date
Sat, 05 Dec 2009 22:48:34 +0000
changeset 29094
1d72af8f11dd
parent 28984
1d84517d56eb
child 29101
aa5f5f35a862
permissions
-rw-r--r--

jabber: Clean up this code a little.

15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
1 /**
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
2 * Purple is the legal property of its developers, whose names are too numerous
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
3 * to list here. Please refer to the COPYRIGHT file distributed with this
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
4 * source distribution.
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
5 *
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
10 *
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
15 *
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19046
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
19 */
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
20
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
22 #include "debug.h"
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
23 #include "mediamanager.h"
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
24 #include "util.h"
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
25 #include "privacy.h"
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
26 #include "dnsquery.h"
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
27 #include "network.h"
15265
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"
28667
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
34 #include "chat.h"
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
35
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
36 #include "jingle/jingle.h"
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
37
23704
9b88c9b23aed Use USE_VV instead of USE_FARSIGHT.
Michael Ruprecht <maiku@pidgin.im>
parents: 23700
diff changeset
38 #ifdef USE_VV
23700
e47be56bdd2b Fix compiling with the --disable-vv switch.
Michael Ruprecht <maiku@pidgin.im>
parents: 23697
diff changeset
39
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
40 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
41 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
42 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
43 } 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
44
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 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
46 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
47 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
48 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
49 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
50 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
51 } 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
52
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 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
54 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
55 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
56 PurpleMedia *media;
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
57 JabberStream *js;
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 char *remote_jid;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
59 gboolean video;
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
60 } 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
61
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
62 static gboolean
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
63 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
64 {
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 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
66 GoogleSessionId *d = (GoogleSessionId*)b;
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
67
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
68 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
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
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
71 static void
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
72 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
73 {
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
74 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
75 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
76 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
77 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
78 }
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
79
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
80 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
81 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
82 {
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
83 xmlnode *node = xmlnode_new("session");
28980
4a0f7340b539 jabber: Add the missing file and fix up the Google session namespaces
Paul Aurich <darkrain42@pidgin.im>
parents: 28979
diff changeset
84 xmlnode_set_namespace(node, NS_GOOGLE_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
85 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
86 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
87 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
88 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
89 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
90
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 void
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
92 google_session_send_candidates(PurpleMedia *media, gchar *session_id,
26164
20f15fbe9b21 Very basic receive only GTalk audio sessions.
Michael Ruprecht <maiku@pidgin.im>
parents: 26160
diff changeset
93 gchar *participant, GoogleSession *session)
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
94 {
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
95 GList *candidates = purple_media_get_local_candidates(
28656
d003bf9b787e A leak fix in the candidate list, and some code simplification.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28593
diff changeset
96 session->media, session_id, session->remote_jid), *iter;
26229
3e786c9ebb62 Duplicate FsCandidate to remove it from the public interface.
Michael Ruprecht <maiku@pidgin.im>
parents: 26223
diff changeset
97 PurpleMediaCandidate *transport;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
98 gboolean video = FALSE;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
99
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
100 if (!strcmp(session_id, "google-video"))
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
101 video = TRUE;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
102
28656
d003bf9b787e A leak fix in the candidate list, and some code simplification.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28593
diff changeset
103 for (iter = candidates; iter; iter = iter->next) {
26485
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
104 JabberIq *iq;
28593
f6efb49aa838 Generate the "preference" attribute correctly for candidates on locales
Marcus Lundblad <malu@pidgin.im>
parents: 28372
diff changeset
105 gchar *ip, *port, *username, *password;
f6efb49aa838 Generate the "preference" attribute correctly for candidates on locales
Marcus Lundblad <malu@pidgin.im>
parents: 28372
diff changeset
106 gchar pref[16];
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
107 PurpleMediaCandidateType type;
26485
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
108 xmlnode *sess;
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
109 xmlnode *candidate;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
110 guint component_id;
28656
d003bf9b787e A leak fix in the candidate list, and some code simplification.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28593
diff changeset
111 transport = PURPLE_MEDIA_CANDIDATE(iter->data);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
112 component_id = purple_media_candidate_get_component_id(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
113 transport);
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
114
26485
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
115 iq = jabber_iq_new(session->js, JABBER_IQ_SET);
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
116 sess = google_session_create_xmlnode(session, "candidates");
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
117 xmlnode_insert_child(iq->node, sess);
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
118 xmlnode_set_attrib(iq->node, "to", session->remote_jid);
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
119
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
120 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
121
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
122 ip = purple_media_candidate_get_ip(transport);
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
123 port = g_strdup_printf("%d",
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
124 purple_media_candidate_get_port(transport));
28593
f6efb49aa838 Generate the "preference" attribute correctly for candidates on locales
Marcus Lundblad <malu@pidgin.im>
parents: 28372
diff changeset
125 g_ascii_dtostr(pref, 16,
f6efb49aa838 Generate the "preference" attribute correctly for candidates on locales
Marcus Lundblad <malu@pidgin.im>
parents: 28372
diff changeset
126 purple_media_candidate_get_priority(transport) / 1000.0);
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
127 username = purple_media_candidate_get_username(transport);
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
128 password = purple_media_candidate_get_password(transport);
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
129 type = purple_media_candidate_get_candidate_type(transport);
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
130
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
131 xmlnode_set_attrib(candidate, "address", ip);
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
132 xmlnode_set_attrib(candidate, "port", port);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
133 xmlnode_set_attrib(candidate, "name",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
134 component_id == PURPLE_MEDIA_COMPONENT_RTP ?
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
135 video ? "video_rtp" : "rtp" :
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
136 component_id == PURPLE_MEDIA_COMPONENT_RTCP ?
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
137 video ? "video_rtcp" : "rtcp" : "none");
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
138 xmlnode_set_attrib(candidate, "username", username);
26201
32baf68eeedd Fix receiving voice calls from Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26199
diff changeset
139 /*
32baf68eeedd Fix receiving voice calls from Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26199
diff changeset
140 * As of this writing, Farsight 2 in Google compatibility
32baf68eeedd Fix receiving voice calls from Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26199
diff changeset
141 * mode doesn't provide a password. The Gmail client
32baf68eeedd Fix receiving voice calls from Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26199
diff changeset
142 * requires this to be set.
32baf68eeedd Fix receiving voice calls from Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26199
diff changeset
143 */
32baf68eeedd Fix receiving voice calls from Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26199
diff changeset
144 xmlnode_set_attrib(candidate, "password",
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
145 password != NULL ? password : "");
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
146 xmlnode_set_attrib(candidate, "preference", pref);
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
147 xmlnode_set_attrib(candidate, "protocol",
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
148 purple_media_candidate_get_protocol(transport)
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
149 == PURPLE_MEDIA_NETWORK_PROTOCOL_UDP ?
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
150 "udp" : "tcp");
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
151 xmlnode_set_attrib(candidate, "type", type ==
26229
3e786c9ebb62 Duplicate FsCandidate to remove it from the public interface.
Michael Ruprecht <maiku@pidgin.im>
parents: 26223
diff changeset
152 PURPLE_MEDIA_CANDIDATE_TYPE_HOST ? "local" :
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
153 type ==
26229
3e786c9ebb62 Duplicate FsCandidate to remove it from the public interface.
Michael Ruprecht <maiku@pidgin.im>
parents: 26223
diff changeset
154 PURPLE_MEDIA_CANDIDATE_TYPE_SRFLX ? "stun" :
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
155 type ==
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
156 PURPLE_MEDIA_CANDIDATE_TYPE_RELAY ? "relay" :
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
157 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
158 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
159 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
160 xmlnode_insert_child(sess, candidate);
26485
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
161
26620
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
162 g_free(ip);
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
163 g_free(port);
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
164 g_free(username);
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
165 g_free(password);
a34fb2386da5 Hide and GObjectify PurpleMediaCandidate.
Michael Ruprecht <maiku@pidgin.im>
parents: 26618
diff changeset
166
26485
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
167 jabber_iq_send(iq);
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
168 }
28656
d003bf9b787e A leak fix in the candidate list, and some code simplification.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 28593
diff changeset
169 purple_media_candidate_list_free(candidates);
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
170 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
171
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
172 static void
26434
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
173 google_session_ready(GoogleSession *session)
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
174 {
26434
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
175 PurpleMedia *media = session->media;
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
176 if (purple_media_codecs_ready(media, NULL) &&
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
177 purple_media_candidates_prepared(media, NULL, NULL)) {
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
178 gchar *me = g_strdup_printf("%s@%s/%s",
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
179 session->js->user->node,
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
180 session->js->user->domain,
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
181 session->js->user->resource);
26434
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
182 JabberIq *iq;
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
183 xmlnode *sess, *desc, *payload;
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
184 GList *codecs, *iter;
26434
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
185 gboolean is_initiator = !strcmp(session->id.initiator, me);
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
186
26434
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
187 if (!is_initiator &&
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
188 !purple_media_accepted(media, NULL, NULL)) {
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
189 g_free(me);
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
190 return;
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
191 }
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
192
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
193 iq = jabber_iq_new(session->js, JABBER_IQ_SET);
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
194
46d8db20a062 Remove ready-new from use.
Michael Ruprecht <maiku@pidgin.im>
parents: 26337
diff changeset
195 if (is_initiator) {
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
196 xmlnode_set_attrib(iq->node, "to", session->remote_jid);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
197 xmlnode_set_attrib(iq->node, "from", session->id.initiator);
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
198 sess = google_session_create_xmlnode(session, "initiate");
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
199 } else {
26485
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
200 google_session_send_candidates(session->media,
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
201 "google-voice", session->remote_jid,
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
202 session);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
203 google_session_send_candidates(session->media,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
204 "google-video", session->remote_jid,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
205 session);
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
206 xmlnode_set_attrib(iq->node, "to", session->remote_jid);
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
207 xmlnode_set_attrib(iq->node, "from", me);
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
208 sess = google_session_create_xmlnode(session, "accept");
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
209 }
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
210 xmlnode_insert_child(iq->node, sess);
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
211 desc = xmlnode_new_child(sess, "description");
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
212 if (session->video)
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
213 xmlnode_set_namespace(desc, NS_GOOGLE_SESSION_VIDEO);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
214 else
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
215 xmlnode_set_namespace(desc, NS_GOOGLE_SESSION_PHONE);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
216
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
217 codecs = purple_media_get_codecs(media, "google-video");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
218
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
219 for (iter = codecs; iter; iter = g_list_next(iter)) {
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
220 PurpleMediaCodec *codec = (PurpleMediaCodec*)iter->data;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
221 gchar *id = g_strdup_printf("%d",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
222 purple_media_codec_get_id(codec));
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
223 gchar *encoding_name =
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
224 purple_media_codec_get_encoding_name(codec);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
225 payload = xmlnode_new_child(desc, "payload-type");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
226 xmlnode_set_attrib(payload, "id", id);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
227 xmlnode_set_attrib(payload, "name", encoding_name);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
228 xmlnode_set_attrib(payload, "width", "320");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
229 xmlnode_set_attrib(payload, "height", "200");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
230 xmlnode_set_attrib(payload, "framerate", "30");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
231 g_free(encoding_name);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
232 g_free(id);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
233 }
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
234 purple_media_codec_list_free(codecs);
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
235
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
236 codecs = purple_media_get_codecs(media, "google-voice");
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
237
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
238 for (iter = codecs; iter; iter = g_list_next(iter)) {
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
239 PurpleMediaCodec *codec = (PurpleMediaCodec*)iter->data;
26618
9e9e610ca1a1 Hide and gobjectify PurpleMediaCodec.
Michael Ruprecht <maiku@pidgin.im>
parents: 26514
diff changeset
240 gchar *id = g_strdup_printf("%d",
9e9e610ca1a1 Hide and gobjectify PurpleMediaCodec.
Michael Ruprecht <maiku@pidgin.im>
parents: 26514
diff changeset
241 purple_media_codec_get_id(codec));
9e9e610ca1a1 Hide and gobjectify PurpleMediaCodec.
Michael Ruprecht <maiku@pidgin.im>
parents: 26514
diff changeset
242 gchar *encoding_name =
9e9e610ca1a1 Hide and gobjectify PurpleMediaCodec.
Michael Ruprecht <maiku@pidgin.im>
parents: 26514
diff changeset
243 purple_media_codec_get_encoding_name(codec);
9e9e610ca1a1 Hide and gobjectify PurpleMediaCodec.
Michael Ruprecht <maiku@pidgin.im>
parents: 26514
diff changeset
244 gchar *clock_rate = g_strdup_printf("%d",
9e9e610ca1a1 Hide and gobjectify PurpleMediaCodec.
Michael Ruprecht <maiku@pidgin.im>
parents: 26514
diff changeset
245 purple_media_codec_get_clock_rate(codec));
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
246 payload = xmlnode_new_child(desc, "payload-type");
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
247 if (session->video)
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
248 xmlnode_set_namespace(payload, NS_GOOGLE_SESSION_PHONE);
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
249 xmlnode_set_attrib(payload, "id", id);
27203
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
250 /*
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
251 * Hack to make Gmail accept speex as the codec.
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
252 * It shouldn't have to be case sensitive.
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
253 */
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
254 if (purple_strequal(encoding_name, "SPEEX"))
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
255 xmlnode_set_attrib(payload, "name", "speex");
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
256 else
f11c3c9a7f53 Make Gmail accept speex as the codec.
Michael Ruprecht <maiku@pidgin.im>
parents: 27202
diff changeset
257 xmlnode_set_attrib(payload, "name", encoding_name);
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
258 xmlnode_set_attrib(payload, "clockrate", clock_rate);
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
259 g_free(clock_rate);
26618
9e9e610ca1a1 Hide and gobjectify PurpleMediaCodec.
Michael Ruprecht <maiku@pidgin.im>
parents: 26514
diff changeset
260 g_free(encoding_name);
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
261 g_free(id);
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
262 }
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
263 purple_media_codec_list_free(codecs);
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
264
26239
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
265 jabber_iq_send(iq);
5c186583ab89 Convert the GTalk code to completely use the new ready signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26238
diff changeset
266
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
267 if (is_initiator) {
26485
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
268 google_session_send_candidates(session->media,
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
269 "google-voice", session->remote_jid,
df2f8d35564b Send candidates more like GMail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26484
diff changeset
270 session);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
271 google_session_send_candidates(session->media,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
272 "google-video", session->remote_jid,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
273 session);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
274 }
26438
786a8c41d80f Don't let initiate or accept be sent again with Google Voice.
Michael Ruprecht <maiku@pidgin.im>
parents: 26434
diff changeset
275
786a8c41d80f Don't let initiate or accept be sent again with Google Voice.
Michael Ruprecht <maiku@pidgin.im>
parents: 26434
diff changeset
276 g_signal_handlers_disconnect_by_func(G_OBJECT(session->media),
786a8c41d80f Don't let initiate or accept be sent again with Google Voice.
Michael Ruprecht <maiku@pidgin.im>
parents: 26434
diff changeset
277 G_CALLBACK(google_session_ready), session);
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
278 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
279 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
280
26238
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
281 static void
26449
9e381dc6ed24 Rename state-changed enum and values.
Michael Ruprecht <maiku@pidgin.im>
parents: 26443
diff changeset
282 google_session_state_changed_cb(PurpleMedia *media, PurpleMediaState state,
26238
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
283 gchar *sid, gchar *name, GoogleSession *session)
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
284 {
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
285 if (sid == NULL && name == NULL) {
26449
9e381dc6ed24 Rename state-changed enum and values.
Michael Ruprecht <maiku@pidgin.im>
parents: 26443
diff changeset
286 if (state == PURPLE_MEDIA_STATE_END) {
26238
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
287 google_session_destroy(session);
26442
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
288 }
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
289 }
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
290 }
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
291
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
292 static void
26443
511064e5b314 Use the right enum for the parameter.
Michael Ruprecht <maiku@pidgin.im>
parents: 26442
diff changeset
293 google_session_stream_info_cb(PurpleMedia *media, PurpleMediaInfoType type,
26496
11e1e5221460 Create purple_media_stream_info. Add local parameter to stream-info signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26495
diff changeset
294 gchar *sid, gchar *name, gboolean local,
11e1e5221460 Create purple_media_stream_info. Add local parameter to stream-info signal.
Michael Ruprecht <maiku@pidgin.im>
parents: 26495
diff changeset
295 GoogleSession *session)
26442
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
296 {
28372
2e425d79d30b Handle the local accept signal with GTalk/Gmail. This was causing calls
Michael Ruprecht <maiku@pidgin.im>
parents: 28329
diff changeset
297 if (sid != NULL || name != NULL)
2e425d79d30b Handle the local accept signal with GTalk/Gmail. This was causing calls
Michael Ruprecht <maiku@pidgin.im>
parents: 28329
diff changeset
298 return;
2e425d79d30b Handle the local accept signal with GTalk/Gmail. This was causing calls
Michael Ruprecht <maiku@pidgin.im>
parents: 28329
diff changeset
299
26442
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
300 if (type == PURPLE_MEDIA_INFO_HANGUP) {
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
301 xmlnode *sess;
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
302 JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
26238
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
303
26442
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
304 xmlnode_set_attrib(iq->node, "to", session->remote_jid);
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
305 sess = google_session_create_xmlnode(session, "terminate");
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
306 xmlnode_insert_child(iq->node, sess);
26238
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
307
26442
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
308 jabber_iq_send(iq);
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
309 } else if (type == PURPLE_MEDIA_INFO_REJECT) {
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
310 xmlnode *sess;
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
311 JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
312
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
313 xmlnode_set_attrib(iq->node, "to", session->remote_jid);
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
314 sess = google_session_create_xmlnode(session, "reject");
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
315 xmlnode_insert_child(iq->node, sess);
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
316
b68f5a57853a Use stream-info instead of state-changed for hangup and reject.
Michael Ruprecht <maiku@pidgin.im>
parents: 26438
diff changeset
317 jabber_iq_send(iq);
28372
2e425d79d30b Handle the local accept signal with GTalk/Gmail. This was causing calls
Michael Ruprecht <maiku@pidgin.im>
parents: 28329
diff changeset
318 } else if (type == PURPLE_MEDIA_INFO_ACCEPT && local == TRUE) {
2e425d79d30b Handle the local accept signal with GTalk/Gmail. This was causing calls
Michael Ruprecht <maiku@pidgin.im>
parents: 28329
diff changeset
319 google_session_ready(session);
26238
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
320 }
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
321 }
544a16676559 Use the state-changed signal in GTalk code.
Michael Ruprecht <maiku@pidgin.im>
parents: 26232
diff changeset
322
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
323 static GParameter *
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
324 jabber_google_session_get_params(JabberStream *js, guint *num)
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
325 {
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
326 guint num_params;
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
327 GParameter *params = jingle_get_params(js, &num_params);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
328 GParameter *new_params = g_new0(GParameter, num_params + 1);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
329
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
330 memcpy(new_params, params, sizeof(GParameter) * num_params);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
331
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
332 purple_debug_info("jabber", "setting Google jingle compatibility param\n");
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
333 new_params[num_params].name = "compatibility-mode";
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
334 g_value_init(&new_params[num_params].value, G_TYPE_UINT);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
335 g_value_set_uint(&new_params[num_params].value, 1); /* NICE_COMPATIBILITY_GOOGLE */
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
336
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
337 g_free(params);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
338 *num = num_params + 1;
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
339 return new_params;
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
340 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
341
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
342
26495
52846ebe1c7d Don't assume a PurpleMedia instance will be created immediately.
Michael Ruprecht <maiku@pidgin.im>
parents: 26485
diff changeset
343 gboolean
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
344 jabber_google_session_initiate(JabberStream *js, const gchar *who, PurpleMediaSessionType type)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
345 {
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
346 GoogleSession *session;
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
347 JabberBuddy *jb;
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
348 JabberBuddyResource *jbr;
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
349 gchar *jid;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
350 GParameter *params;
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
351 guint num_params;
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
352
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
353 /* construct JID to send to */
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
354 jb = jabber_buddy_find(js, who, FALSE);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
355 if (!jb) {
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
356 purple_debug_error("jingle-rtp",
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
357 "Could not find Jabber buddy\n");
26495
52846ebe1c7d Don't assume a PurpleMedia instance will be created immediately.
Michael Ruprecht <maiku@pidgin.im>
parents: 26485
diff changeset
358 return FALSE;
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
359 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
360 jbr = jabber_buddy_find_resource(jb, NULL);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
361 if (!jbr) {
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
362 purple_debug_error("jingle-rtp",
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
363 "Could not find buddy's resource\n");
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
364 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
365
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
366 if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
367 jid = g_strdup_printf("%s/%s", who, jbr->name);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
368 } else {
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
369 jid = g_strdup(who);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
370 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
371
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
372 session = g_new0(GoogleSession, 1);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
373 session->id.id = jabber_get_next_id(js);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
374 session->id.initiator = g_strdup_printf("%s@%s/%s", js->user->node,
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
375 js->user->domain, js->user->resource);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
376 session->state = SENT_INITIATE;
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
377 session->js = js;
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
378 session->remote_jid = jid;
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
379
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
380 if (type & PURPLE_MEDIA_VIDEO)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
381 session->video = TRUE;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
382
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
383 session->media = purple_media_manager_create_media(
26746
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
384 purple_media_manager_get(),
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
385 purple_connection_get_account(js->gc),
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
386 "fsrtpconference", session->remote_jid, TRUE);
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
387
26331
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
388 purple_media_set_prpl_data(session->media, session);
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
389
28329
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
390 g_signal_connect_swapped(G_OBJECT(session->media),
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
391 "candidates-prepared",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
392 G_CALLBACK(google_session_ready), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
393 g_signal_connect_swapped(G_OBJECT(session->media), "codecs-changed",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
394 G_CALLBACK(google_session_ready), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
395 g_signal_connect(G_OBJECT(session->media), "state-changed",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
396 G_CALLBACK(google_session_state_changed_cb), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
397 g_signal_connect(G_OBJECT(session->media), "stream-info",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
398 G_CALLBACK(google_session_stream_info_cb), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
399
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
400 params = jabber_google_session_get_params(js, &num_params);
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
401
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
402 if (purple_media_add_stream(session->media, "google-voice",
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
403 session->remote_jid, PURPLE_MEDIA_AUDIO,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
404 TRUE, "nice", num_params, params) == FALSE ||
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
405 (session->video && purple_media_add_stream(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
406 session->media, "google-video",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
407 session->remote_jid, PURPLE_MEDIA_VIDEO,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
408 TRUE, "nice", num_params, params) == FALSE)) {
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
409 purple_media_error(session->media, "Error adding stream.");
28329
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
410 purple_media_end(session->media, NULL, NULL);
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
411 g_free(params);
26495
52846ebe1c7d Don't assume a PurpleMedia instance will be created immediately.
Michael Ruprecht <maiku@pidgin.im>
parents: 26485
diff changeset
412 return FALSE;
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
413 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
414
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
415 g_free(params);
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
416
26495
52846ebe1c7d Don't assume a PurpleMedia instance will be created immediately.
Michael Ruprecht <maiku@pidgin.im>
parents: 26485
diff changeset
417 return (session->media != NULL) ? TRUE : FALSE;
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
418 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
419
28076
796f5a14f70b Fix a bunch of memory leaks reported by Josh Mueller. Refs #9822.
Paul Aurich <darkrain42@pidgin.im>
parents: 27950
diff changeset
420 static gboolean
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
421 google_session_handle_initiate(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
422 {
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
423 JabberIq *result;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
424 GList *codecs = NULL, *video_codecs = 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
425 xmlnode *desc_element, *codec_element;
26232
f91c96072586 Wrap FsCodec and remove the Farsight2 include from media.h.
Michael Ruprecht <maiku@pidgin.im>
parents: 26229
diff changeset
426 PurpleMediaCodec *codec;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
427 const char *xmlns;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
428 GParameter *params;
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
429 guint num_params;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
430
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
431 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
432 purple_debug_error("jabber", "Received initiate for active session.\n");
28076
796f5a14f70b Fix a bunch of memory leaks reported by Josh Mueller. Refs #9822.
Paul Aurich <darkrain42@pidgin.im>
parents: 27950
diff changeset
433 return FALSE;
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
434 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
435
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
436 desc_element = xmlnode_get_child(sess, "description");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
437 xmlns = xmlnode_get_namespace(desc_element);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
438
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
439 if (purple_strequal(xmlns, NS_GOOGLE_SESSION_PHONE))
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
440 session->video = FALSE;
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
441 else if (purple_strequal(xmlns, NS_GOOGLE_SESSION_VIDEO))
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
442 session->video = TRUE;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
443 else {
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
444 purple_debug_error("jabber", "Received initiate with "
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
445 "invalid namespace %s.\n", xmlns);
28076
796f5a14f70b Fix a bunch of memory leaks reported by Josh Mueller. Refs #9822.
Paul Aurich <darkrain42@pidgin.im>
parents: 27950
diff changeset
446 return FALSE;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
447 }
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
448
26746
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
449 session->media = purple_media_manager_create_media(
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
450 purple_media_manager_get(),
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
451 purple_connection_get_account(js->gc),
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
452 "fsrtpconference", session->remote_jid, FALSE);
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
453
26331
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
454 purple_media_set_prpl_data(session->media, session);
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
455
28329
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
456 g_signal_connect_swapped(G_OBJECT(session->media),
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
457 "candidates-prepared",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
458 G_CALLBACK(google_session_ready), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
459 g_signal_connect_swapped(G_OBJECT(session->media), "codecs-changed",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
460 G_CALLBACK(google_session_ready), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
461 g_signal_connect(G_OBJECT(session->media), "state-changed",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
462 G_CALLBACK(google_session_state_changed_cb), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
463 g_signal_connect(G_OBJECT(session->media), "stream-info",
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
464 G_CALLBACK(google_session_stream_info_cb), session);
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
465
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
466 params = jabber_google_session_get_params(js, &num_params);
26164
20f15fbe9b21 Very basic receive only GTalk audio sessions.
Michael Ruprecht <maiku@pidgin.im>
parents: 26160
diff changeset
467
26514
058053cffc0e Add purple_media_is_initiator.
Michael Ruprecht <maiku@pidgin.im>
parents: 26501
diff changeset
468 if (purple_media_add_stream(session->media, "google-voice",
058053cffc0e Add purple_media_is_initiator.
Michael Ruprecht <maiku@pidgin.im>
parents: 26501
diff changeset
469 session->remote_jid, PURPLE_MEDIA_AUDIO, FALSE,
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
470 "nice", num_params, params) == FALSE ||
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
471 (session->video && purple_media_add_stream(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
472 session->media, "google-video",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
473 session->remote_jid, PURPLE_MEDIA_VIDEO,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
474 FALSE, "nice", num_params, params) == FALSE)) {
26199
a5530443b54d End google call if stream creation fails.
Michael Ruprecht <maiku@pidgin.im>
parents: 26187
diff changeset
475 purple_media_error(session->media, "Error adding stream.");
26499
759bf410db86 Remove purple_media_hangup.
Michael Ruprecht <maiku@pidgin.im>
parents: 26496
diff changeset
476 purple_media_stream_info(session->media,
28329
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
477 PURPLE_MEDIA_INFO_REJECT, NULL, NULL, TRUE);
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
478 g_free(params);
28076
796f5a14f70b Fix a bunch of memory leaks reported by Josh Mueller. Refs #9822.
Paul Aurich <darkrain42@pidgin.im>
parents: 27950
diff changeset
479 return FALSE;
26199
a5530443b54d End google call if stream creation fails.
Michael Ruprecht <maiku@pidgin.im>
parents: 26187
diff changeset
480 }
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
481
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
482 g_free(params);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
483
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
484 for (codec_element = xmlnode_get_child(desc_element, "payload-type");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
485 codec_element; codec_element = codec_element->next) {
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
486 const char *id, *encoding_name, *clock_rate,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
487 *width, *height, *framerate;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
488 gboolean video;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
489 if (codec_element->name &&
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
490 strcmp(codec_element->name, "payload-type"))
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
491 continue;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
492
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
493 xmlns = xmlnode_get_namespace(codec_element);
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
494 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
495 id = xmlnode_get_attrib(codec_element, "id");
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
496
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
497 if (!session->video ||
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
498 (xmlns && !strcmp(xmlns, NS_GOOGLE_SESSION_PHONE))) {
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
499 clock_rate = xmlnode_get_attrib(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
500 codec_element, "clockrate");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
501 video = FALSE;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
502 } else {
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
503 width = xmlnode_get_attrib(codec_element, "width");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
504 height = xmlnode_get_attrib(codec_element, "height");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
505 framerate = xmlnode_get_attrib(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
506 codec_element, "framerate");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
507 clock_rate = "90000";
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
508 video = TRUE;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
509 }
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
510
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
511 if (id) {
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
512 codec = purple_media_codec_new(atoi(id), encoding_name,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
513 video ? PURPLE_MEDIA_VIDEO :
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
514 PURPLE_MEDIA_AUDIO,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
515 clock_rate ? atoi(clock_rate) : 0);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
516 if (video)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
517 video_codecs = g_list_append(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
518 video_codecs, codec);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
519 else
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
520 codecs = g_list_append(codecs, codec);
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
521 }
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
522 }
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
523
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
524 if (codecs)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
525 purple_media_set_remote_codecs(session->media, "google-voice",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
526 session->remote_jid, codecs);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
527 if (video_codecs)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
528 purple_media_set_remote_codecs(session->media, "google-video",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
529 session->remote_jid, video_codecs);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
530
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
531 purple_media_codec_list_free(codecs);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
532 purple_media_codec_list_free(video_codecs);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
533
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
534 result = jabber_iq_new(js, JABBER_IQ_RESULT);
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
535 jabber_iq_set_id(result, iq_id);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
536 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
537 jabber_iq_send(result);
28076
796f5a14f70b Fix a bunch of memory leaks reported by Josh Mueller. Refs #9822.
Paul Aurich <darkrain42@pidgin.im>
parents: 27950
diff changeset
538
796f5a14f70b Fix a bunch of memory leaks reported by Josh Mueller. Refs #9822.
Paul Aurich <darkrain42@pidgin.im>
parents: 27950
diff changeset
539 return TRUE;
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
540 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
541
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
542 static void
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
543 google_session_handle_candidates(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
544 {
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
545 JabberIq *result;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
546 GList *list = NULL, *video_list = 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
547 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
548 static int name = 0;
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
549 char n[4];
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
550
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
551 for (cand = xmlnode_get_child(sess, "candidate"); cand;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
552 cand = xmlnode_get_next_twin(cand)) {
26229
3e786c9ebb62 Duplicate FsCandidate to remove it from the public interface.
Michael Ruprecht <maiku@pidgin.im>
parents: 26223
diff changeset
553 PurpleMediaCandidate *info;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
554 const gchar *cname = xmlnode_get_attrib(cand, "name");
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
555 const gchar *type = xmlnode_get_attrib(cand, "type");
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
556 const gchar *protocol = xmlnode_get_attrib(cand, "protocol");
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
557 const gchar *address = xmlnode_get_attrib(cand, "address");
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
558 const gchar *port = xmlnode_get_attrib(cand, "port");
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
559 guint component_id;
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
560
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
561 if (cname && type && address && port) {
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
562 PurpleMediaCandidateType candidate_type;
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
563
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
564 g_snprintf(n, sizeof(n), "S%d", name++);
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
565
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
566 if (g_str_equal(type, "local"))
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
567 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_HOST;
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
568 else if (g_str_equal(type, "stun"))
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
569 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_PRFLX;
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
570 else if (g_str_equal(type, "relay"))
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
571 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_RELAY;
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
572 else
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
573 candidate_type = PURPLE_MEDIA_CANDIDATE_TYPE_HOST;
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
574
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
575 if (purple_strequal(cname, "rtcp") ||
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
576 purple_strequal(cname, "video_rtcp"))
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
577 component_id = PURPLE_MEDIA_COMPONENT_RTCP;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
578 else
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
579 component_id = PURPLE_MEDIA_COMPONENT_RTP;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
580
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
581 info = purple_media_candidate_new(n, component_id,
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
582 candidate_type,
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
583 purple_strequal(protocol, "udp") ?
26229
3e786c9ebb62 Duplicate FsCandidate to remove it from the public interface.
Michael Ruprecht <maiku@pidgin.im>
parents: 26223
diff changeset
584 PURPLE_MEDIA_NETWORK_PROTOCOL_UDP :
3e786c9ebb62 Duplicate FsCandidate to remove it from the public interface.
Michael Ruprecht <maiku@pidgin.im>
parents: 26223
diff changeset
585 PURPLE_MEDIA_NETWORK_PROTOCOL_TCP,
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
586 address,
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
587 atoi(port));
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
588 g_object_set(info, "username", xmlnode_get_attrib(cand, "username"),
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
589 "password", xmlnode_get_attrib(cand, "password"), NULL);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
590 if (!strncmp(cname, "video_", 6))
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
591 video_list = g_list_append(video_list, info);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
592 else
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
593 list = g_list_append(list, info);
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
594 }
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
595 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
596
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
597 if (list)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
598 purple_media_add_remote_candidates(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
599 session->media, "google-voice",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
600 session->remote_jid, list);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
601 if (video_list)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
602 purple_media_add_remote_candidates(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
603 session->media, "google-video",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
604 session->remote_jid, video_list);
26229
3e786c9ebb62 Duplicate FsCandidate to remove it from the public interface.
Michael Ruprecht <maiku@pidgin.im>
parents: 26223
diff changeset
605 purple_media_candidate_list_free(list);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
606 purple_media_candidate_list_free(video_list);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
607
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
608 result = jabber_iq_new(js, JABBER_IQ_RESULT);
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
609 jabber_iq_set_id(result, iq_id);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
610 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
611 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
612 }
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
613
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
614 static void
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
615 google_session_handle_accept(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
616 {
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
617 xmlnode *desc_element = xmlnode_get_child(sess, "description");
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
618 xmlnode *codec_element = xmlnode_get_child(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
619 desc_element, "payload-type");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
620 GList *codecs = NULL, *video_codecs = NULL;
26484
131c5b5bcf61 Fix Gtalk bug where it would terminate the session after 15 seconds.
Michael Ruprecht <maiku@pidgin.im>
parents: 26454
diff changeset
621 JabberIq *result = NULL;
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
622 const gchar *xmlns = xmlnode_get_namespace(desc_element);
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
623 gboolean video = (xmlns && !strcmp(xmlns, NS_GOOGLE_SESSION_VIDEO));
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
624
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
625 for (; codec_element; codec_element = codec_element->next) {
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
626 const gchar *xmlns, *encoding_name, *id,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
627 *clock_rate, *width, *height, *framerate;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
628 gboolean video_codec = FALSE;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
629
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
630 if (!purple_strequal(codec_element->name, "payload-type"))
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
631 continue;
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
632
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
633 xmlns = xmlnode_get_namespace(codec_element);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
634 encoding_name = xmlnode_get_attrib(codec_element, "name");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
635 id = xmlnode_get_attrib(codec_element, "id");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
636
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
637 if (!video || purple_strequal(xmlns, NS_GOOGLE_SESSION_PHONE))
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
638 clock_rate = xmlnode_get_attrib(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
639 codec_element, "clockrate");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
640 else {
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
641 clock_rate = "90000";
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
642 width = xmlnode_get_attrib(codec_element, "width");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
643 height = xmlnode_get_attrib(codec_element, "height");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
644 framerate = xmlnode_get_attrib(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
645 codec_element, "framerate");
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
646 video_codec = TRUE;
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
647 }
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
648
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
649 if (id && encoding_name) {
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
650 PurpleMediaCodec *codec = purple_media_codec_new(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
651 atoi(id), encoding_name,
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
652 video_codec ? PURPLE_MEDIA_VIDEO :
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
653 PURPLE_MEDIA_AUDIO,
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
654 clock_rate ? atoi(clock_rate) : 0);
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
655 if (video_codec)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
656 video_codecs = g_list_append(
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
657 video_codecs, codec);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
658 else
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
659 codecs = g_list_append(codecs, codec);
26981
93f90b138e5f Avoid crashing on some more atoi calls and ensure required parameters are !NULL
Paul Aurich <darkrain42@pidgin.im>
parents: 26782
diff changeset
660 }
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
661 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
662
27202
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
663 if (codecs)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
664 purple_media_set_remote_codecs(session->media, "google-voice",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
665 session->remote_jid, codecs);
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
666 if (video_codecs)
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
667 purple_media_set_remote_codecs(session->media, "google-video",
5244a5510e0e Add Gmail video support.
Michael Ruprecht <maiku@pidgin.im>
parents: 27169
diff changeset
668 session->remote_jid, video_codecs);
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
669
26501
c186275f46aa Remove purple_media_accept.
Michael Ruprecht <maiku@pidgin.im>
parents: 26499
diff changeset
670 purple_media_stream_info(session->media, PURPLE_MEDIA_INFO_ACCEPT,
c186275f46aa Remove purple_media_accept.
Michael Ruprecht <maiku@pidgin.im>
parents: 26499
diff changeset
671 NULL, NULL, FALSE);
26484
131c5b5bcf61 Fix Gtalk bug where it would terminate the session after 15 seconds.
Michael Ruprecht <maiku@pidgin.im>
parents: 26454
diff changeset
672
131c5b5bcf61 Fix Gtalk bug where it would terminate the session after 15 seconds.
Michael Ruprecht <maiku@pidgin.im>
parents: 26454
diff changeset
673 result = jabber_iq_new(js, JABBER_IQ_RESULT);
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
674 jabber_iq_set_id(result, iq_id);
26484
131c5b5bcf61 Fix Gtalk bug where it would terminate the session after 15 seconds.
Michael Ruprecht <maiku@pidgin.im>
parents: 26454
diff changeset
675 xmlnode_set_attrib(result->node, "to", session->remote_jid);
131c5b5bcf61 Fix Gtalk bug where it would terminate the session after 15 seconds.
Michael Ruprecht <maiku@pidgin.im>
parents: 26454
diff changeset
676 jabber_iq_send(result);
26205
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
677 }
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
678
f20bb7e9e311 Support initiating voice calls to GTalk and Gmail.
Michael Ruprecht <maiku@pidgin.im>
parents: 26201
diff changeset
679 static void
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
680 google_session_handle_reject(JabberStream *js, GoogleSession *session, xmlnode *sess)
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
681 {
26264
c062fc1f212f Added purple_media_end and removed the purple_media_got_hangup.
Michael Ruprecht <maiku@pidgin.im>
parents: 26248
diff changeset
682 purple_media_end(session->media, NULL, NULL);
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
683 }
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
684
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
685 static void
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
686 google_session_handle_terminate(JabberStream *js, GoogleSession *session, xmlnode *sess)
19885
593613a22e57 You can actually receive Google Talk voice calls with crappy UI now
Sean Egan <seanegan@pidgin.im>
parents: 19882
diff changeset
687 {
26264
c062fc1f212f Added purple_media_end and removed the purple_media_got_hangup.
Michael Ruprecht <maiku@pidgin.im>
parents: 26248
diff changeset
688 purple_media_end(session->media, NULL, 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
689 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
690
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
691 static void
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
692 google_session_parse_iq(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
693 {
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
694 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
695
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
696 if (!strcmp(type, "initiate")) {
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
697 google_session_handle_initiate(js, session, sess, iq_id);
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
698 } else if (!strcmp(type, "accept")) {
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
699 google_session_handle_accept(js, session, sess, iq_id);
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
700 } else if (!strcmp(type, "reject")) {
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
701 google_session_handle_reject(js, session, 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
702 } else if (!strcmp(type, "terminate")) {
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
703 google_session_handle_terminate(js, session, 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
704 } else if (!strcmp(type, "candidates")) {
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
705 google_session_handle_candidates(js, session, sess, iq_id);
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
706 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
707 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
708
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
709 void
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
710 jabber_google_session_parse(JabberStream *js, const char *from,
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
711 JabberIqType type, const char *iq_id,
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
712 xmlnode *session_node)
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
713 {
26331
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
714 GoogleSession *session = 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
715 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
716
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
717 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
718
26331
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
719 GList *iter = NULL;
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
720
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
721 if (type != JABBER_IQ_SET)
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
722 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
723
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
724 id.id = (gchar*)xmlnode_get_attrib(session_node, "id");
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
725 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
726 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
727
23697
299bafcd8eb8 Updates voice and video to use Farsight 2, gets XMPP voice conferences
Michael Ruprecht <maiku@pidgin.im>
parents: 22648
diff changeset
728 id.initiator = (gchar*)xmlnode_get_attrib(session_node, "initiator");
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
729 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
730 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
731
26746
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
732 iter = purple_media_manager_get_media_by_account(
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
733 purple_media_manager_get(),
2a2d45ac9774 Switch media to store accounts rather than connections.
Michael Ruprecht <maiku@pidgin.im>
parents: 26698
diff changeset
734 purple_connection_get_account(js->gc));
26331
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
735 for (; iter; iter = g_list_delete_link(iter, iter)) {
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
736 GoogleSession *gsession =
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
737 purple_media_get_prpl_data(iter->data);
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
738 if (google_session_id_equal(&(gsession->id), &id)) {
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
739 session = gsession;
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
740 break;
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
741 }
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
742 }
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
743 if (iter != NULL) {
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
744 g_list_free(iter);
d5ebef68c29d Remove static sessions variable from google.c.
Michael Ruprecht <maiku@pidgin.im>
parents: 26286
diff changeset
745 }
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
746
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
747 if (session) {
26698
417e1c82963b And google session handling
Paul Aurich <darkrain42@pidgin.im>
parents: 26693
diff changeset
748 google_session_parse_iq(js, session, session_node, iq_id);
19882
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
749 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
750 }
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
751
d8c2a2fc1fbf Basic Google Talk voice call support. No UI; receiving a call auto-accepts it.
Sean Egan <seanegan@pidgin.im>
parents: 19046
diff changeset
752 /* 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
753 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
754 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
755 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
756 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
757 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
758 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
759 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
760 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
761 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
762 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
763 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
764
28329
0300f09b9cd6 Gracefully handle failures to create an FsStream. This was caused by
Michael Ruprecht <maiku@pidgin.im>
parents: 28318
diff changeset
765 google_session_handle_initiate(js, session, session_node, iq_id);
26454
94130b583e0b Clean up usage of USE_VV in the XMPP protocol.
Michael Ruprecht <maiku@pidgin.im>
parents: 26449
diff changeset
766 }
23704
9b88c9b23aed Use USE_VV instead of USE_FARSIGHT.
Michael Ruprecht <maiku@pidgin.im>
parents: 23700
diff changeset
767 #endif /* USE_VV */
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
768
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
769 static void
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
770 jabber_gmail_parse(JabberStream *js, const char *from,
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
771 JabberIqType type, const char *id,
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
772 xmlnode *packet, gpointer nul)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
773 {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
774 xmlnode *child;
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
775 xmlnode *message;
27570
e54277ae75cb disapproval of revision '0eb69320deac850f1a1eb6ff8ea6c64103095ee8'
Paul Aurich <darkrain42@pidgin.im>
parents: 27506
diff changeset
776 const char *to, *url;
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
777 const char *in_str;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
778 char *to_name;
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
779
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
780 int i, count = 1, returned_count;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
781
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
782 const char **tos, **froms, **urls;
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
783 char **subjects;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
784
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
785 if (type == JABBER_IQ_ERROR)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
786 return;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
787
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
788 child = xmlnode_get_child(packet, "mailbox");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
789 if (!child)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
790 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
791
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
792 in_str = xmlnode_get_attrib(child, "total-matched");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
793 if (in_str && *in_str)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
794 count = atoi(in_str);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
795
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
796 /* If Gmail doesn't tell us who the mail is to, let's use our JID */
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
797 to = xmlnode_get_attrib(packet, "to");
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
798
20114
96e715e155e0 applied changes from 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
Richard Laager <rlaager@pidgin.im>
parents: 20107
diff changeset
799 message = xmlnode_get_child(child, "mail-thread-info");
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
800
20114
96e715e155e0 applied changes from 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
Richard Laager <rlaager@pidgin.im>
parents: 20107
diff changeset
801 if (count == 0 || !message) {
25746
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
802 if (count > 0) {
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
803 char *bare_jid = jabber_get_bare_jid(to);
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
804 const char *default_tos[2] = { bare_jid };
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
805
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
806 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, default_tos, NULL, NULL, NULL);
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
807 g_free(bare_jid);
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
808 } else {
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
809 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, NULL, NULL, NULL, NULL);
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
810 }
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
811
20097
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
812 return;
f5bef80db09e applied changes from 19e3744fd4b392cdc631c9efe0ce658537070713
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
813 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
814
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
815 /* 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
816 * accordingly */
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
817 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
818
25746
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
819 froms = g_new0(const char* , returned_count + 1);
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
820 tos = g_new0(const char* , returned_count + 1);
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
821 subjects = g_new0(char* , returned_count + 1);
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
822 urls = g_new0(const char* , returned_count + 1);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
823
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
824 to = xmlnode_get_attrib(packet, "to");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
825 to_name = jabber_get_bare_jid(to);
27570
e54277ae75cb disapproval of revision '0eb69320deac850f1a1eb6ff8ea6c64103095ee8'
Paul Aurich <darkrain42@pidgin.im>
parents: 27506
diff changeset
826 url = xmlnode_get_attrib(child, "url");
e54277ae75cb disapproval of revision '0eb69320deac850f1a1eb6ff8ea6c64103095ee8'
Paul Aurich <darkrain42@pidgin.im>
parents: 27506
diff changeset
827 if (!url || !*url)
e54277ae75cb disapproval of revision '0eb69320deac850f1a1eb6ff8ea6c64103095ee8'
Paul Aurich <darkrain42@pidgin.im>
parents: 27506
diff changeset
828 url = "http://www.gmail.com";
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
829
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
830 message= xmlnode_get_child(child, "mail-thread-info");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
831 for (i=0; message; message = xmlnode_get_next_twin(message), i++) {
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
832 xmlnode *sender_node, *subject_node;
27570
e54277ae75cb disapproval of revision '0eb69320deac850f1a1eb6ff8ea6c64103095ee8'
Paul Aurich <darkrain42@pidgin.im>
parents: 27506
diff changeset
833 const char *from, *tid;
26687
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
834 char *subject;
1e799151fabe Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents: 26088
diff changeset
835
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
836 subject_node = xmlnode_get_child(message, "subject");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
837 sender_node = xmlnode_get_child(message, "senders");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
838 sender_node = xmlnode_get_child(sender_node, "sender");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
839
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
840 while (sender_node && (!xmlnode_get_attrib(sender_node, "unread") ||
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
841 !strcmp(xmlnode_get_attrib(sender_node, "unread"),"0")))
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
842 sender_node = xmlnode_get_next_twin(sender_node);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
843
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
844 if (!sender_node) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
845 i--;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
846 continue;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
847 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
848
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
849 from = xmlnode_get_attrib(sender_node, "name");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
850 if (!from || !*from)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
851 from = xmlnode_get_attrib(sender_node, "address");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
852 subject = xmlnode_get_data(subject_node);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
853 /*
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
854 * url = xmlnode_get_attrib(message, "url");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
855 */
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
856 tos[i] = (to_name != NULL ? to_name : "");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
857 froms[i] = (from != NULL ? from : "");
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
858 subjects[i] = (subject != NULL ? subject : g_strdup(""));
20225
684334efdc19 applied changes from d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
Luke Schierer <lschiere@pidgin.im>
parents: 20209
diff changeset
859 urls[i] = url;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
860
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
861 tid = xmlnode_get_attrib(message, "tid");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
862 if (tid &&
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
863 (js->gmail_last_tid == NULL || strcmp(tid, js->gmail_last_tid) > 0)) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
864 g_free(js->gmail_last_tid);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
865 js->gmail_last_tid = g_strdup(tid);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
866 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
867 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
868
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
869 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
870 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
871 urls, NULL, NULL);
15261
109ac4fcc3e7 [gaim-migrate @ 17989]
Sean Egan <seanegan@pidgin.im>
parents: 15225
diff changeset
872
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
873 g_free(to_name);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
874 g_free(tos);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
875 g_free(froms);
25746
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
876 for (i = 0; i < returned_count; i++)
e97bb5964b19 *** Plucked rev f9080d0b (khc@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents: 23540
diff changeset
877 g_free(subjects[i]);
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
878 g_free(subjects);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
879 g_free(urls);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
880
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
881 in_str = xmlnode_get_attrib(child, "result-time");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
882 if (in_str && *in_str) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
883 g_free(js->gmail_last_time);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
884 js->gmail_last_time = g_strdup(in_str);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
885 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
886 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
887
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
888 void
25817
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 25566
diff changeset
889 jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type,
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 25566
diff changeset
890 const char *id, xmlnode *new_mail)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
891 {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
892 xmlnode *query;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
893 JabberIq *iq;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
894
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
895 /* bail if the user isn't interested */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
896 if (!purple_account_get_check_mail(js->gc->account))
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
897 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
898
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
899 /* Is this an initial incoming mail notification? If so, send a request for more info */
25817
09d6a40a341d Pass IQ handlers type, from, id, and the child node
Paul Aurich <darkrain42@pidgin.im>
parents: 25566
diff changeset
900 if (type != JABBER_IQ_SET)
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
901 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
902
27062
84edb52aea5b Ack the mail notification IQ. Refs #8240.
Paul Aurich <darkrain42@pidgin.im>
parents: 26981
diff changeset
903 /* Acknowledge the notification */
84edb52aea5b Ack the mail notification IQ. Refs #8240.
Paul Aurich <darkrain42@pidgin.im>
parents: 26981
diff changeset
904 iq = jabber_iq_new(js, JABBER_IQ_RESULT);
27081
51d62a0b66f9 Avoid an assertion when acking the gmail poke
Paul Aurich <darkrain42@pidgin.im>
parents: 27062
diff changeset
905 if (from)
51d62a0b66f9 Avoid an assertion when acking the gmail poke
Paul Aurich <darkrain42@pidgin.im>
parents: 27062
diff changeset
906 xmlnode_set_attrib(iq->node, "to", from);
27062
84edb52aea5b Ack the mail notification IQ. Refs #8240.
Paul Aurich <darkrain42@pidgin.im>
parents: 26981
diff changeset
907 xmlnode_set_attrib(iq->node, "id", id);
84edb52aea5b Ack the mail notification IQ. Refs #8240.
Paul Aurich <darkrain42@pidgin.im>
parents: 26981
diff changeset
908 jabber_iq_send(iq);
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
909
28828
7c1855f037e7 jabber: Convert to purple_debug_* convenience functions.
Paul Aurich <darkrain42@pidgin.im>
parents: 28757
diff changeset
910 purple_debug_misc("jabber",
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
911 "Got new mail notification. Sending request for more info\n");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
912
28984
1d84517d56eb jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents: 28980
diff changeset
913 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY);
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
914 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
915 query = xmlnode_get_child(iq->node, "query");
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
916
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
917 if (js->gmail_last_time)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
918 xmlnode_set_attrib(query, "newer-than-time", js->gmail_last_time);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
919 if (js->gmail_last_tid)
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
920 xmlnode_set_attrib(query, "newer-than-tid", js->gmail_last_tid);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
921
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
922 jabber_iq_send(iq);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
923 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
924 }
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
925
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
926 void jabber_gmail_init(JabberStream *js) {
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
927 JabberIq *iq;
27486
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
928 xmlnode *usersetting, *mailnotifications;
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
929
27486
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
930 if (!purple_account_get_check_mail(purple_connection_get_account(js->gc)))
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
931 return;
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
932
27486
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
933 /*
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
934 * Quoting http://code.google.com/apis/talk/jep_extensions/usersettings.html:
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
935 * To ensure better compatibility with other clients, rather than
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
936 * setting this value to "false" to turn off notifications, it is
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
937 * recommended that a client set this to "true" and filter incoming
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
938 * email notifications itself.
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
939 */
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
940 iq = jabber_iq_new(js, JABBER_IQ_SET);
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
941 usersetting = xmlnode_new_child(iq->node, "usersetting");
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
942 xmlnode_set_namespace(usersetting, "google:setting");
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
943 mailnotifications = xmlnode_new_child(usersetting, "mailnotifications");
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
944 xmlnode_set_attrib(mailnotifications, "value", "true");
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
945 jabber_iq_send(iq);
f075cba58507 Fix Google Mail notifications when they inexplicably weren't working. Fixes #3300.
Paul Aurich <darkrain42@pidgin.im>
parents: 27361
diff changeset
946
28984
1d84517d56eb jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents: 28980
diff changeset
947 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY);
15225
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
948 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
949 jabber_iq_send(iq);
d04a059065dd [gaim-migrate @ 17949]
Sean Egan <seanegan@pidgin.im>
parents:
diff changeset
950 }
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
951
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
952 void jabber_google_roster_init(JabberStream *js)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
953 {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
954 JabberIq *iq;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
955 xmlnode *query;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
956
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
957 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
958 query = xmlnode_get_child(iq->node, "query");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
959
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
960 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
961 xmlnode_set_attrib(query, "gr:ext", "2");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
962
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
963 jabber_iq_send(iq);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
964 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
965
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
966 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
967 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
968 PurpleAccount *account = purple_connection_get_account(js->gc);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
969 GSList *list = account->deny;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
970 const char *jid = xmlnode_get_attrib(item, "jid");
27950
5482259bd140 --warnings;
Paul Aurich <darkrain42@pidgin.im>
parents: 27937
diff changeset
971 char *jid_norm = (char *)jabber_normalize(account, jid);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
972
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
973 while (list) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
974 if (!strcmp(jid_norm, (char*)list->data)) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
975 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
27937
8b3b0d69f8d6 Fix a small leak and remove a duplicate xmlnode_set_attrib.
Paul Aurich <darkrain42@pidgin.im>
parents: 27779
diff changeset
976 xmlnode_set_attrib(query, "gr:ext", "2");
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
977 xmlnode_set_attrib(item, "gr:t", "B");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
978 return;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
979 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
980 list = list->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
981 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
982 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
983
15530
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
984 gboolean jabber_google_roster_incoming(JabberStream *js, xmlnode *item)
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
985 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
986 PurpleAccount *account = purple_connection_get_account(js->gc);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
987 const char *jid = xmlnode_get_attrib(item, "jid");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
988 gboolean on_block_list = FALSE;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
989
20209
c1bbdde1f373 applied changes from 6b5f1f48667171fe73de619dd8f80cacd231a2e2
Luke Schierer <lschiere@pidgin.im>
parents: 20186
diff changeset
990 char *jid_norm;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
991
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
992 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
993 const char *subscription = xmlnode_get_attrib(item, "subscription");
28757
055c0bc2a3dd jabber: Don't ignore Google buddies with subscription="none", but ask="subscribe".
Paul Aurich <darkrain42@pidgin.im>
parents: 28669
diff changeset
994 const char *ask = xmlnode_get_attrib(item, "ask");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
995
28757
055c0bc2a3dd jabber: Don't ignore Google buddies with subscription="none", but ask="subscribe".
Paul Aurich <darkrain42@pidgin.im>
parents: 28669
diff changeset
996 if ((!subscription || !strcmp(subscription, "none")) && !ask) {
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
997 /* 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
998 * 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
999 */
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
1000 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
1001 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1002
20209
c1bbdde1f373 applied changes from 6b5f1f48667171fe73de619dd8f80cacd231a2e2
Luke Schierer <lschiere@pidgin.im>
parents: 20186
diff changeset
1003 jid_norm = g_strdup(jabber_normalize(account, jid));
c1bbdde1f373 applied changes from 6b5f1f48667171fe73de619dd8f80cacd231a2e2
Luke Schierer <lschiere@pidgin.im>
parents: 20186
diff changeset
1004
27277
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1005 on_block_list = NULL != g_slist_find_custom(account->deny, jid_norm,
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1006 (GCompareFunc)strcmp);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1007
15530
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1008 if (grt && (*grt == 'H' || *grt == 'h')) {
27277
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1009 /* Hidden; don't show this buddy. */
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1010 GSList *buddies = purple_find_buddies(account, jid_norm);
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1011 if (buddies)
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1012 purple_debug_info("jabber", "Removing %s from local buddy list\n",
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1013 jid_norm);
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1014
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1015 for ( ; buddies; buddies = g_slist_delete_link(buddies, buddies)) {
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1016 purple_blist_remove_buddy(buddies->data);
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1017 }
8a2ecbdd70e4 Various roster cleanups. Refs #7008.
Paul Aurich <darkrain42@pidgin.im>
parents: 27203
diff changeset
1018
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
1019 g_free(jid_norm);
15530
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1020 return FALSE;
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1021 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1022
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1023 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
1024 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
1025 purple_privacy_deny_add(account, jid_norm, TRUE);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1026 } 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
1027 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
1028 purple_privacy_deny_remove(account, jid_norm, TRUE);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1029 }
18739
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
1030
3cd45d53cf26 Various leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 18233
diff changeset
1031 g_free(jid_norm);
15530
9355a1be068e Make deleting Google Talk buddies work
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1032 return TRUE;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1033 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1034
29094
1d72af8f11dd jabber: Clean up this code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 28984
diff changeset
1035 void jabber_google_roster_add_deny(JabberStream *js, const char *who)
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1036 {
29094
1d72af8f11dd jabber: Clean up this code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 28984
diff changeset
1037 PurpleAccount *account;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1038 GSList *buddies;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1039 JabberIq *iq;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1040 xmlnode *query;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1041 xmlnode *item;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1042 xmlnode *group;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
1043 PurpleBuddy *b;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1044 JabberBuddy *jb;
24950
143f594f0cd0 Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24944
diff changeset
1045 const char *balias;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1046
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1047 jb = jabber_buddy_find(js, who, TRUE);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1048
29094
1d72af8f11dd jabber: Clean up this code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 28984
diff changeset
1049 account = purple_connection_get_account(js->gc);
1d72af8f11dd jabber: Clean up this code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 28984
diff changeset
1050 buddies = purple_find_buddies(account, who);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1051 if(!buddies)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1052 return;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1053
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1054 b = buddies->data;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1055
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1056 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1057
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1058 query = xmlnode_get_child(iq->node, "query");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1059 item = xmlnode_new_child(query, "item");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1060
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1061 while(buddies) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
1062 PurpleGroup *g;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1063
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1064 b = buddies->data;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
1065 g = purple_buddy_get_group(b);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1066
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1067 group = xmlnode_new_child(item, "group");
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23540
diff changeset
1068 xmlnode_insert_data(group, purple_group_get_name(g), -1);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1069
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1070 buddies = buddies->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1071 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1072
24950
143f594f0cd0 Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24944
diff changeset
1073 balias = purple_buddy_get_local_buddy_alias(b);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1074 xmlnode_set_attrib(item, "jid", who);
24950
143f594f0cd0 Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24944
diff changeset
1075 xmlnode_set_attrib(item, "name", balias ? balias : "");
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1076 xmlnode_set_attrib(item, "gr:t", "B");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1077 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1078 xmlnode_set_attrib(query, "gr:ext", "2");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1079
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1080 jabber_iq_send(iq);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1081
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1082 /* Synthesize a sign-off */
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1083 if (jb) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1084 JabberBuddyResource *jbr;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1085 GList *l = jb->resources;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1086 while (l) {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1087 jbr = l->data;
15346
ef48613b5b9b [gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents: 15265
diff changeset
1088 if (jbr && jbr->name)
ef48613b5b9b [gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents: 15265
diff changeset
1089 {
28828
7c1855f037e7 jabber: Convert to purple_debug_* convenience functions.
Paul Aurich <darkrain42@pidgin.im>
parents: 28757
diff changeset
1090 purple_debug_misc("jabber", "Removing resource %s\n", jbr->name);
15346
ef48613b5b9b [gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents: 15265
diff changeset
1091 jabber_buddy_remove_resource(jb, jbr->name);
ef48613b5b9b [gaim-migrate @ 18074]
Evan Schoenberg <evands@pidgin.im>
parents: 15265
diff changeset
1092 }
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1093 l = l->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1094 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1095 }
28828
7c1855f037e7 jabber: Convert to purple_debug_* convenience functions.
Paul Aurich <darkrain42@pidgin.im>
parents: 28757
diff changeset
1096
29094
1d72af8f11dd jabber: Clean up this code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 28984
diff changeset
1097 purple_prpl_got_user_status(account, who, "offline", NULL);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1098 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1099
29094
1d72af8f11dd jabber: Clean up this code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 28984
diff changeset
1100 void jabber_google_roster_rem_deny(JabberStream *js, const char *who)
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1101 {
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1102 GSList *buddies;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1103 JabberIq *iq;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1104 xmlnode *query;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1105 xmlnode *item;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1106 xmlnode *group;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
1107 PurpleBuddy *b;
24950
143f594f0cd0 Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24944
diff changeset
1108 const char *balias;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1109
24942
ec72b773a9da More struct hiding work
Richard Laager <rlaager@pidgin.im>
parents: 23540
diff changeset
1110 buddies = purple_find_buddies(purple_connection_get_account(js->gc), who);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1111 if(!buddies)
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1112 return;
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1113
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1114 b = buddies->data;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1115
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1116 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1117
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1118 query = xmlnode_get_child(iq->node, "query");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1119 item = xmlnode_new_child(query, "item");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1120
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1121 while(buddies) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
1122 PurpleGroup *g;
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1123
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1124 b = buddies->data;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15587
diff changeset
1125 g = purple_buddy_get_group(b);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1126
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1127 group = xmlnode_new_child(item, "group");
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23540
diff changeset
1128 xmlnode_insert_data(group, purple_group_get_name(g), -1);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1129
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1130 buddies = buddies->next;
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1131 }
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1132
24950
143f594f0cd0 Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24944
diff changeset
1133 balias = purple_buddy_get_local_buddy_alias(b);
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1134 xmlnode_set_attrib(item, "jid", who);
24950
143f594f0cd0 Alias foo. I think blist.h structs are now completely hidden.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24944
diff changeset
1135 xmlnode_set_attrib(item, "name", balias ? balias : "");
15265
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1136 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1137 xmlnode_set_attrib(query, "gr:ext", "2");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1138
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1139 jabber_iq_send(iq);
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1140
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1141 /* See if he's online */
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1142 jabber_presence_subscription_set(js, who, "probe");
a5b0ab58b05d [gaim-migrate @ 17993]
Sean Egan <seanegan@pidgin.im>
parents: 15261
diff changeset
1143 }
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1144
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1145 /* 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
1146 * 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
1147 * 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
1148 * 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
1149 * 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
1150 */
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1151 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
1152 {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1153 const char *p;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1154
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1155 /* 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
1156 gboolean preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1157
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1158 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
1159 gboolean in_tag = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1160
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1161 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
1162
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1163 GString *str;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1164
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1165 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
1166 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
1167 if (c == '*' && !in_tag) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1168 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
1169 *(p+1) == '\0' ||
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1170 *(p+1) == '<')) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1171 bold_count++;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1172 in_bold = FALSE;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
1173 } 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
1174 bold_count++;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1175 in_bold = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1176 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1177 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1178 } 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
1179 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
1180 *(p+1) == '\0' ||
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1181 *(p+1) == '<')) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1182 italic_count++;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1183 in_italic = FALSE;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
1184 } 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
1185 italic_count++;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1186 in_italic = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1187 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1188 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1189 } 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
1190 in_tag = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1191 } 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
1192 in_tag = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1193 } else if (!in_tag) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1194 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
1195 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1196 else
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1197 preceding_space = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1198 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1199 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1200
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1201 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
1202 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
1203 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1204
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1205 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
1206 gunichar c = g_utf8_get_char(p);
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1207
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1208 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
1209 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
1210 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
1211 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1212
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1213
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1214 if (c == '*' && !in_tag) {
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1215 if (in_bold &&
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1216 (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
1217 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
1218 in_bold = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1219 bold_count--;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
1220 } 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
1221 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
1222 bold_count--;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1223 in_bold = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1224 } else {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1225 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
1226 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1227 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1228 } 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
1229 if (in_italic &&
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1230 (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
1231 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
1232 italic_count--;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1233 in_italic = FALSE;
16988
1aaf51bf0f23 Patch #265. Fix to Google Talk formatting
Sean Egan <seanegan@pidgin.im>
parents: 15884
diff changeset
1234 } 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
1235 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
1236 italic_count--;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1237 in_italic = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1238 } else {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1239 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
1240 }
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1241 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1242 } 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
1243 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
1244 in_tag = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1245 } 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
1246 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
1247 in_tag = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1248 } else if (!in_tag) {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1249 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
1250 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
1251 preceding_space = TRUE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1252 else
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1253 preceding_space = FALSE;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1254 } else {
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1255 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
1256 }
18233
32e258000a57 whitespace
Nathan Walp <nwalp@pidgin.im>
parents: 17327
diff changeset
1257 }
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15530
diff changeset
1258 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
1259 }
21195
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1260
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1261 void jabber_google_presence_incoming(JabberStream *js, const char *user, JabberBuddyResource *jbr)
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1262 {
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1263 if (!js->googletalk)
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1264 return;
27774
343bf770ea2a We have a convenience function to do this. Also, plug a leak of the status
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27701
diff changeset
1265 if (jbr->status && purple_str_has_prefix(jbr->status, "♫ ")) {
21195
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1266 purple_prpl_got_user_status(js->gc->account, user, "tune",
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1267 PURPLE_TUNE_TITLE, jbr->status + strlen("♫ "), NULL);
27774
343bf770ea2a We have a convenience function to do this. Also, plug a leak of the status
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27701
diff changeset
1268 g_free(jbr->status);
21195
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1269 jbr->status = NULL;
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1270 } else {
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1271 purple_prpl_got_user_status_deactive(js->gc->account, user, "tune");
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1272 }
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1273 }
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1274
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1275 char *jabber_google_presence_outgoing(PurpleStatus *tune)
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1276 {
21714
5956ea2cb4af don't set the current tune title if it's NULL
Ka-Hing Cheung <khc@pidgin.im>
parents: 21204
diff changeset
1277 const char *attr = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
5956ea2cb4af don't set the current tune title if it's NULL
Ka-Hing Cheung <khc@pidgin.im>
parents: 21204
diff changeset
1278 return attr ? g_strdup_printf("♫ %s", attr) : g_strdup("");
21195
fd63ef5027d7 Music support for Google Talk
Sean Egan <seanegan@pidgin.im>
parents: 20107
diff changeset
1279 }
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1280
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1281 static void
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
1282 jabber_google_stun_lookup_cb(GSList *hosts, gpointer data,
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1283 const char *error_message)
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1284 {
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1285 JabberStream *js = (JabberStream *) data;
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1287 if (error_message) {
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1288 purple_debug_error("jabber", "Google STUN lookup failed: %s\n",
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1289 error_message);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1290 g_slist_free(hosts);
28317
e706c9dcce0a jabber: Unset the PurpleDnsQueryData when a query fails. Refs #9274.
Paul Aurich <darkrain42@pidgin.im>
parents: 28076
diff changeset
1291 js->stun_query = NULL;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1292 return;
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1293 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1294
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1295 if (hosts && g_slist_next(hosts)) {
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
1296 struct sockaddr *addr = g_slist_next(hosts)->data;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1297 char dst[INET6_ADDRSTRLEN];
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1298 int port;
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1299
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1300 if (addr->sa_family == AF_INET6) {
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
1301 inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1302 dst, sizeof(dst));
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1303 port = ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1304 } else {
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
1305 inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr,
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1306 dst, sizeof(dst));
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1307 port = ntohs(((struct sockaddr_in *) addr)->sin_port);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1308 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1309
28318
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1310 if (js->stun_ip)
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1311 g_free(js->stun_ip);
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1312 js->stun_ip = g_strdup(dst);
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1313 js->stun_port = port;
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1314
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1315 purple_debug_info("jabber", "set Google STUN IP/port address: "
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1316 "%s:%d\n", dst, port);
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1317
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1318 /* unmark ongoing query */
e02ded498369 jabber: Simplify; js is the callback data and can't be NULL.
Paul Aurich <darkrain42@pidgin.im>
parents: 28317
diff changeset
1319 js->stun_query = NULL;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1320 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1321
26782
0d61de90ae02 Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <darkrain42@pidgin.im>
parents: 26746
diff changeset
1322 while (hosts != NULL) {
0d61de90ae02 Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <darkrain42@pidgin.im>
parents: 26746
diff changeset
1323 hosts = g_slist_delete_link(hosts, hosts);
0d61de90ae02 Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <darkrain42@pidgin.im>
parents: 26746
diff changeset
1324 /* Free the address */
0d61de90ae02 Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <darkrain42@pidgin.im>
parents: 26746
diff changeset
1325 g_free(hosts->data);
0d61de90ae02 Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <darkrain42@pidgin.im>
parents: 26746
diff changeset
1326 hosts = g_slist_delete_link(hosts, hosts);
0d61de90ae02 Don't leak the struct sockaddr* from purple_dnsquery_a.
Paul Aurich <darkrain42@pidgin.im>
parents: 26746
diff changeset
1327 }
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1328 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1329
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1330 static void
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1331 jabber_google_jingle_info_common(JabberStream *js, const char *from,
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1332 JabberIqType type, xmlnode *query)
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1333 {
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1334 const xmlnode *stun = xmlnode_get_child(query, "stun");
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1335 gchar *my_bare_jid;
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1336
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1337 /*
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1338 * Make sure that random people aren't sending us STUN servers. Per
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1339 * http://code.google.com/apis/talk/jep_extensions/jingleinfo.html, these
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1340 * stanzas are stamped from our bare JID.
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1341 */
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1342 if (from) {
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1343 my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1344 if (!purple_strequal(from, my_bare_jid)) {
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1345 purple_debug_warning("jabber", "got google:jingleinfo with invalid from (%s)\n",
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1346 from);
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1347 g_free(my_bare_jid);
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1348 return;
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1349 }
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1350
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1351 g_free(my_bare_jid);
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1352 }
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1353
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1354 if (type == JABBER_IQ_ERROR || type == JABBER_IQ_GET)
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1355 return;
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1356
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1357 purple_debug_info("jabber", "got google:jingleinfo\n");
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1358
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1359 if (stun) {
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1360 xmlnode *server = xmlnode_get_child(stun, "server");
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1361
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1362 if (server) {
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1363 const gchar *host = xmlnode_get_attrib(server, "host");
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1364 const gchar *udp = xmlnode_get_attrib(server, "udp");
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1365
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1366 if (host && udp) {
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1367 int port = atoi(udp);
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
1368 /* if there, would already be an ongoing query,
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1369 cancel it */
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1370 if (js->stun_query)
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1371 purple_dnsquery_destroy(js->stun_query);
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1372
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
1373 js->stun_query = purple_dnsquery_a(host, port,
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1374 jabber_google_stun_lookup_cb, js);
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1375 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1376 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1377 }
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1378 /* should perhaps handle relays later on, or maybe wait until
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1379 Google supports a common standard... */
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1380 }
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1381
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1382 static void
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1383 jabber_google_jingle_info_cb(JabberStream *js, const char *from,
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1384 JabberIqType type, const char *id,
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1385 xmlnode *packet, gpointer data)
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1386 {
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1387 xmlnode *query = xmlnode_get_child_with_namespace(packet, "query",
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
1388 NS_GOOGLE_JINGLE_INFO);
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1389
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1390 if (query)
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1391 jabber_google_jingle_info_common(js, from, type, query);
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1392 else
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1393 purple_debug_warning("jabber", "Got invalid google:jingleinfo\n");
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1394 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1395
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1396 void
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1397 jabber_google_handle_jingle_info(JabberStream *js, const char *from,
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1398 JabberIqType type, const char *id,
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1399 xmlnode *child)
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1400 {
26693
0365dcbeaff6 Migrate googleinfo:jabber handlers and add some safety checks.
Paul Aurich <darkrain42@pidgin.im>
parents: 26692
diff changeset
1401 jabber_google_jingle_info_common(js, from, type, child);
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1402 }
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1403
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1404 void
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1405 jabber_google_send_jingle_info(JabberStream *js)
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1406 {
27155
53502d71efdd Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents: 27089
diff changeset
1407 JabberIq *jingle_info =
28979
191942cc7747 jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
1408 jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_JINGLE_INFO);
26286
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1409
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1410 jabber_iq_set_callback(jingle_info, jabber_google_jingle_info_cb,
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1411 NULL);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1412 purple_debug_info("jabber", "sending google:jingleinfo query\n");
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1413 jabber_iq_send(jingle_info);
443041606e32 Add automatic discovery of GTalk STUN servers when using a Gtalk account
Marcus Lundblad <malu@pidgin.im>
parents: 26264
diff changeset
1414 }
28667
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1415
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1416 void google_buddy_node_chat(PurpleBlistNode *node, gpointer data)
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1417 {
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1418 PurpleBuddy *buddy;
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1419 PurpleConnection *gc;
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1420 JabberStream *js;
28669
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1421 JabberChat *chat;
28667
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1422 gchar *room;
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1423 guint32 tmp, a, b;
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1424
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1425 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1426
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1427 buddy = PURPLE_BUDDY(node);
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1428 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
28669
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1429 g_return_if_fail(gc != NULL);
28667
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1430 js = purple_connection_get_protocol_data(gc);
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1431
28669
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1432 /* Generate a version 4 UUID */
28667
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1433 tmp = g_random_int();
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1434 a = 0x4000 | (tmp & 0xFFF); /* 0x4000 to 0x4FFF */
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1435 tmp >>= 12;
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1436 b = ((1 << 3) << 12) | (tmp & 0x3FFF); /* 0x8000 to 0xBFFF */
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1437
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1438 tmp = g_random_int();
28669
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1439 room = g_strdup_printf("private-chat-%08x-%04x-%04x-%04x-%04x%08x",
28667
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1440 g_random_int(),
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1441 tmp & 0xFFFF,
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1442 a,
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1443 b,
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1444 (tmp >> 16) & 0xFFFF, g_random_int());
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1445
28669
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1446 chat = jabber_join_chat(js, room, GOOGLE_GROUPCHAT_SERVER, js->user->node,
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1447 NULL, NULL);
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1448 if (chat) {
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1449 chat->muc = TRUE;
f67839ca0064 jabber: Use the newly refactored code to simplify "Initiate Chat".
Paul Aurich <darkrain42@pidgin.im>
parents: 28667
diff changeset
1450 jabber_chat_invite(gc, chat->id, "", buddy->name);
28667
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1451 }
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1452
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1453 g_free(room);
7bab19738f5e jabber: Add an "Initiate Chat" blist context menu option for GTalk accounts.
Eion Robb <eion@robbmob.com>
parents: 28656
diff changeset
1454 }

mercurial