annotate src/protocols/jabber/jabber.c @ 3427:8fa61405af2b

[gaim-migrate @ 3453] Who never commits anything *now*, Etan? I changed most of the error message text around. If you think any of it should be different, just let me know, or send a patch. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sun, 25 Aug 2002 10:51:24 +0000
parents 000546860da7
children b48065e52337
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 * gaim
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * (at your option) any later version.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * GNU General Public License for more details.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 #include "config.h"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 #endif
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 #include <netdb.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 #include <unistd.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 #include <errno.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 #include <netinet/in.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 #include <arpa/inet.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 #include <string.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 #include <stdlib.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 #include <stdio.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 #include <time.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 #include <sys/socket.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 #include <sys/utsname.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 #include <sys/stat.h>
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 #include "multi.h"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 #include "prpl.h"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 #include "gaim.h"
2232
14e8978f86bb [gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2231
diff changeset
44 #ifdef MAX
14e8978f86bb [gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2231
diff changeset
45 #undef MAX
14e8978f86bb [gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2231
diff changeset
46 #endif
14e8978f86bb [gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2231
diff changeset
47 #ifdef MIN
14e8978f86bb [gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2231
diff changeset
48 #undef MIN
14e8978f86bb [gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2231
diff changeset
49 #endif
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 #include "jabber.h"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 #include "proxy.h"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 #include "pixmaps/available.xpm"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 #include "pixmaps/available-away.xpm"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 #include "pixmaps/available-chat.xpm"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 #include "pixmaps/available-xa.xpm"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 #include "pixmaps/available-dnd.xpm"
3259
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
58 #include "pixmaps/available-error.xpm"
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 /* The priv member of gjconn's is a gaim_connection for now. */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 #define GJ_GC(x) ((struct gaim_connection *)(x)->priv)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 #define IQID_AUTH "__AUTH__"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 #define IQ_NONE -1
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 #define IQ_AUTH 0
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 #define IQ_ROSTER 1
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68
3259
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
69 #define UC_AWAY (0x02 | UC_UNAVAILABLE)
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
70 #define UC_CHAT 0x04
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
71 #define UC_XA (0x08 | UC_UNAVAILABLE)
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
72 #define UC_DND (0x10 | UC_UNAVAILABLE)
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
73 #define UC_ERROR (0x20 | UC_UNAVAILABLE)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 #define DEFAULT_SERVER "jabber.org"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 #define DEFAULT_GROUPCHAT "conference.jabber.org"
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 #define DEFAULT_PORT 5222
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 #define USEROPT_PORT 0
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
81 #define JABBER_TYPING_NOTIFY_INT 15 /* Delay (in seconds) between sending typing notifications */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
82
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
83 /*
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
84 * Note: "was_connected" may seem redundant, but it was needed and I
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
85 * didn't want to touch the Jabber state stuff not specific to Gaim.
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
86 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 typedef struct gjconn_struct {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 /* Core structure */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 pool p; /* Memory allocation pool */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 int state; /* Connection state flag */
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
91 int was_connected; /* We were once connected */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 int fd; /* Connection file descriptor */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 jid user; /* User info */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 char *pass; /* User passwd */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 /* Stream stuff */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 int id; /* id counter for jab_getid() function */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 char idbuf[9]; /* temporary storage for jab_getid() */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 char *sid; /* stream id from server, for digest auth */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 XML_Parser parser; /* Parser instance */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 xmlnode current; /* Current node in parsing instance.. */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 /* Event callback ptrs */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
104 void (*on_state)(struct gjconn_struct *gjc, int state);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
105 void (*on_packet)(struct gjconn_struct *gjc, jpacket p);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
106
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
107 GHashTable *queries; /* query tracker */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 void *priv;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 } *gjconn, gjconn_struct;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
113 typedef void (*gjconn_state_h)(gjconn gjc, int state);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
114 typedef void (*gjconn_packet_h)(gjconn gjc, jpacket p);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 static gjconn gjab_new(char *user, char *pass, void *priv);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
117 static void gjab_delete(gjconn gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
118 static void gjab_state_handler(gjconn gjc, gjconn_state_h h);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
119 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
120 static void gjab_start(gjconn gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
121 static void gjab_stop(gjconn gjc);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 /*
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
123 static int gjab_getfd(gjconn gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
124 static jid gjab_getjid(gjconn gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
125 static char *gjab_getsid(gjconn gjc);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
127 static char *gjab_getid(gjconn gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
128 static void gjab_send(gjconn gjc, xmlnode x);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
129 static void gjab_send_raw(gjconn gjc, const char *str);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
130 static void gjab_recv(gjconn gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
131 static void gjab_auth(gjconn gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
132
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
133 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
134 * It is *this* to which we point the gaim_connection proto_data
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
135 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 struct jabber_data {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
137 gjconn gjc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 gboolean did_import;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
139 GSList *chats;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 time_t idle;
2800
0ad63a625eec [gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2791
diff changeset
141 gboolean die;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
142 GHashTable *buddies;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 };
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
145 /*
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
146 * Used in jabber_buddy_data.invisible, below
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
147 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
148 #define JABBER_NOT_INVIS 0x00
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
149 #define JABBER_SERV_INVIS 0x01 /* Invisible set on server */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
150 #define JABBER_BUD_INVIS 0x02 /* Invisible set on buddy */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
151
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
152 /*
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
153 * It is *this* to which we point the buddy proto_data
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
154 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
155 struct jabber_buddy_data {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
156 GSList *resources;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
157 char *error_msg;
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
158 unsigned invisible; /* We've set presence type invisible for this buddy */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
159 };
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
160
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
161 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
162 * per-resource info
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
163 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
164 typedef struct jabber_resource_info {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
165 char *name;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
166 int priority;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
167 int state;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
168 char *away_msg;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
169 char *thread_id;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
170 gboolean has_composing;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
171 } *jab_res_info;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
172
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
173 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
174 * For our own jid handling
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
175 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
176 * We do our own so we can cleanly parse buddy names
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
177 * (user@server/resource) and rid ourselves of the
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
178 * struct when we're done with it. The Jabber lib
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
179 * structs last the life of the pool--we frequently
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
180 * don't want that.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
181 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
182 * We use the real jid structs so we can make use of
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
183 * jid_safe(), jid_cmp() and some others.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
184 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
185 * BE CAREFUL using the Jabber lib routines.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
186 * Many of them assume pool use and are not
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
187 * amenable to use with our own!
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
188 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
189 * We give them special names so we know, throughout
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
190 * the code, that they're not alloc'd out of pool
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
191 * memory and we can, and must, dispose of them when
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
192 * we're done with 'em.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
193 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
194 #define gaim_jid_struct jid_struct
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
195 typedef struct gaim_jid_struct *gaim_jid;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
196
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
197 /*
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
198 * Jabber "chat group" info. Pointers to these go in jabber_data
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
199 * pending and existing chats lists.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
200 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 struct jabber_chat {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
202 gaim_jid gjid;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 struct gaim_connection *gc;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 struct conversation *b;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 int id;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
206 int state;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 };
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
209 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
210 * Jabber chat states...
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
211 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
212 * Note: due to a bug in one version of the Jabber server, subscriptions
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
213 * to chat groups aren't (always?) properly removed at the server. The
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
214 * result is clients receive Jabber "presence" notifications for JIDs
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
215 * they no longer care about. The problem with such vestigial notifies is
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
216 * that we really have no way of telling if it's vestigial or if it's a
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
217 * valid "buddy" presence notification. So we keep jabber_chat structs
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
218 * around after leaving a chat group and simply mark them "closed." That
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
219 * way we can test for such errant presence notifications. I.e.: if we
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
220 * get a presence notfication from a JID that matches a chat group JID,
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
221 * we disregard it.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
222 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
223 #define JCS_PENDING 1 /* pending */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
224 #define JCS_ACTIVE 2 /* active */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
225 #define JCS_CLOSED 3 /* closed */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
226
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
227
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 static char *jabber_name()
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 return "Jabber";
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
233 #define STATE_EVT(arg) if(gjc->on_state) { (gjc->on_state)(gjc, (arg) ); }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
234
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
235 static void jabber_handlevcard(gjconn, xmlnode, char *);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 static char *create_valid_jid(const char *given, char *server, char *resource)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239 char *valid;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 if (!strchr(given, '@'))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 valid = g_strdup_printf("%s@%s/%s", given, server, resource);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 else if (!strchr(strchr(given, '@'), '/'))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 valid = g_strdup_printf("%s/%s", given, resource);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246 valid = g_strdup(given);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248 return valid;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
251 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
252 * Dispose of a gaim_jid_struct
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
253 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
254 static void gaim_jid_free(gaim_jid gjid)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
255 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
256 if(gjid) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
257 if(gjid->resource)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
258 free(gjid->resource);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
259 if(gjid->user)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
260 free(gjid->user);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
261 if(gjid->server)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
262 free(gjid->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
263 if(gjid->full)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
264 free(gjid->full);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
265 free(gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
266 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
267 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
268
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
269 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
270 * Create a new gjid struct
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
271 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
272 * Unlike jid_new(), also creates "full."
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
273 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
274 * Shamelessly copied, in part, from jid.c: jid_new()
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
275 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
276 * Caller is responsible for freeing the space allocated by this via
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
277 * gaim_jid_free().
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
278 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
279 * JFIXME: Has a local declaration for jid.c:jid_safe(). I've put in a
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
280 * request to have that added to libjabber's lib.h file. (JSeymour)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
281 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
282 static gaim_jid gaim_jid_new(char *name)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
283 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
284 extern jid jid_safe(jid); /* *retch* */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
285
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
286 gaim_jid gjid = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
287
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
288 if(name && strlen(name)) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
289 char *server, *resource, *type, *str;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
290 int full_len = 0;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
291
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
292 /* user@server/resource */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
293
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
294 str = strdup(name); /* we mangle a copy */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
295
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
296 gjid = calloc(1, sizeof(struct gaim_jid_struct));
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
297
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
298 if((resource = strstr(str, "/")) != NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
299 *resource = '\0';
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
300 ++resource;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
301 if((full_len = strlen(resource)) > 0) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
302 gjid->resource = strdup(resource);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
303 ++full_len; /* for later "/" addition */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
304 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
305 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
306 resource = str + strlen(str); /* point to end */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
307 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
308
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
309 type = strstr(str, ":");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
310 if(type != NULL && type < resource) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
311 *type = '\0';
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
312 ++type;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
313 str = type; /* ignore the type: prefix */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
314 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
315
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
316 server = strstr(str, "@");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
317
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
318 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
319 * if there's no @, it's just the server address
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
320 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
321 if(server == NULL || server > resource) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
322 gjid->server = strdup(str);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
323 full_len += strlen(str);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
324 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
325 *server = '\0';
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
326 ++server;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
327 gjid->server = strdup(server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
328 full_len += strlen(server) + 1; /* account for later "@" */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
329 if(strlen(str) > 0) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
330 gjid->user = strdup(str);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
331 full_len += strlen(str);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
332 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
333 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
334
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
335 free(str);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
336
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
337 if(!jid_safe(gjid)) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
338 gaim_jid_free(gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
339 gjid = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
340 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
341 if(full_len) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
342 char *s = gjid->full = malloc(++full_len);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
343
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
344 if(gjid->user) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
345 strcpy(s, gjid->user);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
346 s += strlen(gjid->user);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
347 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
348 if(gjid->server) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
349 if(s > gjid->full)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
350 *(s++) = '@';
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
351 strcpy(s, gjid->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
352 s += strlen(gjid->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
353 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
354 if(gjid->resource) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
355 *(s++) = '/';
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
356 strcpy(s, gjid->resource);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
357 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
358 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
359 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
360 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
361
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
362 return gjid;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
363 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
364
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
365 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
366 * Get a "username@server" from unadorned "username"
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
367 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
368 * If there's no "@server" part and "who" doesn't match the
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
369 * gjconn server (which would indicate that "who" *is* the
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
370 * server in case of server messages), the gjconn server is
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
371 * appended.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
372 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
373 * If incl_resource is TRUE (non-0), the returned string
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
374 * includes the "/resource" part (if it exists), otherwise not.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
375 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
376 * Allocates space for returned string. Caller is
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
377 * responsible for freeing it with g_free().
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
378 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
379 * If "gjid" is non-null, sets that as well. Caller is
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
380 * reponsible for freeing that via gaim_jid_free() when done
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
381 * with it.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
382 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
383 static gchar *get_realwho(gjconn gjc, char *who, int incl_resource, gaim_jid *gjid)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
384 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
385 gaim_jid my_gjid;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
386 gchar *my_who;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
387 gchar *realwho = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
388
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
389 if(!(who && who[0])) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
390 return NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
391 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
392
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
393 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
394 * Bare username and "username" not the server itself?
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
395 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
396 if(!strchr(who, '@') && strcasecmp(who, gjc->user->server)) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
397 my_who = g_strdup_printf("%s@%s", who, gjc->user->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
398 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
399 my_who = g_strdup(who);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
400 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
401
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
402 if((my_gjid = gaim_jid_new(my_who)) != NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
403 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
404 * If there's no "user" part, "who" was just the server or perhaps a transport (?)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
405 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
406 if(my_gjid->user) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
407 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
408 * Include "/resource" bit?
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
409 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
410 if(incl_resource) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
411 realwho = g_strdup(my_gjid->full);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
412 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
413 realwho = g_strdup_printf("%s@%s", my_gjid->user, my_gjid->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
414 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
415 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
416 realwho = g_strdup(my_gjid->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
417 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
418 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
419
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
420 g_free(my_who);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
421
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
422 if(gjid) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
423 *gjid = my_gjid;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
424 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
425 gaim_jid_free(my_gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
426 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
427
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
428 return realwho;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
429 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
430
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 static gjconn gjab_new(char *user, char *pass, void *priv)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
432 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433 pool p;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
434 gjconn gjc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
436 if (!user)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
437 return (NULL);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439 p = pool_new();
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440 if (!p)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441 return (NULL);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
442 gjc = pmalloc_x(p, sizeof(gjconn_struct), 0);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
443 if (!gjc) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
444 pool_free(p); /* no need for this anymore! */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445 return (NULL);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
446 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
447 gjc->p = p;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
448
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
449 if((gjc->user = jid_new(p, user)) == NULL) {
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
450 pool_free(p); /* no need for this anymore! */
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
451 return (NULL);
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
452 }
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
453
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
454 gjc->pass = strdup(pass);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
455
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
456 gjc->state = JCONN_STATE_OFF;
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
457 gjc->was_connected = 0;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
458 gjc->id = 1;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
459 gjc->fd = -1;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
460
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
461 gjc->priv = priv;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
462
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
463 return gjc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
466 static void gjab_delete(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
468 if (!gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
469 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
471 gjab_stop(gjc);
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
472 free(gjc->pass);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
473 pool_free(gjc->p);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
476 static void gjab_state_handler(gjconn gjc, gjconn_state_h h)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
477 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
478 if (!gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
479 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
481 gjc->on_state = h;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
482 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
484 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
486 if (!gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
489 gjc->on_packet = h;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
491
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
492 static void gjab_stop(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
494 if (!gjc || gjc->state == JCONN_STATE_OFF)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
496
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
497 gjab_send_raw(gjc, "</stream:stream>");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
498 gjc->state = JCONN_STATE_OFF;
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
499 gjc->was_connected = 0;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
500 close(gjc->fd);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
501 gjc->fd = -1;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
502 XML_ParserFree(gjc->parser);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
503 gjc->parser = NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
504 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
505
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
506 /*
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
507 static int gjab_getfd(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
509 if (gjc)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
510 return gjc->fd;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
511 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
512 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
513 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
514
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
515 static jid gjab_getjid(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
516 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
517 if (gjc)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
518 return (gjc->user);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
523 static char *gjab_getsid(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
525 if (gjc)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
526 return (gjc->sid);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
532 static char *gjab_getid(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
534 snprintf(gjc->idbuf, 8, "%d", gjc->id++);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
535 return &gjc->idbuf[0];
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
537
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
538 static void gjab_send(gjconn gjc, xmlnode x)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
540 if (gjc && gjc->state != JCONN_STATE_OFF) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
541 char *buf = xmlnode2str(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 if (buf)
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
543 write(gjc->fd, buf, strlen(buf));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 debug_printf("gjab_send: %s\n", buf);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
545 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
546 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
547
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
548 static void gjab_send_raw(gjconn gjc, const char *str)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
549 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
550 if (gjc && gjc->state != JCONN_STATE_OFF) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
551 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
552 * JFIXME: No error detection?!?!
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
553 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
554 if(write(gjc->fd, str, strlen(str)) < 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
555 fprintf(stderr, "DBG: Problem sending. Error: %d\n", errno);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
556 fflush(stderr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
557 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
558 debug_printf("gjab_send_raw: %s\n", str);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
561
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
562 static void gjab_reqroster(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
563 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
564 xmlnode x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
565
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
566 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
567 xmlnode_put_attrib(x, "id", gjab_getid(gjc));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
568
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
569 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
573 static void gjab_reqauth(gjconn gjc)
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
574 {
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
575 xmlnode x, y, z;
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
576 char *user;
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
577
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
578 if (!gjc)
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
579 return;
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
580
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
581 x = jutil_iqnew(JPACKET__GET, NS_AUTH);
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
582 xmlnode_put_attrib(x, "id", IQID_AUTH);
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
583 y = xmlnode_get_tag(x, "query");
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
584
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
585 user = gjc->user->user;
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
586
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
587 if (user) {
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
588 z = xmlnode_insert_tag(y, "username");
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
589 xmlnode_insert_cdata(z, user, -1);
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
590 }
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
591
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
592 gjab_send(gjc, x);
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
593 xmlnode_free(x);
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
594 }
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
595
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
596 static void gjab_auth(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
597 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
598 xmlnode x, y, z;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
599 char *hash, *user;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
600
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
601 if (!gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
602 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
603
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
604 x = jutil_iqnew(JPACKET__SET, NS_AUTH);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
605 xmlnode_put_attrib(x, "id", IQID_AUTH);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
606 y = xmlnode_get_tag(x, "query");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
607
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
608 user = gjc->user->user;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
609
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
610 if (user) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
611 z = xmlnode_insert_tag(y, "username");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
612 xmlnode_insert_cdata(z, user, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
613 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
615 z = xmlnode_insert_tag(y, "resource");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
616 xmlnode_insert_cdata(z, gjc->user->resource, -1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
617
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
618 if (gjc->sid) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
619 debug_printf("digest authentication (sid %s)\n", gjc->sid);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620 z = xmlnode_insert_tag(y, "digest");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
621 hash = pmalloc(x->p, strlen(gjc->sid) + strlen(gjc->pass) + 1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
622 strcpy(hash, gjc->sid);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
623 strcat(hash, gjc->pass);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
624 hash = shahash(hash);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
625 xmlnode_insert_cdata(z, hash, 40);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
626 } else {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
627 z = xmlnode_insert_tag(y, "password");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
628 xmlnode_insert_cdata(z, gjc->pass, -1);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
629 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
630
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
631 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
632 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
633
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
634 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
635 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
636
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
637 static void gjab_recv(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
638 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
639 static char buf[4096];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
640 int len;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
641
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
642 if (!gjc || gjc->state == JCONN_STATE_OFF)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
643 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
644
3234
6a96436a542a [gaim-migrate @ 3251]
Jim Seymour <jseymour>
parents: 3229
diff changeset
645 if ((len = read(gjc->fd, buf, sizeof(buf) - 1)) > 0) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
646 struct jabber_data *jd = GJ_GC(gjc)->proto_data;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
647 buf[len] = '\0';
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
648 debug_printf("input (len %d): %s\n", len, buf);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
649 XML_Parse(gjc->parser, buf, len, 0);
2800
0ad63a625eec [gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2791
diff changeset
650 if (jd->die)
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
651 signoff(GJ_GC(gjc));
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
652 } else if (len < 0 || errno != EAGAIN) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
653 STATE_EVT(JCONN_STATE_OFF)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
654 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
655 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
656
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
657 static void startElement(void *userdata, const char *name, const char **attribs)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
658 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
659 xmlnode x;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
660 gjconn gjc = (gjconn) userdata;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
661
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
662 if (gjc->current) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
663 /* Append the node to the current one */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
664 x = xmlnode_insert_tag(gjc->current, name);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
665 xmlnode_put_expat_attribs(x, attribs);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
666
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
667 gjc->current = x;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
668 } else {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
669 x = xmlnode_new_tag(name);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
670 xmlnode_put_expat_attribs(x, attribs);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
671 if (strcmp(name, "stream:stream") == 0) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
672 /* special case: name == stream:stream */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
673 /* id attrib of stream is stored for digest auth */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
674 gjc->sid = g_strdup(xmlnode_get_attrib(x, "id"));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
675 /* STATE_EVT(JCONN_STATE_AUTH) */
2635
8c75e59e4bdf [gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2607
diff changeset
676 xmlnode_free(x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
677 } else {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
678 gjc->current = x;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
679 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
680 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
681 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
682
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
683 static void endElement(void *userdata, const char *name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
684 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
685 gjconn gjc = (gjconn) userdata;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
686 xmlnode x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
687 jpacket p;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
688
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
689 if (gjc->current == NULL) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
690 /* we got </stream:stream> */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
691 STATE_EVT(JCONN_STATE_OFF)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
692 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
693 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
694
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
695 x = xmlnode_get_parent(gjc->current);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
696
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
697 if (!x) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
698 /* it is time to fire the event */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
699 p = jpacket_new(gjc->current);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
700
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
701 if (gjc->on_packet)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
702 (gjc->on_packet) (gjc, p);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
703 else
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
704 xmlnode_free(gjc->current);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
705 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
706
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
707 gjc->current = x;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
708 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
709
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
710 static void jabber_callback(gpointer data, gint source, GaimInputCondition condition)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
711 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
712 struct gaim_connection *gc = (struct gaim_connection *)data;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
713 struct jabber_data *jd = (struct jabber_data *)gc->proto_data;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
714
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
715 gjab_recv(jd->gjc);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
716 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
717
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
718 static void charData(void *userdata, const char *s, int slen)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
719 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
720 gjconn gjc = (gjconn) userdata;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
721
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
722 if (gjc->current)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
723 xmlnode_insert_cdata(gjc->current, s, slen);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
724 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
725
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2086
diff changeset
726 static void gjab_connected(gpointer data, gint source, GaimInputCondition cond)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
727 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
728 xmlnode x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
729 char *t, *t2;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
730 struct gaim_connection *gc = data;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
731 struct jabber_data *jd;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
732 gjconn gjc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
733
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
734 if (!g_slist_find(connections, gc)) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
735 close(source);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
736 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
737 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
738
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
739 jd = gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
740 gjc = jd->gjc;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
741
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
742 if (gjc->fd != source)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
743 gjc->fd = source;
2300
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2289
diff changeset
744
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
745 if (source == -1) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
746 STATE_EVT(JCONN_STATE_OFF)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
747 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
748 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
749
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
750 gjc->state = JCONN_STATE_CONNECTED;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
751 STATE_EVT(JCONN_STATE_CONNECTED)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
752
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
753 /* start stream */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
754 x = jutil_header(NS_CLIENT, gjc->user->server);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
755 t = xmlnode2str(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
756 /* this is ugly, we can create the string here instead of jutil_header */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
757 /* what do you think about it? -madcat */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
758 t2 = strstr(t, "/>");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
759 *t2++ = '>';
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
760 *t2 = '\0';
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
761 gjab_send_raw(gjc, "<?xml version='1.0'?>");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
762 gjab_send_raw(gjc, t);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
763 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
764
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
765 gjc->state = JCONN_STATE_ON;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
766 STATE_EVT(JCONN_STATE_ON);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
767
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
768 gc = GJ_GC(gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
769 gc->inpa = gaim_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
770 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
771
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
772 static void gjab_start(gjconn gjc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
773 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
774 struct aim_user *user;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
775 int port;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
776
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
777 if (!gjc || gjc->state != JCONN_STATE_OFF)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
778 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
779
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
780 user = GJ_GC(gjc)->user;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
781 port = user->proto_opt[USEROPT_PORT][0] ? atoi(user->proto_opt[USEROPT_PORT]) : DEFAULT_PORT;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
782
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
783 gjc->parser = XML_ParserCreate(NULL);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
784 XML_SetUserData(gjc->parser, (void *)gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
785 XML_SetElementHandler(gjc->parser, startElement, endElement);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
786 XML_SetCharacterDataHandler(gjc->parser, charData);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
787
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
788 gjc->fd = proxy_connect(gjc->user->server, port, gjab_connected, GJ_GC(gjc));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
789 if (!user->gc || (gjc->fd < 0)) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
790 STATE_EVT(JCONN_STATE_OFF)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
791 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
792 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
793 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
794
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
795 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
796 * Find chat by chat group name
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
797 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
798 static struct conversation *find_chat(struct gaim_connection *gc, char *name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
799 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
800 GSList *bcs = gc->buddy_chats;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
801 struct conversation *b = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
802 char *chat = g_strdup(normalize(name));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
803
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
804 while (bcs) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
805 b = bcs->data;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
806 if (!strcasecmp(normalize(b->name), chat))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
807 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
808 b = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
809 bcs = bcs->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
810 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
811
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
812 g_free(chat);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
813 return b;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
814 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
815
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
816 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
817 * Find chat by "chat id"
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
818 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
819 * Returns: 0 on success and jabber_chat pointer set
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
820 * or -EINVAL on error and jabber_chat pointer is
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
821 * undefined.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
822 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
823 * TBD: Slogging through the buddy_chats list seems
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
824 * redundant since the chat i.d. is mirrored in the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
825 * jabber_chat struct list. But that's the way it
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
826 * was, so that's the way I'm leaving it--for now.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
827 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
828 static int jabber_find_chat_by_convo_id(struct gaim_connection *gc, int id, struct jabber_chat **jc)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
829 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
830 GSList *bcs = gc->buddy_chats;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
831 struct conversation *b = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
832 struct jabber_data *jd = gc->proto_data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
833
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
834 *jc = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
835
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
836 while(bcs != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
837 b = bcs->data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
838 if (id == b->id)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
839 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
840 bcs = bcs->next;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
841 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
842
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
843 if (bcs != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
844 bcs = jd->chats;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
845 while (bcs != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
846 *jc = bcs->data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
847 if ((*jc)->state == JCS_ACTIVE && (*jc)->b == b)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
848 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
849 bcs = bcs->next;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
850 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
851 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
852
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
853 return(bcs == NULL? -EINVAL : 0);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
854 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
855
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
856 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
857 * Find any chat
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
858 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
859 static struct jabber_chat *find_any_chat(struct gaim_connection *gc, jid chat)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
860 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
861 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
862 struct jabber_chat *jc = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
863
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
864 while (jcs) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
865 jc = jcs->data;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
866 if (!jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER))
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
867 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
868 jc = NULL;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
869 jcs = jcs->next;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
870 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
871
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
872 return jc;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
873 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
874
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
875
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
876 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
877 * Find existing/active Jabber chat
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
878 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
879 static struct jabber_chat *find_existing_chat(struct gaim_connection *gc, jid chat)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
880 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
881 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
882 struct jabber_chat *jc = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
883
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
884 while (jcs) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
885 jc = jcs->data;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
886 if (jc->state == JCS_ACTIVE && !jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER))
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
887 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
888 jc = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
889 jcs = jcs->next;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
890 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
891
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
892 return jc;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
893 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
894
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
895 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
896 * Find pending chat
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
897 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
898 static struct jabber_chat *find_pending_chat(struct gaim_connection *gc, jid chat)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
899 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
900 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
901 struct jabber_chat *jc = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
902
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
903 while (jcs) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
904 jc = jcs->data;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
905 if (jc->state == JCS_PENDING && !jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER))
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
906 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
907 jc = NULL;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
908 jcs = jcs->next;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
909 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
910
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
911 return jc;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
912 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
913
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
914 static gboolean find_chat_buddy(struct conversation *b, char *name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
915 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
916 GList *m = b->in_room;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
917
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
918 while (m) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
919 if (!strcmp(m->data, name))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
920 return TRUE;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
921 m = m->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
922 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
923
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
924 return FALSE;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
925 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
926
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
927 /*
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
928 * Remove a buddy from the (gaim) buddylist (if he's on it)
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
929 */
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
930 static void jabber_remove_gaim_buddy(struct gaim_connection *gc, char *buddyname)
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
931 {
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
932 struct buddy *b;
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
933
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
934 if ((b = find_buddy(gc, buddyname)) != NULL) {
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
935 struct group *group;
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
936
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
937 group = find_group_by_buddy(gc, buddyname);
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
938 debug_printf("removing buddy [1]: %s, from group: %s\n", buddyname, group->name);
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
939 remove_buddy(gc, group, b);
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
940 do_export(gc);
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
941 }
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
942 }
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
943
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
944 static void jabber_change_passwd(struct gaim_connection *gc, char *old, char *new)
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
945 {
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
946 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
947
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
948 if(strcmp(old, gjc->pass))
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
949 {
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
950 do_error_dialog(_("Unable to change password."),
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
951 _("The current password you entered is incorrect. Your password has "
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
952 "not been changed."), GAIM_ERROR);
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
953 }
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
954 else if(!strcmp(old, new))
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
955 {
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
956 do_error_dialog(_("Unable to change password"),
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
957 _("The new password you entered is the same as your current passord. "
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
958 "Your password remains the same."), GAIM_ERROR);
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
959 }
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
960 else
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
961 {
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
962 xmlnode x, y, z;
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
963 char *id;
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
964
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
965 x = jutil_iqnew(JPACKET__SET, NS_REGISTER);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
966 xmlnode_put_attrib(x, "to", gjc->user->server);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
967 y = xmlnode_get_tag(x, "query");
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
968 z = xmlnode_insert_tag(y, "username");
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
969 xmlnode_insert_cdata(z, gjc->user->user, -1);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
970 z = xmlnode_insert_tag(y, "password");
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
971 xmlnode_insert_cdata(z, new, -1);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
972
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
973 id = gjab_getid(gjc);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
974 xmlnode_put_attrib(x, "id", id);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
975
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
976 free(gjc->pass);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
977 gjc->pass = strdup(new);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
978
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
979 g_hash_table_insert(gjc->queries, g_strdup(id), g_strdup("change_password"));
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
980
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
981 gjab_send(gjc, x);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
982 xmlnode_free(x);
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
983 }
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
984 }
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
985
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
986 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
987 * Return pointer to jabber_buddy_data if buddy found. Create if necessary.
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
988 */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
989 static struct jabber_buddy_data* jabber_find_buddy(struct gaim_connection *gc, char *buddy)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
990 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
991 struct jabber_data *jd = gc->proto_data;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
992 gpointer val;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
993 char *realwho;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
994
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
995 if((realwho = get_realwho(jd->gjc, buddy, FALSE, NULL)) == NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
996 return NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
997
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
998 val = g_hash_table_lookup(jd->buddies, realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
999 if(val) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1000 g_free(realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1001 return (struct jabber_buddy_data *)val;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1002
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1003 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1004 struct jabber_buddy_data *jbd = g_new0(struct jabber_buddy_data, 1);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1005 jbd->error_msg = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1006 jbd->resources = NULL;
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
1007 jbd->invisible = JABBER_NOT_INVIS;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1008 g_hash_table_insert(jd->buddies, g_strdup(realwho), jbd);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1009 g_free(realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1010 return jbd;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1011 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1012 }
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
1013
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
1014 /*
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1015 * find a resource by name, or if no name given, return the "default" resource
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1016 * default being the highest priority one.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1017 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1018
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1019 static jab_res_info jabber_find_resource(struct gaim_connection *gc, char *who)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1020 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1021 GSList *resources;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1022 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, who);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1023 jab_res_info jri = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1024 char *res = strstr(who, "/");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1025
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1026 if(res)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1027 res++;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1028
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1029 if(jbd)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1030 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1031 resources = jbd->resources;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1032 while(resources)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1033 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1034 if(!jri && !res) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1035 jri = (jab_res_info) resources->data;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1036 } else if(!res) { /* we're looking for the default priority, so... */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1037 if(((jab_res_info) resources->data)->priority >= jri->priority)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1038 jri = (jab_res_info) resources->data;
3337
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1039 } else if(((jab_res_info)resources->data)->name) {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1040 if(!strcasecmp(((jab_res_info) resources->data)->name, res)) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1041 jri = (jab_res_info) resources->data;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1042 break;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1043 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1044 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1045 resources = resources->next;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1046 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1047 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1048
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1049 return jri;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1050 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1051
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1052 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1053 * if the resource doesn't exist, create it. otherwise, just update the priority
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1054 */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1055 static void jabber_track_resource(struct gaim_connection *gc,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1056 char *buddy,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1057 char *res,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1058 int priority,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1059 int state)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1060 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1061 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1062
3337
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1063 if(jbd) {
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1064 char *who;
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1065 jab_res_info jri;
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1066 if(res)
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1067 who = g_strdup_printf("%s/%s", buddy, res);
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1068 else
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1069 who = g_strdup(buddy);
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1070 jri = jabber_find_resource(gc, who);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1071 g_free(who);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1072 if(!jri) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1073 jri = g_new0(struct jabber_resource_info, 1);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1074 jri->name = g_strdup(res);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1075 jri->away_msg = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1076 jbd->resources = g_slist_append(jbd->resources, jri);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1077 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1078 jri->priority = priority;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1079 jri->state = state;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1080 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1081 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1082
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1083 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1084 * remove the resource, if it exists
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1085 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1086 static void jabber_remove_resource(struct gaim_connection *gc, char *buddy, char *res)
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1087 {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1088 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy);
3337
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1089 if(jbd) {
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1090 char *who;
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1091 jab_res_info jri;
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1092 if(res)
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1093 who = g_strdup_printf("%s/%s", buddy, res);
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1094 else
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1095 who = g_strdup(buddy);
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1096 jri = jabber_find_resource(gc, who);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1097 g_free(who);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1098 if(jri) {
3337
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1099 if(jri->name)
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1100 g_free(jri->name);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1101 if(jri->away_msg)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1102 g_free(jri->away_msg);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1103 jbd->resources = g_slist_remove(jbd->resources, jri);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1104 g_free(jri);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1105 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1106 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1107 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1108
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1109 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1110 * grab the away message for the default resource
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1111 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1112 static char *jabber_lookup_away(gjconn gjc, char *name)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1113 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1114 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1115
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1116 if(!jri || !jri->away_msg)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1117 return _("Unknown");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1118
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1119 return jri->away_msg;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1120 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1121
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1122 static void jabber_track_away(gjconn gjc, jpacket p, char *type)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1123 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1124 char *show;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1125 char *vshow = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1126 char *status = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1127 char *msg = NULL;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1128 jab_res_info jri = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1129
3337
e77fcff466a1 [gaim-migrate @ 3356]
Jim Seymour <jseymour>
parents: 3328
diff changeset
1130 if(!p || !p->from || !p->from->user)
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1131 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1132
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1133 jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from));
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1134
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1135 if(!jri)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1136 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1137
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1138 if (type && (strcasecmp(type, "unavailable") == 0)) {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1139 vshow = _("Unavailable");
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1140 } else {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1141 if((show = xmlnode_get_tag_data(p->x, "show")) != NULL) {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1142 if (!strcasecmp(show, "away")) {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1143 vshow = _("Away");
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1144 } else if (!strcasecmp(show, "chat")) {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1145 vshow = _("Online");
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1146 } else if (!strcasecmp(show, "xa")) {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1147 vshow = _("Extended Away");
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1148 } else if (!strcasecmp(show, "dnd")) {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1149 vshow = _("Do Not Disturb");
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1150 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1151 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1152 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1153
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1154 status = g_strdup(xmlnode_get_tag_data(p->x, "status"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1155
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1156 if(vshow != NULL || status != NULL ) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1157 /* kinda hokey, but it works :-) */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1158 msg = g_strdup_printf("%s%s%s",
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1159 (vshow == NULL? "" : vshow),
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1160 (vshow == NULL || status == NULL? "" : ": "),
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1161 (status == NULL? "" : status));
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1162 } else {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
1163 msg = g_strdup(_("Online"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1164 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1165
3259
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1166 g_free(status);
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1167
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1168 if(jri->away_msg)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1169 g_free(jri->away_msg);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1170
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1171 jri->away_msg = msg;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1172 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1173
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1174 static void jabber_convo_closed(struct gaim_connection *gc, char *name)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1175 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1176 jab_res_info jri = jabber_find_resource(gc, name);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1177
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1178 if(jri) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1179 if(jri->thread_id)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1180 g_free(jri->thread_id);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1181
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1182 jri->thread_id = NULL;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1183 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1184 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1185
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1186 static void jabber_track_convo_thread(gjconn gjc, char *name, char *thread_id)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1187 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1188 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1189
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1190 if(jri) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1191 if(jri->thread_id)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1192 g_free(jri->thread_id);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1193
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1194 jri->thread_id = g_strdup(thread_id);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1195 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1196 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1197
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1198 static char *jabber_get_convo_thread(gjconn gjc, char *name)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1199 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1200 char *ct = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1201 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1202
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1203 if(jri) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1204 if(jri->thread_id)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1205 ct = g_strdup(jri->thread_id);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1206 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1207
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1208 return ct;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1209 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1210
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1211
3159
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1212 static time_t iso8601_to_time(char *timestamp)
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1213 {
3229
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1214 struct tm t;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1215 time_t retval = 0;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1216
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1217 if(sscanf(timestamp, "%04d%02d%02dT%02d:%02d:%02d",
3229
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1218 &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec))
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1219 {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1220 t.tm_year -= 1900;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1221 t.tm_mon -= 1;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1222 t.tm_isdst = 0;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1223 retval = mktime(&t);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1224 # ifdef HAVE_TM_GMTOFF
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1225 retval += t.tm_gmtoff;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1226 # else
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1227 # ifdef HAVE_TIMEZONE
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1228 tzset(); /* making sure */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1229 retval -= timezone;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1230 # endif
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1231 # endif
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1232 }
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1233
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1234 return retval;
3159
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1235 }
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1236
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1237 static void jabber_handlemessage(gjconn gjc, jpacket p)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1238 {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1239 xmlnode y, subj;
3159
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1240 time_t time_sent = time(NULL);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1241 gboolean typing = FALSE;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1242
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1243 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1244 char *thread_id = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1245 char *conference_room = NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1246 char m[BUF_LONG * 2];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1247
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1248 type = xmlnode_get_attrib(p->x, "type");
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1249
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1250 if ((y = xmlnode_get_tag(p->x, "thread")))
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1251 thread_id = xmlnode_get_data(y);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1252
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1253 y = xmlnode_get_firstchild(p->x);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1254
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1255 while(y) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1256 if(NSCHECK(y, NS_DELAY)) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1257 char *timestamp = xmlnode_get_attrib(y, "stamp");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1258 time_sent = iso8601_to_time(timestamp);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1259 } else if(NSCHECK(y, "jabber:x:event")) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1260 if(xmlnode_get_tag(y, "composing"))
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1261 typing = TRUE;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1262 } else if(NSCHECK(y, "jabber:x:conference")) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1263 conference_room = xmlnode_get_attrib(y, "jid");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1264 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1265 y = xmlnode_get_nextsibling(y);
3159
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1266 }
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1267
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1268 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1269
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1270 from = jid_full(p->from);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1271 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1272 if ((y = xmlnode_get_tag(p->x, "html"))) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1273 msg = xmlnode_get_data(y);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1274 } else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1275 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1276 if ((y = xmlnode_get_tag(p->x, "body"))) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1277 msg = xmlnode_get_data(y);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1278 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1279
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1280 msg = utf8_to_str(msg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1281
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1282 if (!from)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1283 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1284
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1285 if (conference_room) {
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
1286 GList *m = NULL;
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
1287 char **data;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1288
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1289 data = g_strsplit(conference_room, "@", 2);
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
1290 m = g_list_append(m, g_strdup(data[0]));
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
1291 m = g_list_append(m, g_strdup(data[1]));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1292 m = g_list_append(m, g_strdup(gjc->user->user));
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
1293 g_strfreev(data);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1294
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1295 serv_got_chat_invite(GJ_GC(gjc), conference_room, from, msg, m);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1296 } else if (msg) { /* whisper */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1297 struct jabber_chat *jc;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1298 g_snprintf(m, sizeof(m), "%s", msg);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1299 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b)
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1300 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 1, m,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1301 time_sent);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1302 else {
2278
00a8b7bcef6c [gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2232
diff changeset
1303 int flags = 0;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1304 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from));
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1305 if(jri && typing)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1306 jri->has_composing = TRUE;
2278
00a8b7bcef6c [gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2232
diff changeset
1307 if (xmlnode_get_tag(p->x, "gaim"))
00a8b7bcef6c [gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2232
diff changeset
1308 flags = IM_FLAG_GAIMUSER;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1309 if ((y = xmlnode_get_tag(p->x, "thread")))
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1310 jabber_track_convo_thread(gjc, jid_full(p->from),
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1311 xmlnode_get_data(y));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1312 if (find_conversation(jid_full(p->from)))
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1313 serv_got_im(GJ_GC(gjc), jid_full(p->from), m, flags,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1314 time_sent, -1);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1315 else {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1316 if(p->from->user) {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1317 from = g_strdup_printf("%s@%s", p->from->user,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1318 p->from->server);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1319 } else {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1320 /* server message? */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1321 from = g_strdup(p->from->server);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1322 }
3159
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1323 serv_got_im(GJ_GC(gjc), from, m, flags, time_sent, -1);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1324 g_free(from);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1325 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1326 }
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1327 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1328 /* a non-message message! */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1329 from = g_strdup_printf("%s@%s", p->from->user, p->from->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1330 if(typing)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1331 serv_got_typing(GJ_GC(gjc), from, 0);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1332 else
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1333 serv_got_typing_stopped(GJ_GC(gjc), from);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1334 g_free(from);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1335 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1336
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1337 if (msg)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1338 g_free(msg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1339
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1340 } else if (!strcasecmp(type, "error")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1341 if ((y = xmlnode_get_tag(p->x, "error"))) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1342 type = xmlnode_get_attrib(y, "code");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1343 msg = xmlnode_get_data(y);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1344 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1345
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1346 if (msg) {
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
1347 from = g_strdup_printf(_("Jabber Error %s"), type ? type : "");
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
1348 do_error_dialog(from, msg, GAIM_ERROR);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1349 g_free(from);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1350 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1351 } else if (!strcasecmp(type, "groupchat")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1352 struct jabber_chat *jc;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1353 static int i = 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1354
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1355 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1356 if ((y = xmlnode_get_tag(p->x, "html"))) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1357 msg = xmlnode_get_data(y);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1358 } else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1359 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1360 if ((y = xmlnode_get_tag(p->x, "body"))) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1361 msg = xmlnode_get_data(y);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1362 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1363
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1364 msg = utf8_to_str(msg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1365
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1366 if ((subj = xmlnode_get_tag(p->x, "subject"))) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1367 topic = xmlnode_get_data(subj);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1368 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1369 topic = utf8_to_str(topic);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1370
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1371 jc = find_existing_chat(GJ_GC(gjc), p->from);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1372 if (!jc) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1373 /* we're not in this chat. are we supposed to be? */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1374 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1375 /* yes, we're supposed to be. so now we are. */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1376 jc->b = serv_got_joined_chat(GJ_GC(gjc), i++, p->from->user);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1377 jc->id = jc->b->id;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1378 jc->state = JCS_ACTIVE;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1379 } else {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1380 /* no, we're not supposed to be. */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1381 g_free(msg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1382 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1383 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1384 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1385 if (p->from->resource) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1386 if (!y) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1387 if (!find_chat_buddy(jc->b, p->from->resource)) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1388 add_chat_buddy(jc->b, p->from->resource);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1389 } else if ((y = xmlnode_get_tag(p->x, "status"))) {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1390 jabber_track_away(gjc, p, NULL);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1391 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1392 } else if (jc->b && msg) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1393 char buf[8192];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1394
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1395 if (topic) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1396 char tbuf[8192];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1397 g_snprintf(tbuf, sizeof(tbuf), "%s", topic);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1398 chat_set_topic(jc->b, p->from->resource, tbuf);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1399 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1400
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1401 g_snprintf(buf, sizeof(buf), "%s", msg);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1402 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1403 time_sent);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1404 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1405 } else { /* message from the server */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1406 if(jc->b && topic) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1407 char tbuf[8192];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1408 g_snprintf(tbuf, sizeof(tbuf), "%s", topic);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1409 chat_set_topic(jc->b, "", tbuf);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1410 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1411 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1412
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1413 g_free(msg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1414 g_free(topic);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1415
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1416 } else {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1417 debug_printf("unhandled message %s\n", type);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1418 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1419 }
3159
fce1883cc608 [gaim-migrate @ 3175]
Sean Egan <seanegan@gmail.com>
parents: 3150
diff changeset
1420
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1421 static void jabber_handlepresence(gjconn gjc, jpacket p)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1422 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1423 char *to, *from, *type;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1424 struct buddy *b = NULL;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1425 gaim_jid gjid;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1426 char *buddy;
3194
fdd20785e1e1 [gaim-migrate @ 3211]
Jim Seymour <jseymour>
parents: 3161
diff changeset
1427 xmlnode y;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1428 char *show;
2501
227cc42ffa6e [gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2382
diff changeset
1429 int state = 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1430 struct conversation *cnv = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1431 struct jabber_chat *jc = NULL;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1432 int priority = 0;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1433 struct jabber_buddy_data *jbd;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1434
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1435 to = xmlnode_get_attrib(p->x, "to");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1436 from = xmlnode_get_attrib(p->x, "from");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1437 type = xmlnode_get_attrib(p->x, "type");
3150
0097f5462ac2 [gaim-migrate @ 3166]
Sean Egan <seanegan@gmail.com>
parents: 3136
diff changeset
1438
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1439 if((buddy = get_realwho(gjc, from, FALSE, &gjid)) == NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1440 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1441
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1442 if (gjid->user == NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1443 /* FIXME: transport */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1444 g_free(buddy);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1445 gaim_jid_free(gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1446 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1447 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1448
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1449 jbd = jabber_find_buddy(GJ_GC(gjc), buddy);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1450
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1451 if(jbd->error_msg) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1452 g_free(jbd->error_msg);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1453 jbd->error_msg = NULL;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1454 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1455
3259
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1456 if(type && !strcasecmp(type, "error")) {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1457 state = UC_ERROR;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1458 if((y = xmlnode_get_tag(p->x, "error")) != NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1459 jbd->error_msg = g_strdup_printf(_("Error %s: %s"),
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1460 xmlnode_get_attrib(y, "code"), xmlnode_get_data(y));
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1461 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1462 jbd->error_msg = g_strdup(_("Unknown Error in presence"));
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1463 }
3259
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1464 } else {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1465 if ((y = xmlnode_get_tag(p->x, "show"))) {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1466 show = xmlnode_get_data(y);
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1467 if (!show) {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1468 state = 0;
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1469 } else if (!strcasecmp(show, "away")) {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1470 state = UC_AWAY;
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1471 } else if (!strcasecmp(show, "chat")) {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1472 state = UC_CHAT;
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1473 } else if (!strcasecmp(show, "xa")) {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1474 state = UC_XA;
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1475 } else if (!strcasecmp(show, "dnd")) {
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1476 state = UC_DND;
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1477 }
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1478 } else {
2501
227cc42ffa6e [gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2382
diff changeset
1479 state = 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1480 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1481 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1482
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1483 if ((y = xmlnode_get_tag(p->x, "priority")))
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1484 priority = atoi(xmlnode_get_data(y));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1485
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1486 /* um. we're going to check if it's a chat. if it isn't, and there are pending
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1487 * chats, create the chat. if there aren't pending chats and we don't have the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1488 * buddy on our list, simply bail out. */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1489 if ((cnv = find_chat(GJ_GC(gjc), gjid->user)) == NULL) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1490 static int i = 0x70;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1491 if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1492 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1493 jc->id = jc->b->id;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1494 jc->state = JCS_ACTIVE;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1495 } else if ((b = find_buddy(GJ_GC(gjc), buddy)) == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1496 g_free(buddy);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1497 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1498 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1499 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1500 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1501
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1502 if (type && (strcasecmp(type, "unavailable") == 0))
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1503 jabber_remove_resource(GJ_GC(gjc), buddy, gjid->resource);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1504 else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1505 jabber_track_resource(GJ_GC(gjc), buddy, gjid->resource, priority, state);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1506
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1507 /* keep track of away msg somewhat the same as the yahoo plugin */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1508 jabber_track_away(gjc, p, type);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1509 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1510
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1511
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1512 if (!cnv) {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1513 /* this is where we handle presence information for "regular" buddies */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1514 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), buddy);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1515 if(jri) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1516 serv_got_update(GJ_GC(gjc), buddy, 1, 0, b->signon, b->idle, jri->state, 0);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1517 } else
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1518 serv_got_update(GJ_GC(gjc), buddy, 0, 0, 0, 0, 0, 0);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1519
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1520 } else {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1521 if (gjid->resource) {
3259
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
1522 if (type && (!strcasecmp(type, "unavailable"))) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1523 struct jabber_data *jd;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1524 if (!jc && !(jc = find_existing_chat(GJ_GC(gjc), gjid))) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1525 g_free(buddy);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1526 gaim_jid_free(gjid);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1527 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1528 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1529 jd = jc->gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1530 /* if it's not ourselves...*/
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1531 if (strcmp(gjid->resource, jc->gjid->resource) && jc->b) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1532 remove_chat_buddy(jc->b, gjid->resource, NULL);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1533 g_free(buddy);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1534 gaim_jid_free(gjid);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1535 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1536 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1537
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1538 jc->state = JCS_CLOSED;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1539 serv_got_chat_left(GJ_GC(gjc), jc->id);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1540 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1541 * TBD: put back some day?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1542 jd->chats = g_slist_remove(jd->chats, jc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1543 g_free(jc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1544 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1545 } else {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1546 if ((!jc && !(jc = find_existing_chat(GJ_GC(gjc), gjid))) || !jc->b) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1547 g_free(buddy);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1548 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1549 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1550 }
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1551 if (!find_chat_buddy(jc->b, gjid->resource)) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1552 add_chat_buddy(jc->b, gjid->resource);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1553 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1554 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1555 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1556 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1557
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1558 g_free(buddy);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1559 gaim_jid_free(gjid);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1560
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1561 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1562 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1563
3229
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1564 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1565 * Used only by Jabber accept/deny add stuff just below
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1566 */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1567 struct jabber_add_permit {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1568 gjconn gjc;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1569 gchar *user;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1570 };
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1571
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1572 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1573 * Common part for Jabber accept/deny adds
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1574 *
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1575 * "type" says whether we'll permit/deny the subscribe request
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1576 */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1577 static void jabber_accept_deny_add(struct jabber_add_permit *jap, const char *type)
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1578 {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1579 xmlnode g = xmlnode_new_tag("presence");
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1580
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1581 xmlnode_put_attrib(g, "to", jap->user);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1582 xmlnode_put_attrib(g, "type", type);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1583 gjab_send(jap->gjc, g);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1584
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1585 xmlnode_free(g);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1586 }
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1587
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1588 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1589 * Callback from "accept" in do_ask_dialog() invoked by jabber_handles10n()
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1590 */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1591 static void jabber_accept_add(gpointer w, struct jabber_add_permit *jap)
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1592 {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1593 jabber_accept_deny_add(jap, "subscribed");
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1594 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1595 * If we don't already have the buddy on *our* buddylist,
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1596 * ask if we want him or her added.
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1597 */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1598 if(find_buddy(GJ_GC(jap->gjc), jap->user) == NULL) {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1599 show_got_added(GJ_GC(jap->gjc), NULL, jap->user, NULL, NULL);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1600 }
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1601 g_free(jap->user);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1602 g_free(jap);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1603 }
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1604
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1605 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1606 * Callback from "deny/cancel" in do_ask_dialog() invoked by jabber_handles10n()
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1607 */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1608 static void jabber_deny_add(gpointer w, struct jabber_add_permit *jap)
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1609 {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1610 jabber_accept_deny_add(jap, "unsubscribed");
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1611 g_free(jap->user);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1612 g_free(jap);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1613 }
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1614
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1615 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1616 * Handle subscription requests
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1617 */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1618 static void jabber_handles10n(gjconn gjc, jpacket p)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1619 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1620 xmlnode g;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1621 char *Jid = xmlnode_get_attrib(p->x, "from");
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1622 char *type = xmlnode_get_attrib(p->x, "type");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1623
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1624 g = xmlnode_new_tag("presence");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1625 xmlnode_put_attrib(g, "to", Jid);
3229
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1626
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1627 if (!strcmp(type, "subscribe")) {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1628 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1629 * A "subscribe to us" request was received - put up the approval dialog
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1630 */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1631 struct jabber_add_permit *jap = g_new0(struct jabber_add_permit, 1);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1632 gchar *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."),
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1633 Jid);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1634
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1635 jap->gjc = gjc;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1636 jap->user = g_strdup(Jid);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1637 do_ask_dialog(msg, jap, jabber_accept_add, jabber_deny_add);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1638
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1639 g_free(msg);
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1640 xmlnode_free(g); /* Never needed it here anyway */
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1641 return;
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1642
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1643 } else if (!strcmp(type, "unsubscribe")) {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1644 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1645 * An "unsubscribe to us" was received - simply "approve" it
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1646 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1647 xmlnode_put_attrib(g, "type", "unsubscribed");
3229
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1648 } else {
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1649 /*
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1650 * Did we attempt to subscribe to somebody and they do not exist?
20612da83d8c [gaim-migrate @ 3246]
Jim Seymour <jseymour>
parents: 3203
diff changeset
1651 */
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1652 if (!strcmp(type, "unsubscribed")) {
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1653 xmlnode y;
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1654 char *status;
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1655 if((y = xmlnode_get_tag(p->x, "status")) && (status = xmlnode_get_data(y)) &&
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1656 !strcmp(status, "Not Found")) {
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
1657 char *msg = g_strdup_printf(_("The Jabber user %s does not exist and was therefore "
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
1658 "not added to your roster."),
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
1659 xmlnode_get_attrib(p->x, "from"));
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
1660 do_error_dialog(_("No such user."), msg, GAIM_ERROR );
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1661 g_free(msg);
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1662 }
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1663 }
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1664
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1665 xmlnode_free(g);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1666 return;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1667 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1668
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1669 gjab_send(gjc, g);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1670 xmlnode_free(g);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1671 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1672
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1673 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1674 * Pending subscription to a buddy?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1675 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1676 #define BUD_SUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1677 (ask) != NULL && !strcasecmp((ask), "subscribe"))
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1678
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1679 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1680 * Subscribed to a buddy?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1681 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1682 #define BUD_SUBD_TO(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1683 ((ask) == NULL || !strcasecmp((ask), "subscribe")))
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1684
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1685 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1686 * Pending unsubscription to a buddy?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1687 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1688 #define BUD_USUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1689 (ask) != NULL && !strcasecmp((ask), "unsubscribe"))
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1690
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1691 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1692 * Unsubscribed to a buddy?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1693 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1694 #define BUD_USUBD_TO(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1695 ((ask) == NULL || !strcasecmp((ask), "unsubscribe")))
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1696
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1697 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1698 * If a buddy is added or removed from the roster on another resource
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1699 * jabber_handlebuddy is called
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1700 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1701 * Called with roster item node.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1702 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1703 static void jabber_handlebuddy(gjconn gjc, xmlnode x)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1704 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1705 xmlnode g;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1706 char *who, *name, *sub, *ask;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1707 gaim_jid gjid;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1708 struct buddy *b = NULL;
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1709 char *buddyname, *groupname = NULL;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1710
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1711 who = xmlnode_get_attrib(x, "jid");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1712 name = xmlnode_get_attrib(x, "name");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1713 sub = xmlnode_get_attrib(x, "subscription");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1714 ask = xmlnode_get_attrib(x, "ask");
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1715
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1716 if((buddyname = get_realwho(gjc, who, FALSE, &gjid)) == NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1717 return;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1718
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1719 /* JFIXME: jabber_handleroster() had a "FIXME: transport" at this
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1720 * equivilent point. So...
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1721 *
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1722 * We haven't done anything interesting to this point, so we'll
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1723 * violate Good Coding Structure here by simply bailing out.
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1724 */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1725 if(!gjid->user) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1726 g_free(buddyname);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1727 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1728 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1729 }
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1730 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1731
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
1732 if((g = xmlnode_get_tag(x, "group")) != NULL) {
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1733 groupname = xmlnode_get_data(g);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1734 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1735
3059
966c4e460ebb [gaim-migrate @ 3073]
Sean Egan <seanegan@gmail.com>
parents: 3048
diff changeset
1736 /*
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1737 * Add or remove a buddy? Change buddy's alias or group?
3059
966c4e460ebb [gaim-migrate @ 3073]
Sean Egan <seanegan@gmail.com>
parents: 3048
diff changeset
1738 */
3328
d183c2703508 [gaim-migrate @ 3346]
Jim Seymour <jseymour>
parents: 3314
diff changeset
1739 if(name)
d183c2703508 [gaim-migrate @ 3346]
Jim Seymour <jseymour>
parents: 3314
diff changeset
1740 name = utf8_to_str(name);
d183c2703508 [gaim-migrate @ 3346]
Jim Seymour <jseymour>
parents: 3314
diff changeset
1741
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1742 if (BUD_SUB_TO_PEND(sub, ask) || BUD_SUBD_TO(sub, ask)) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1743 if ((b = find_buddy(GJ_GC(gjc), buddyname)) == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1744 debug_printf("adding buddy [4]: %s\n", buddyname);
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1745 b = add_buddy(GJ_GC(gjc), groupname ? groupname : _("Buddies"), buddyname,
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1746 name ? name : buddyname);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1747 do_export(GJ_GC(gjc));
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1748 } else {
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1749 struct group *c_grp = find_group_by_buddy(GJ_GC(gjc), buddyname);
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1750
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1751 /*
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1752 * If the buddy's in a new group or his/her alias is changed...
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1753 */
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1754 if(groupname && c_grp && strcmp(c_grp->name, groupname)) {
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1755 int present = b->present; /* save presence state */
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1756 int uc = b->uc; /* and away state (?) */
3150
0097f5462ac2 [gaim-migrate @ 3166]
Sean Egan <seanegan@gmail.com>
parents: 3136
diff changeset
1757 int idle = b->idle;
0097f5462ac2 [gaim-migrate @ 3166]
Sean Egan <seanegan@gmail.com>
parents: 3136
diff changeset
1758 int signon = b->signon;
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1759
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1760 /*
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1761 * seems rude, but it seems to be the only way...
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1762 */
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1763 remove_buddy(GJ_GC(gjc), c_grp, b);
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1764 b = add_buddy(GJ_GC(gjc), groupname, buddyname,
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1765 name ? name : buddyname);
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1766 do_export(GJ_GC(gjc));
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1767 if(present) {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1768 serv_got_update(GJ_GC(gjc), buddyname, 1, 0, signon, idle,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
1769 uc, 0);
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1770 }
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1771 } else if(name != NULL && strcmp(b->show, name)) {
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1772 strncpy(b->show, name, BUDDY_ALIAS_MAXLEN);
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1773 b->show[BUDDY_ALIAS_MAXLEN - 1] = '\0'; /* cheap safety feature */
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1774 handle_buddy_rename(b, buddyname);
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
1775 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1776 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1777 } else if (BUD_USUB_TO_PEND(sub, ask) || BUD_USUBD_TO(sub, ask) || !strcasecmp(sub, "remove")) {
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
1778 jabber_remove_gaim_buddy(GJ_GC(gjc), buddyname);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1779 }
3328
d183c2703508 [gaim-migrate @ 3346]
Jim Seymour <jseymour>
parents: 3314
diff changeset
1780
d183c2703508 [gaim-migrate @ 3346]
Jim Seymour <jseymour>
parents: 3314
diff changeset
1781 if(name)
d183c2703508 [gaim-migrate @ 3346]
Jim Seymour <jseymour>
parents: 3314
diff changeset
1782 g_free(name);
d183c2703508 [gaim-migrate @ 3346]
Jim Seymour <jseymour>
parents: 3314
diff changeset
1783
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1784 g_free(buddyname);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1785
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1786 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1787
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1788 static void jabber_handleroster(gjconn gjc, xmlnode querynode)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1789 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1790 xmlnode x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1791
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1792 x = xmlnode_get_firstchild(querynode);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1793 while (x) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1794 jabber_handlebuddy(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1795 x = xmlnode_get_nextsibling(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1796 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1797
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1798 x = jutil_presnew(0, NULL, "Online");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1799 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1800 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1801 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1802
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1803 static void jabber_handleauthresp(gjconn gjc, jpacket p)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1804 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1805 if (jpacket_subtype(p) == JPACKET__RESULT) {
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1806 if (xmlnode_has_children(p->x)) {
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1807 xmlnode query = xmlnode_get_tag(p->x, "query");
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
1808 set_login_progress(GJ_GC(gjc), 4, _("Authenticating"));
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1809 if (!xmlnode_get_tag(query, "digest")) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1810 g_free(gjc->sid);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1811 gjc->sid = NULL;
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1812 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1813 gjab_auth(gjc);
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1814 } else {
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1815 debug_printf("auth success\n");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1816
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1817 account_online(GJ_GC(gjc));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1818 serv_finish_login(GJ_GC(gjc));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1819
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1820 if (bud_list_cache_exists(GJ_GC(gjc)))
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1821 do_import(GJ_GC(gjc), NULL);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1822
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1823 ((struct jabber_data *)GJ_GC(gjc)->proto_data)->did_import = TRUE;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1824
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1825 gjab_reqroster(gjc);
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1826 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1827 } else {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1828 xmlnode xerr;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1829 char *errmsg = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1830 int errcode = 0;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1831 struct jabber_data *jd = GJ_GC(gjc)->proto_data;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1832
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1833 debug_printf("auth failed\n");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1834 xerr = xmlnode_get_tag(p->x, "error");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1835 if (xerr) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1836 char msg[BUF_LONG];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1837 errmsg = xmlnode_get_data(xerr);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1838 if (xmlnode_get_attrib(xerr, "code")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1839 errcode = atoi(xmlnode_get_attrib(xerr, "code"));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1840 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1841 } else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1842 g_snprintf(msg, sizeof(msg), "%s", errmsg);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1843 hide_login_progress(GJ_GC(gjc), msg);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1844 } else {
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
1845 hide_login_progress(GJ_GC(gjc), _("Unknown login error"));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1846 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1847
2800
0ad63a625eec [gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2791
diff changeset
1848 jd->die = TRUE;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1849 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1850 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1851
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1852 static void jabber_handleversion(gjconn gjc, xmlnode iqnode) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1853 xmlnode querynode, x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1854 char *id, *from;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1855 char os[1024];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1856 struct utsname osinfo;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1857
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1858 uname(&osinfo);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1859 g_snprintf(os, sizeof os, "%s %s %s", osinfo.sysname, osinfo.release, osinfo.machine);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1860
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1861 id = xmlnode_get_attrib(iqnode, "id");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1862 from = xmlnode_get_attrib(iqnode, "from");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1863
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1864 x = jutil_iqnew(JPACKET__RESULT, NS_VERSION);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1865
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1866 xmlnode_put_attrib(x, "to", from);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1867 xmlnode_put_attrib(x, "id", id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1868 querynode = xmlnode_get_tag(x, "query");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1869 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "name"), PACKAGE, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1870 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "version"), VERSION, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1871 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "os"), os, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1872
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1873 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1874
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1875 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1876 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1877
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1878 static void jabber_handletime(gjconn gjc, xmlnode iqnode) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1879 xmlnode querynode, x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1880 char *id, *from;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1881 time_t now_t;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1882 struct tm *now;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1883 char buf[1024];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1884
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1885 time(&now_t);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1886 now = localtime(&now_t);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1887
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1888 id = xmlnode_get_attrib(iqnode, "id");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1889 from = xmlnode_get_attrib(iqnode, "from");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1890
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1891 x = jutil_iqnew(JPACKET__RESULT, NS_TIME);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1892
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1893 xmlnode_put_attrib(x, "to", from);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1894 xmlnode_put_attrib(x, "id", id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1895 querynode = xmlnode_get_tag(x, "query");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1896
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1897 strftime(buf, 1024, "%Y%m%dT%T", now);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1898 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "utc"), buf, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1899 strftime(buf, 1024, "%Z", now);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1900 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "tz"), buf, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1901 strftime(buf, 1024, "%d %b %Y %T", now);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1902 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "display"), buf, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1903
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1904 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1905
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1906 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1907 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1908
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1909 static void jabber_handlelast(gjconn gjc, xmlnode iqnode) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1910 xmlnode x, querytag;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1911 char *id, *from;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1912 struct jabber_data *jd = GJ_GC(gjc)->proto_data;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1913 char idle_time[32];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1914
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1915 id = xmlnode_get_attrib(iqnode, "id");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1916 from = xmlnode_get_attrib(iqnode, "from");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1917
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1918 x = jutil_iqnew(JPACKET__RESULT, "jabber:iq:last");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1919
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1920 xmlnode_put_attrib(x, "to", from);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1921 xmlnode_put_attrib(x, "id", id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1922 querytag = xmlnode_get_tag(x, "query");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1923 g_snprintf(idle_time, sizeof idle_time, "%ld", jd->idle ? time(NULL) - jd->idle : 0);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1924 xmlnode_put_attrib(querytag, "seconds", idle_time);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1925
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1926 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1927 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1928 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1929
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1930 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1931 * delete == TRUE: delete found entry
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1932 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1933 * returns pointer to (local) copy of value if found, NULL otherwise
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1934 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1935 * Note: non-reentrant! Local static storage re-used on subsequent calls.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1936 * If you're going to need to keep the returned value, make a copy!
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1937 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1938 static gchar *jabber_track_queries(GHashTable *queries, gchar *key, gboolean delete)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1939 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1940 gpointer my_key, my_val;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1941 static gchar *ret_val = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1942
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1943 if(ret_val != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1944 g_free(ret_val);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1945 ret_val = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1946 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1947
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1948 /* self-protection */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1949 if(queries != NULL && key != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1950 if(g_hash_table_lookup_extended(queries, key, &my_key, &my_val)) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1951 ret_val = g_strdup((gchar *) my_val);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1952 if(delete) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1953 g_hash_table_remove(queries, key);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1954 g_free(my_key);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1955 g_free(my_val);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1956 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1957 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1958 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1959
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1960 return(ret_val);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1961 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1962
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1963 static void jabber_handlepacket(gjconn gjc, jpacket p)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1964 {
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1965 char *id;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1966 switch (p->type) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1967 case JPACKET_MESSAGE:
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1968 jabber_handlemessage(gjc, p);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1969 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1970 case JPACKET_PRESENCE:
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1971 jabber_handlepresence(gjc, p);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1972 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1973 case JPACKET_IQ:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1974 debug_printf("jpacket_subtype: %d\n", jpacket_subtype(p));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1975
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1976 id = xmlnode_get_attrib(p->x, "id");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1977 if (id != NULL && !strcmp(id, IQID_AUTH)) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1978 jabber_handleauthresp(gjc, p);
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1979 break;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1980 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1981
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1982 if (jpacket_subtype(p) == JPACKET__SET) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1983 xmlnode querynode;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1984 querynode = xmlnode_get_tag(p->x, "query");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1985 if (NSCHECK(querynode, "jabber:iq:roster")) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1986 jabber_handlebuddy(gjc, xmlnode_get_firstchild(querynode));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1987 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1988 } else if (jpacket_subtype(p) == JPACKET__GET) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1989 xmlnode querynode;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1990 querynode = xmlnode_get_tag(p->x, "query");
2814
f4f9e5a01890 [gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2800
diff changeset
1991 if (NSCHECK(querynode, NS_VERSION)) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1992 jabber_handleversion(gjc, p->x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1993 } else if (NSCHECK(querynode, NS_TIME)) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1994 jabber_handletime(gjc, p->x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1995 } else if (NSCHECK(querynode, "jabber:iq:last")) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
1996 jabber_handlelast(gjc, p->x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1997 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1998 } else if (jpacket_subtype(p) == JPACKET__RESULT) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1999 xmlnode querynode, vcard;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2000 char *xmlns, *from;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2001
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2002 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2003 * TBD: ISTM maybe this part could use a serious re-work?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2004 */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2005 from = xmlnode_get_attrib(p->x, "from");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2006 querynode = xmlnode_get_tag(p->x, "query");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2007 vcard = xmlnode_get_tag(p->x, "vCard");
2316
ebb5ecb2cd5b [gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2309
diff changeset
2008 if (!vcard)
ebb5ecb2cd5b [gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2309
diff changeset
2009 vcard = xmlnode_get_tag(p->x, "VCARD");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2010
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2011 if (NSCHECK(querynode, NS_ROSTER)) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2012 jabber_handleroster(gjc, querynode);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2013 } else if (NSCHECK(querynode, NS_VCARD)) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2014 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2015 jabber_handlevcard(gjc, querynode, from);
2316
ebb5ecb2cd5b [gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2309
diff changeset
2016 } else if (vcard) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2017 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2018 jabber_handlevcard(gjc, vcard, from);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2019 } else if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2020 debug_printf("jabber:iq:query: %s\n", xmlns);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2021 } else {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2022 char *val;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2023
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2024 debug_printf("jabber:iq: %s\n", xmlnode2str(p->x));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2025
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2026 /* handle "null" query results */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2027 if((val = jabber_track_queries(gjc->queries, id, TRUE)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2028 if(strcmp((char *) val, "vCard") == 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2029 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2030 * No actual vCard, but there's other stuff. This
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2031 * way the user always gets some kind of response.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2032 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2033 jabber_handlevcard(gjc, NULL, from);
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
2034 } else if(!strcmp((char *) val, "change_password")) {
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
2035 char buf[BUF_LONG];
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2036 sprintf(buf, _("Password successfully changed."));
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
2037
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2038 do_error_dialog(buf, NULL, GAIM_INFO);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2039 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2040 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2041 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2042
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2043 } else if (jpacket_subtype(p) == JPACKET__ERROR) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2044 xmlnode xerr;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2045 char *from, *errmsg = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2046 int errcode = 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2047
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2048 from = xmlnode_get_attrib(p->x, "from");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2049 xerr = xmlnode_get_tag(p->x, "error");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2050 if (xerr) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2051 errmsg = xmlnode_get_data(xerr);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2052 if (xmlnode_get_attrib(xerr, "code"))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2053 errcode = atoi(xmlnode_get_attrib(xerr, "code"));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2054 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2055
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2056 from = g_strdup_printf("Jabber Error %d (%s)", errcode, from);
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2057 do_error_dialog(from, errmsg, GAIM_ERROR);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2058 g_free(from);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2059
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2060 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2061
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2062 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2063 case JPACKET_S10N:
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2064 jabber_handles10n(gjc, p);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2065 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2066 default:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2067 debug_printf("jabber: packet type %d (%s)\n", p->type, xmlnode2str(p->x));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2068 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2069
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2070 xmlnode_free(p->x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2071
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2072 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2073 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2074
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2075 static void jabber_handlestate(gjconn gjc, int state)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2076 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2077 switch (state) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2078 case JCONN_STATE_OFF:
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
2079 if(gjc->was_connected) {
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
2080 hide_login_progress_error(GJ_GC(gjc), _("Connection lost"));
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
2081 } else {
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
2082 hide_login_progress(GJ_GC(gjc), _("Unable to connect"));
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
2083 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2084 signoff(GJ_GC(gjc));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2085 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2086 case JCONN_STATE_CONNECTED:
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
2087 gjc->was_connected = 1;
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
2088 set_login_progress(GJ_GC(gjc), 2, _("Connected"));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2089 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2090 case JCONN_STATE_ON:
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
2091 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2092 gjab_reqauth(gjc);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2093 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2094 default:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2095 debug_printf("state change: %d\n", state);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2096 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2097 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2098 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2099
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2100 static void jabber_login(struct aim_user *user)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2101 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2102 struct gaim_connection *gc = new_gaim_conn(user);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2103 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2104 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "GAIM");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2105
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2106 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2107 jd->chats = NULL; /* we have no chats yet */
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2108
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
2109 set_login_progress(gc, 1, _("Connecting"));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2110
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2111 if (!(jd->gjc = gjab_new(loginname, user->password, gc))) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2112 g_free(loginname);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2113 debug_printf("jabber: unable to connect (jab_new failed)\n");
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
2114 hide_login_progress(gc, _("Unable to connect"));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2115 signoff(gc);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2116 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2117 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2118
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2119 g_free(loginname);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2120 gjab_state_handler(jd->gjc, jabber_handlestate);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2121 gjab_packet_handler(jd->gjc, jabber_handlepacket);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2122 jd->gjc->queries = g_hash_table_new(g_str_hash, g_str_equal);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2123 gjab_start(jd->gjc);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2124 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2125
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2126 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2127 g_free(key);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2128 g_free(val);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2129 return TRUE;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2130 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2131
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2132 static gboolean jabber_destroy_buddy_hash(gpointer key, gpointer val, gpointer data) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2133 struct jabber_buddy_data *jbd = val;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2134 while (jbd->resources) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2135 g_free(((jab_res_info) ((GSList *)jbd->resources)->data)->name);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2136 if(((jab_res_info) ((GSList *)jbd->resources)->data)->away_msg)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2137 g_free(((jab_res_info) ((GSList *)jbd->resources)->data)->away_msg);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2138 g_free(((GSList *)jbd->resources)->data);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2139 jbd->resources = g_slist_remove(jbd->resources, ((GSList *)jbd->resources)->data);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2140
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2141 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2142 if(jbd->error_msg)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2143 g_free(jbd->error_msg);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2144 g_free(key);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2145 g_free(jbd);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2146 return TRUE;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2147 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2148
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2149
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2150 static gboolean jabber_free(gpointer data)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2151 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2152 struct jabber_data *jd = data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2153
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2154 if(jd->gjc != NULL) {
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2155 gjab_delete(jd->gjc);
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2156 g_free(jd->gjc->sid);
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2157 jd->gjc = NULL;
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2158 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2159 g_free(jd);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2160
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2161 return FALSE;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2162 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2163
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2164 static void jabber_close(struct gaim_connection *gc)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2165 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2166 struct jabber_data *jd = gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2167
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2168 if(jd) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2169 GSList *jcs = jd->chats;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2170
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2171 /* Free-up the jabber_chat struct allocs and the list */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2172 while (jcs) {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2173 gaim_jid_free(((struct jabber_chat *)jcs->data)->gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2174 g_free(jcs->data);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2175 jcs = jcs->next;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2176 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2177 g_slist_free(jd->chats);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2178
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2179 /* Free-up the buddy data hash */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2180 if(jd->buddies != NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2181 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2182 g_hash_table_foreach_remove(jd->buddies, jabber_destroy_buddy_hash, NULL);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2183 g_hash_table_destroy(jd->buddies);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2184 jd->buddies = NULL;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2185 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2186
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2187 /* Free-up the pending queries memories and the list */
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2188 if(jd->gjc != NULL && jd->gjc->queries != NULL) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2189 g_hash_table_foreach_remove(jd->gjc->queries, jabber_destroy_hash, NULL);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2190 g_hash_table_destroy(jd->gjc->queries);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2191 jd->gjc->queries = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2192 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2193 }
2300
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2289
diff changeset
2194 if (gc->inpa)
d2686f757d6e [gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2289
diff changeset
2195 gaim_input_remove(gc->inpa);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2196
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2197 if(jd) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2198 g_timeout_add(50, jabber_free, jd);
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2199 if(jd->gjc != NULL)
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2200 xmlnode_free(jd->gjc->current);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2201 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2202 gc->proto_data = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2203 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2204
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2205 static int jabber_send_typing(struct gaim_connection *gc, char *who, int typing)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2206 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2207 xmlnode x, y;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2208 char *realwho;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2209 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2210 jab_res_info jri = jabber_find_resource(gc, who);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2211
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2212 if(!jri || !jri->has_composing)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2213 return 0;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2214
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2215 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2216 return 0;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2217
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2218 x = xmlnode_new_tag("message");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2219 xmlnode_put_attrib(x, "to", realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2220 xmlnode_insert_tag(x, "gaim");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2221
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2222 y = xmlnode_insert_tag(x, "x");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2223 xmlnode_put_attrib(y, "xmlns", "jabber:x:event");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2224
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2225 if(typing)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2226 xmlnode_insert_tag(y, "composing");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2227
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2228 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2229 xmlnode_free(x);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2230 g_free(realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2231 return JABBER_TYPING_NOTIFY_INT;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2232 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2233
3033
1143524a2eaf [gaim-migrate @ 3046]
Sean Egan <seanegan@gmail.com>
parents: 2975
diff changeset
2234 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2235 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2236 xmlnode x, y;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2237 char *realwho;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2238 char *thread_id = NULL;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2239 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2240
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2241 if (!who || !message)
2123
56c4382f2909 [gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2112
diff changeset
2242 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2243
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2244 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2245 return 0;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2246
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2247 x = xmlnode_new_tag("message");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2248 xmlnode_put_attrib(x, "to", realwho);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2249
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2250 thread_id = jabber_get_convo_thread(gjc, realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2251 if(thread_id)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2252 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2253 y = xmlnode_insert_tag(x, "thread");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2254 xmlnode_insert_cdata(y, thread_id, -1);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2255 g_free(thread_id);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2256 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2257
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2258 g_free(realwho);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2259
2278
00a8b7bcef6c [gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2232
diff changeset
2260 xmlnode_insert_tag(x, "gaim");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2261 xmlnode_put_attrib(x, "type", "chat");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2262
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2263 /* let other clients know we support typing notification */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2264 y = xmlnode_insert_tag(x, "x");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2265 xmlnode_put_attrib(y, "xmlns", "jabber:x:event");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2266 xmlnode_insert_tag(y, "composing");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2267
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2268 if (message && strlen(message)) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2269 char *utf8 = str_to_utf8(message);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2270 y = xmlnode_insert_tag(x, "body");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2271 xmlnode_insert_cdata(y, utf8, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2272 g_free(utf8);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2273 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2274
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2275 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2276 xmlnode_free(x);
2303
f5bf315e6104 [gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2300
diff changeset
2277 return 1;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2278 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2279
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2280 /*
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2281 * Add/update buddy's roster entry on server
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2282 *
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2283 * If "alias" or "group" are NULL, gets them from Gaim's current buddylist values
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2284 * for the buddy.
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2285 */
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2286 static void jabber_roster_update(struct gaim_connection *gc, char *name, char *alias, char *group)
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2287 {
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2288 xmlnode x, y;
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2289 char *realwho;
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2290 gjconn gjc;
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2291 struct buddy *buddy = NULL;
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2292 struct group *buddy_group = NULL;
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2293 char *my_alias = NULL;
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2294 char *my_group = NULL;
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2295
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2296 if(gc && gc->proto_data && ((struct jabber_data *)gc->proto_data)->gjc && name) {
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2297 gaim_jid gjid;
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2298 gjc = ((struct jabber_data *)gc->proto_data)->gjc;
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2299
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2300 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2301 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2302
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2303 /* FIXME: transport */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2304 if(gjid->user == NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2305 g_free(realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2306 gaim_jid_free(gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2307 return;
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2308 }
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2309 gaim_jid_free(gjid);
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2310
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2311 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2312 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2313 xmlnode_put_attrib(y, "jid", realwho);
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2314
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2315 /*
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2316 * See if there's an explict (new?) alias for the buddy or we can pull
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2317 * one out of current Gaim buddylist data for him.
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2318 */
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2319 if(alias && alias[0] != '\0') {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2320 my_alias = alias;
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2321 } else if((buddy = find_buddy(gc, realwho)) != NULL) {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2322 my_alias = buddy->show;
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2323 }
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2324
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2325 /* If there's an alias for the buddy, it's not 0-length
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2326 * and it doesn't match his JID, add the "name" attribute.
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2327 */
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2328 if(my_alias != NULL && my_alias[0] != '\0' && strcmp(realwho, my_alias))
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2329 {
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2330 char *utf8 = str_to_utf8(my_alias);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2331 xmlnode_put_attrib(y, "name", utf8);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2332 g_free(utf8);
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2333 }
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2334
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2335 /*
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2336 * See if there's an explict (new?) group for the buddy or pull
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2337 * one out of current Gaim buddylist data for him.
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2338 */
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2339 if(group && group[0] != '\0') {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2340 my_group = group;
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2341 } else if((buddy_group = find_group_by_buddy(gc, realwho)) != NULL) {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2342 my_group = buddy_group->name;
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2343 }
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2344
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2345 /*
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2346 * Send what group the buddy's in along with the roster item.
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2347 */
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2348 if(my_group != NULL && my_group[0] != '\0') {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2349 xmlnode z = xmlnode_insert_tag(y, "group");
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2350 xmlnode_insert_cdata(z, my_group, -1);
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2351 }
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2352
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2353 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2354
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2355 xmlnode_free(x);
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2356 g_free(realwho);
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2357 }
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2358 }
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2359
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2360 /*
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2361 * Add/update buddy's alias on server
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2362 *
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2363 * This is just a roster update using existing, local buddylist data
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2364 */
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2365 static void jabber_alias_buddy(struct gaim_connection *gc, char *name)
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2366 {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2367 jabber_roster_update(gc, name, NULL, NULL);
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2368 }
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2369
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2370 /*
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2371 * Change buddy's group on server roster
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2372 */
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2373 static void jabber_group_change(struct gaim_connection *gc, char *name, char *old_group, char *new_group)
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2374 {
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2375 if(old_group && new_group && strcmp(old_group, new_group))
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2376 jabber_roster_update(gc, name, NULL, new_group);
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2377 }
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2378
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2379 /*
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2380 * Group rename
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2381 *
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2382 * Jabber doesn't have "groups," per se. "Group" is simply a JID attribute.
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2383 * So we iterate through the list of buddies that are in the group and change
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2384 * the group attribute for each of them.
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2385 */
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2386 static void jabber_rename_group(struct gaim_connection *gc,
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2387 char *old_group,
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2388 char *new_group,
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2389 GList *members)
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2390 {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2391 if(old_group && new_group && strcmp(old_group, new_group))
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2392 while(members) {
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2393 jabber_group_change(gc, (char *)(members->data), old_group, new_group);
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2394 members = members->next;
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2395 }
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2396 }
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2397
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2398 static void jabber_add_buddy(struct gaim_connection *gc, char *name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2399 {
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
2400 xmlnode x;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2401 char *realwho;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2402 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2403 gaim_jid gjid;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2404
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2405 if (!((struct jabber_data *)gc->proto_data)->did_import)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2406 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2407
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2408 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2409 * If there's no name or the name is ourself
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2410 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2411 if(!name || !strcmp(gc->username, name))
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2412 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2413
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2414 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL) {
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2415 char *msg = g_strdup_printf(_("The user %s is an invalid Jabber I.D. and was "
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2416 "therefore not added."), name);
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2417 do_error_dialog("Unable to add buddy.", _("Jabber Error"), GAIM_ERROR);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2418 g_free(msg);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2419 jabber_remove_gaim_buddy(gc, name);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2420 return;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2421 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2422
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2423 /* FIXME: transport */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2424 if(gjid->user == NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2425 g_free(realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2426 gaim_jid_free(gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2427 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2428 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2429 gaim_jid_free(gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2430
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2431 x = xmlnode_new_tag("presence");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2432 xmlnode_put_attrib(x, "to", realwho);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2433 xmlnode_put_attrib(x, "type", "subscribe");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2434 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2435 xmlnode_free(x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2436
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
2437 jabber_roster_update(gc, realwho, NULL, NULL);
3105
da324fe688b3 [gaim-migrate @ 3119]
Sean Egan <seanegan@gmail.com>
parents: 3074
diff changeset
2438
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2439 g_free(realwho);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2440 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2441
2681
37d80035e77f [gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2635
diff changeset
2442 static void jabber_remove_buddy(struct gaim_connection *gc, char *name, char *group)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2443 {
3048
e729c064bc1b [gaim-migrate @ 3061]
Sean Egan <seanegan@gmail.com>
parents: 3033
diff changeset
2444 xmlnode x;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2445 char *realwho;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2446 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2447
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2448 if(!name || (realwho = get_realwho(gjc, name, FALSE, NULL)) == NULL)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2449 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2450
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2451 x = xmlnode_new_tag("presence");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2452 xmlnode_put_attrib(x, "to", realwho);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2453 xmlnode_put_attrib(x, "type", "unsubscribe");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2454 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2455 g_free(realwho);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2456 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2457 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2458
3314
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2459 /*
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2460 * Remove a buddy item from the roster entirely
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2461 */
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2462 static void jabber_remove_buddy_roster_item(struct gaim_connection *gc, char *name)
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2463 {
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2464 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
3314
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2465 char *realwho;
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2466
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2467 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2468 xmlnode x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2469 xmlnode y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2470 xmlnode_put_attrib(y, "jid", realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2471 xmlnode_put_attrib(y, "subscription", "remove");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2472 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2473 g_free(realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2474 xmlnode_free(x);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2475 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2476 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2477
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2478 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2479 * Unsubscribe a buddy from our presence
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2480 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2481 static void jabber_unsubscribe_buddy_from_us(struct gaim_connection *gc, char *name)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2482 {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2483 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2484 char *realwho;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2485
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2486 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2487 xmlnode g = xmlnode_new_tag("presence");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2488 xmlnode_put_attrib(g, "to", realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2489 xmlnode_put_attrib(g, "type", "unsubscribed");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2490 gjab_send(gjc, g);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2491 xmlnode_free(g);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2492 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2493 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2494
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2495 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2496 * Common code for setting ourselves invisible/visible to buddy
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2497 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2498 static void jabber_invisible_to_buddy_common(struct gaim_connection *gc, char *name, gboolean invisible)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2499 {
3314
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2500 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2501 char *realwho;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2502
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2503 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2504 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2505 xmlnode g = xmlnode_new_tag("presence");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2506
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2507 xmlnode_put_attrib(g, "to", realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2508
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2509 if(invisible)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2510 xmlnode_put_attrib(g, "type", "invisible");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2511
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2512 gjab_send(gjc, g);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2513
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2514 g_free(realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2515 xmlnode_free(g);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2516
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2517 if(jbd) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2518 if(invisible) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2519 jbd->invisible |= JABBER_BUD_INVIS;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2520 } else {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2521 jbd->invisible &= ~JABBER_BUD_INVIS;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2522 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2523 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2524 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2525 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2526
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2527 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2528 * Make ourselves temporarily invisible to a buddy
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2529 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2530 static void jabber_invisible_to_buddy(struct gaim_connection *gc, char *name)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2531 {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2532 jabber_invisible_to_buddy_common(gc, name, TRUE);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2533 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2534
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2535 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2536 * Make ourselves visible to a buddy
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2537 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2538 static void jabber_visible_to_buddy(struct gaim_connection *gc, char *name)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2539 {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2540 jabber_invisible_to_buddy_common(gc, name, FALSE);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2541 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2542
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2543 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2544 * Function used by the g_hash_table_foreach() in invisible_to_all_buddies() to
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2545 * actually set the status.
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2546 *
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2547 * key is unused
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2548 * value is the pointer to the jabber_buddy_data struct
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2549 * data is gboolean: TRUE (invisible) or FALSE (not invisible)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2550 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2551 static void set_invisible_to_buddy_status(gpointer key, gpointer val, gpointer data) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2552 struct jabber_buddy_data *jbd = val;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2553 gboolean invisible = (gboolean) data;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2554
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2555 if(jbd) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2556 if(invisible) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2557 jbd->invisible = JABBER_SERV_INVIS | JABBER_BUD_INVIS;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2558 } else {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2559 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2560 * If we've asserted server-level invisibility, cancelling
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2561 * it removes explicit buddy invisibility settings too.
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2562 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2563 if(jbd->invisible & JABBER_SERV_INVIS)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2564 jbd->invisible = JABBER_NOT_INVIS;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2565 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2566 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2567 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2568
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2569 /*
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2570 * Show we've set ourselves invisible/visible to all buddies on the server
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2571 *
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2572 * Used when we set server-wide invisibility so that individual buddy menu
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2573 * entries show the proper option.
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2574 */
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2575 static void invisible_to_all_buddies(struct gaim_connection *gc, gboolean invisible)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2576 {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2577 struct jabber_data *jd = gc->proto_data;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2578
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2579 if(jd->buddies != NULL)
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
2580 g_hash_table_foreach(jd->buddies, set_invisible_to_buddy_status, (gpointer) invisible);
3314
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2581 }
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
2582
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2583 static char **jabber_list_icon(int uc)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2584 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2585 switch (uc) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2586 case UC_AWAY:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2587 return available_away_xpm;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2588 case UC_CHAT:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2589 return available_chat_xpm;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2590 case UC_XA:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2591 return available_xa_xpm;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2592 case UC_DND:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2593 return available_dnd_xpm;
3259
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
2594 case UC_ERROR:
8b1309bea7e5 [gaim-migrate @ 3277]
Jim Seymour <jseymour>
parents: 3257
diff changeset
2595 return available_error_xpm;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2596 default:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2597 return available_xpm;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2598 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2599 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2600
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2601 static GList *jabber_chat_info(struct gaim_connection *gc)
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2602 {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2603 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2604
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2605 static char *confserv = NULL; /* this pointer must be persistent */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2606 gchar *server;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2607
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2608 GList *m = NULL;
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2609 struct proto_chat_entry *pce;
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2610
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2611 /* This is a scientific wild-ass guess...
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2612 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2613 * If there are more than two "components" to the current server name,
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2614 * lop-off the left-most component and replace with "conference."
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2615 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2616 if(confserv != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2617 g_free(confserv); /* dispose of the old value */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2618 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2619
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2620 if((server = g_strdup(gjc->user->server)) == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2621 confserv = g_strdup(DEFAULT_GROUPCHAT);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2622 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2623 gchar **splits, **index;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2624 gchar *tmp;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2625 int cnt = 0;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2626
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2627
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2628 index = splits = g_strsplit(server, ".", -1); /* split the connected server */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2629
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2630 while(*(index++)) /* index to the end--counting the parts */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2631 ++cnt;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2632
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2633 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2634 * If we've more than two parts, point to the second part. Else point
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2635 * to the start.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2636 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2637 if(cnt > 2) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2638 index -= cnt;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2639 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2640 index = splits;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2641 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2642
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2643 /* Put it together */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2644 confserv = g_strjoin(".", "conference", (tmp = g_strjoinv(".", index)), NULL);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2645
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2646 g_free(server); /* we don't need this stuff no more */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2647 g_free(tmp);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2648 g_strfreev(splits);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2649 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2650
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2651 pce = g_new0(struct proto_chat_entry, 1);
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2652 pce->label = _("Room:");
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2653 m = g_list_append(m, pce);
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2654
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2655 pce = g_new0(struct proto_chat_entry, 1);
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2656 pce->label = _("Server:");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2657 pce->def = confserv;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2658 m = g_list_append(m, pce);
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2659
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2660 pce = g_new0(struct proto_chat_entry, 1);
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2661 pce->label = _("Handle:");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2662 pce->def = gjc->user->user;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2663 m = g_list_append(m, pce);
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2664
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2665 return m;
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2666 }
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2667
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2668 static void jabber_join_chat(struct gaim_connection *gc, GList *data)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2669 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2670 xmlnode x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2671 char *realwho;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2672 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2673 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2674 struct jabber_chat *jc;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2675 gaim_jid gjid;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2676
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2677 if (!data || !data->next || !data->next->next)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2678 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2679
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2680 realwho = create_valid_jid(data->data, data->next->data, data->next->next->data);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2681 debug_printf("%s\n", realwho);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2682
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2683 if((gjid = gaim_jid_new(realwho)) == NULL) {
3427
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2684 char *msg = g_strdup_printf("The Jabber I.D. %s is invalid.", realwho);
8fa61405af2b [gaim-migrate @ 3453]
Sean Egan <seanegan@gmail.com>
parents: 3349
diff changeset
2685 do_error_dialog(_("Unable to join chat"), msg, GAIM_ERROR);
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2686 g_free(msg);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2687 g_free(realwho);
3236
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2688 return;
6796fdeed022 [gaim-migrate @ 3253]
Jim Seymour <jseymour>
parents: 3234
diff changeset
2689 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2690
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2691 if((jc = find_any_chat(gc, gjid)) != NULL) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2692 switch(jc->state) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2693 case JCS_PENDING:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2694 debug_printf("attempt to re-join already pending Jabber chat! (ignoring)\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2695 g_free(realwho); /* yuck! */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2696 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2697 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2698 case JCS_ACTIVE:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2699 debug_printf("attempt to re-join already active Jabber chat! (ignoring)\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2700 g_free(realwho); /* yuck! */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2701 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2702 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2703 case JCS_CLOSED:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2704 debug_printf("rejoining previously closed Jabber chat\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2705 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2706 default:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2707 debug_printf("found Jabber chat in unknown state! (ignoring)\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2708 g_free(realwho); /* yuck! */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2709 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2710 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2711 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2712 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2713 debug_printf("joining completely new Jabber chat\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2714 jc = g_new0(struct jabber_chat, 1);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2715 jc->gjid = gjid;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2716 jc->gc = gc;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2717 ((struct jabber_data *)gc->proto_data)->chats = g_slist_append(jcs, jc);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2718 add_buddy(gc, _("Chats"), realwho, realwho);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2719 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2720
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2721 jc->state = JCS_PENDING;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2722
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2723 x = jutil_presnew(0, realwho, NULL);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2724 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2725 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2726 g_free(realwho);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2727 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2728
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2729 static void jabber_chat_invite(struct gaim_connection *gc, int id, char *message, char *name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2730 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2731 xmlnode x, y;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2732 struct jabber_data *jd = gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2733 gjconn gjc = jd->gjc;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2734 struct jabber_chat *jc = NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2735 char *realwho, *subject;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2736
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2737 if(!name || (realwho = get_realwho(gjc, name, FALSE, NULL)) == NULL)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2738 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2739
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2740 /* find which chat we're inviting to */
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2741 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2742 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2743
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2744 x = xmlnode_new_tag("message");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2745 xmlnode_put_attrib(x, "to", realwho);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2746
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2747 g_free(realwho);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2748
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2749 y = xmlnode_insert_tag(x, "x");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2750 xmlnode_put_attrib(y, "xmlns", "jabber:x:conference");
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2751 subject = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2752 xmlnode_put_attrib(y, "jid", subject);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2753 g_free(subject);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2754
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2755 if (message && strlen(message)) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2756 char *utf8 = str_to_utf8(message);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2757 y = xmlnode_insert_tag(x, "body");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2758 xmlnode_insert_cdata(y, utf8, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2759 g_free(utf8);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2760 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2761
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2762 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2763 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2764 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2765
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2766 static void jabber_chat_leave(struct gaim_connection *gc, int id)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2767 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2768 struct jabber_data *jd = gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2769 gjconn gjc = jd->gjc;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2770 struct jabber_chat *jc = NULL;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2771 char *chatname;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2772 xmlnode x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2773
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2774 /* Find out which chat we're leaving */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2775 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2776 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2777
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2778 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2779 x = jutil_presnew(0, chatname, NULL);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2780 g_free(chatname);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2781 xmlnode_put_attrib(x, "type", "unavailable");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2782 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2783 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2784 jc->b = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2785 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2786
2167
edf8c5a70e5b [gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2162
diff changeset
2787 static int jabber_chat_send(struct gaim_connection *gc, int id, char *message)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2788 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2789 xmlnode x, y;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2790 struct jabber_chat *jc = NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2791 char *chatname;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2792 int retval = 0;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2793
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2794 /* Find out which chat we're sending to */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2795 if((retval = jabber_find_chat_by_convo_id(gc, id, &jc)) != 0)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2796 return(retval);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2797
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2798 x = xmlnode_new_tag("message");
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2799 xmlnode_put_attrib(x, "from", jc->gjid->full);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2800 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2801 xmlnode_put_attrib(x, "to", chatname);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2802 g_free(chatname);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2803 xmlnode_put_attrib(x, "type", "groupchat");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2804
2289
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2805 if (message && strlen(message) > strlen("/topic ") &&
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2806 !g_strncasecmp(message, "/topic ", strlen("/topic "))) {
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2807 char buf[8192];
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2808 char *utf8 = str_to_utf8(message + strlen("/topic "));
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2809 y = xmlnode_insert_tag(x, "subject");
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2810 xmlnode_insert_cdata(y, utf8, -1);
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2811 y = xmlnode_insert_tag(x, "body");
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2812 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", utf8);
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2813 xmlnode_insert_cdata(y, buf, -1);
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2814 g_free(utf8);
38e156136896 [gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2278
diff changeset
2815 } else if (message && strlen(message)) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2816 char *utf8 = str_to_utf8(message);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2817 y = xmlnode_insert_tag(x, "body");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2818 xmlnode_insert_cdata(y, utf8, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2819 g_free(utf8);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2820 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2821
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2822 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2823 xmlnode_free(x);
2167
edf8c5a70e5b [gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2162
diff changeset
2824 return 0;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2825 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2826
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2827 static void jabber_chat_whisper(struct gaim_connection *gc, int id, char *who, char *message)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2828 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2829 xmlnode x, y;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
2830 struct jabber_chat *jc = NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2831 char *chatname;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2832
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2833 /* Find out which chat we're whispering to */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2834 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2835 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2836
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2837 x = xmlnode_new_tag("message");
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2838 xmlnode_put_attrib(x, "from", jc->gjid->full);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2839 chatname = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2840 xmlnode_put_attrib(x, "to", chatname);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2841 g_free(chatname);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2842 xmlnode_put_attrib(x, "type", "normal");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2843
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2844 if (message && strlen(message)) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2845 char *utf8 = str_to_utf8(message);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2846 y = xmlnode_insert_tag(x, "body");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2847 xmlnode_insert_cdata(y, utf8, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2848 g_free(utf8);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2849 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2850
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2851 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2852 xmlnode_free(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2853 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2854
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2855 static char *jabber_normalize(const char *s)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2856 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2857 static char buf[BUF_LEN];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2858 char *t, *u;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2859 int x = 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2860
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2861 g_return_val_if_fail((s != NULL), NULL);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2862
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2863 /* Somebody called us with s == NULL once... */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2864 if(s == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2865 return(NULL);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2866 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2867 u = t = g_strdup(s);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2868
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2869 g_strdown(t);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2870
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2871 while (*t && (x < BUF_LEN - 1)) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2872 if (*t != ' ')
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2873 buf[x++] = *t;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2874 t++;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2875 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2876 buf[x] = '\0';
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2877 g_free(u);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2878
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2879 if (!strchr(buf, '@')) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2880 strcat(buf, "@jabber.org"); /* this isn't always right, but eh */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2881 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2882 *u = '\0';
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2883 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2884
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2885 return buf;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2886 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2887 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2888
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2889 static void jabber_get_info(struct gaim_connection *gc, char *who) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2890 xmlnode x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2891 char *id;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2892 char *realwho;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2893 struct jabber_data *jd = gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2894 gjconn gjc = jd->gjc;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2895
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2896 if((realwho = get_realwho(gjc, who, TRUE, NULL)) == NULL)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2897 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2898
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2899 x = jutil_iqnew(JPACKET__GET, NS_VCARD);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2900 xmlnode_put_attrib(x, "to", realwho);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2901
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2902 g_free(realwho);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2903
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2904 id = gjab_getid(gjc);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2905 xmlnode_put_attrib(x, "id", id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2906
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2907 g_hash_table_insert(jd->gjc->queries, g_strdup(id), g_strdup("vCard"));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2908
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2909 gjab_send(gjc, x);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2910
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2911 xmlnode_free(x);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2912 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2913
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2914 static void jabber_get_error_msg(struct gaim_connection *gc, char *who) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2915 struct jabber_data *jd = gc->proto_data;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2916 gjconn gjc = jd->gjc;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2917 gchar **str_arr = (gchar **) g_new(gpointer, 3);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2918 gchar **ap = str_arr;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2919 gchar *realwho, *final;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2920 struct jabber_buddy_data *jbd;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2921
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2922 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2923 g_strfreev(str_arr);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2924 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2925 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2926
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2927 jbd = jabber_find_buddy(gc, realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2928
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2929 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2930 *ap++ = g_strdup_printf("<B>Error:</B> %s<BR>\n", jbd->error_msg);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2931 *ap = NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2932
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2933 final= g_strjoinv(NULL, str_arr);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2934
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2935 g_strfreev(str_arr);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2936
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2937 g_show_info_text(gc, realwho, 2, final, NULL);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2938 g_free(realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2939 g_free(final);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2940 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2941
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2942 static void jabber_get_away_msg(struct gaim_connection *gc, char *who) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2943 struct jabber_data *jd = gc->proto_data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2944 gjconn gjc = jd->gjc;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2945 int num_resources;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2946 gaim_jid gjid;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2947 char *buddy = get_realwho(gjc, who, FALSE, &gjid);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2948 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2949 gchar **str_arr;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2950 gchar **ap;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2951 gchar *realwho, *final;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2952 GSList *resources;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2953 int i;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2954
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2955 if(!buddy)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2956 return;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2957
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2958 if(!gjid->resource) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2959 num_resources = g_slist_length(jbd->resources);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2960 resources = jbd->resources;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2961 } else {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2962 num_resources = 1;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2963 resources = jbd->resources;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2964 while(strcasecmp(((jab_res_info)resources->data)->name, gjid->resource))
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2965 resources = resources->next;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2966 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2967
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2968 gaim_jid_free(gjid);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2969
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2970 /* space for all elements: Jabber I.D. + "status" + NULL (list terminator) */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2971 str_arr = (gchar **) g_new(gpointer, num_resources*2 + 1);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2972 ap = str_arr;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2973
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2974 for(i=0; i<num_resources; i++)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2975 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2976 jab_res_info jri = resources->data;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2977 realwho = g_strdup_printf("%s/%s", buddy, jri->name);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2978 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2979 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", jabber_lookup_away(gjc, realwho));
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2980 g_free(realwho);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2981 resources = resources->next;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2982 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2983
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2984 *ap = NULL;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2985
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2986 g_free(buddy);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2987
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2988 final= g_strjoinv(NULL, str_arr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2989 g_strfreev(str_arr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2990
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
2991 g_show_info_text(gc, who, 2, final, NULL);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2992 g_free(final);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2993
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2994 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2995
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2996 static void jabber_get_cb_info(struct gaim_connection *gc, int cid, char *who) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2997 struct jabber_chat *jc = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2998 char *realwho;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
2999
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3000 /* Find out which chat */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3001 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3002 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3003
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3004 realwho = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3005
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3006 jabber_get_info(gc, realwho);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3007 g_free(realwho);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3008 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3009
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3010 static void jabber_get_cb_away_msg(struct gaim_connection *gc, int cid, char *who) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3011 struct jabber_chat *jc = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3012 char *realwho;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3013
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3014 /* Find out which chat */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3015 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3016 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3017
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3018 realwho = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3019
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3020 jabber_get_away_msg(gc, realwho);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3021 g_free(realwho);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3022
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3023 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3024
2170
c24595d3c364 [gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2167
diff changeset
3025 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) {
c24595d3c364 [gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2167
diff changeset
3026 GList *m = NULL;
c24595d3c364 [gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2167
diff changeset
3027 struct proto_buddy_menu *pbm;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3028 struct buddy *b = find_buddy(gc, who);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3029
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3030 if(b->uc == UC_ERROR)
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3031 {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3032 pbm = g_new0(struct proto_buddy_menu, 1);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3033 pbm->label = _("View Error Msg");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3034 pbm->callback = jabber_get_error_msg;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3035 pbm->gc = gc;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3036 m = g_list_append(m, pbm);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3037 } else {
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3038 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3039 char *realwho = get_realwho(gjc, who, FALSE, NULL);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3040 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3041
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3042 g_free(realwho);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3043
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3044 pbm = g_new0(struct proto_buddy_menu, 1);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3045 pbm->label = _("Get Info");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3046 pbm->callback = jabber_get_info;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3047 pbm->gc = gc;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3048 m = g_list_append(m, pbm);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3049 pbm = g_new0(struct proto_buddy_menu, 1);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3050 pbm->label = _("Get Away Msg");
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3051 pbm->callback = jabber_get_away_msg;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3052 pbm->gc = gc;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3053 m = g_list_append(m, pbm);
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3054
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3055 pbm = g_new0(struct proto_buddy_menu, 1);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3056 if(jbd && (jbd->invisible & JABBER_BUD_INVIS)) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3057 pbm->label = _("Un-hide From");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3058 pbm->callback = jabber_visible_to_buddy;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3059 } else {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3060 pbm->label = _("Temporarily Hide From");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3061 pbm->callback = jabber_invisible_to_buddy;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3062 }
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3063 pbm->gc = gc;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3064 m = g_list_append(m, pbm);
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3065 }
2170
c24595d3c364 [gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2167
diff changeset
3066
c24595d3c364 [gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2167
diff changeset
3067 return m;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3068 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3069
3314
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3070 /*
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3071 * Jabber protocol-specific "edit buddy menu" item(s)
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3072 */
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3073 static GList *jabber_edit_buddy_menu(struct gaim_connection *gc, char *who) {
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3074 GList *m = NULL;
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3075 struct proto_buddy_menu *pbm;
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3076
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3077 pbm = g_new0(struct proto_buddy_menu, 1);
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3078 pbm->label = _("Remove From Roster");
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3079 pbm->callback = jabber_remove_buddy_roster_item;
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3080 pbm->gc = gc;
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3081 m = g_list_append(m, pbm);
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3082 pbm = g_new0(struct proto_buddy_menu, 1);
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3083 pbm->label = _("Cancel Presence Notification");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3084 pbm->callback = jabber_unsubscribe_buddy_from_us;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3085 pbm->gc = gc;
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3086 m = g_list_append(m, pbm);
3314
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3087
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3088 return m;
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3089 }
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3090
2501
227cc42ffa6e [gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2382
diff changeset
3091 static GList *jabber_away_states(struct gaim_connection *gc) {
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3092 GList *m = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3093
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3094 m = g_list_append(m, "Online");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3095 m = g_list_append(m, "Chatty");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3096 m = g_list_append(m, "Away");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3097 m = g_list_append(m, "Extended Away");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3098 m = g_list_append(m, "Do Not Disturb");
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3099 m = g_list_append(m, "Invisible");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3100
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3101 return m;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3102 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3103
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3104 static void jabber_set_away(struct gaim_connection *gc, char *state, char *message)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3105 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3106 xmlnode x, y;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3107 struct jabber_data *jd = gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3108 gjconn gjc = jd->gjc;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3109 GSList *jcs;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3110 struct jabber_chat *jc;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3111 char *chatname;
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3112 gboolean invisible = FALSE;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3113
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3114 gc->away = NULL; /* never send an auto-response */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3115
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3116 x = xmlnode_new_tag("presence");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3117
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3118 if (!strcmp(state, GAIM_AWAY_CUSTOM)) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3119 /* oh goody. Gaim is telling us what to do. */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3120 if (message) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3121 /* Gaim wants us to be away */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3122 y = xmlnode_insert_tag(x, "show");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3123 xmlnode_insert_cdata(y, "away", -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3124 y = xmlnode_insert_tag(x, "status");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3125 xmlnode_insert_cdata(y, message, -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3126 gc->away = "";
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3127 } else {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3128 /* Gaim wants us to not be away */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3129 /* but for Jabber, we can just send presence with no other information. */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3130 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3131 } else {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3132 /* state is one of our own strings. it won't be NULL. */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3133 if (!strcmp(state, "Online")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3134 /* once again, we don't have to put anything here */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3135 } else if (!strcmp(state, "Chatty")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3136 y = xmlnode_insert_tag(x, "show");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3137 xmlnode_insert_cdata(y, "chat", -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3138 } else if (!strcmp(state, "Away")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3139 y = xmlnode_insert_tag(x, "show");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3140 xmlnode_insert_cdata(y, "away", -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3141 gc->away = "";
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3142 } else if (!strcmp(state, "Extended Away")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3143 y = xmlnode_insert_tag(x, "show");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3144 xmlnode_insert_cdata(y, "xa", -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3145 gc->away = "";
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3146 } else if (!strcmp(state, "Do Not Disturb")) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3147 y = xmlnode_insert_tag(x, "show");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3148 xmlnode_insert_cdata(y, "dnd", -1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3149 gc->away = "";
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3150 } else if (!strcmp(state, "Invisible")) {
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3151 xmlnode_put_attrib(x, "type", "invisible");
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3152 gc->away = "";
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3153 invisible = TRUE;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3154 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3155 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3156
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3157 gjab_send(gjc, x); /* Notify "individuals" */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3158
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3159 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3160 * As of jabberd-1.4.2: simply sending presence to the server doesn't result in
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3161 * it being propagated to conference rooms. So we wade thru the list of chats,
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3162 * sending our new presence status to each and every one.
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3163 */
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3164 for(jcs = jd->chats; jcs; jcs = jcs->next) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3165 jc = jcs->data;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3166 if(jc->state == JCS_ACTIVE) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3167 xmlnode_put_attrib(x, "from", jc->gjid->full);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3168 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3169 xmlnode_put_attrib(x, "to", chatname);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3170 gjab_send(gjc, x);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3171 g_free(chatname);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3172 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3173 }
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3174
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3175 xmlnode_free(x);
3340
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3176
f56b36347375 [gaim-migrate @ 3359]
Jim Seymour <jseymour>
parents: 3337
diff changeset
3177 invisible_to_all_buddies(gc, invisible);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3178 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3179
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3180 static void jabber_set_idle(struct gaim_connection *gc, int idle) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3181 struct jabber_data *jd = (struct jabber_data *)gc->proto_data;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3182 debug_printf("jabber_set_idle: setting idle %i\n", idle);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3183 jd->idle = idle ? time(NULL) - idle : idle;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3184 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3185
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3186 static void jabber_keepalive(struct gaim_connection *gc) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3187 struct jabber_data *jd = (struct jabber_data *)gc->proto_data;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3188 gjab_send_raw(jd->gjc, " \t ");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3189 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3190
2154
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3191 static GList *jabber_user_opts()
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3192 {
2154
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3193 GList *m = NULL;
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3194 struct proto_user_opt *puo;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3195
2154
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3196 puo = g_new0(struct proto_user_opt, 1);
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3197 puo->label = "Port:";
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3198 puo->def = "5222";
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3199 puo->pos = USEROPT_PORT;
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3200 m = g_list_append(m, puo);
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3201
2154
cff133e0ec0c [gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2137
diff changeset
3202 return m;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3203 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3204
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3205 /*---------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3206 /* Jabber "set info" (vCard) support */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3207 /*---------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3208
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3209 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3210 * V-Card format:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3211 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3212 * <vCard prodid='' version='' xmlns=''>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3213 * <FN></FN>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3214 * <N>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3215 * <FAMILY/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3216 * <GIVEN/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3217 * </N>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3218 * <NICKNAME/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3219 * <URL/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3220 * <ADR>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3221 * <STREET/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3222 * <EXTADD/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3223 * <LOCALITY/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3224 * <REGION/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3225 * <PCODE/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3226 * <COUNTRY/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3227 * </ADR>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3228 * <TEL/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3229 * <EMAIL/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3230 * <ORG>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3231 * <ORGNAME/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3232 * <ORGUNIT/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3233 * </ORG>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3234 * <TITLE/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3235 * <ROLE/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3236 * <DESC/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3237 * <BDAY/>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3238 * </vCard>
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3239 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3240 * See also:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3241 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3242 * http://docs.jabber.org/proto/html/vcard-temp.html
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3243 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3244 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3245
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3246 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3247 * Cross-reference user-friendly V-Card entry labels to vCard XML tags
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3248 * and attributes.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3249 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3250 * Order is (or should be) unimportant. For example: we have no way of
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3251 * knowing in what order real data will arrive.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3252 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3253 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3254 * name, XML tag's parent tag "path" (relative to vCard node).
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3255 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3256 * List is terminated by a NULL label pointer.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3257 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3258 * Entries with no label text, but with XML tag and parent tag
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3259 * entries, are used by V-Card XML construction routines to
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3260 * "automagically" construct the appropriate XML node tree.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3261 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3262 * Thoughts on future direction/expansion
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3263 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3264 * This is a "simple" vCard.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3265 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3266 * It is possible for nodes other than the "vCard" node to have
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3267 * attributes. Should that prove necessary/desirable, add an
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3268 * "attributes" pointer to the vcard_template struct, create the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3269 * necessary tag_attr structs, and add 'em to the vcard_dflt_data
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3270 * array.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3271 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3272 * The above changes will (obviously) require changes to the vCard
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3273 * construction routines.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3274 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3275
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3276 struct vcard_template {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3277 char *label; /* label text pointer */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3278 char *text; /* entry text pointer */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3279 int visible; /* should entry field be "visible?" */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3280 int editable; /* should entry field be editable? */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3281 char *tag; /* tag text */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3282 char *ptag; /* parent tag "path" text */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3283 char *url; /* vCard display format if URL */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3284 } vcard_template_data[] = {
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3285 {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3286 {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3287 {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3288 {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3289 {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3290 {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3291 {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3292 {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3293 {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3294 {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3295 {N_("Country"), NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3296 {N_("Telephone"), NULL, TRUE, TRUE, "TELEPHONE", NULL, NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3297 {N_("Email"), NULL, TRUE, TRUE, "EMAIL", NULL, "<A HREF=\"mailto:%s\">%s</A>"},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3298 {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3299 {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3300 {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3301 {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3302 {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL},
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3303 {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL},
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3304 {"", NULL, TRUE, TRUE, "N", NULL, NULL},
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3305 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL},
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3306 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL},
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3307 {NULL, NULL, 0, 0, NULL, NULL, NULL}
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3308 };
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3309
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3310 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3311 * The "vCard" tag's attibute list...
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3312 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3313 struct tag_attr {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3314 char *attr;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3315 char *value;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3316 } vcard_tag_attr_list[] = {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3317 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"},
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3318 {"version", "2.0", },
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3319 {"xmlns", "vcard-temp", },
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3320 {NULL, NULL},
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3321 };
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3322
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3323
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3324 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3325 * V-Card user instructions
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3326 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3327 static char *multi_entry_instructions =
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3328 N_("All items below are optional. Enter only the information with which you feel comfortable");
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3329 static char *entries_title = N_("User Identity");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3330
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3331 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3332 * Used by routines to parse an XML-encoded string into an xmlnode tree
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3333 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3334 typedef struct {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3335 XML_Parser parser;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3336 xmlnode current;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3337 } *xmlstr2xmlnode_parser, xmlstr2xmlnode_parser_struct;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3338
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3339
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3340 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3341 * Display a Jabber vCard
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3342 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3343 static void jabber_handlevcard(gjconn gjc, xmlnode querynode, char *from)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3344 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3345 struct gaim_connection *gc = GJ_GC(gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3346 char *cdata, *status;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3347 struct vcard_template *vc_tp = vcard_template_data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3348
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3349 /* space for all vCard elements + Jabber I.D. + "status" + NULL (list terminator) */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3350 gchar **str_arr = (gchar **) g_new(gpointer,
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3351 (sizeof(vcard_template_data)/sizeof(struct vcard_template)) + 3);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3352 gchar **ap = str_arr;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3353 gchar *buddy, *final;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3354
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3355 if((buddy = get_realwho(gjc, from, TRUE, NULL)) == NULL) {
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3356 g_strfreev(str_arr);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3357 return;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3358 }
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3359
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3360 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", buddy);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3361
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3362 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3363 if(strcmp(vc_tp->tag, "DESC") == 0)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3364 continue; /* special handling later */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3365 if(vc_tp->ptag == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3366 cdata = xmlnode_get_tag_data(querynode, vc_tp->tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3367 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3368 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3369 cdata = xmlnode_get_tag_data(querynode, tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3370 g_free(tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3371 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3372 if(cdata != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3373 if(vc_tp->url == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3374 *ap++ = g_strdup_printf("<B>%s:</B> %s<BR>\n", vc_tp->label, cdata);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3375 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3376 gchar *fmt = g_strdup_printf("<B>%%s:</B> %s<BR>\n", vc_tp->url);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3377 *ap++ = g_strdup_printf(fmt, vc_tp->label, cdata, cdata);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3378 g_free(fmt);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3379 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3380 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3381 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3382
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3383 status = jabber_lookup_away(gjc, buddy);
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3384
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3385 *ap++ = g_strdup_printf("<B>Status:</B> %s<BR>\n", status);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3386
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3387 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3388 * "Description" handled as a special case: get a copy of the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3389 * string and HTML-ize.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3390 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3391 if((cdata = xmlnode_get_tag_data(querynode, "DESC")) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3392 gchar *tmp = g_strdup_printf("<HR>%s<BR>", cdata);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3393 *ap++ = strdup_withhtml(tmp);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3394 g_free(tmp);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3395 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3396
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3397 *ap = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3398
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3399 final= g_strjoinv(NULL, str_arr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3400 g_strfreev(str_arr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3401
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3402 g_show_info_text(gc, buddy, 2, final, NULL);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3403 g_free(buddy);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3404 g_free(final);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3405 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3406
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3407 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3408 * Used by XML_Parse on parsing CDATA
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3409 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3410 static void xmlstr2xmlnode_charData(void *userdata, const char *s, int slen)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3411 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3412 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3413
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3414 if (xmlp->current)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3415 xmlnode_insert_cdata(xmlp->current, s, slen);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3416 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3417
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3418 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3419 * Used by XML_Parse to start or append to an xmlnode
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3420 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3421 static void xmlstr2xmlnode_startElement(void *userdata, const char *name, const char **attribs)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3422 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3423 xmlnode x;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3424 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3425
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3426 if (xmlp->current) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3427 /* Append the node to the current one */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3428 x = xmlnode_insert_tag(xmlp->current, name);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3429 xmlnode_put_expat_attribs(x, attribs);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3430
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3431 xmlp->current = x;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3432 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3433 x = xmlnode_new_tag(name);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3434 xmlnode_put_expat_attribs(x, attribs);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3435 xmlp->current = x;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3436 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3437 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3438
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3439 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3440 * Used by XML_Parse to end an xmlnode
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3441 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3442 static void xmlstr2xmlnode_endElement(void *userdata, const char *name)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3443 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3444 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3445 xmlnode x;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3446
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3447 if (xmlp->current != NULL && (x = xmlnode_get_parent(xmlp->current)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3448 xmlp->current = x;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3449 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3450 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3451
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3452 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3453 * Parse an XML-encoded string into an xmlnode tree
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3454 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3455 * Caller is responsible for freeing the returned xmlnode
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3456 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3457 static xmlnode xmlstr2xmlnode(char *xmlstring)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3458 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3459 xmlstr2xmlnode_parser my_parser = g_new(xmlstr2xmlnode_parser_struct, 1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3460 xmlnode x = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3461
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3462 my_parser->parser = XML_ParserCreate(NULL);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3463 my_parser->current = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3464
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3465 XML_SetUserData(my_parser->parser, (void *)my_parser);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3466 XML_SetElementHandler(my_parser->parser, xmlstr2xmlnode_startElement, xmlstr2xmlnode_endElement);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3467 XML_SetCharacterDataHandler(my_parser->parser, xmlstr2xmlnode_charData);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3468 XML_Parse(my_parser->parser, xmlstring, strlen(xmlstring), 0);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3469
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3470 x = my_parser->current;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3471
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3472 XML_ParserFree(my_parser->parser);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3473 g_free(my_parser);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3474
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3475 return(x);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3476 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3477
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3478 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3479 * Insert a tag node into an xmlnode tree, recursively inserting parent tag
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3480 * nodes as necessary
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3481 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3482 * Returns pointer to inserted node
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3483 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3484 * Note to hackers: this code is designed to be re-entrant (it's recursive--it
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3485 * calls itself), so don't put any "static"s in here!
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3486 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3487 static xmlnode insert_tag_to_parent_tag(xmlnode start, const char *parent_tag, const char *new_tag)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3488 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3489 xmlnode x = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3490
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3491 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3492 * If the parent tag wasn't specified, see if we can get it
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3493 * from the vCard template struct.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3494 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3495 if(parent_tag == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3496 struct vcard_template *vc_tp = vcard_template_data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3497
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3498 while(vc_tp->label != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3499 if(strcmp(vc_tp->tag, new_tag) == 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3500 parent_tag = vc_tp->ptag;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3501 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3502 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3503 ++vc_tp;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3504 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3505 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3506
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3507 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3508 * If we have a parent tag...
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3509 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3510 if(parent_tag != NULL ) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3511 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3512 * Try to get the parent node for a tag
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3513 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3514 if((x = xmlnode_get_tag(start, parent_tag)) == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3515 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3516 * Descend?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3517 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3518 char *grand_parent = strcpy(g_malloc(strlen(parent_tag) + 1), parent_tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3519 char *parent;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3520
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3521 if((parent = strrchr(grand_parent, '/')) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3522 *(parent++) = '\0';
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3523 x = insert_tag_to_parent_tag(start, grand_parent, parent);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3524 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3525 x = xmlnode_insert_tag(start, grand_parent);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3526 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3527 g_free(grand_parent);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3528 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3529 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3530 * We found *something* to be the parent node.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3531 * Note: may be the "root" node!
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3532 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3533 xmlnode y;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3534 if((y = xmlnode_get_tag(x, new_tag)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3535 return(y);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3536 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3537 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3538 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3539
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3540 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3541 * insert the new tag into its parent node
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3542 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3543 return(xmlnode_insert_tag((x == NULL? start : x), new_tag));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3544 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3545
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3546 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3547 * Find the tag name for a label
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3548 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3549 * Returns NULL on not found
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3550 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3551 static char *tag_for_label(const char *label)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3552 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3553 struct vcard_template *vc_tp = vcard_template_data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3554 char *p = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3555
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3556 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3557 if(strcmp(label, vc_tp->label) == 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3558 p = vc_tp->tag;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3559 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3560 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3561 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3562
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3563 return(p);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3564 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3565
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3566 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3567 * Send vCard info to Jabber server
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3568 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3569 static void jabber_set_info(struct gaim_connection *gc, char *info)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3570 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3571 xmlnode x, vc_node;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3572 char *id;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3573 struct jabber_data *jd = gc->proto_data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3574 gjconn gjc = jd->gjc;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3575
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3576 x = xmlnode_new_tag("iq");
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3577 xmlnode_put_attrib(x, "type", "set");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3578
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3579 id = gjab_getid(gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3580
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3581 xmlnode_put_attrib(x, "id", id);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3582
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3583 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3584 * Send only if there's actually any *information* to send
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3585 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3586 if((vc_node = xmlstr2xmlnode(info)) != NULL && xmlnode_get_name(vc_node) != NULL &&
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3587 g_strncasecmp(xmlnode_get_name(vc_node), "vcard", 5) == 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3588 xmlnode_insert_tag_node(x, vc_node);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3589 debug_printf("jabber: vCard packet: %s\n", xmlnode2str(x));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3590 gjab_send(gjc, x);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3591 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3592
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3593 xmlnode_free(x);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3594 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3595
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3596 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3597 * This is the callback from the "ok clicked" for "set vCard"
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3598 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3599 * Formats GSList data into XML-encoded string and returns a pointer
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3600 * to said string.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3601 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3602 * g_free()'ing the returned string space is the responsibility of
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3603 * the caller.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3604 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3605 static gchar *jabber_format_info(MultiEntryDlg *b)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3606 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3607 xmlnode vc_node;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3608 GSList *list;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3609 MultiEntryData *med;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3610 MultiTextData *mtd;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3611 char *p;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3612
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3613 struct tag_attr *tag_attr;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3614
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3615 vc_node = xmlnode_new_tag("vCard");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3616
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3617 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3618 xmlnode_put_attrib(vc_node, tag_attr->attr, tag_attr->value);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3619
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3620 for(list = b->multi_entry_items; list != NULL; list = list->next) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3621 med = (MultiEntryData *) list->data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3622 if(med->label != NULL && med->text != NULL && (med->text)[0] != '\0') {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3623 if((p = tag_for_label(med->label)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3624 xmlnode xp;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3625 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3626 xmlnode_insert_cdata(xp, med->text, -1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3627 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3628 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3629 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3630 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3631
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3632 for(list = b->multi_text_items; list != NULL; list = list->next) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3633 mtd = (MultiTextData *) list->data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3634 if(mtd->label != NULL && mtd->text != NULL && (mtd->text)[0] != '\0') {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3635 if((p = tag_for_label(mtd->label)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3636 xmlnode xp;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3637 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3638 xmlnode_insert_cdata(xp, mtd->text, -1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3639 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3640 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3641 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3642 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3643
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3644
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3645 p = g_strdup(xmlnode2str(vc_node));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3646 xmlnode_free(vc_node);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3647
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3648 return(p);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3649 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3650
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3651 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3652 * This gets executed by the proto action
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3653 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3654 * Creates a new MultiEntryDlg struct, gets the XML-formatted user_info
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3655 * string (if any) into GSLists for the (multi-entry) edit dialog and
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3656 * calls the set_vcard dialog.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3657 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3658 static void jabber_setup_set_info(struct gaim_connection *gc)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3659 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3660 MultiEntryData *data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3661 const struct vcard_template *vc_tp;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3662 char *user_info;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3663 MultiEntryDlg *b = multi_entry_dialog_new();
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3664 char *cdata;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3665 xmlnode x_vc_data = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3666 struct aim_user *tmp = gc->user;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3667 b->user = tmp;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3668
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3669
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3670 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3671 * Get existing, XML-formatted, user info
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3672 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3673 if((user_info = g_malloc(strlen(tmp->user_info) + 1)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3674 strcpy(user_info, tmp->user_info);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3675 x_vc_data = xmlstr2xmlnode(user_info);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3676 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3677
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3678 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3679 * Set up GSLists for edit with labels from "template," data from user info
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3680 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3681 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3682 if((vc_tp->label)[0] == '\0')
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3683 continue;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3684 if(vc_tp->ptag == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3685 cdata = xmlnode_get_tag_data(x_vc_data, vc_tp->tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3686 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3687 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3688 cdata = xmlnode_get_tag_data(x_vc_data, tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3689 g_free(tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3690 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3691 if(strcmp(vc_tp->tag, "DESC") == 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3692 multi_text_list_update(&(b->multi_text_items),
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3693 vc_tp->label, cdata, TRUE);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3694 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3695 data = multi_entry_list_update(&(b->multi_entry_items),
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3696 vc_tp->label, cdata, TRUE);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3697 data->visible = vc_tp->visible;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3698 data->editable = vc_tp->editable;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3699 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3700 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3701
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3702
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3703 if(x_vc_data != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3704 xmlnode_free(x_vc_data);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3705 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3706 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3707 * Early Beta versions had a different user_info storage format--let's
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3708 * see if that works.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3709 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3710 * This goes away RSN.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3711 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3712 const char *record_separator = "<BR>";
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3713 const char *field_separator = ": ";
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3714 gchar **str_list, **str_list_ptr, **str_list2;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3715
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3716 if((str_list = g_strsplit(user_info, record_separator, 0)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3717 for(str_list_ptr = str_list; *str_list_ptr != NULL; ++str_list_ptr) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3718 str_list2 = g_strsplit(*str_list_ptr, field_separator, 2);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3719 if(str_list2[0] != NULL && str_list2[1] != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3720 g_strstrip(str_list2[0]);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3721 g_strstrip(str_list2[1]);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3722 /* this is ugly--so far */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3723 if(strcmp(str_list2[0], "Description") == 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3724 multi_text_list_update(&(b->multi_text_items),
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3725 str_list2[0], str_list2[1], FALSE);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3726 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3727 multi_entry_list_update(&(b->multi_entry_items),
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3728 str_list2[0], str_list2[1], FALSE);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3729 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3730 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3731 g_strfreev(str_list2);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3732 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3733 g_strfreev(str_list);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3734 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3735 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3736
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3737 if(user_info != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3738 g_free(user_info);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3739 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3740
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3741 b->title = _("Gaim - Edit Jabber vCard");
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3742 b->wmclass_name = "set_info";
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3743 b->wmclass_class = "Gaim";
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3744 b->instructions->text = g_strdup(multi_entry_instructions);
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3745 b->entries_title = g_strdup(entries_title);
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3746
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3747 b->custom = (void *) jabber_format_info;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3748
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3749 show_set_vcard(b);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3750 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3751
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3752 /*---------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3753 /* End Jabber "set info" (vCard) support */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3754 /*---------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3755
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3756 /*----------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3757 /* Jabber "user registration" support */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3758 /*----------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3759
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3760 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3761 * Three of the following four functions duplicate much of what
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3762 * exists elsewhere:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3763 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3764 * jabber_handleregresp()
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3765 * gjab_reqreg()
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3766 * jabber_handle_registration_state()
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3767 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3768 * It may be that an additional flag could be added to one of
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3769 * the "local" structs and the duplicated code modified to
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3770 * account for it--thus eliminating the duplication. Then again:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3771 * doing it the way it is may be much cleaner.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3772 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3773 * TBD: Code to support requesting additional information server
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3774 * wants at registration--incl. dialog.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3775 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3776
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3777 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3778 * Like jabber_handlepacket(), only different
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3779 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3780 static void jabber_handleregresp(gjconn gjc, jpacket p)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3781 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3782 if (jpacket_subtype(p) == JPACKET__RESULT) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3783 xmlnode querynode;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3784
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3785 if((querynode = xmlnode_get_tag(p->x, "query")) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3786 char *xmlns;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3787
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3788 /* we damn well *better* have this! */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3789 if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL &&
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3790 strcmp(xmlns, NS_REGISTER) == 0) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3791
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3792 char *tag;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3793 xmlnode child = xmlnode_get_firstchild(querynode);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3794
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3795 debug_printf("got registration requirments response!\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3796
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3797 while(child != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3798 if((tag = xmlnode_get_name(child)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3799 char *data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3800
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3801 fprintf(stderr, "DBG: got node: \"%s\"\n", tag);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3802 fflush(stderr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3803
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3804 if((data = xmlnode_get_data(child)) != NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3805 fprintf(stderr, "DBG: got data: \"%s\"\n", data);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3806 fflush(stderr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3807 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3808 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3809 child = xmlnode_get_nextsibling(child);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3810 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3811 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3812 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3813 debug_printf("registration successful!\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3814
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3815 hide_login_progress_notice(GJ_GC(gjc), _("Server Registration successful!"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3816 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3817 * TBD: is this the correct way to do away with a
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3818 * gaim_connection and all its associated memory
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3819 * allocs, etc.?
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3820 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3821 signoff(GJ_GC(gjc));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3822 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3823
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3824 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3825 xmlnode xerr;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3826 char *errmsg = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3827 int errcode = 0;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3828 struct jabber_data *jd = GJ_GC(gjc)->proto_data;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3829
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3830 debug_printf("registration failed\n");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3831 xerr = xmlnode_get_tag(p->x, "error");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3832 if (xerr) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3833 char msg[BUF_LONG];
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3834 errmsg = xmlnode_get_data(xerr);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3835 if (xmlnode_get_attrib(xerr, "code")) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3836 errcode = atoi(xmlnode_get_attrib(xerr, "code"));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3837 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3838 } else
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3839 g_snprintf(msg, sizeof(msg), "%s", errmsg);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3840 hide_login_progress(GJ_GC(gjc), msg);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3841 } else {
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3842 hide_login_progress(GJ_GC(gjc), _("Unknown registration error"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3843 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3844
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3845 jd->die = TRUE;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3846 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3847 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3848
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3849 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3850 * Like gjab_reqauth(), only different
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3851 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3852 static void gjab_reqreg(gjconn gjc)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3853 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3854 xmlnode x, y, z;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3855 char *user;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3856
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3857 if (!gjc)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3858 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3859
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3860 x = jutil_iqnew(JPACKET__SET, NS_REGISTER);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3861 y = xmlnode_get_tag(x, "query");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3862
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3863 user = gjc->user->user;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3864
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3865 if (user) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3866 z = xmlnode_insert_tag(y, "username");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3867 xmlnode_insert_cdata(z, user, -1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3868 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3869 z = xmlnode_insert_tag(y, "password");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3870 xmlnode_insert_cdata(z, gjc->pass, -1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3871
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3872 debug_printf("jabber: registration packet: %s\n", xmlnode2str(x));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3873 gjab_send(gjc, x);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3874 xmlnode_free(x);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3875 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3876
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3877 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3878 * Like jabber_handlestate(), only different
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3879 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3880 static void jabber_handle_registration_state(gjconn gjc, int state)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3881 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3882 switch (state) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3883 case JCONN_STATE_OFF:
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
3884 if(gjc->was_connected) {
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
3885 hide_login_progress_error(GJ_GC(gjc), _("Connection lost"));
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
3886 } else {
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
3887 hide_login_progress(GJ_GC(gjc), _("Unable to connect"));
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
3888 }
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3889 signoff(GJ_GC(gjc));
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3890 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3891 case JCONN_STATE_CONNECTED:
3074
793fb2e9d53b [gaim-migrate @ 3088]
Sean Egan <seanegan@gmail.com>
parents: 3059
diff changeset
3892 gjc->was_connected = 1;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3893 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3894 * TBD?
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3895 set_login_progress(GJ_GC(gjc), 2, _("Connected"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3896 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3897 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3898 case JCONN_STATE_ON:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3899 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3900 * TBD?
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3901 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3902 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3903 gjab_reqreg(gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3904 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3905 * TBD: A work-in-progress
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3906 gjab_reqregreqs(gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3907 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3908 break;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3909 default:
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3910 debug_printf("state change: %d\n", state);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3911 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3912 return;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3913 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3914
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3915 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3916 * Like jabber_login(), only different
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3917 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3918 void jabber_register_user(struct aim_user *au)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3919 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3920 struct gaim_connection *gc = new_gaim_conn(au);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3921 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3922 char *loginname = create_valid_jid(au->username, DEFAULT_SERVER, "GAIM");
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3923
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3924 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3925 * These do nothing during registration
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3926 */
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
3927 jd->buddies = NULL;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3928 jd->chats = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3929
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3930 if ((jd->gjc = gjab_new(loginname, au->password, gc)) == NULL) {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3931 g_free(loginname);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3932 debug_printf("jabber: unable to connect (jab_new failed)\n");
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3933 hide_login_progress(gc, _("Unable to connect"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3934 signoff(gc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3935 } else {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3936 gjab_state_handler(jd->gjc, jabber_handle_registration_state);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3937 gjab_packet_handler(jd->gjc, jabber_handleregresp);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3938 jd->gjc->queries = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3939 gjab_start(jd->gjc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3940 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3941
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3942 g_free(loginname);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3943 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3944
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3945 /*----------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3946 /* End Jabber "user registration" support */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3947 /*----------------------------------------*/
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3948
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3949 static void jabber_do_action(struct gaim_connection *gc, char *act)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3950 {
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3951 if (!strcmp(act, _("Set User Info"))) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3952 jabber_setup_set_info(gc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3953 /*
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3954 } else if (!strcmp(act, _("Set Dir Info"))) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3955 show_set_dir(gc);
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
3956 */
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3957 } else if (!strcmp(act, _("Change Password"))) {
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3958 show_change_passwd(gc);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3959 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3960 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3961
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3962 static GList *jabber_actions()
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3963 {
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3964 GList *m = NULL;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3965
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3966 m = g_list_append(m, _("Set User Info"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3967 /*
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3968 m = g_list_append(m, _("Set Dir Info"));
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
3969 */
2975
626729653436 [gaim-migrate @ 2988]
Rob Flynn <gaim@robflynn.com>
parents: 2956
diff changeset
3970 m = g_list_append(m, _("Change Password"));
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3971
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3972 return m;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3973 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3974
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3975 static struct prpl *my_protocol = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3976
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3977 void jabber_init(struct prpl *ret)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3978 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3979 /* the NULL's aren't required but they're nice to have */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3980 ret->protocol = PROTO_JABBER;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3981 ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3982 ret->name = jabber_name;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3983 ret->list_icon = jabber_list_icon;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3984 ret->away_states = jabber_away_states;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3985 ret->actions = jabber_actions;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3986 ret->do_action = jabber_do_action;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3987 ret->buddy_menu = jabber_buddy_menu;
3314
52db87ab4083 [gaim-migrate @ 3332]
Jim Seymour <jseymour>
parents: 3311
diff changeset
3988 ret->edit_buddy_menu = jabber_edit_buddy_menu;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3989 ret->user_opts = jabber_user_opts;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3990 ret->login = jabber_login;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3991 ret->close = jabber_close;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3992 ret->send_im = jabber_send_im;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3993 ret->set_info = jabber_set_info;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3994 ret->get_info = jabber_get_info;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3995 ret->get_cb_info = jabber_get_cb_info;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
3996 ret->get_cb_away = jabber_get_cb_away_msg;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3997 ret->set_away = jabber_set_away;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3998 ret->set_dir = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3999 ret->get_dir = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4000 ret->dir_search = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4001 ret->set_idle = jabber_set_idle;
3257
4c28751180f9 [gaim-migrate @ 3275]
Jim Seymour <jseymour>
parents: 3254
diff changeset
4002 ret->change_passwd = jabber_change_passwd;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4003 ret->add_buddy = jabber_add_buddy;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4004 ret->add_buddies = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4005 ret->remove_buddy = jabber_remove_buddy;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4006 ret->add_permit = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4007 ret->add_deny = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4008 ret->rem_permit = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4009 ret->rem_deny = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4010 ret->set_permit_deny = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4011 ret->warn = NULL;
2205
cff4fbe01c7b [gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2170
diff changeset
4012 ret->chat_info = jabber_chat_info;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4013 ret->join_chat = jabber_join_chat;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4014 ret->chat_invite = jabber_chat_invite;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4015 ret->chat_leave = jabber_chat_leave;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4016 ret->chat_whisper = jabber_chat_whisper;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4017 ret->chat_send = jabber_chat_send;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4018 ret->keepalive = jabber_keepalive;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4019 ret->normalize = jabber_normalize;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2856
diff changeset
4020 ret->register_user = jabber_register_user;
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
4021 ret->alias_buddy = jabber_alias_buddy;
3136
1bd472b7f7a2 [gaim-migrate @ 3151]
Rob Flynn <gaim@robflynn.com>
parents: 3105
diff changeset
4022 ret->group_buddy = jabber_group_change;
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4023 ret->send_typing = jabber_send_typing;
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4024 ret->convo_closed = jabber_convo_closed;
3349
000546860da7 [gaim-migrate @ 3368]
Jim Seymour <jseymour>
parents: 3340
diff changeset
4025 ret->rename_group = jabber_rename_group;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4026
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4027 my_protocol = ret;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4028 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4029
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4030 #ifndef STATIC
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4031
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4032 char *gaim_plugin_init(GModule *handle)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4033 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4034 load_protocol(jabber_init, sizeof(struct prpl));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4035 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4036 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4037
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4038 void gaim_plugin_remove()
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4039 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4040 struct prpl *p = find_prpl(PROTO_JABBER);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4041 if (p == my_protocol)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4042 unload_protocol(p);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4043 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4044
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4045 char *name()
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4046 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4047 return "Jabber";
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4048 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4049
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4050 char *description()
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4051 {
2162
a464da684307 [gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2154
diff changeset
4052 return PRPL_DESC("Jabber");
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4053 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4054
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4055 #endif
3311
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4056
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4057 /*
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4058 * Local variables:
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4059 * c-indentation-style: k&r
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4060 * c-basic-offset: 8
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4061 * indent-tabs-mode: notnil
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4062 * End:
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4063 *
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4064 * vim: shiftwidth=8:
522f37c9f9d2 [gaim-migrate @ 3329]
Jim Seymour <jseymour>
parents: 3260
diff changeset
4065 */