libpurple/protocols/myspace/myspace.c

Mon, 13 Aug 2007 00:43:11 +0000

author
Jeff Connelly <jeff2@soc.pidgin.im>
date
Mon, 13 Aug 2007 00:43:11 +0000
branch
soc.2007.msimprpl
changeset 19168
e5a076b03a7a
parent 19167
4ec67fc6d814
child 19169
d48efc7ada4e
permissions
-rw-r--r--

Conditionally compile out a few advanced configuration options (status text
and emoticon translation) to keep things simple.

18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1 /* MySpaceIM Protocol Plugin
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3 * \author Jeff Connelly
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
6 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
7 * Based on Purple's "C Plugin HOWTO" hello world example.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
8 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
9 * Code also drawn from mockprpl:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
10 * http://snarfed.org/space/purple+mock+protocol+plugin
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
11 * Copyright (C) 2004-2007, Ryan Barrett <mockprpl@ryanb.org>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
12 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
13 * and some constructs also based on existing Purple plugins, which are:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
14 * Copyright (C) 2003, Robbert Haarman <purple@inglorion.net>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
15 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
16 * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
17 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
18 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
19 * This program is free software; you can redistribute it and/or modify
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
20 * it under the terms of the GNU General Public License as published by
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
21 * the Free Software Foundation; either version 2 of the License, or
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
22 * (at your option) any later version.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
23 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
24 * This program is distributed in the hope that it will be useful,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
27 * GNU General Public License for more details.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
28 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
29 * You should have received a copy of the GNU General Public License
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
30 * along with this program; if not, write to the Free Software
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
32 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
33
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
34 #define PURPLE_PLUGIN
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
35
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
36 #include "message.h"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
37 #include "persist.h"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
38 #include "myspace.h"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
39
18047
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
40
18050
3ac6d13d25cd Recognize non-canonical emoticon forms from Pidgin, and turn them into
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18049
diff changeset
41 /* Loosely based on Miranda plugin by Scott Ellis, formatting.cpp,
18047
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
42 * https://server.scottellis.com.au/websvn/filedetails.php?repname=Miranda+Plugins&path=%2FMySpace%2Fformatting.cpp&rev=0&sc=0 */
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
43
18050
3ac6d13d25cd Recognize non-canonical emoticon forms from Pidgin, and turn them into
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18049
diff changeset
44 /* The names in in emoticon_names (for <i n=whatever>) map to corresponding
3ac6d13d25cd Recognize non-canonical emoticon forms from Pidgin, and turn them into
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18049
diff changeset
45 * entries in emoticon_symbols (for the ASCII representation of the emoticon).
19147
d10ca94b89d1 Use an array of structs instead of parallel arrays for the emoticon
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19146
diff changeset
46 *
d10ca94b89d1 Use an array of structs instead of parallel arrays for the emoticon
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19146
diff changeset
47 * Multiple emoticon symbols in Pidgin can map to one name. List the
18050
3ac6d13d25cd Recognize non-canonical emoticon forms from Pidgin, and turn them into
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18049
diff changeset
48 * canonical form, as inserted by the "Smile!" dialog, first. For example,
3ac6d13d25cd Recognize non-canonical emoticon forms from Pidgin, and turn them into
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18049
diff changeset
49 * :) comes before :-), because although both are recognized as 'happy',
19148
50e50a9a564f Convert password to lowercase using g_utf8_strdown(), better because
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19147
diff changeset
50 * the first is inserted by the smiley button.
18050
3ac6d13d25cd Recognize non-canonical emoticon forms from Pidgin, and turn them into
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18049
diff changeset
51 *
3ac6d13d25cd Recognize non-canonical emoticon forms from Pidgin, and turn them into
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18049
diff changeset
52 * Note that symbols are case-sensitive in Pidgin -- :-X is not :-x. */
19147
d10ca94b89d1 Use an array of structs instead of parallel arrays for the emoticon
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19146
diff changeset
53 static struct MSIM_EMOTICON
d10ca94b89d1 Use an array of structs instead of parallel arrays for the emoticon
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19146
diff changeset
54 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
55 gchar *name;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
56 gchar *symbol;
19147
d10ca94b89d1 Use an array of structs instead of parallel arrays for the emoticon
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19146
diff changeset
57 } msim_emoticons[] = {
19157
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
58 /* Unfortunately, this list duplicates much of the file
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
59 * pidgin/pidgin/pixmaps/emotes/default/22/default.theme.in, because
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
60 * that file is part of Pidgin, but we're part of libpurple.
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
61 */
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
62 { "bigsmile", ":D" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
63 { "bigsmile", ":-D" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
64 { "devil", "}:)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
65 { "frazzled", ":Z" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
66 { "geek", "B)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
67 { "googles", "%)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
68 { "growl", ":E" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
69 { "laugh", ":))" }, /* Must be before ':)' */
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
70 { "happy", ":)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
71 { "happy", ":-)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
72 { "happi", ":)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
73 { "heart", ":X" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
74 { "mohawk", "-:" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
75 { "mad", "X(" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
76 { "messed", "X)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
77 { "nerd", "Q)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
78 { "oops", ":G" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
79 { "pirate", "P)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
80 { "scared", ":O" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
81 { "sidefrown", ":{" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
82 { "sinister", ":B" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
83 { "smirk", ":," },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
84 { "straight", ":|" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
85 { "tongue", ":P" },
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
86 { "tongue", ":p" },
19157
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
87 { "tongy", ":P" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
88 { "upset", "B|" },
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
89 { "wink", ";-)" },
19157
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
90 { "wink", ";)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
91 { "winc", ";)" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
92 { "worried", ":[" },
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
93 { "kiss", ":x" },
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
94 { NULL, NULL }
19147
d10ca94b89d1 Use an array of structs instead of parallel arrays for the emoticon
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19146
diff changeset
95 };
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
96
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
97 /* Internal functions */
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
98 static void msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
99
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
100 #ifdef MSIM_DEBUG_MSG
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
101 static void print_hash_item(gpointer key, gpointer value, gpointer user_data);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
102 #endif
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
103
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
104 static int msim_send_really_raw(PurpleConnection *gc, const char *buf,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
105 int total_bytes);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
106 static gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
107 static const gchar *msim_compute_login_response(
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
108 const gchar nonce[2 * NONCE_SIZE], const gchar *email,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
109 const gchar *password, guint *response_len);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
110 static gboolean msim_send_bm(MsimSession *session, const gchar *who,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
111 const gchar *text, int type);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
112
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
113 static guint msim_point_to_purple_size(MsimSession *session, guint point);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
114 static guint msim_purple_size_to_point(MsimSession *session, guint size);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
115 static guint msim_height_to_point(MsimSession *session, guint height);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
116 static guint msim_point_to_height(MsimSession *session, guint point);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
117
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
118 static void msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
119
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
120 static void msim_markup_tag_to_html(MsimSession *, xmlnode *root,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
121 gchar **begin, gchar **end);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
122 static void html_tag_to_msim_markup(MsimSession *, xmlnode *root,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
123 gchar **begin, gchar **end);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
124 static gchar *msim_convert_xml(MsimSession *, const gchar *raw,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
125 MSIM_XMLNODE_CONVERT f);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
126 static gchar *msim_convert_smileys_to_markup(gchar *before);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
127
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
128 /* High-level msim markup <=> html conversion functions. */
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
129 static gchar *msim_markup_to_html(MsimSession *, const gchar *raw);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
130 static gchar *html_to_msim_markup(MsimSession *, const gchar *raw);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
131
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
132 static MsimUser *msim_get_user_from_buddy(PurpleBuddy *buddy);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
133 static MsimUser *msim_find_user(MsimSession *session, const gchar *username);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
134
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
135 static gboolean msim_incoming_bm_record_cv(MsimSession *session,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
136 MsimMessage *msg);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
137 static gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
138 static gboolean msim_incoming_status(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
139 static gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
140 static gboolean msim_incoming_zap(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
141 static gboolean msim_incoming_action(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
142 static gboolean msim_incoming_media(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
143 static gboolean msim_incoming_unofficial_client(MsimSession *session,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
144 MsimMessage *msg);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
145
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
146 #ifdef MSIM_SEND_CLIENT_VERSION
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
147 static gboolean msim_send_unofficial_client(MsimSession *session,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
148 gchar *username);
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
149 #endif
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
150
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
151 static void msim_get_info_cb(MsimSession *session, MsimMessage *userinfo, gpointer data);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
152 static gchar *msim_format_now_playing(gchar *band, gchar *song);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
153
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
154 static void msim_set_status_code(MsimSession *session, guint code,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
155 gchar *statstring);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
156
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
157 static void msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
158 static void msim_store_user_info_each(gpointer key, gpointer value,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
159 gpointer user_data);
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
160 static gboolean msim_store_user_info(MsimSession *session, MsimMessage *msg, MsimUser *user);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
161 static gboolean msim_process_server_info(MsimSession *session,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
162 MsimMessage *msg);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
163 static gboolean msim_web_challenge(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
164 static gboolean msim_process_reply(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
165
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
166 static gboolean msim_preprocess_incoming(MsimSession *session,MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
167
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
168 #ifdef MSIM_USE_KEEPALIVE
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
169 static gboolean msim_check_alive(gpointer data);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
170 #endif
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
171
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
172 static gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
173
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
174 static gboolean msim_process(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
175
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
176 static MsimMessage *msim_do_postprocessing(MsimMessage *msg,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
177 const gchar *uid_field_name, const gchar *uid_before, guint uid);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
178 static void msim_postprocess_outgoing_cb(MsimSession *session,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
179 MsimMessage *userinfo, gpointer data);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
180 static gboolean msim_postprocess_outgoing(MsimSession *session,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
181 MsimMessage *msg, const gchar *username, const gchar *uid_field_name,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
182 const gchar *uid_before);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
183
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
184 static gboolean msim_error(MsimSession *session, MsimMessage *msg);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
185
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
186 static void msim_check_inbox_cb(MsimSession *session, MsimMessage *userinfo,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
187 gpointer data);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
188 static gboolean msim_check_inbox(gpointer data);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
189
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
190 static void msim_input_cb(gpointer gc_uncasted, gint source,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
191 PurpleInputCondition cond);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
192
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
193 static guint msim_new_reply_callback(MsimSession *session,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
194 MSIM_USER_LOOKUP_CB cb, gpointer data);
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
195
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
196 static void msim_connect_cb(gpointer data, gint source,
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
197 const gchar *error_message);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
198
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
199 static gboolean msim_is_userid(const gchar *user);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
200 static gboolean msim_is_email(const gchar *user);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
201
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
202 static void msim_lookup_user(MsimSession *session, const gchar *user,
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
203 MSIM_USER_LOOKUP_CB cb, gpointer data);
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
204
19146
86baf2b1b688 Always use our own msim_round() instead of checking for C99's round and using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19144
diff changeset
205 double msim_round(double round);
18061
76e936ec829e Implement round() if it is not available, using floor().
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18059
diff changeset
206
76e936ec829e Implement round() if it is not available, using floor().
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18059
diff changeset
207 /* round is part of C99, but sometimes is unavailable before then.
76e936ec829e Implement round() if it is not available, using floor().
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18059
diff changeset
208 * Based on http://forums.belution.com/en/cpp/000/050/13.shtml
76e936ec829e Implement round() if it is not available, using floor().
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18059
diff changeset
209 */
19146
86baf2b1b688 Always use our own msim_round() instead of checking for C99's round and using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19144
diff changeset
210 double msim_round(double value)
18061
76e936ec829e Implement round() if it is not available, using floor().
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18059
diff changeset
211 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
212 if (value < 0) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
213 return -(floor(-value + 0.5));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
214 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
215 return floor( value + 0.5);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
216 }
18061
76e936ec829e Implement round() if it is not available, using floor().
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18059
diff changeset
217 }
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
218
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
219 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
220 * Load the plugin.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
221 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
222 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
223 msim_load(PurplePlugin *plugin)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
224 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
225 /* If compiled to use RC4 from libpurple, check if it is really there. */
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
226 if (!purple_ciphers_find_cipher("rc4")) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
227 purple_debug_error("msim", "rc4 not in libpurple, but it is required - not loading MySpaceIM plugin!\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
228 purple_notify_error(plugin, _("Missing Cipher"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
229 _("The RC4 cipher could not be found"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
230 _("Upgrade "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
231 "to a libpurple with RC4 support (>= 2.0.1). MySpaceIM "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
232 "plugin will not be loaded."));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
233 return FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
234 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
235 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
236 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
237
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
238 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
239 * Get possible user status types. Based on mockprpl.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
240 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
241 * @return GList of status types.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
242 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
243 GList *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
244 msim_status_types(PurpleAccount *acct)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
245 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
246 GList *types;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
247 PurpleStatusType *status;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
248
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
249 purple_debug_info("myspace", "returning status types\n");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
250
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
251 types = NULL;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
252
18034
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
253 /* Statuses are almost all the same. Define a macro to reduce code repetition. */
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
254 #define _MSIM_ADD_NEW_STATUS(prim) status = \
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
255 purple_status_type_new_with_attrs( \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
256 prim, /* PurpleStatusPrimitive */ \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
257 NULL, /* id - use default */ \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
258 NULL, /* name - use default */ \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
259 TRUE, /* savable */ \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
260 TRUE, /* user_settable */ \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
261 FALSE, /* not independent */ \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
262 \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
263 /* Attributes - each status can have a message. */ \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
264 "message", \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
265 _("Message"), \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
266 purple_value_new(PURPLE_TYPE_STRING), \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
267 NULL); \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
268 \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
269 \
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
270 types = g_list_append(types, status)
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
271
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
272
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
273 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AVAILABLE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
274 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AWAY);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
275 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_OFFLINE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
276 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_INVISIBLE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
277
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
278
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
279 return types;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
280 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
281
18053
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
282 /** Zap someone. Callback from msim_blist_node_menu zap menu. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
283 static void
18053
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
284 msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr)
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
285 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
286 PurpleBuddy *buddy;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
287 PurpleConnection *gc;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
288 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
289 gchar *username, *zap_string, *zap_text;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
290 guint zap;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
291 const gchar *zap_gerund[10];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
292
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
293 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
294 /* Only know about buddies for now. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
295 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
296 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
297
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
298 zap_gerund[0] = _("Zapping");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
299 zap_gerund[1] = _("Whacking");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
300 zap_gerund[2] = _("Torching");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
301 zap_gerund[3] = _("Smooching");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
302 zap_gerund[4] = _("Hugging");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
303 zap_gerund[5] = _("Bslapping");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
304 zap_gerund[6] = _("Goosing");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
305 zap_gerund[7] = _("Hi-fiving");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
306 zap_gerund[8] = _("Punking");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
307 zap_gerund[9] = _("Raspberry'ing");
18053
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
308
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
309 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
310
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
311 buddy = (PurpleBuddy *)node;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
312 gc = purple_account_get_connection(buddy->account);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
313 g_return_if_fail(gc != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
314
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
315 session = (MsimSession *)gc->proto_data;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
316 g_return_if_fail(session != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
317
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
318 username = buddy->name;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
319 g_return_if_fail(username != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
320
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
321 zap = GPOINTER_TO_INT(zap_num_ptr);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
322 zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", zap);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
323 zap_text = g_strdup_printf("*** %s! ***", zap_gerund[zap]);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
324
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
325 serv_got_im(session->gc, username, zap_text,
18053
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
326 PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_SYSTEM, time(NULL));
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
327
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
328 if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION)) {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
329 purple_debug_info("msim_send_zap", "msim_send_bm failed: zapping %s with %s",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
330 username, zap_string);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
331 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
332
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
333 g_free(zap_string);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
334 g_free(zap_text);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
335 return;
18053
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
336 }
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
337
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
338
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
339 /** Return menu, if any, for a buddy list node. */
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
340 GList *
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
341 msim_blist_node_menu(PurpleBlistNode *node)
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
342 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
343 GList *menu, *zap_menu;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
344 PurpleMenuAction *act;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
345 const gchar *zap_names[10];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
346 guint i;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
347
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
348 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
349 /* Only know about buddies for now. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
350 return NULL;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
351 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
352
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
353 /* Names from official client. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
354 zap_names[0] = _("zap");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
355 zap_names[1] = _("whack");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
356 zap_names[2] = _("torch");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
357 zap_names[3] = _("smooch");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
358 zap_names[4] = _("hug");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
359 zap_names[5] = _("bslap");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
360 zap_names[6] = _("goose");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
361 zap_names[7] = _("hi-five");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
362 zap_names[8] = _("punk'd");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
363 zap_names[9] = _("raspberry");
18053
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
364
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
365 menu = zap_menu = NULL;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
366
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
367 /* TODO: move to / command, or better yet new API */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
368 for (i = 0; i < sizeof(zap_names) / sizeof(zap_names[0]); ++i) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
369 act = purple_menu_action_new(zap_names[i], PURPLE_CALLBACK(msim_send_zap),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
370 GUINT_TO_POINTER(i), NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
371 zap_menu = g_list_append(zap_menu, act);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
372 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
373
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
374 act = purple_menu_action_new(_("Zap"), NULL, NULL, zap_menu);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
375 menu = g_list_append(menu, act);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
376
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
377 return menu;
18053
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
378 }
e0e7522cda38 Allow sending zaps through buddy list menu.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18052
diff changeset
379
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
380 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
381 * Return the icon name for a buddy and account.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
382 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
383 * @param acct The account to find the icon for, or NULL for protocol icon.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
384 * @param buddy The buddy to find the icon for, or NULL for the account icon.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
385 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
386 * @return The base icon name string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
387 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
388 const gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
389 msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
390 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
391 /* Use a MySpace icon submitted by hbons at
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
392 * http://developer.pidgin.im/wiki/MySpaceIM. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
393 return "myspace";
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
394 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
395
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
396 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
397 * Replace 'old' with 'new' in 'str'.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
398 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
399 * @param str The original string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
400 * @param old The substring of 'str' to replace.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
401 * @param new The replacement for 'old' within 'str'.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
402 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
403 * @return A _new_ string, based on 'str', with 'old' replaced
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
404 * by 'new'. Must be g_free()'d by caller.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
405 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
406 * This string replace method is based on
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
407 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
408 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
409 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
410 gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
411 str_replace(const gchar *str, const gchar *old, const gchar *new)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
412 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
413 gchar **items;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
414 gchar *ret;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
415
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
416 items = g_strsplit(str, old, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
417 ret = g_strjoinv(new, items);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
418 g_free(items);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
419 return ret;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
420 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
421
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
422 #ifdef MSIM_DEBUG_MSG
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
423 static void
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
424 print_hash_item(gpointer key, gpointer value, gpointer user_data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
425 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
426 purple_debug_info("msim", "%s=%s\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
427 key ? (gchar *)key : "(NULL)",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
428 value ? (gchar *)value : "(NULL)");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
429 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
430 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
431
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
432 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
433 * Send raw data (given as a NUL-terminated string) to the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
434 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
435 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
436 * @param msg The raw data to send, in a NUL-terminated string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
437 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
438 * @return TRUE if succeeded, FALSE if not.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
439 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
440 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
441 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
442 msim_send_raw(MsimSession *session, const gchar *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
443 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
444 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
445 g_return_val_if_fail(msg != NULL, FALSE);
18034
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
446
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
447 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
448
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
449 return msim_send_really_raw(session->gc, msg, strlen(msg)) ==
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
450 strlen(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
451 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
452
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
453 /** Send raw data to the server, possibly with embedded NULs.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
454 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
455 * Used in prpl_info struct, so that plugins can have the most possible
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
456 * control of what is sent over the connection. Inside this prpl,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
457 * msim_send_raw() is used, since it sends NUL-terminated strings (easier).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
458 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
459 * @param gc PurpleConnection
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
460 * @param buf Buffer to send
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
461 * @param total_bytes Size of buffer to send
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
462 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
463 * @return Bytes successfully sent, or -1 on error.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
464 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
465 static int
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
466 msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
467 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
468 int total_bytes_sent;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
469 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
470
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
471 g_return_val_if_fail(gc != NULL, -1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
472 g_return_val_if_fail(buf != NULL, -1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
473 g_return_val_if_fail(total_bytes >= 0, -1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
474
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
475 session = (MsimSession *)gc->proto_data;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
476
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
477 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
478
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
479 /* Loop until all data is sent, or a failure occurs. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
480 total_bytes_sent = 0;
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
481 do {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
482 int bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
483
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
484 bytes_sent = send(session->fd, buf + total_bytes_sent,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
485 total_bytes - total_bytes_sent, 0);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
486
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
487 if (bytes_sent < 0) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
488 purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
489 buf, g_strerror(errno));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
490 return total_bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
491 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
492 total_bytes_sent += bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
493
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
494 } while(total_bytes_sent < total_bytes);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
495
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
496 return total_bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
497 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
498
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
499
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
500 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
501 * Start logging in to the MSIM servers.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
502 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
503 * @param acct Account information to use to login.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
504 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
505 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
506 msim_login(PurpleAccount *acct)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
507 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
508 PurpleConnection *gc;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
509 const gchar *host;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
510 int port;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
511
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
512 g_return_if_fail(acct != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
513 g_return_if_fail(acct->username != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
514
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
515 purple_debug_info("msim", "logging in %s\n", acct->username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
516
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
517 gc = purple_account_get_connection(acct);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
518 gc->proto_data = msim_session_new(acct);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
519 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
520
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
521 /* Passwords are limited in length. */
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
522 if (strlen(acct->password) > MSIM_MAX_PASSWORD_LENGTH) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
523 gchar *str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
524
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
525 str = g_strdup_printf(
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
526 _("Sorry, passwords over %d characters in length (yours is "
19152
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
527 "%d) are not supported by MySpace."),
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
528 MSIM_MAX_PASSWORD_LENGTH,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
529 (int)strlen(acct->password));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
530
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
531 /* Notify an error message also, because this is important! */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
532 purple_notify_error(acct, g_strdup(_("MySpaceIM Error")), str, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
533
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
534 purple_connection_error(gc, str);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
535
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
536 g_free(str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
537 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
538
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
539 /* 1. connect to server */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
540 purple_connection_update_progress(gc, _("Connecting"),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
541 0, /* which connection step this is */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
542 4); /* total number of steps */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
543
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
544 host = purple_account_get_string(acct, "server", MSIM_SERVER);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
545 port = purple_account_get_int(acct, "port", MSIM_PORT);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
546
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
547 /* From purple.sf.net/api:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
548 * """Note that this function name can be misleading--although it is called
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
549 * "proxy connect," it is used for establishing any outgoing TCP connection,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
550 * whether through a proxy or not.""" */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
551
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
552 /* Calls msim_connect_cb when connected. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
553 if (!purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
554 /* TODO: try other ports if in auto mode, then save
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
555 * working port and try that first next time. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
556 purple_connection_error(gc, _("Couldn't create socket"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
557 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
558 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
559 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
560
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
561 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
562 * Process a login challenge, sending a response.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
563 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
564 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
565 * @param msg Login challenge message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
566 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
567 * @return TRUE if successful, FALSE if not
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
568 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
569 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
570 msim_login_challenge(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
571 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
572 PurpleAccount *account;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
573 const gchar *response;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
574 guint response_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
575 gchar *nc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
576 gsize nc_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
577
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
578 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
579 g_return_val_if_fail(msg != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
580
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
581 g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
582
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
583 account = session->account;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
584
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
585 g_return_val_if_fail(account != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
586
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
587 purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
588
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
589 purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
590
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
591 if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
592 purple_debug_info("msim", "bad nc length: %x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
593 purple_connection_error(session->gc, _("Unexpected challenge length from server"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
594 return FALSE;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
595 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
596
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
597 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
598
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
599 response_len = 0;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
600 response = msim_compute_login_response(nc, account->username, account->password, &response_len);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
601
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
602 g_free(nc);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
603
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
604 return msim_send(session,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
605 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
606 /* This is actually user's email address. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
607 "username", MSIM_TYPE_STRING, g_strdup(account->username),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
608 /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
609 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
610 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
611 "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
612 "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH),
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
613 "reconn", MSIM_TYPE_INTEGER, 0,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
614 "status", MSIM_TYPE_INTEGER, 100,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
615 "id", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
616 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
617 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
618
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
619 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
620 * Compute the base64'd login challenge response based on username, password, nonce, and IPs.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
621 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
622 * @param nonce The base64 encoded nonce ('nc') field from the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
623 * @param email User's email address (used as login name).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
624 * @param password User's cleartext password.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
625 * @param response_len Will be written with response length.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
626 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
627 * @return Binary login challenge response, ready to send to the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
628 * Must be g_free()'d when finished. NULL if error.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
629 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
630 static const gchar *
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
631 msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE],
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
632 const gchar *email, const gchar *password, guint *response_len)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
633 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
634 PurpleCipherContext *key_context;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
635 PurpleCipher *sha1;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
636 PurpleCipherContext *rc4;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
637
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
638 guchar hash_pw[HASH_SIZE];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
639 guchar key[HASH_SIZE];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
640 gchar *password_utf16le, *password_utf8_lc;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
641 guchar *data;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
642 guchar *data_out;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
643 size_t data_len, data_out_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
644 gsize conv_bytes_read, conv_bytes_written;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
645 GError *conv_error;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
646 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
647 int i;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
648 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
649
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
650 g_return_val_if_fail(nonce != NULL, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
651 g_return_val_if_fail(email != NULL, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
652 g_return_val_if_fail(password != NULL, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
653 g_return_val_if_fail(response_len != NULL, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
654
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
655 /* Convert password to lowercase (required for passwords containing
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
656 * uppercase characters). MySpace passwords are lowercase,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
657 * see ticket #2066. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
658 password_utf8_lc = g_utf8_strdown(password, -1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
659
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
660 /* Convert ASCII password to UTF16 little endian */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
661 purple_debug_info("msim", "converting password to UTF-16LE\n");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
662 conv_error = NULL;
19148
50e50a9a564f Convert password to lowercase using g_utf8_strdown(), better because
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19147
diff changeset
663 password_utf16le = g_convert(password_utf8_lc, -1, "UTF-16LE", "UTF-8",
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
664 &conv_bytes_read, &conv_bytes_written, &conv_error);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
665 g_free(password_utf8_lc);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
666
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
667 g_return_val_if_fail(conv_bytes_read == strlen(password), NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
668
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
669 if (conv_error != NULL) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
670 purple_debug_error("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
671 "g_convert password UTF8->UTF16LE failed: %s",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
672 conv_error->message);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
673 g_error_free(conv_error);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
674 return NULL;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
675 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
676
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
677 /* Compute password hash */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
678 purple_cipher_digest_region("sha1", (guchar *)password_utf16le,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
679 conv_bytes_written, sizeof(hash_pw), hash_pw, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
680 g_free(password_utf16le);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
681
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
682 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
683 purple_debug_info("msim", "pwhash = ");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
684 for (i = 0; i < sizeof(hash_pw); i++)
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
685 purple_debug_info("msim", "%.2x ", hash_pw[i]);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
686 purple_debug_info("msim", "\n");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
687 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
688
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
689 /* key = sha1(sha1(pw) + nonce2) */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
690 sha1 = purple_ciphers_find_cipher("sha1");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
691 key_context = purple_cipher_context_new(sha1, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
692 purple_cipher_context_append(key_context, hash_pw, HASH_SIZE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
693 purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
694 purple_cipher_context_digest(key_context, sizeof(key), key, NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
695
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
696 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
697 purple_debug_info("msim", "key = ");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
698 for (i = 0; i < sizeof(key); i++) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
699 purple_debug_info("msim", "%.2x ", key[i]);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
700 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
701 purple_debug_info("msim", "\n");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
702 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
703
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
704 rc4 = purple_cipher_context_new_by_name("rc4", NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
705
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
706 /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
707 * but only first 0x10 used for the RC4 key. */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
708 purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
709 purple_cipher_context_set_key(rc4, key);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
710
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
711 /* TODO: obtain IPs of network interfaces */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
712
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
713 /* rc4 encrypt:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
714 * nonce1+email+IP list */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
715
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
716 data_len = NONCE_SIZE + strlen(email) + MSIM_LOGIN_IP_LIST_LEN;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
717 data = g_new0(guchar, data_len);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
718 memcpy(data, nonce, NONCE_SIZE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
719 memcpy(data + NONCE_SIZE, email, strlen(email));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
720 memcpy(data + NONCE_SIZE + strlen(email), MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
721
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
722 data_out = g_new0(guchar, data_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
723
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
724 purple_cipher_context_encrypt(rc4, (const guchar *)data,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
725 data_len, data_out, &data_out_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
726 purple_cipher_context_destroy(rc4);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
727
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
728 g_assert(data_out_len == data_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
729
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
730 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
731 purple_debug_info("msim", "response=<%s>\n", data_out);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
732 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
733
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
734 *response_len = data_out_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
735
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
736 return (const gchar *)data_out;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
737 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
738
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
739 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
740 * Schedule an IM to be sent once the user ID is looked up.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
741 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
742 * @param gc Connection.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
743 * @param who A user id, email, or username to send the message to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
744 * @param message Instant message text to send.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
745 * @param flags Flags.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
746 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
747 * @return 1 if successful or postponed, -1 if failed
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
748 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
749 * Allows sending to a user by username, email address, or userid. If
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
750 * a username or email address is given, the userid must be looked up.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
751 * This function does that by calling msim_postprocess_outgoing().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
752 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
753 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
754 msim_send_im(PurpleConnection *gc, const gchar *who, const gchar *message,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
755 PurpleMessageFlags flags)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
756 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
757 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
758 gchar *message_msim;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
759 int rc;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
760
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
761 g_return_val_if_fail(gc != NULL, -1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
762 g_return_val_if_fail(who != NULL, -1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
763 g_return_val_if_fail(message != NULL, -1);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
764
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
765 /* 'flags' has many options, not used here. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
766
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
767 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
768
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
769 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
770
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
771 message_msim = html_to_msim_markup(session, message);
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
772
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
773 if (msim_send_bm(session, who, message_msim, MSIM_BM_INSTANT)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
774 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
775 * return 1 even if the message could not be sent, since I don't know if
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
776 * it has failed yet--because the IM is only sent after the userid is
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
777 * retrieved from the server (which happens after this function returns).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
778 */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
779 /* TODO: maybe if message is delayed, don't echo to conv window,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
780 * but do echo it to conv window manually once it is actually
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
781 * sent? Would be complicated. */
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
782 rc = 1;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
783 } else {
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
784 rc = -1;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
785 }
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
786
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
787 g_free(message_msim);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
788
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
789 /*
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
790 * In MySpace, you login with your email address, but don't talk to other
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
791 * users using their email address. So there is currently an asymmetry in the
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
792 * IM windows when using this plugin:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
793 *
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
794 * you@example.com: hello
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
795 * some_other_user: what's going on?
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
796 * you@example.com: just coding a prpl
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
797 *
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
798 * TODO: Make the sent IM's appear as from the user's username, instead of
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
799 * their email address. Purple uses the login (in MSIM, the email)--change this.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
800 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
801
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
802 return rc;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
803 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
804
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
805 /** Send a buddy message of a given type.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
806 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
807 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
808 * @param who Username to send message to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
809 * @param text Message text to send. Not freed; will be copied.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
810 * @param type A MSIM_BM_* constant.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
811 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
812 * @return TRUE if success, FALSE if fail.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
813 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
814 * Buddy messages ('bm') include instant messages, action messages, status messages, etc.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
815 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
816 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
817 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
818 msim_send_bm(MsimSession *session, const gchar *who, const gchar *text,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
819 int type)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
820 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
821 gboolean rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
822 MsimMessage *msg;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
823 const gchar *from_username;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
824
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
825 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
826 g_return_val_if_fail(who != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
827 g_return_val_if_fail(text != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
828
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
829 from_username = session->account->username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
830
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
831 g_return_val_if_fail(from_username != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
832
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
833 purple_debug_info("msim", "sending %d message from %s to %s: %s\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
834 type, from_username, who, text);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
835
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
836 msg = msim_msg_new(
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
837 "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type),
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
838 "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
839 /* 't' will be inserted here */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
840 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
841 "msg", MSIM_TYPE_STRING, g_strdup(text),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
842 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
843
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
844 rc = msim_postprocess_outgoing(session, msg, who, "t", "cv");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
845
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
846 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
847
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
848 return rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
849 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
850
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
851 /* Indexes of this array + 1 map HTML font size to scale of normal font size. *
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
852 * Based on _point_sizes from libpurple/gtkimhtml.c
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
853 * 1 2 3 4 5 6 7 */
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
854 static gdouble _font_scale[] = { .85, .95, 1, 1.2, 1.44, 1.728, 2.0736 };
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
855
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
856 #define MAX_FONT_SIZE 7 /* Purple maximum font size */
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
857 #define POINTS_PER_INCH 72 /* How many pt's in an inch */
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
858
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
859 /** Convert typographical font point size to HTML font size.
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
860 * Based on libpurple/gtkimhtml.c */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
861 static guint
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
862 msim_point_to_purple_size(MsimSession *session, guint point)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
863 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
864 guint size, this_point, base;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
865 gdouble scale;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
866
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
867 base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
868
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
869 for (size = 0;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
870 size < sizeof(_font_scale) / sizeof(_font_scale[0]);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
871 ++size) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
872 scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
873 this_point = (guint)msim_round(scale * base);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
874
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
875 if (this_point >= point) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
876 purple_debug_info("msim", "msim_point_to_purple_size: %d pt -> size=%d\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
877 point, size);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
878 return size;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
879 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
880 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
881
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
882 /* No HTML font size was this big; return largest possible. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
883 return this_point;
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
884 }
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
885
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
886 /** Convert HTML font size to point size. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
887 static guint
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
888 msim_purple_size_to_point(MsimSession *session, guint size)
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
889 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
890 gdouble scale;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
891 guint point;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
892 guint base;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
893
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
894 scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
895
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
896 base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
897
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
898 point = (guint)msim_round(scale * base);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
899
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
900 purple_debug_info("msim", "msim_purple_size_to_point: size=%d -> %d pt\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
901 size, point);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
902
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
903 return point;
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
904 }
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
905
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
906 /** Convert a msim markup font pixel height to the more usual point size, for incoming messages. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
907 static guint
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
908 msim_height_to_point(MsimSession *session, guint height)
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
909 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
910 guint dpi;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
911
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
912 dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
913
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
914 return (guint)msim_round((POINTS_PER_INCH * 1. / dpi) * height);
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
915
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
916 /* See also: libpurple/protocols/bonjour/jabber.c
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
917 * _font_size_ichat_to_purple */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
918 }
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
919
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
920 /** Convert point size to msim pixel height font size specification, for outgoing messages. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
921 static guint
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
922 msim_point_to_height(MsimSession *session, guint point)
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
923 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
924 guint dpi;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
925
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
926 dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
927
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
928 return (guint)msim_round((dpi * 1. / POINTS_PER_INCH) * point);
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
929 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
930
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
931 /** Convert the msim markup <f> (font) tag into HTML. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
932 static void
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
933 msim_markup_f_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
934 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
935 const gchar *face, *height_str, *decor_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
936 GString *gs_end, *gs_begin;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
937 guint decor, height;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
938
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
939 face = xmlnode_get_attrib(root, "f");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
940 height_str = xmlnode_get_attrib(root, "h");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
941 decor_str = xmlnode_get_attrib(root, "s");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
942
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
943 if (height_str) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
944 height = atol(height_str);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
945 } else {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
946 height = 12;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
947 }
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
948
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
949 if (decor_str) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
950 decor = atol(decor_str);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
951 } else {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
952 decor = 0;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
953 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
954
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
955 gs_begin = g_string_new("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
956 /* TODO: get font size working */
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
957 if (height && !face) {
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
958 g_string_printf(gs_begin, "<font size='%d'>",
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
959 msim_point_to_purple_size(session, msim_height_to_point(session, height)));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
960 } else if (height && face) {
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
961 g_string_printf(gs_begin, "<font face='%s' size='%d'>", face,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
962 msim_point_to_purple_size(session, msim_height_to_point(session, height)));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
963 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
964 g_string_printf(gs_begin, "<font>");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
965 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
966
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
967 /* No support for font-size CSS? */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
968 /* g_string_printf(gs_begin, "<span style='font-family: %s; font-size: %dpt'>", face,
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
969 msim_height_to_point(height)); */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
970
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
971 gs_end = g_string_new("</font>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
972
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
973 if (decor & MSIM_TEXT_BOLD) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
974 g_string_append(gs_begin, "<b>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
975 g_string_prepend(gs_end, "</b>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
976 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
977
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
978 if (decor & MSIM_TEXT_ITALIC) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
979 g_string_append(gs_begin, "<i>");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
980 g_string_append(gs_end, "</i>");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
981 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
982
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
983 if (decor & MSIM_TEXT_UNDERLINE) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
984 g_string_append(gs_begin, "<u>");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
985 g_string_append(gs_end, "</u>");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
986 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
987
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
988
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
989 *begin = gs_begin->str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
990 *end = gs_end->str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
991 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
992
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
993 /** Convert a msim markup color to a color suitable for libpurple.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
994 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
995 * @param msim Either a color name, or an rgb(x,y,z) code.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
996 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
997 * @return A new string, either a color name or #rrggbb code. Must g_free().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
998 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
999 static char *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1000 msim_color_to_purple(const char *msim)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1001 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1002 guint red, green, blue;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1003
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1004 if (!msim) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1005 return g_strdup("black");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1006 }
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1007
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1008 if (sscanf(msim, "rgb(%d,%d,%d)", &red, &green, &blue) != 3) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1009 /* Color name. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1010 return g_strdup(msim);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1011 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1012 /* TODO: rgba (alpha). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1013
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1014 return g_strdup_printf("#%.2x%.2x%.2x", red, green, blue);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1015 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1016
19158
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1017 /** Convert the msim markup <a> (anchor) tag into HTML. */
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1018 static void
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1019 msim_markup_a_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1020 {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1021 const gchar *href;
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1022
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1023 href = xmlnode_get_attrib(root, "h");
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1024 if (!href) {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1025 href = "";
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1026 }
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1027
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1028 *begin = g_strdup_printf("<a href=\"%s\">%s", href, href);
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1029 *end = g_strdup("</a>");
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1030 }
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1031
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1032 /** Convert the msim markup <p> (paragraph) tag into HTML. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1033 static void
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1034 msim_markup_p_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1035 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1036 /* Just pass through unchanged.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1037 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1038 * Note: attributes currently aren't passed, if there are any. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1039 *begin = g_strdup("<p>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1040 *end = g_strdup("</p>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1041 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1042
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1043 /** Convert the msim markup <c> tag (text color) into HTML. TODO: Test */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1044 static void
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1045 msim_markup_c_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1046 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1047 const gchar *color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1048 gchar *purple_color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1049
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1050 color = xmlnode_get_attrib(root, "v");
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1051 if (!color) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1052 purple_debug_info("msim", "msim_markup_c_to_html: <c> tag w/o v attr");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1053 *begin = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1054 *end = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1055 /* TODO: log as unrecognized */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1056 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1057 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1058
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1059 purple_color = msim_color_to_purple(color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1060
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1061 *begin = g_strdup_printf("<font color='%s'>", purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1062
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1063 g_free(purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1064
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1065 /* *begin = g_strdup_printf("<span style='color: %s'>", color); */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1066 *end = g_strdup("</font>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1067 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1068
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1069 /** Convert the msim markup <b> tag (background color) into HTML. TODO: Test */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1070 static void
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1071 msim_markup_b_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1072 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1073 const gchar *color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1074 gchar *purple_color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1075
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1076 color = xmlnode_get_attrib(root, "v");
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1077 if (!color) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1078 *begin = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1079 *end = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1080 purple_debug_info("msim", "msim_markup_b_to_html: <b> w/o v attr");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1081 /* TODO: log as unrecognized. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1082 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1083 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1084
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1085 purple_color = msim_color_to_purple(color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1086
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1087 /* TODO: find out how to set background color. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1088 *begin = g_strdup_printf("<span style='background-color: %s'>",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1089 purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1090 g_free(purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1091
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1092 *end = g_strdup("</p>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1093 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1094
18046
bb35d08adf0b Support emoticons on incoming messages, approximating MySpaceIM's smileys
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18045
diff changeset
1095 /** Convert the msim markup <i> tag (emoticon image) into HTML. */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1096 static void
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1097 msim_markup_i_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1098 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1099 const gchar *name;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1100 guint i;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1101 struct MSIM_EMOTICON *emote;
19157
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
1102
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1103 name = xmlnode_get_attrib(root, "n");
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1104 if (!name) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1105 purple_debug_info("msim", "msim_markup_i_to_html: <i> w/o n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1106 *begin = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1107 *end = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1108 /* TODO: log as unrecognized */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1109 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1110 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1111
19157
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
1112 /* Find and use canonical form of smiley symbol. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1113 for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) {
19157
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
1114 if (!strcmp(name, emote->name)) {
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
1115 *begin = g_strdup(emote->symbol);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1116 *end = g_strdup("");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1117 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1118 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1119 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1120
19157
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
1121 /* Couldn't find it, sorry. Try to degrade gracefully. */
6e6b5596c49a Support all emoticons used in the official MySpaceIM client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19153
diff changeset
1122 *begin = g_strdup_printf("**%s**", name);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1123 *end = g_strdup("");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1124 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1125
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1126 /** Convert an individual msim markup tag to HTML. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1127 static void
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1128 msim_markup_tag_to_html(MsimSession *session, xmlnode *root, gchar **begin,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1129 gchar **end)
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1130 {
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1131 if (!strcmp(root->name, "f")) {
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1132 msim_markup_f_to_html(session, root, begin, end);
19158
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1133 } else if (!strcmp(root->name, "a")) {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1134 msim_markup_a_to_html(session, root, begin, end);
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1135 } else if (!strcmp(root->name, "p")) {
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1136 msim_markup_p_to_html(session, root, begin, end);
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1137 } else if (!strcmp(root->name, "c")) {
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1138 msim_markup_c_to_html(session, root, begin, end);
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1139 } else if (!strcmp(root->name, "b")) {
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1140 msim_markup_b_to_html(session, root, begin, end);
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1141 } else if (!strcmp(root->name, "i")) {
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1142 msim_markup_i_to_html(session, root, begin, end);
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1143 } else {
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1144 purple_debug_info("msim", "msim_markup_tag_to_html: "
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
1145 "unknown tag name=%s, ignoring",
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1146 (root && root->name) ? root->name : "(NULL)");
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1147 *begin = g_strdup("");
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1148 *end = g_strdup("");
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1149 }
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1150 }
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1151
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1152 /** Convert an individual HTML tag to msim markup. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1153 static void
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1154 html_tag_to_msim_markup(MsimSession *session, xmlnode *root, gchar **begin,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1155 gchar **end)
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1156 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1157 /* TODO: Coalesce nested tags into one <f> tag!
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1158 * Currently, the 's' value will be overwritten when b/i/u is nested
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1159 * within another one, and only the inner-most formatting will be
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1160 * applied to the text. */
19161
e83ad99e6e52 Replace non-portable stricmp() with two calls to strcmp(), one uppercase and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19159
diff changeset
1161 if (!strcmp(root->name, "root")) {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1162 *begin = g_strdup("");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1163 *end = g_strdup("");
19161
e83ad99e6e52 Replace non-portable stricmp() with two calls to strcmp(), one uppercase and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19159
diff changeset
1164 } else if (!strcmp(root->name, "b") || !strcmp(root->name, "B")) {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1165 *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_BOLD);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1166 *end = g_strdup("</f>");
19161
e83ad99e6e52 Replace non-portable stricmp() with two calls to strcmp(), one uppercase and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19159
diff changeset
1167 } else if (!strcmp(root->name, "i") || !strcmp(root->name, "I")) {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1168 *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_ITALIC);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1169 *end = g_strdup("</f>");
19161
e83ad99e6e52 Replace non-portable stricmp() with two calls to strcmp(), one uppercase and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19159
diff changeset
1170 } else if (!strcmp(root->name, "u") || !strcmp(root->name, "U")) {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1171 *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_UNDERLINE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1172 *end = g_strdup("</f>");
19161
e83ad99e6e52 Replace non-portable stricmp() with two calls to strcmp(), one uppercase and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19159
diff changeset
1173 } else if (!strcmp(root->name, "a") || !strcmp(root->name, "A")) {
19158
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1174 const gchar *href, *link_text;
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1175
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1176 href = xmlnode_get_attrib(root, "href");
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1177
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1178 if (!href) {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1179 href = xmlnode_get_attrib(root, "HREF");
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1180 }
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1181
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1182 link_text = xmlnode_get_data(root);
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1183
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1184 if (href) {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1185 if (!strcmp(link_text, href)) {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1186 /* Purple gives us: <a href="URL">URL</a>
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1187 * Translate to <a h='URL' />
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1188 * Displayed as text of URL with link to URL
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1189 */
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1190 *begin = g_strdup_printf("<a h='%s' />", href);
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1191 } else {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1192 /* But if we get: <a href="URL">text</a>
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1193 * Translate to: text: <a h='URL' />
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1194 *
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1195 * Because official client only supports self-closed <a>
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1196 * tags; you can't change the link text.
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1197 */
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1198 *begin = g_strdup_printf("%s: <a h='%s' />", link_text, href);
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1199 }
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1200 } else {
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1201 *begin = g_strdup("<a />");
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1202 }
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1203
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1204 /* Sorry, kid. MySpace doesn't support you within <a> tags. */
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1205 xmlnode_free(root->child);
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1206 root->child = NULL;
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1207
d190ad19c386 Support sending and receiving hyperlinks.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19157
diff changeset
1208 *end = g_strdup("");
19161
e83ad99e6e52 Replace non-portable stricmp() with two calls to strcmp(), one uppercase and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19159
diff changeset
1209 } else if (!strcmp(root->name, "font") || !strcmp(root->name, "FONT")) {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1210 const gchar *size;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1211 const gchar *face;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1212
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1213 size = xmlnode_get_attrib(root, "size");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1214 face = xmlnode_get_attrib(root, "face");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1215
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1216 if (face && size) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1217 *begin = g_strdup_printf("<f f='%s' h='%d'>", face,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1218 msim_point_to_height(session,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1219 msim_purple_size_to_point(session, atoi(size))));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1220 } else if (face) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1221 *begin = g_strdup_printf("<f f='%s'>", face);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1222 } else if (size) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1223 *begin = g_strdup_printf("<f h='%d'>",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1224 msim_point_to_height(session,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1225 msim_purple_size_to_point(session, atoi(size))));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1226 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1227 *begin = g_strdup("<f>");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1228 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1229
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1230 *end = g_strdup("</f>");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1231
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1232 /* TODO: color (bg uses <body>), emoticons */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1233 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1234 *begin = g_strdup_printf("[%s]", root->name);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1235 *end = g_strdup_printf("[/%s]", root->name);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1236 }
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1237 }
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1238
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1239 /** Convert an xmlnode of msim markup or HTML to an HTML string or msim markup.
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1240 *
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1241 * @param f Function to convert tags.
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1242 *
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1243 * @return An HTML string. Caller frees.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1244 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1245 static gchar *
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1246 msim_convert_xmlnode(MsimSession *session, xmlnode *root, MSIM_XMLNODE_CONVERT f)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1247 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1248 xmlnode *node;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1249 gchar *begin, *inner, *end;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1250 GString *final;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1251
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1252 if (!root || !root->name) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1253 return g_strdup("");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1254 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1255
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1256 purple_debug_info("msim", "msim_convert_xmlnode: got root=%s\n",
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1257 root->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1258
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1259 begin = inner = end = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1260
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1261 final = g_string_new("");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1262
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1263 f(session, root, &begin, &end);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1264
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1265 g_string_append(final, begin);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1266
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1267 /* Loop over all child nodes. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1268 for (node = root->child; node != NULL; node = node->next) {
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1269 switch (node->type) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1270 case XMLNODE_TYPE_ATTRIB:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1271 /* Attributes handled above. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1272 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1273
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1274 case XMLNODE_TYPE_TAG:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1275 /* A tag or tag with attributes. Recursively descend. */
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1276 inner = msim_convert_xmlnode(session, node, f);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1277 g_return_val_if_fail(inner != NULL, NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1278
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
1279 purple_debug_info("msim", " ** node name=%s\n",
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1280 (node && node->name) ? node->name : "(NULL)");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1281 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1282
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1283 case XMLNODE_TYPE_DATA:
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1284 /* Literal text. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1285 inner = g_new0(char, node->data_sz + 1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1286 strncpy(inner, node->data, node->data_sz);
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
1287 inner[node->data_sz] = 0;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1288
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
1289 purple_debug_info("msim", " ** node data=%s\n",
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1290 inner ? inner : "(NULL)");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1291 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1292
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1293 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1294 purple_debug_info("msim",
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1295 "msim_convert_xmlnode: strange node\n");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1296 inner = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1297 }
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
1298
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1299 if (inner) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1300 g_string_append(final, inner);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1301 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1302 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1303
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1304 /* TODO: Note that msim counts each piece of text enclosed by <f> as
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1305 * a paragraph and will display each on its own line. You actually have
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1306 * to _nest_ <f> tags to intersperse different text in one paragraph!
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1307 * Comment out this line below to see. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1308 g_string_append(final, end);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1309
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1310 purple_debug_info("msim", "msim_markup_xmlnode_to_gtkhtml: RETURNING %s\n",
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
1311 (final && final->str) ? final->str : "(NULL)");
18036
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
1312
532aa29d4dda Support font sizes in sending and receiving formatted text.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18035
diff changeset
1313 return final->str;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1314 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1315
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1316 /** Convert XML to something based on MSIM_XMLNODE_CONVERT. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1317 static gchar *
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1318 msim_convert_xml(MsimSession *session, const gchar *raw, MSIM_XMLNODE_CONVERT f)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1319 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1320 xmlnode *root;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1321 gchar *str;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1322 gchar *enclosed_raw;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1323
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1324 g_return_val_if_fail(raw != NULL, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1325
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1326 /* Enclose text in one root tag, to try to make it valid XML for parsing. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1327 enclosed_raw = g_strconcat("<root>", raw, "</root>", NULL);
18048
c8f29e1916c2 Add account option to send emoticons, defaulting to off since can't currently
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18047
diff changeset
1328
c8f29e1916c2 Add account option to send emoticons, defaulting to off since can't currently
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18047
diff changeset
1329 root = xmlnode_from_str(enclosed_raw, -1);
c8f29e1916c2 Add account option to send emoticons, defaulting to off since can't currently
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18047
diff changeset
1330
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1331 if (!root) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1332 purple_debug_info("msim", "msim_markup_to_html: couldn't parse "
18048
c8f29e1916c2 Add account option to send emoticons, defaulting to off since can't currently
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18047
diff changeset
1333 "%s as XML, returning raw: %s\n", enclosed_raw, raw);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1334 /* TODO: msim_unrecognized */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1335 g_free(enclosed_raw);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1336 return g_strdup(raw);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1337 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1338
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1339 g_free(enclosed_raw);
18048
c8f29e1916c2 Add account option to send emoticons, defaulting to off since can't currently
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18047
diff changeset
1340
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1341 str = msim_convert_xmlnode(session, root, f);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1342 g_return_val_if_fail(str != NULL, NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1343 purple_debug_info("msim", "msim_markup_to_html: returning %s\n", str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1344
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1345 xmlnode_free(root);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1346
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1347 return str;
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1348 }
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1349
18047
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1350 /** Convert plaintext smileys to <i> markup tags.
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1351 *
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1352 * @param before Original text with ASCII smileys. Will be freed.
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1353 * @return A new string with <i> tags, if applicable. Must be g_free()'d.
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1354 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1355 static gchar *
18047
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1356 msim_convert_smileys_to_markup(gchar *before)
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1357 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1358 gchar *old, *new, *replacement;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1359 guint i;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1360 struct MSIM_EMOTICON *emote;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1361
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1362 old = before;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1363 new = NULL;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1364
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1365 for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1366 gchar *name, *symbol;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1367
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1368 name = emote->name;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1369 symbol = emote->symbol;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1370
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1371 replacement = g_strdup_printf("<i n=\"%s\"/>", name);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1372
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1373 purple_debug_info("msim", "msim_convert_smileys_to_markup: %s->%s\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1374 symbol ? symbol : "(NULL)",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1375 replacement ? replacement : "(NULL)");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1376 new = str_replace(old, symbol, replacement);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1377
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1378 g_free(replacement);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1379 g_free(old);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1380
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1381 old = new;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1382 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1383
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1384 return new;
18047
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1385 }
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1386
18047
c58fc8a8e378 Add support for sending emoticons.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18046
diff changeset
1387
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1388 /** High-level function to convert MySpaceIM markup to Purple (HTML) markup.
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1389 *
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1390 * @return Purple markup string, must be g_free()'d. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1391 static gchar *
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1392 msim_markup_to_html(MsimSession *session, const gchar *raw)
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1393 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1394 return msim_convert_xml(session, raw,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1395 (MSIM_XMLNODE_CONVERT)(msim_markup_tag_to_html));
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1396 }
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1397
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1398 /** High-level function to convert Purple (HTML) to MySpaceIM markup.
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1399 *
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1400 * @return HTML markup string, must be g_free()'d. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1401 static gchar *
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1402 html_to_msim_markup(MsimSession *session, const gchar *raw)
18028
85ed2582be94 Support sending some formatted text in instant messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18026
diff changeset
1403 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1404 gchar *markup;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1405
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1406 markup = msim_convert_xml(session, raw,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1407 (MSIM_XMLNODE_CONVERT)(html_tag_to_msim_markup));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1408
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1409 if (purple_account_get_bool(session->account, "emoticons", TRUE)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1410 /* Frees markup and allocates a new one. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1411 markup = msim_convert_smileys_to_markup(markup);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1412 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1413
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1414 return markup;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1415 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1416
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1417 /** Get the MsimUser from a PurpleBuddy, creating it if needed. */
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1418 static MsimUser *
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1419 msim_get_user_from_buddy(PurpleBuddy *buddy)
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1420 {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1421 MsimUser *user;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1422
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1423 if (!buddy) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1424 return NULL;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1425 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1426
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1427 if (!buddy->proto_data) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1428 /* TODO: where is this freed? */
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1429 user = g_new0(MsimUser, 1);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1430 user->buddy = buddy;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1431 buddy->proto_data = (gpointer)user;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1432 purple_debug_info("msim_get_user_from_buddy",
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1433 "creating new user for %s to %X\n",
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1434 buddy->name, buddy->proto_data);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1435 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1436
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1437 user = (MsimUser *)(buddy->proto_data);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1438
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1439 return user;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1440 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1441
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1442 /** Find and return an MsimUser * representing a user on the buddy list, or NULL. */
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1443 static MsimUser *
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1444 msim_find_user(MsimSession *session, const gchar *username)
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1445 {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1446 PurpleBuddy *buddy;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1447 MsimUser *user;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1448
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1449 buddy = purple_find_buddy(session->account, username);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1450 if (!buddy) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1451 return NULL;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1452 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1453
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1454 user = msim_get_user_from_buddy(buddy);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1455
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1456 return user;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1457 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1458
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1459
18045
7e4b117d740b Show official client build in buddy profiles.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18044
diff changeset
1460 /** Record the client version in the buddy list, from an incoming message. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1461 static gboolean
18045
7e4b117d740b Show official client build in buddy profiles.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18044
diff changeset
1462 msim_incoming_bm_record_cv(MsimSession *session, MsimMessage *msg)
7e4b117d740b Show official client build in buddy profiles.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18044
diff changeset
1463 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1464 gchar *username, *cv;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1465 gboolean ret;
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1466 MsimUser *user;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1467
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1468 username = msim_msg_get_string(msg, "_username");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1469 cv = msim_msg_get_string(msg, "cv");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1470
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1471 g_return_val_if_fail(username != NULL, FALSE);
19162
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
1472 if (!cv) {
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
1473 /* No client version to record, don't worry about it. */
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
1474 return FALSE;
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
1475 }
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1476
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1477 user = msim_find_user(session, username);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1478
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1479 if (user) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1480 user->client_cv = atol(cv);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1481 ret = TRUE;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1482 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1483 ret = FALSE;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1484 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1485
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1486 g_free(username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1487 g_free(cv);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1488
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1489 return ret;
18045
7e4b117d740b Show official client build in buddy profiles.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18044
diff changeset
1490 }
7e4b117d740b Show official client build in buddy profiles.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18044
diff changeset
1491
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1492 /** Handle an incoming buddy message. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1493 static gboolean
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1494 msim_incoming_bm(MsimSession *session, MsimMessage *msg)
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1495 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1496 guint bm;
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1497
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1498 bm = msim_msg_get_integer(msg, "bm");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1499
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1500 msim_incoming_bm_record_cv(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1501
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1502 switch (bm) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1503 case MSIM_BM_STATUS:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1504 return msim_incoming_status(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1505 case MSIM_BM_INSTANT:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1506 return msim_incoming_im(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1507 case MSIM_BM_ACTION:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1508 return msim_incoming_action(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1509 case MSIM_BM_MEDIA:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1510 return msim_incoming_media(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1511 case MSIM_BM_UNOFFICIAL_CLIENT:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1512 return msim_incoming_unofficial_client(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1513 default:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1514 /* Not really an IM, but show it for informational
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1515 * purposes during development. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1516 return msim_incoming_im(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1517 }
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1518 }
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1519
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1520 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1521 * Handle an incoming instant message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1522 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1523 * @param session The session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1524 * @param msg Message from the server, containing 'f' (userid from) and 'msg'.
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1525 * Should also contain username in _username from preprocessing.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1526 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1527 * @return TRUE if successful.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1528 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1529 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1530 msim_incoming_im(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1531 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1532 gchar *username, *msg_msim_markup, *msg_purple_markup;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1533
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1534 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1535 g_return_val_if_fail(msg != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1536
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1537 username = msim_msg_get_string(msg, "_username");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1538 g_return_val_if_fail(username != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1539
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1540 msg_msim_markup = msim_msg_get_string(msg, "msg");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1541 g_return_val_if_fail(msg_msim_markup != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1542
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
1543 msg_purple_markup = msim_markup_to_html(session, msg_msim_markup);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1544 g_free(msg_msim_markup);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1545
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1546 serv_got_im(session->gc, username, msg_purple_markup,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1547 PURPLE_MESSAGE_RECV, time(NULL));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1548
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1549 g_free(username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1550 g_free(msg_purple_markup);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1551
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1552 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1553 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1554
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1555 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1556 * Process unrecognized information.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1557 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1558 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1559 * @param msg An MsimMessage that was unrecognized, or NULL.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1560 * @param note Information on what was unrecognized, or NULL.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1561 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1562 static void
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1563 msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1564 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1565 /* TODO: Some more context, outwardly equivalent to a backtrace,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1566 * for helping figure out what this msg is for. What was going on?
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1567 * But not too much information so that a user
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1568 * posting this dump reveals confidential information.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1569 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1570
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1571 /* TODO: dump unknown msgs to file, so user can send them to me
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1572 * if they wish, to help add support for new messages (inspired
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1573 * by Alexandr Shutko, who maintains OSCAR protocol documentation). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1574
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1575 purple_debug_info("msim", "Unrecognized data on account for %s\n",
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1576 session->account->username ? session->account->username
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1577 : "(NULL)");
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1578 if (note) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1579 purple_debug_info("msim", "(Note: %s)\n", note);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1580 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1581
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1582 if (msg) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1583 msim_msg_dump("Unrecognized message dump: %s\n", msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1584 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1585 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1586
18052
49c29865fde5 Support incoming zaps.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18051
diff changeset
1587 /** Process an incoming zap. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1588 static gboolean
18052
49c29865fde5 Support incoming zaps.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18051
diff changeset
1589 msim_incoming_zap(MsimSession *session, MsimMessage *msg)
49c29865fde5 Support incoming zaps.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18051
diff changeset
1590 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1591 gchar *msg_text, *username, *zap_text;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1592 gint zap;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1593 const gchar *zap_past_tense[10];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1594
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1595 zap_past_tense[0] = _("zapped");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1596 zap_past_tense[1] = _("whacked");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1597 zap_past_tense[2] = _("torched");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1598 zap_past_tense[3] = _("smooched");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1599 zap_past_tense[4] = _("hugged");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1600 zap_past_tense[5] = _("bslapped");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1601 zap_past_tense[6] = _("goosed");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1602 zap_past_tense[7] = _("hi-fived");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1603 zap_past_tense[8] = _("punk'd");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1604 zap_past_tense[9] = _("raspberried");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1605
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1606 msg_text = msim_msg_get_string(msg, "msg");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1607 username = msim_msg_get_string(msg, "_username");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1608
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1609 g_return_val_if_fail(msg_text != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1610 g_return_val_if_fail(username != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1611
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1612 g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1613
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1614 zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0]));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1615
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1616 zap_text = g_strdup_printf(_("*** You have been %s! ***"), zap_past_tense[zap]);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1617
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1618 serv_got_im(session->gc, username, zap_text,
18052
49c29865fde5 Support incoming zaps.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18051
diff changeset
1619 PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, time(NULL));
49c29865fde5 Support incoming zaps.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18051
diff changeset
1620
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1621 g_free(zap_text);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1622 g_free(msg_text);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1623 g_free(username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1624
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1625 return TRUE;
18052
49c29865fde5 Support incoming zaps.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18051
diff changeset
1626 }
49c29865fde5 Support incoming zaps.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18051
diff changeset
1627
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1628 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1629 * Handle an incoming action message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1630 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1631 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1632 * @param msg
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1633 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1634 * @return TRUE if successful.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1635 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1636 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1637 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1638 msim_incoming_action(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1639 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1640 gchar *msg_text, *username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1641 gboolean rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1642
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1643 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1644 g_return_val_if_fail(msg != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1645
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1646 msg_text = msim_msg_get_string(msg, "msg");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1647 g_return_val_if_fail(msg_text != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1648
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1649 username = msim_msg_get_string(msg, "_username");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1650 g_return_val_if_fail(username != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1651
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1652 purple_debug_info("msim", "msim_incoming_action: action <%s> from <%d>\n",
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1653 msg_text, username);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1654
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
1655 if (strcmp(msg_text, "%typing%") == 0) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1656 /* TODO: find out if msim repeatedly sends typing messages, so we can
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1657 * give it a timeout. Right now, there does seem to be an inordinately
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1658 * amount of time between typing stopped-typing notifications. */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1659 serv_got_typing(session->gc, username, 0, PURPLE_TYPING);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1660 rc = TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1661 } else if (strcmp(msg_text, "%stoptyping%") == 0) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1662 serv_got_typing_stopped(session->gc, username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1663 rc = TRUE;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1664 } else if (strstr(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_")) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1665 rc = msim_incoming_zap(session, msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1666 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1667 msim_unrecognized(session, msg,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1668 "got to msim_incoming_action but unrecognized value for 'msg'");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1669 rc = FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1670 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1671
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1672 g_free(msg_text);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1673 g_free(username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1674
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1675 return rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1676 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1677
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1678 /* Process an incoming media (buddy icon) message. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1679 static gboolean
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1680 msim_incoming_media(MsimSession *session, MsimMessage *msg)
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1681 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1682 gchar *username, *text;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1683
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1684 username = msim_msg_get_string(msg, "_username");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1685 text = msim_msg_get_string(msg, "msg");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1686
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1687 g_return_val_if_fail(username != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1688 g_return_val_if_fail(text != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1689
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1690 purple_debug_info("msim", "msim_incoming_media: from %s, got msg=%s\n", username, text);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1691
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1692 /* Media messages are sent when the user opens a window to someone.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1693 * Tell libpurple they started typing and stopped typing, to inform the Psychic
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1694 * Mode plugin so it too can open a window to the user. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1695 serv_got_typing(session->gc, username, 0, PURPLE_TYPING);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1696 serv_got_typing_stopped(session->gc, username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1697
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1698 g_free(username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1699
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1700 return TRUE;
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1701 }
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1702
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1703 /* Process an incoming "unofficial client" message. The plugin for
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1704 * Miranda IM sends this message with the plugin information. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1705 static gboolean
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1706 msim_incoming_unofficial_client(MsimSession *session, MsimMessage *msg)
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1707 {
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1708 MsimUser *user;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1709 gchar *username, *client_info;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1710
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1711 username = msim_msg_get_string(msg, "_username");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1712 client_info = msim_msg_get_string(msg, "msg");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1713
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1714 g_return_val_if_fail(username != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1715 g_return_val_if_fail(client_info != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1716
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1717 purple_debug_info("msim", "msim_incoming_unofficial_client: %s is using client %s\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1718 username, client_info);
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1719
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1720 user = msim_find_user(session, username);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1721
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1722 g_return_val_if_fail(user != NULL, FALSE);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1723
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1724 if (user->client_info) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1725 g_free(user->client_info);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1726 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1727 user->client_info = client_info;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1728
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1729 g_free(username);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1730 /* Do not free client_info - the MsimUser now owns it. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1731
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1732 return TRUE;
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1733 }
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1734
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1735
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
1736 #ifdef MSIM_SEND_CLIENT_VERSION
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1737 /** Send our client version to another unofficial client that understands it. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1738 static gboolean
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1739 msim_send_unofficial_client(MsimSession *session, gchar *username)
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1740 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1741 gchar *our_info;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1742 gboolean ret;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1743
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1744 our_info = g_strdup_printf("Libpurple %d.%d.%d - msimprpl %s",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1745 PURPLE_MAJOR_VERSION,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1746 PURPLE_MINOR_VERSION,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1747 PURPLE_MICRO_VERSION,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1748 MSIM_PRPL_VERSION_STRING);
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1749
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1750 ret = msim_send_bm(session, username, our_info, MSIM_BM_UNOFFICIAL_CLIENT);
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1751
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1752 return ret;
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1753 }
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
1754 #endif
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1755
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1756 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1757 * Handle when our user starts or stops typing to another user.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1758 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1759 * @param gc
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1760 * @param name The buddy name to which our user is typing to
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1761 * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1762 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1763 * @return 0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1764 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1765 unsigned int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1766 msim_send_typing(PurpleConnection *gc, const gchar *name,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1767 PurpleTypingState state)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1768 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1769 const gchar *typing_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1770 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1771
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1772 g_return_val_if_fail(gc != NULL, 0);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1773 g_return_val_if_fail(name != NULL, 0);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1774
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1775 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1776
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1777 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1778
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1779 switch (state) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1780 case PURPLE_TYPING:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1781 typing_str = "%typing%";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1782 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1783
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1784 case PURPLE_TYPED:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1785 case PURPLE_NOT_TYPING:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1786 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1787 typing_str = "%stoptyping%";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1788 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1789 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1790
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1791 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1792 msim_send_bm(session, name, typing_str, MSIM_BM_ACTION);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1793 return 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1794 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1795
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1796 /** Format the "now playing" indicator, showing the artist and song.
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1797 * @return Return a new string (must be g_free()'d), or NULL.
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1798 */
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1799 static gchar *
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1800 msim_format_now_playing(gchar *band, gchar *song)
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1801 {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1802 if ((band && strlen(band)) || (song && strlen(song))) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1803 return g_strdup_printf("%s - %s",
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1804 (band && strlen(band)) ? band : "Unknown Artist",
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1805 (song && strlen(song)) ? song : "Unknown Song");
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1806 } else {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1807 return NULL;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1808 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1809 }
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1810
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1811 /** Append user information to a PurpleNotifyUserInfo, given an MsimUser.
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1812 * Used by msim_tooltip_text() and msim_get_info_cb() to show a user's profile.
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1813 */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1814 static void
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1815 msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full)
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1816 {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1817 gchar *str;
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1818 guint uid;
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1819 guint cv;
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1820
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1821 /* Useful to identify the account the tooltip refers to.
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1822 * Other prpls show this. */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1823 if (user->username) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1824 purple_notify_user_info_add_pair(user_info, _("User"), user->username);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1825 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1826
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1827 uid = purple_blist_node_get_int(&user->buddy->node, "UserID");
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1828
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1829 if (full) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1830 purple_notify_user_info_add_pair(user_info, _("User ID"), g_strdup_printf("%d", uid));
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1831 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1832
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1833
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1834 /* a/s/l...the vitals */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1835 if (user->age) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1836 purple_notify_user_info_add_pair(user_info, _("Age"),
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1837 g_strdup_printf("%d", user->age));
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1838 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1839
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1840 if (user->gender && strlen(user->gender)) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1841 purple_notify_user_info_add_pair(user_info, _("Gender"), user->gender);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1842 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1843
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1844 if (user->location && strlen(user->location)) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1845 purple_notify_user_info_add_pair(user_info, _("Location"), user->location);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1846 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1847
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1848 /* Other information */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1849 if (user->headline && strlen(user->headline)) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1850 purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1851 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1852
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1853 str = msim_format_now_playing(user->band_name, user->song_name);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1854 if (str && strlen(str)) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1855 purple_notify_user_info_add_pair(user_info, _("Song"), str);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1856 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1857
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1858 /* Note: total friends only available if looked up by uid, not username. */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1859 if (user->total_friends) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1860 purple_notify_user_info_add_pair(user_info, _("Total Friends"),
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1861 g_strdup_printf("%d", user->total_friends));
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1862 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1863
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1864 if (full) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1865 /* Client information */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1866
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1867 str = user->client_info;
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1868 cv = user->client_cv;
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1869
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1870 if (str && cv != 0) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1871 purple_notify_user_info_add_pair(user_info, _("Client Version"),
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1872 g_strdup_printf("%s (build %d)", str, cv));
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1873 } else if (str) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1874 purple_notify_user_info_add_pair(user_info, _("Client Version"),
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1875 g_strdup(str));
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1876 } else if (cv) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1877 purple_notify_user_info_add_pair(user_info, _("Client Version"),
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1878 g_strdup_printf("Build %d", cv));
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1879 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1880 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1881 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1882
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1883 /** Callback for msim_get_info(), for when user info is received. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1884 static void
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
1885 msim_get_info_cb(MsimSession *session, MsimMessage *user_info_msg,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1886 gpointer data)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1887 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1888 MsimMessage *msg;
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1889 gchar *username;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1890 PurpleNotifyUserInfo *user_info;
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1891 MsimUser *user;
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1892 gboolean temporary_user;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1893
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1894 g_return_if_fail(MSIM_SESSION_VALID(session));
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1895
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1896 /* Get user{name,id} from msim_get_info, passed as an MsimMessage for
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1897 orthogonality. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1898 msg = (MsimMessage *)data;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1899 g_return_if_fail(msg != NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1900
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1901 username = msim_msg_get_string(msg, "user");
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1902 if (!username) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1903 purple_debug_info("msim", "msim_get_info_cb: no 'user' in msg");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1904 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1905 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1906
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1907 msim_msg_free(msg);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1908 purple_debug_info("msim", "msim_get_info_cb: got for user: %s\n", username);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1909
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1910 user = msim_find_user(session, username);
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1911
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1912 if (!user) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1913 /* User isn't on blist, create a temporary user to store info. */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1914 temporary_user = TRUE;
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1915 user = g_new0(MsimUser, 1);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1916 } else {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1917 temporary_user = FALSE;
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1918 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1919
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1920 /* Update user structure with new information */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1921 msim_store_user_info(session, user_info_msg, user);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1922
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1923 user_info = purple_notify_user_info_new();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1924
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1925 /* Append data from MsimUser to PurpleNotifyUserInfo for display, full */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1926 msim_append_user_info(session, user_info, user, TRUE);
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
1927
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1928 purple_notify_userinfo(session->gc, username, user_info, NULL, NULL);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1929 purple_debug_info("msim", "msim_get_info_cb: username=%s\n", username);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1930
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1931 purple_notify_user_info_destroy(user_info);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1932 /* TODO: do not free username, since it will be used by user_info? */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1933
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1934 if (temporary_user) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1935 g_free(user->client_info);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1936 g_free(user->gender);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1937 g_free(user->location);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1938 g_free(user->headline);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1939 g_free(user->display_name);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1940 g_free(user->username);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1941 g_free(user->band_name);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1942 g_free(user->song_name);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1943 g_free(user->image_url);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1944 g_free(user);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
1945 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1946
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1947 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1948
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1949 /** Retrieve a user's profile.
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1950 * @param username Username, user ID, or email address to lookup.
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1951 */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1952 void
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1953 msim_get_info(PurpleConnection *gc, const gchar *username)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1954 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1955 MsimSession *session;
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1956 MsimUser *user;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1957 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1958 gchar *user_to_lookup;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1959 MsimMessage *user_msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1960
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1961 g_return_if_fail(gc != NULL);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1962 g_return_if_fail(username != NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1963
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1964 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1965
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1966 g_return_if_fail(MSIM_SESSION_VALID(session));
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1967
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1968 /* Obtain uid of buddy. */
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1969 user = msim_find_user(session, username);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1970
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1971 /* If is on buddy list, lookup by uid since it is faster. */
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1972 if (user && (uid = purple_blist_node_get_int(&user->buddy->node, "UserID"))) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1973 user_to_lookup = g_strdup_printf("%d", uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1974 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1975 /* Looking up buddy not on blist. Lookup by whatever user entered. */
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1976 user_to_lookup = g_strdup(username);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1977 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1978
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1979 /* Pass the username to msim_get_info_cb(), because since we lookup
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1980 * by userid, the userinfo message will only contain the uid (not
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1981 * the username) but it would be useful to display the username too.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1982 */
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
1983 user_msg = msim_msg_new(
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1984 "user", MSIM_TYPE_STRING, g_strdup(username),
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1985 NULL);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
1986 purple_debug_info("msim", "msim_get_info, setting up lookup, user=%s\n", username);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1987
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1988 msim_lookup_user(session, user_to_lookup, msim_get_info_cb, user_msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1989
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1990 g_free(user_to_lookup);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1991 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1992
18035
2c401f444456 Remove MSIM_FAKE_SELF_ONLINE option, since our own status is actually updated
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18034
diff changeset
1993 /** Set your status - callback for when user manually sets it. */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1994 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1995 msim_set_status(PurpleAccount *account, PurpleStatus *status)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1996 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1997 PurpleStatusType *type;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1998 MsimSession *session;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
1999 guint status_code;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2000 const gchar *statstring;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2001
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2002 session = (MsimSession *)account->gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2003
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2004 g_return_if_fail(MSIM_SESSION_VALID(session));
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2005
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2006 type = purple_status_get_type(status);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2007
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
2008 switch (purple_status_type_get_primitive(type)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2009 case PURPLE_STATUS_AVAILABLE:
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2010 purple_debug_info("msim", "msim_set_status: available (%d->%d)\n", PURPLE_STATUS_AVAILABLE,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2011 MSIM_STATUS_CODE_ONLINE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2012 status_code = MSIM_STATUS_CODE_ONLINE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2013 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2014
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2015 case PURPLE_STATUS_INVISIBLE:
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2016 purple_debug_info("msim", "msim_set_status: invisible (%d->%d)\n", PURPLE_STATUS_INVISIBLE,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2017 MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2018 status_code = MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2019 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2020
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2021 case PURPLE_STATUS_AWAY:
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2022 purple_debug_info("msim", "msim_set_status: away (%d->%d)\n", PURPLE_STATUS_AWAY,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2023 MSIM_STATUS_CODE_AWAY);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2024 status_code = MSIM_STATUS_CODE_AWAY;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2025 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2027 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2028 purple_debug_info("msim", "msim_set_status: unknown "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2029 "status interpreting as online");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2030 status_code = MSIM_STATUS_CODE_ONLINE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2031 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2032 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2033
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2034 statstring = purple_status_get_attr_string(status, "message");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2035
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2036 if (!statstring) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2037 statstring = g_strdup("");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2038 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2039
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2040 msim_set_status_code(session, status_code, g_strdup(statstring));
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2041 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2042
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2043 /** Go idle. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2044 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2045 msim_set_idle(PurpleConnection *gc, int time)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2046 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2047 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2048
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2049 g_return_if_fail(gc != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2050
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2051 session = (MsimSession *)gc->proto_data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2052
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2053 g_return_if_fail(MSIM_SESSION_VALID(session));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2054
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2055 if (time == 0) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2056 /* Going back from idle. In msim, idle is mutually exclusive
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2057 * from the other states (you can only be away or idle, but not
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2058 * both, for example), so by going non-idle I go online.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2059 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2060 /* TODO: find out how to keep old status string? */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2061 msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE, g_strdup(""));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2062 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2063 /* msim doesn't support idle time, so just go idle */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2064 msim_set_status_code(session, MSIM_STATUS_CODE_IDLE, g_strdup(""));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2065 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2066 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2067
18034
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
2068 /** Set status using an MSIM_STATUS_CODE_* value.
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
2069 * @param status_code An MSIM_STATUS_CODE_* value.
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
2070 * @param statstring Status string, must be a dynamic string (will be freed by msim_send).
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
2071 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2072 static void
18034
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
2073 msim_set_status_code(MsimSession *session, guint status_code, gchar *statstring)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2074 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2075 g_return_if_fail(MSIM_SESSION_VALID(session));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2076 g_return_if_fail(statstring != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2077
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2078 purple_debug_info("msim", "msim_set_status_code: going to set status to code=%d,str=%s\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2079 status_code, statstring);
18034
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
2080
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2081 if (!msim_send(session,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2082 "status", MSIM_TYPE_INTEGER, status_code,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2083 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
18034
e1b21d1e5c7a Allow setting status string messages. Known bug: custom status messages always
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18032
diff changeset
2084 "statstring", MSIM_TYPE_STRING, statstring,
18029
48e7b6d97f1f Fix compile warnings on Unix (missing sentinel and time_t to int typecast).
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18028
diff changeset
2085 "locstring", MSIM_TYPE_STRING, g_strdup(""),
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2086 NULL))
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2087 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2088 purple_debug_info("msim", "msim_set_status: failed to set status");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2089 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2090
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2091 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2092
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2093 /** After a uid is resolved to username, tag it with the username and submit for processing.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2094 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2095 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2096 * @param userinfo Response messsage to resolving request.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2097 * @param data MsimMessage *, the message to attach information to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2098 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2099 static void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2100 msim_incoming_resolved(MsimSession *session, MsimMessage *userinfo,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2101 gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2102 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2103 gchar *body_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2104 GHashTable *body;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2105 gchar *username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2106 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2107
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2108 g_return_if_fail(MSIM_SESSION_VALID(session));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2109 g_return_if_fail(userinfo != NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2110
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2111 body_str = msim_msg_get_string(userinfo, "body");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2112 g_return_if_fail(body_str != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2113 body = msim_parse_body(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2114 g_return_if_fail(body != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2115 g_free(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2116
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2117 username = g_hash_table_lookup(body, "UserName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2118 g_return_if_fail(username != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2119
18055
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
2120
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2121 msg = (MsimMessage *)data;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2122 g_return_if_fail(msg != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2123
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2124 /* TODO: more elegant solution than below. attach whole message? */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2125 /* Special elements name beginning with '_', we'll use internally within the
18055
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
2126 * program (did not come directly from the wire). */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2127 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
18055
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
2128
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2129 /* TODO: attach more useful information, like ImageURL */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2130
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2131 msim_process(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2132
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2133 /* TODO: Free copy cloned from msim_preprocess_incoming(). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2134 //XXX msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2135 g_hash_table_destroy(body);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2136 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2137
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2138 /* Lookup a username by userid, from buddy list.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2139 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2140 * @param wanted_uid
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2141 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2142 * @return Username of wanted_uid, if on blist, or NULL. Static string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2143 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2144 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2145 static const gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2146 msim_uid2username_from_blist(MsimSession *session, guint wanted_uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2147 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2148 GSList *buddies, *cur;
19152
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
2149 gchar *ret;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2150
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2151 buddies = purple_find_buddies(session->account, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2152
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2153 if (!buddies)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2154 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2155 purple_debug_info("msim", "msim_uid2username_from_blist: no buddies?");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2156 return NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2157 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2158
19152
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
2159 ret = NULL;
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
2160
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2161 for (cur = buddies; cur != NULL; cur = g_slist_next(cur))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2162 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2163 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2164 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2165 const gchar *name;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2166
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2167 /* See finch/gnthistory.c */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2168 buddy = cur->data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2169
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2170 uid = purple_blist_node_get_int(&buddy->node, "UserID");
19152
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
2171 name = purple_buddy_get_name(buddy);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2172
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2173 if (uid == wanted_uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2174 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2175 ret = g_strdup(name);
19152
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
2176 break;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2177 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2178 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2179
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2180 g_slist_free(buddies);
19152
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
2181 return ret;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2182 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2183
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2184 /** Preprocess incoming messages, resolving as needed, calling msim_process() when ready to process.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2185 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2186 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2187 * @param msg MsimMessage *, freed by caller.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2188 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2189 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2190 msim_preprocess_incoming(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2191 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2192 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2193 g_return_val_if_fail(msg != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2194
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
2195 if (msim_msg_get(msg, "bm") && msim_msg_get(msg, "f")) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2196 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2197 const gchar *username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2198
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2199 /* 'f' = userid message is from, in buddy messages */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2200 uid = msim_msg_get_integer(msg, "f");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2201
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2202 username = msim_uid2username_from_blist(session, uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2203
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
2204 if (username) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2205 /* Know username already, use it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2206 purple_debug_info("msim", "msim_preprocess_incoming: tagging with _username=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2207 username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2208 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2209 return msim_process(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2210
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2211 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2212 gchar *from;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2213
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2214 /* Send lookup request. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2215 /* XXX: where is msim_msg_get_string() freed? make _strdup and _nonstrdup. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2216 purple_debug_info("msim", "msim_incoming: sending lookup, setting up callback\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2217 from = msim_msg_get_string(msg, "f");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2218 msim_lookup_user(session, from, msim_incoming_resolved, msim_msg_clone(msg));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2219 g_free(from);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2220
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2221 /* indeterminate */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2222 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2223 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2224 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2225 /* Nothing to resolve - send directly to processing. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2226 return msim_process(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2227 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2228 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2229
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2230 #ifdef MSIM_USE_KEEPALIVE
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2231 /** Check if the connection is still alive, based on last communication. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2232 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2233 msim_check_alive(gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2234 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2235 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2236 time_t delta;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2237 gchar *errmsg;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2238
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2239 session = (MsimSession *)data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2240
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2241 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2242
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2243 delta = time(NULL) - session->last_comm;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2244 //purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2245 if (delta >= MSIM_KEEPALIVE_INTERVAL) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2246 errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), (int)delta);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2247
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2248 purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2249 errmsg, MSIM_KEEPALIVE_INTERVAL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2250 purple_connection_error(session->gc, errmsg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2251
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2252 purple_notify_error(session->gc, NULL, errmsg, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2253
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2254 g_free(errmsg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2255
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2256 return FALSE;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2257 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2258
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2259 return TRUE;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2260 }
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2261 #endif
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2262
18038
4a904c0a564e Notify of new inbox messages (friend requests, inbox messages, comments),
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18037
diff changeset
2263 /** Handle mail reply checks. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2264 static void
18038
4a904c0a564e Notify of new inbox messages (friend requests, inbox messages, comments),
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18037
diff changeset
2265 msim_check_inbox_cb(MsimSession *session, MsimMessage *reply, gpointer data)
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2266 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2267 GHashTable *body;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2268 gchar *body_str;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2269 GString *notification;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2270 guint old_inbox_status;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2271 guint i, n;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2272 const gchar *froms[5], *tos[5], *urls[5], *subjects[5];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2273
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2274 /* Three parallel arrays for each new inbox message type. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2275 static const gchar *inbox_keys[] =
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2276 {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2277 "Mail",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2278 "BlogComment",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2279 "ProfileComment",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2280 "FriendRequest",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2281 "PictureComment"
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2282 };
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2283
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2284 static const guint inbox_bits[] =
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2285 {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2286 MSIM_INBOX_MAIL,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2287 MSIM_INBOX_BLOG_COMMENT,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2288 MSIM_INBOX_PROFILE_COMMENT,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2289 MSIM_INBOX_FRIEND_REQUEST,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2290 MSIM_INBOX_PICTURE_COMMENT
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2291 };
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2292
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2293 static const gchar *inbox_urls[] =
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2294 {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2295 "http://messaging.myspace.com/index.cfm?fuseaction=mail.inbox",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2296 "http://blog.myspace.com/index.cfm?fuseaction=blog",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2297 "http://home.myspace.com/index.cfm?fuseaction=user",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2298 "http://messaging.myspace.com/index.cfm?fuseaction=mail.friendRequests",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2299 "http://home.myspace.com/index.cfm?fuseaction=user"
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2300 };
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2301
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2302 static const gchar *inbox_text[5];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2303
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2304 /* Can't write _()'d strings in array initializers. Workaround. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2305 inbox_text[0] = _("New mail messages");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2306 inbox_text[1] = _("New blog comments");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2307 inbox_text[2] = _("New profile comments");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2308 inbox_text[3] = _("New friend requests!");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2309 inbox_text[4] = _("New picture comments");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2310
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2311 g_return_if_fail(reply != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2312
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2313 msim_msg_dump("msim_check_inbox_cb: reply=%s\n", reply);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2314
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2315 body_str = msim_msg_get_string(reply, "body");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2316 g_return_if_fail(body_str != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2317
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2318 body = msim_parse_body(body_str);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2319 g_free(body_str);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2320
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2321 notification = g_string_new("");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2322
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2323 old_inbox_status = session->inbox_status;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2324
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2325 n = 0;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2326
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2327 for (i = 0; i < sizeof(inbox_keys) / sizeof(inbox_keys[0]); ++i) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2328 const gchar *key;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2329 guint bit;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2330
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2331 key = inbox_keys[i];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2332 bit = inbox_bits[i];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2333
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2334 if (g_hash_table_lookup(body, key)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2335 /* Notify only on when _changes_ from no mail -> has mail
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2336 * (edge triggered) */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2337 if (!(session->inbox_status & bit)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2338 purple_debug_info("msim", "msim_check_inbox_cb: got %s, at %d\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2339 key ? key : "(NULL)", n);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2340
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2341 subjects[n] = inbox_text[i];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2342 froms[n] = _("MySpace");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2343 tos[n] = session->username;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2344 /* TODO: append token, web challenge, so automatically logs in.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2345 * Would also need to free strings because they won't be static
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2346 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2347 urls[n] = inbox_urls[i];
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2348
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2349 ++n;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2350 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2351 purple_debug_info("msim",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2352 "msim_check_inbox_cb: already notified of %s\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2353 key ? key : "(NULL)");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2354 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2355
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2356 session->inbox_status |= bit;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2357 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2358 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2359
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2360 if (n) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2361 purple_debug_info("msim",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2362 "msim_check_inbox_cb: notifying of %d\n", n);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2363
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2364 /* TODO: free strings with callback _if_ change to dynamic (w/ token) */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2365 purple_notify_emails(session->gc, /* handle */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2366 n, /* count */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2367 TRUE, /* detailed */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2368 subjects, froms, tos, urls,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2369 NULL, /* PurpleNotifyCloseCallback cb */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2370 NULL); /* gpointer user_data */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2371
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2372 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2373
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2374 g_hash_table_destroy(body);
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2375 }
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2376
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2377 /* Send request to check if there is new mail. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2378 static gboolean
18038
4a904c0a564e Notify of new inbox messages (friend requests, inbox messages, comments),
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18037
diff changeset
2379 msim_check_inbox(gpointer data)
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2380 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2381 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2382
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2383 session = (MsimSession *)data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2384
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2385 purple_debug_info("msim", "msim_check_inbox: checking mail\n");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2386 g_return_val_if_fail(msim_send(session,
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2387 "persist", MSIM_TYPE_INTEGER, 1,
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2388 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2389 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_GET,
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2390 "dsn", MSIM_TYPE_INTEGER, MG_CHECK_MAIL_DSN,
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2391 "lid", MSIM_TYPE_INTEGER, MG_CHECK_MAIL_LID,
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2392 "uid", MSIM_TYPE_INTEGER, session->userid,
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2393 "rid", MSIM_TYPE_INTEGER,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2394 msim_new_reply_callback(session, msim_check_inbox_cb, NULL),
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2395 "body", MSIM_TYPE_STRING, g_strdup(""),
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2396 NULL), TRUE);
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2397
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2398 /* Always return true, so that we keep checking for mail. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2399 return TRUE;
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2400 }
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2401
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2402 /** Called when the session key arrives. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2403 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2404 msim_we_are_logged_on(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2405 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2406 MsimMessage *body;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2407
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2408 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2409 g_return_val_if_fail(msg != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2410
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2411 session->sesskey = msim_msg_get_integer(msg, "sesskey");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2412 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2413
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2414 /* What is proof? Used to be uid, but now is 52 base64'd bytes... */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2415
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2416 /* Comes with: proof,profileid,userid,uniquenick -- all same values
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2417 * some of the time, but can vary. This is our own user ID. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2418 session->userid = msim_msg_get_integer(msg, "userid");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2419
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2420 /* Not sure what profileid is used for. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2421 if (msim_msg_get_integer(msg, "profileid") != session->userid) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2422 msim_unrecognized(session, msg,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2423 "Profile ID didn't match user ID, don't know why");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2424 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2425
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2426 /* We now know are our own username, only after we're logged in..
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2427 * which is weird, but happens because you login with your email
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2428 * address and not username. Will be freed in msim_session_destroy(). */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2429 session->username = msim_msg_get_string(msg, "uniquenick");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2430
19163
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2431 /* The session is now set up, ready to be connected. This emits the
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2432 * signedOn signal, so clients can now do anything with msimprpl, and
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2433 * we're ready for it (session key, userid, username all setup). */
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2434 purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2435 purple_connection_set_state(session->gc, PURPLE_CONNECTED);
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2436
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2437
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2438 /* Additional post-connect operations */
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2439
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2440
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2441 if (msim_msg_get_integer(msg, "uniquenick") == session->userid) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2442 purple_debug_info("msim_we_are_logged_on", "TODO: pick username");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2443 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2444
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
2445 body = msim_msg_new(
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2446 "UserID", MSIM_TYPE_INTEGER, session->userid,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2447 NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2448
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2449 /* Request IM info about ourself. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2450 msim_send(session,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2451 "persist", MSIM_TYPE_STRING, g_strdup("persist"),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2452 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2453 "dsn", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_DSN,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2454 "uid", MSIM_TYPE_INTEGER, session->userid,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2455 "lid", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_LID,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2456 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2457 "body", MSIM_TYPE_DICTIONARY, body,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2458 NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2459
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2460 /* Request MySpace info about ourself. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2461 msim_send(session,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2462 "persist", MSIM_TYPE_STRING, g_strdup("persist"),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2463 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2464 "dsn", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_DSN,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2465 "uid", MSIM_TYPE_INTEGER, session->userid,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2466 "lid", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_LID,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2467 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2468 "body", MSIM_TYPE_STRING, g_strdup(""),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2469 NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2470
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2471 /* TODO: set options (persist cmd=514,dsn=1,lid=10) */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2472 /* TODO: set blocklist */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2473
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2474 /* Notify servers of our current status. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2475 purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2476 msim_set_status(session->account,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2477 purple_account_get_active_status(session->account));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2478
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2479 /* TODO: setinfo */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2480 /*
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
2481 body = msim_msg_new(
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2482 "TotalFriends", MSIM_TYPE_INTEGER, 666,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2483 NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2484 msim_send(session,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2485 "setinfo", MSIM_TYPE_BOOLEAN, TRUE,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2486 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2487 "info", MSIM_TYPE_DICTIONARY, body,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2488 NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2489 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2490
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2491 /* Disable due to problems with timeouts. TODO: fix. */
18038
4a904c0a564e Notify of new inbox messages (friend requests, inbox messages, comments),
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18037
diff changeset
2492 #ifdef MSIM_USE_KEEPALIVE
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2493 purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2494 (GSourceFunc)msim_check_alive, session);
18038
4a904c0a564e Notify of new inbox messages (friend requests, inbox messages, comments),
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18037
diff changeset
2495 #endif
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2496
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2497 purple_timeout_add(MSIM_MAIL_INTERVAL_CHECK,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2498 (GSourceFunc)msim_check_inbox, session);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2499
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2500 msim_check_inbox(session);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2501
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2502 return TRUE;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2503 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2504
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2505 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2506 * Process a message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2507 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2508 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2509 * @param msg A message from the server, ready for processing (possibly with resolved username information attached). Caller frees.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2510 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2511 * @return TRUE if successful. FALSE if processing failed.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2512 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2513 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2514 msim_process(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2515 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2516 g_return_val_if_fail(session != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2517 g_return_val_if_fail(msg != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2518
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2519 #ifdef MSIM_DEBUG_MSG
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2520 msim_msg_dump("ready to process: %s\n", msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2521 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2522
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2523 if (msim_msg_get_integer(msg, "lc") == 1) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2524 return msim_login_challenge(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2525 } else if (msim_msg_get_integer(msg, "lc") == 2) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2526 return msim_we_are_logged_on(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2527 } else if (msim_msg_get(msg, "bm")) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2528 return msim_incoming_bm(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2529 } else if (msim_msg_get(msg, "rid")) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2530 return msim_process_reply(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2531 } else if (msim_msg_get(msg, "error")) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2532 return msim_error(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2533 } else if (msim_msg_get(msg, "ka")) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2534 return TRUE;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2535 } else {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2536 msim_unrecognized(session, msg, "in msim_process");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2537 return FALSE;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2538 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2539 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2540
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2541 /** Store a field of information about a buddy. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2542 static void
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2543 msim_store_user_info_each(gpointer key, gpointer value, gpointer user_data)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2544 {
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2545 MsimUser *user;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2546 gchar *key_str, *value_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2547
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2548 user = (MsimUser *)user_data;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2549 key_str = (gchar *)key;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2550 value_str = (gchar *)value;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2551
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2552 if (!strcmp(key_str, "UserID")) {
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2553 /* Save to buddy list, if it exists, for quick cached uid lookup with msim_uid2username_from_blist(). */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2554 if (user->buddy)
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2555 {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2556 purple_debug_info("msim", "associating uid %s with username %s\n", key_str, user->buddy->name);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2557 purple_blist_node_set_int(&user->buddy->node, "UserID", atol(value_str));
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2558 }
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2559 /* Need to store in MsimUser, too? What if not on blist? */
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2560 } else if (!strcmp(key_str, "Age")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2561 user->age = atol(value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2562 } else if (!strcmp(key_str, "Gender")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2563 user->gender = g_strdup(value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2564 } else if (!strcmp(key_str, "Location")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2565 user->location = g_strdup(value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2566 } else if (!strcmp(key_str, "TotalFriends")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2567 user->total_friends = atol(value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2568 } else if (!strcmp(key_str, "DisplayName")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2569 user->display_name = g_strdup(value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2570 } else if (!strcmp(key_str, "BandName")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2571 user->band_name = g_strdup(value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2572 } else if (!strcmp(key_str, "SongName")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2573 user->song_name = g_strdup(value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2574 } else if (!strcmp(key_str, "UserName")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2575 /* Ignore because PurpleBuddy knows this already */
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2576 ;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2577 } else if (!strcmp(key_str, "ImageURL")) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2578 user->image_url = g_strdup(value_str);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2579 } else {
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2580 /* TODO: other fields in MsimUser */
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2581 gchar *msg;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2582
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2583 msg = g_strdup_printf("msim_store_user_info_each: unknown field %s=%s",
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2584 key_str, value_str);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2585
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2586 msim_unrecognized(NULL, NULL, msg);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2587
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2588 g_free(msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2589 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2590 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2591
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2592 /** Save buddy information to the buddy list from a user info reply message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2593 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2594 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2595 * @param msg The user information reply, with any amount of information.
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2596 * @param user The structure to save to, or NULL to save in PurpleBuddy->proto_data.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2597 *
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2598 * Variable information is saved to the passed MsimUser structure. Permanent
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2599 * information (UserID) is stored in the blist node of the buddy list (and
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2600 * ends up in blist.xml, persisted to disk) if it exists.
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2601 *
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2602 * If the function has no buddy information, this function
19162
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
2603 * is a no-op (and returns FALSE).
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
2604 *
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2605 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2606 static gboolean
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2607 msim_store_user_info(MsimSession *session, MsimMessage *msg, MsimUser *user)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2608 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2609 GHashTable *body;
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2610 gchar *username, *body_str;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2611
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2612 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2613 g_return_val_if_fail(msg != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2614
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2615 body_str = msim_msg_get_string(msg, "body");
19162
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
2616 if (!body_str) {
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
2617 return FALSE;
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
2618 }
184ae953539f Fix some assertion failures, that should really not be assertions. Found by using
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19161
diff changeset
2619
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2620 g_return_val_if_fail(body_str != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2621 body = msim_parse_body(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2622 g_free(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2623
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2624
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2625 /* TODO: implement a better hash-like interface, and use it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2626 username = g_hash_table_lookup(body, "UserName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2627
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
2628 if (!username) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2629 purple_debug_info("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2630 "msim_process_reply: not caching body, no UserName\n");
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2631 g_hash_table_destroy(body);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2632 return FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2633 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2634
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2635 /* Null user = find and store in PurpleBuddy's proto_data */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2636 if (!user) {
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2637 user = msim_find_user(session, username);
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2638 g_return_val_if_fail(user != NULL, FALSE);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2639 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2640
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2641 g_hash_table_foreach(body, msim_store_user_info_each, user);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2642
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2643 if (msim_msg_get_integer(msg, "dsn") == MG_OWN_IM_INFO_DSN &&
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2644 msim_msg_get_integer(msg, "lid") == MG_OWN_IM_INFO_LID) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2645 /* TODO: do something with our own IM info, if we need it for some
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2646 * specific purpose. Otherwise it is available on the buddy list,
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2647 * if the user has themselves as their own buddy.
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2648 *
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2649 * However, much of the info is already available in MsimSession,
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2650 * stored in msim_we_are_logged_on(). */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2651 } else if (msim_msg_get_integer(msg, "dsn") == MG_OWN_MYSPACE_INFO_DSN &&
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2652 msim_msg_get_integer(msg, "lid") == MG_OWN_MYSPACE_INFO_LID) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2653 /* TODO: same as above, but for MySpace info. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2654 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2655
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2656 g_hash_table_destroy(body);
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
2657
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2658 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2659 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2660
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2661 /** Process the initial server information from the server. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2662 static gboolean
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2663 msim_process_server_info(MsimSession *session, MsimMessage *msg)
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2664 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2665 gchar *body_str;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2666 GHashTable *body;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2667
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2668 body_str = msim_msg_get_string(msg, "body");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2669 g_return_val_if_fail(body_str != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2670 body = msim_parse_body(body_str);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2671 g_free(body_str);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2672 g_return_val_if_fail(body != NULL, FALSE);
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2673
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2674 /* Example body:
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2675 AdUnitRefreshInterval=10.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2676 AlertPollInterval=360.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2677 AllowChatRoomEmoticonSharing=False.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2678 ChatRoomUserIDs=78744676;163733130;1300326231;123521495;142663391.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2679 CurClientVersion=673.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2680 EnableIMBrowse=True.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2681 EnableIMStuffAvatars=False.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2682 EnableIMStuffZaps=False.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2683 MaxAddAllFriends=100.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2684 MaxContacts=1000.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2685 MinClientVersion=594.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2686 MySpaceIM_ENGLISH=78744676.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2687 MySpaceNowTimer=720.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2688 PersistenceDataTimeout=900.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2689 UseWebChallenge=1.
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2690 WebTicketGoHome=False
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2691
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2692 Anything useful? TODO: use what is useful, and use it.
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2693 */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2694 purple_debug_info("msim_process_server_info",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2695 "maximum contacts: %s\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2696 g_hash_table_lookup(body, "MaxContacts") ?
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2697 g_hash_table_lookup(body, "MaxContacts") : "(NULL)");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2698
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2699 session->server_info = body;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2700 /* session->server_info freed in msim_session_destroy */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2701
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2702 return TRUE;
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2703 }
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2704
18057
77eb36712aca Update login process to more closely match official client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18056
diff changeset
2705 /** Process a web challenge, used to login to the web site. */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2706 static gboolean
18057
77eb36712aca Update login process to more closely match official client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18056
diff changeset
2707 msim_web_challenge(MsimSession *session, MsimMessage *msg)
77eb36712aca Update login process to more closely match official client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18056
diff changeset
2708 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2709 /* TODO: web challenge, store token */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2710 return FALSE;
18057
77eb36712aca Update login process to more closely match official client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18056
diff changeset
2711 }
77eb36712aca Update login process to more closely match official client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18056
diff changeset
2712
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2713 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2714 * Process a persistance message reply from the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2715 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2716 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2717 * @param msg Message reply from server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2718 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2719 * @return TRUE if successful.
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2720 *
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
2721 * msim_lookup_user sets callback for here
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2722 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2723 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2724 msim_process_reply(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2725 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2726 MSIM_USER_LOOKUP_CB cb;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2727 gpointer data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2728 guint rid, cmd, dsn, lid;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2729
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2730 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2731 g_return_val_if_fail(msg != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2732
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2733 msim_store_user_info(session, msg, NULL);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2734
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2735 rid = msim_msg_get_integer(msg, "rid");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2736 cmd = msim_msg_get_integer(msg, "cmd");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2737 dsn = msim_msg_get_integer(msg, "dsn");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2738 lid = msim_msg_get_integer(msg, "lid");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2739
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2740 /* Unsolicited messages */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2741 if (cmd == (MSIM_CMD_BIT_REPLY | MSIM_CMD_GET)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2742 if (dsn == MG_SERVER_INFO_DSN && lid == MG_SERVER_INFO_LID) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2743 return msim_process_server_info(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2744 } else if (dsn == MG_WEB_CHALLENGE_DSN && lid == MG_WEB_CHALLENGE_LID) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2745 return msim_web_challenge(session, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2746 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2747 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2748
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2749 /* If a callback is registered for this userid lookup, call it. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2750 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2751 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2752
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2753 if (cb) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2754 purple_debug_info("msim",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2755 "msim_process_body: calling callback now\n");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2756 /* Clone message, so that the callback 'cb' can use it (needs to free it also). */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2757 cb(session, msim_msg_clone(msg), data);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2758 g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2759 g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2760 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2761 purple_debug_info("msim",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2762 "msim_process_body: no callback for rid %d\n", rid);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2763 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2764
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2765 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2766 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2767
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2768 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2769 * Handle an error from the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2770 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2771 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2772 * @param msg The message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2773 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2774 * @return TRUE if successfully reported error.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2775 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2776 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2777 msim_error(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2778 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2779 gchar *errmsg, *full_errmsg;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2780 guint err;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2781
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2782 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2783 g_return_val_if_fail(msg != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2784
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2785 err = msim_msg_get_integer(msg, "err");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2786 errmsg = msim_msg_get_string(msg, "errmsg");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2787
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2788 full_errmsg = g_strdup_printf(_("Protocol error, code %d: %s"), err,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2789 errmsg ? errmsg : "no 'errmsg' given");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2790
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2791 g_free(errmsg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2792
19163
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2793 purple_debug_info("msim", "msim_error (sesskey=%d): %s\n",
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
2794 session->sesskey, full_errmsg);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2795
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2796 purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2797 full_errmsg, NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2798
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2799 /* Destroy session if fatal. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2800 if (msim_msg_get(msg, "fatal")) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2801 purple_debug_info("msim", "fatal error, closing\n");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2802 purple_connection_error(session->gc, full_errmsg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2803 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2804
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2805 return TRUE;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2806 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2807
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2808 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2809 * Process incoming status messages.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2810 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2811 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2812 * @param msg Status update message. Caller frees.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2813 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2814 * @return TRUE if successful.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2815 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
2816 static gboolean
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
2817 msim_incoming_status(MsimSession *session, MsimMessage *msg)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2818 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2819 PurpleBuddyList *blist;
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2820 MsimUser *user;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2821 GList *list;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2822 gchar *status_headline;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2823 gint status_code, purple_status_code;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2824 gchar *username;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2825
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2826 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2827 g_return_val_if_fail(msg != NULL, FALSE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2828
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2829 msim_msg_dump("msim_status msg=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2830
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2831 /* Helpfully looked up by msim_incoming_resolve() for us. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2832 username = msim_msg_get_string(msg, "_username");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2833 g_return_val_if_fail(username != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2834
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2835 {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2836 gchar *ss;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2837
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2838 ss = msim_msg_get_string(msg, "msg");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2839 purple_debug_info("msim",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2840 "msim_status: updating status for <%s> to <%s>\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2841 username, ss ? ss : "(NULL)");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2842 g_free(ss);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2843 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2844
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2845 /* Example fields:
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2846 * |s|0|ss|Offline
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2847 * |s|1|ss|:-)|ls||ip|0|p|0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2848 */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2849 list = msim_msg_get_list(msg, "msg");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2850
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2851 status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2852 purple_debug_info("msim", "msim_status: %s's status code = %d\n", username, status_code);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2853 status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2854
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2855 blist = purple_get_blist();
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2856
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2857 /* Add buddy if not found */
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2858 user = msim_find_user(session, username);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2859 if (!user) {
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2860 PurpleBuddy *buddy;
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2861
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2862 purple_debug_info("msim",
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2863 "msim_status: making new buddy for %s\n", username);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2864 buddy = purple_buddy_new(session->account, username, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2865 purple_blist_add_buddy(buddy, NULL, NULL, NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2866
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2867 user = msim_get_user_from_buddy(buddy);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2868
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2869 /* All buddies on list should have 'uid' integer associated with them. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2870 purple_blist_node_set_int(&buddy->node, "UserID", msim_msg_get_integer(msg, "f"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2871
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
2872 msim_store_user_info(session, msg, NULL);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2873 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2874 purple_debug_info("msim", "msim_status: found buddy %s\n", username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2875 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2876
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
2877 user->headline = g_strdup(status_headline);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2878
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2879 /* Set user status */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2880 switch (status_code) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2881 case MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN:
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2882 purple_status_code = PURPLE_STATUS_OFFLINE;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2883 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2884
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2885 case MSIM_STATUS_CODE_ONLINE:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2886 purple_status_code = PURPLE_STATUS_AVAILABLE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2887 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2888
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2889 case MSIM_STATUS_CODE_AWAY:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2890 purple_status_code = PURPLE_STATUS_AWAY;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2891 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2892
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2893 case MSIM_STATUS_CODE_IDLE:
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2894 /* will be handled below */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2895 purple_status_code = -1;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2896 break;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2897
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2898 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2899 purple_debug_info("msim", "msim_status for %s, unknown status code %d, treating as available\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2900 username, status_code);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2901 purple_status_code = PURPLE_STATUS_AVAILABLE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2902 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2903
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2904 purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2905
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2906 if (status_code == MSIM_STATUS_CODE_IDLE) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2907 purple_debug_info("msim", "msim_status: got idle: %s\n", username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2908 purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2909 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2910 /* All other statuses indicate going back to non-idle. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2911 purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2912 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2913
18064
527bea0f11ab Disable sending third-party client version to oncoming buddies.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18063
diff changeset
2914 #ifdef MSIM_SEND_CLIENT_VERSION
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2915 if (status_code == MSIM_STATUS_CODE_ONLINE) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2916 /* Secretly whisper to unofficial clients our own version as they come online */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2917 msim_send_unofficial_client(session, username);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2918 }
18064
527bea0f11ab Disable sending third-party client version to oncoming buddies.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18063
diff changeset
2919 #endif
18043
6c7ea1ce1beb Support unofficial bm code 200, also used by Miranda IM plugin, to report
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18042
diff changeset
2920
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2921 g_free(username);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2922 msim_msg_list_free(list);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2923
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2924 return TRUE;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2925 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2926
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2927 /** Add a buddy to user's buddy list. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2928 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2929 msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2930 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2931 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2932 MsimMessage *msg;
19164
1fd7022f57eb Update for 0.14.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19163
diff changeset
2933 /* MsimMessage *msg_persist; */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2934 MsimMessage *body;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2935
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2936 session = (MsimSession *)gc->proto_data;
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
2937 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n",
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2938 buddy->name, (group && group->name) ? group->name : "(no group)");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2939
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
2940 msg = msim_msg_new(
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2941 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2942 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2943 /* "newprofileid" will be inserted here with uid. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2944 "reason", MSIM_TYPE_STRING, g_strdup(""),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2945 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2946
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
2947 if (!msim_postprocess_outgoing(session, msg, buddy->name, "newprofileid", "reason")) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2948 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed."));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2949 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2950 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2951 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2952 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2953
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2954 /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2955 * buddy list since Purple adds it locally. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2956
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
2957 body = msim_msg_new(
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2958 "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2959 "GroupName", MSIM_TYPE_STRING, g_strdup(group->name),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2960 "Position", MSIM_TYPE_INTEGER, 1000,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2961 "Visibility", MSIM_TYPE_INTEGER, 1,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2962 "NickName", MSIM_TYPE_STRING, g_strdup(""),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2963 "NameSelect", MSIM_TYPE_INTEGER, 0,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2964 NULL);
19135
705302b2c7f7 Use the new dictionary data type when:
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19133
diff changeset
2965
19139
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2966 /* TODO: Update blocklist. */
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2967
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2968 #if 0
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
2969 msg_persist = msim_msg_new(
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2970 "persist", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2971 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2972 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_PUT,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2973 "dsn", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_DSN,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2974 "lid", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_LID,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2975 /* TODO: Use msim_new_reply_callback to get rid. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2976 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
19135
705302b2c7f7 Use the new dictionary data type when:
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19133
diff changeset
2977 "body", MSIM_TYPE_DICTIONARY, body,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
2978 NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2979
19139
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2980 if (!msim_postprocess_outgoing(session, msg_persist, buddy->name, "body", NULL))
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2981 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2982 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed"));
19139
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2983 msim_msg_free(msg_persist);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2984 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2985 }
19139
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2986 msim_msg_free(msg_persist);
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2987 #endif
e6854f8ecea4 Use the right message in the persistance command for adding buddies, but
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19137
diff changeset
2988
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2989 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2990
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2991 /** Perform actual postprocessing on a message, adding userid as specified.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2992 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2993 * @param msg The message to postprocess.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2994 * @param uid_before Name of field where to insert new field before, or NULL for end.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2995 * @param uid_field_name Name of field to add uid to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2996 * @param uid The userid to insert.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2997 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2998 * If the field named by uid_field_name already exists, then its string contents will
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2999 * be used for the field, except "<uid>" will be replaced by the userid.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3000 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3001 * If the field named by uid_field_name does not exist, it will be added before the
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3002 * field named by uid_before, as an integer, with the userid.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3003 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3004 * Does not handle sending, or scheduling userid lookup. For that, see msim_postprocess_outgoing().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3005 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3006 static MsimMessage *
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3007 msim_do_postprocessing(MsimMessage *msg, const gchar *uid_before,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3008 const gchar *uid_field_name, guint uid)
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3009 {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3010 msim_msg_dump("msim_do_postprocessing msg: %s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3011
19135
705302b2c7f7 Use the new dictionary data type when:
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19133
diff changeset
3012 /* First, check - if the field already exists, replace <uid> within it */
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3013 if (msim_msg_get(msg, uid_field_name)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3014 MsimMessageElement *elem;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3015 gchar *fmt_string;
19135
705302b2c7f7 Use the new dictionary data type when:
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19133
diff changeset
3016 gchar *uid_str, *new_str;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3017
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3018 /* Warning: this is a delicate, but safe, operation */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3019
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3020 elem = msim_msg_get(msg, uid_field_name);
19137
fb04b5cf5817 Use a list when updating the blocklist when removing the buddy, since
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19135
diff changeset
3021
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3022 /* Get the packed element, flattening it. This allows <uid> to be
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3023 * replaced within nested data structures, since the replacement is done
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3024 * on the linear, packed data, not on a complicated data structure.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3025 *
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3026 * For example, if the field was originally a dictionary or a list, you
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3027 * would have to iterate over all the items in it to see what needs to
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3028 * be replaced. But by packing it first, the <uid> marker is easily replaced
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3029 * just by a string replacement.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3030 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3031 fmt_string = msim_msg_pack_element_data(elem);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3032
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3033 uid_str = g_strdup_printf("%d", uid);
19135
705302b2c7f7 Use the new dictionary data type when:
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19133
diff changeset
3034 new_str = str_replace(fmt_string, "<uid>", uid_str);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3035 g_free(uid_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3036 g_free(fmt_string);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3037
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3038 /* Free the old element data */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3039 msim_msg_free_element_data(elem->data);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3040
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3041 /* Replace it with our new data */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3042 elem->data = new_str;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3043 elem->type = MSIM_TYPE_RAW;
19135
705302b2c7f7 Use the new dictionary data type when:
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19133
diff changeset
3044
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3045 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3046 /* Otherwise, insert new field into outgoing message. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3047 msg = msim_msg_insert_before(msg, uid_before, uid_field_name, MSIM_TYPE_INTEGER, GUINT_TO_POINTER(uid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3048 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3049
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3050 msim_msg_dump("msim_postprocess_outgoing_cb: postprocessed msg=%s\n", msg);
19137
fb04b5cf5817 Use a list when updating the blocklist when removing the buddy, since
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19135
diff changeset
3051
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3052 return msg;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3053 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3054
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3055 /** Callback for msim_postprocess_outgoing() to add a userid to a message, and send it (once receiving userid).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3056 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3057 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3058 * @param userinfo The user information reply message, containing the user ID
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3059 * @param data The message to postprocess and send.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3060 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3061 * The data message should contain these fields:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3062 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3063 * _uid_field_name: string, name of field to add with userid from userinfo message
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3064 * _uid_before: string, name of field before field to insert, or NULL for end
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3065 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3066 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3067 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3068 static void
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3069 msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo,
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3070 gpointer data)
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3071 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3072 gchar *body_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3073 GHashTable *body;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3074 gchar *uid, *uid_field_name, *uid_before;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3075 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3076
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3077 msg = (MsimMessage *)data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3078
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3079 msim_msg_dump("msim_postprocess_outgoing_cb() got msg=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3080
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3081 /* Obtain userid from userinfo message. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3082 body_str = msim_msg_get_string(userinfo, "body");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3083 g_return_if_fail(body_str != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3084 body = msim_parse_body(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3085 g_free(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3086
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3087 uid = g_strdup(g_hash_table_lookup(body, "UserID"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3088 g_hash_table_destroy(body);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3089
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3090 uid_field_name = msim_msg_get_string(msg, "_uid_field_name");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3091 uid_before = msim_msg_get_string(msg, "_uid_before");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3092
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3093 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, atol(uid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3094
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3095 /* Send */
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3096 if (!msim_msg_send(session, msg)) {
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
3097 msim_msg_dump("msim_postprocess_outgoing_cb: sending failed for message: %s\n", msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3098 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3099
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3100
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3101 /* Free field names AFTER sending message, because MsimMessage does NOT copy
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3102 * field names - instead, treats them as static strings (which they usually are).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3103 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3104 g_free(uid_field_name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3105 g_free(uid_before);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3106
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3107 g_hash_table_destroy(body);
18037
038a99b09d35 Add msim_check_mail to check for new mail (called periodically), and
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18036
diff changeset
3108
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3109 //msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3110 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3111
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3112 /** Postprocess and send a message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3113 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3114 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3115 * @param msg Message to postprocess. Will NOT be freed.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3116 * @param username Username to resolve. Assumed to be a static string (will not be freed or copied).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3117 * @param uid_field_name Name of new field to add, containing uid of username. Static string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3118 * @param uid_before Name of existing field to insert username field before. Static string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3119 *
18063
619ec16f2e6d Fix crash when deleting buddies on Windows. This was done by
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18062
diff changeset
3120 * @return TRUE if successful.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3121 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3122 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3123 msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3124 const gchar *username, const gchar *uid_field_name,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3125 const gchar *uid_before)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3126 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3127 PurpleBuddy *buddy;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3128 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3129 gboolean rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3130
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3131 g_return_val_if_fail(msg != NULL, FALSE);
18063
619ec16f2e6d Fix crash when deleting buddies on Windows. This was done by
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18062
diff changeset
3132
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3133 /* Store information for msim_postprocess_outgoing_cb(). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3134 msim_msg_dump("msim_postprocess_outgoing: msg before=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3135 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3136 msg = msim_msg_append(msg, "_uid_field_name", MSIM_TYPE_STRING, g_strdup(uid_field_name));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3137 msg = msim_msg_append(msg, "_uid_before", MSIM_TYPE_STRING, g_strdup(uid_before));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3138
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3139 /* First, try the most obvious. If numeric userid is given, use that directly. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3140 if (msim_is_userid(username)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3141 uid = atol(username);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3142 } else {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3143 /* Next, see if on buddy list and know uid. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3144 buddy = purple_find_buddy(session->account, username);
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3145 if (buddy) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3146 uid = purple_blist_node_get_int(&buddy->node, "UserID");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3147 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3148 uid = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3149 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3150
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3151 if (!buddy || !uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3152 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3153 /* Don't have uid offhand - need to ask for it, and wait until hear back before sending. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3154 purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n",
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
3155 username ? username : "(NULL)");
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3156 msim_msg_dump("msim_postprocess_outgoing - scheduling lookup, msg=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3157 /* TODO: where is cloned message freed? Should be in _cb. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3158 msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg));
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3159 return TRUE; /* not sure of status yet - haven't sent! */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3160 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3161 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3162
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3163 /* Already have uid, postprocess and send msg immediately. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3164 purple_debug_info("msim", "msim_postprocess_outgoing: found username %s has uid %d\n",
18066
101acc0b44be Be more careful about null strings in %s format specifier in debug messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18064
diff changeset
3165 username ? username : "(NULL)", uid);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3166
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3167 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3168
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3169 msim_msg_dump("msim_postprocess_outgoing: msg after (uid immediate)=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3170
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3171 rc = msim_msg_send(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3172
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3173 //msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3174
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3175 return rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3176 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3177
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3178 /** Remove a buddy from the user's buddy list. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3179 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3180 msim_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3181 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3182 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3183 MsimMessage *delbuddy_msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3184 MsimMessage *persist_msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3185 MsimMessage *blocklist_msg;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3186 GList *blocklist_updates;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3187
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3188 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3189
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
3190 delbuddy_msg = msim_msg_new(
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3191 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3192 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3193 /* 'delprofileid' with uid will be inserted here. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3194 NULL);
18063
619ec16f2e6d Fix crash when deleting buddies on Windows. This was done by
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18062
diff changeset
3195
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3196 if (!msim_postprocess_outgoing(session, delbuddy_msg, buddy->name, "delprofileid", NULL)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3197 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed"));
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3198 msim_msg_free(delbuddy_msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3199 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3200 }
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3201 msim_msg_free(delbuddy_msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3202
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
3203 persist_msg = msim_msg_new(
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3204 "persist", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3205 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3206 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_DELETE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3207 "dsn", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_DSN,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3208 "lid", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_LID,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3209 "uid", MSIM_TYPE_INTEGER, session->userid,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3210 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3211 /* <uid> will be replaced by postprocessing */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3212 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3213 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3214
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3215 if (!msim_postprocess_outgoing(session, persist_msg, buddy->name, "body", NULL)) {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3216 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3217 msim_msg_free(persist_msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3218 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3219 }
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3220 msim_msg_free(persist_msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3221
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3222 blocklist_updates = NULL;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3223 blocklist_updates = g_list_prepend(blocklist_updates, "a-");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3224 blocklist_updates = g_list_prepend(blocklist_updates, "<uid>");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3225 blocklist_updates = g_list_prepend(blocklist_updates, "b-");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3226 blocklist_updates = g_list_prepend(blocklist_updates, "<uid>");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3227 blocklist_updates = g_list_reverse(blocklist_updates);
19133
81e7c23bbb7f In msim_msg_pack_element_dict(), separate keys and values with '=' for
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18066
diff changeset
3228
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
3229 blocklist_msg = msim_msg_new(
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3230 "blocklist", MSIM_TYPE_BOOLEAN, TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3231 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
19133
81e7c23bbb7f In msim_msg_pack_element_dict(), separate keys and values with '=' for
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18066
diff changeset
3232 /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */
19137
fb04b5cf5817 Use a list when updating the blocklist when removing the buddy, since
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19135
diff changeset
3233 //"idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"),
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3234 "idlist", MSIM_TYPE_LIST, blocklist_updates,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3235 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3236
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3237 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3238 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed"));
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3239 msim_msg_free(blocklist_msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3240 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3241 }
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3242 msim_msg_free(blocklist_msg);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3243 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3244
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3245 /** Return whether the buddy can be messaged while offline.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3246 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3247 * The protocol supports offline messages in just the same way as online
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3248 * messages.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3249 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3250 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3251 msim_offline_message(const PurpleBuddy *buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3252 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3253 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3254 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3255
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3256 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3257 * Callback when input available.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3258 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3259 * @param gc_uncasted A PurpleConnection pointer.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3260 * @param source File descriptor.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3261 * @param cond PURPLE_INPUT_READ
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3262 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3263 * Reads the input, and calls msim_preprocess_incoming() to handle it.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3264 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3265 static void
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3266 msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3267 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3268 PurpleConnection *gc;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3269 PurpleAccount *account;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3270 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3271 gchar *end;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3272 int n;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3273
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3274 g_return_if_fail(gc_uncasted != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3275 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3276
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3277 gc = (PurpleConnection *)(gc_uncasted);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3278 account = purple_connection_get_account(gc);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3279 session = gc->proto_data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3280
19163
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
3281 /* libpurple/eventloop.h only defines these two */
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
3282 if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) {
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
3283 purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond);
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
3284 purple_connection_error(gc, _("Invalid input condition"));
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
3285 return;
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
3286 }
c96b3c02a849 Only say we are connected after the MsimSession structure is fully setup.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19162
diff changeset
3287
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3288 g_return_if_fail(cond == PURPLE_INPUT_READ);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3289 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3290
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3291 /* Mark down that we got data, so don't timeout. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3292 session->last_comm = time(NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3293
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3294 /* Only can handle so much data at once...
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3295 * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3296 * Should be large enough to hold the largest protocol message.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3297 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3298 if (session->rxoff >= MSIM_READ_BUF_SIZE) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3299 purple_debug_error("msim",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3300 "msim_input_cb: %d-byte read buffer full! rxoff=%d\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3301 MSIM_READ_BUF_SIZE, session->rxoff);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3302 purple_connection_error(gc, _("Read buffer full"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3303 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3304 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3305
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3306 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3307 session->rxoff, MSIM_READ_BUF_SIZE,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3308 MSIM_READ_BUF_SIZE - session->rxoff);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3309
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3310 /* Read into buffer. On Win32, need recv() not read(). session->fd also holds
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3311 * the file descriptor, but it sometimes differs from the 'source' parameter.
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3312 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3313 n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3314
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3315 if (n < 0 && errno == EAGAIN) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3316 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3317 } else if (n < 0) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3318 purple_debug_error("msim", "msim_input_cb: read error, ret=%d, "
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3319 "error=%s, source=%d, fd=%d (%X))\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3320 n, strerror(errno), source, session->fd, session->fd);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3321 purple_connection_error(gc, _("Read error"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3322 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3323 } else if (n == 0) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3324 purple_debug_info("msim", "msim_input_cb: server disconnected\n");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3325 purple_connection_error(gc, _("Server has disconnected"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3326 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3327 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3328
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3329 if (n + session->rxoff >= MSIM_READ_BUF_SIZE) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3330 purple_debug_info("msim_input_cb", "received %d bytes, pushing rxoff to %d, over buffer size of %d\n",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3331 n, n + session->rxoff, MSIM_READ_BUF_SIZE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3332 /* TODO: g_realloc like msn, yahoo, irc, jabber? */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3333 purple_connection_error(gc, _("Read buffer full"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3334 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3335
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3336 /* Null terminate */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3337 purple_debug_info("msim", "msim_input_cb: going to null terminate "
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3338 "at n=%d\n", n);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3339 session->rxbuf[session->rxoff + n] = 0;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3340
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3341 #ifdef MSIM_CHECK_EMBEDDED_NULLS
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3342 /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3343 if (strlen(session->rxbuf + session->rxoff) != n) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3344 /* Occurs after login, but it is not a null byte. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3345 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes"
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3346 "--null byte encountered?\n",
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3347 strlen(session->rxbuf + session->rxoff), n);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3348 //purple_connection_error(gc, "Invalid message - null byte on input");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3349 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3350 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3351 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3352
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3353 session->rxoff += n;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3354 purple_debug_info("msim", "msim_input_cb: read=%d\n", n);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3355
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3356 #ifdef MSIM_DEBUG_RXBUF
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3357 purple_debug_info("msim", "buf=<%s>\n", session->rxbuf);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3358 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3359
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3360 /* Look for \\final\\ end markers. If found, process message. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3361 while((end = strstr(session->rxbuf, MSIM_FINAL_STRING))) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3362 MsimMessage *msg;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3363
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3364 #ifdef MSIM_DEBUG_RXBUF
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3365 purple_debug_info("msim", "in loop: buf=<%s>\n", session->rxbuf);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3366 #endif
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3367 *end = 0;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3368 msg = msim_parse(g_strdup(session->rxbuf));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3369 if (!msg) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3370 purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3371 purple_connection_error(gc, _("Unparseable message"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3372 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3373 /* Process message and then free it (processing function should
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3374 * clone message if it wants to keep it afterwards.) */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3375 if (!msim_preprocess_incoming(session, msg)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3376 msim_msg_dump("msim_input_cb: preprocessing message failed on msg: %s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3377 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3378 msim_msg_free(msg);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3379 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3380
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3381 /* Move remaining part of buffer to beginning. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3382 session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3383 memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3384 MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3385
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3386 /* Clear end of buffer */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3387 //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3388 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3389 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3390
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3391 /* Setup a callback, to be called when a reply is received with the returned rid.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3392 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3393 * @param cb The callback, an MSIM_USER_LOOKUP_CB.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3394 * @param data Arbitrary user data to be passed to callback (probably an MsimMessage *).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3395 *
18041
cbfd0466decf Update for 0.12.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18040
diff changeset
3396 * @return The request/reply ID, used to link replies with requests, or -1.
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3397 * Put the rid in your request, 'rid' field.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3398 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3399 * TODO: Make more generic and more specific:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3400 * 1) MSIM_USER_LOOKUP_CB - make it for PERSIST_REPLY, not just user lookup
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3401 * 2) data - make it an MsimMessage?
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3402 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3403 static guint
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3404 msim_new_reply_callback(MsimSession *session, MSIM_USER_LOOKUP_CB cb,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3405 gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3406 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3407 guint rid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3408
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3409 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
18041
cbfd0466decf Update for 0.12.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18040
diff changeset
3410
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3411 rid = session->next_rid++;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3412
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3413 g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3414 g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3415
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3416 return rid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3417 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3418
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3419 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3420 * Callback when connected. Sets up input handlers.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3421 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3422 * @param data A PurpleConnection pointer.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3423 * @param source File descriptor.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3424 * @param error_message
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3425 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3426 static void
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3427 msim_connect_cb(gpointer data, gint source, const gchar *error_message)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3428 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3429 PurpleConnection *gc;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3430 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3431
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3432 g_return_if_fail(data != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3433
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3434 gc = (PurpleConnection *)data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3435 session = (MsimSession *)gc->proto_data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3436
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3437 if (source < 0) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3438 purple_connection_error(gc, _("Couldn't connect to host"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3439 purple_connection_error(gc, g_strdup_printf(
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3440 _("Couldn't connect to host: %s (%d)"),
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3441 error_message ? error_message : "no message given",
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3442 source));
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3443 return;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3444 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3445
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3446 session->fd = source;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3447
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3448 gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3449 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3450
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3451 /* Session methods */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3452
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3453 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3454 * Create a new MSIM session.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3455 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3456 * @param acct The account to create the session from.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3457 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3458 * @return Pointer to a new session. Free with msim_session_destroy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3459 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3460 MsimSession *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3461 msim_session_new(PurpleAccount *acct)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3462 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3463 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3464
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3465 g_return_val_if_fail(acct != NULL, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3466
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3467 session = g_new0(MsimSession, 1);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3468
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3469 session->magic = MSIM_SESSION_STRUCT_MAGIC;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3470 session->account = acct;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3471 session->gc = purple_account_get_connection(acct);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3472 session->sesskey = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3473 session->userid = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3474 session->username = NULL;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3475 session->fd = -1;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3476
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3477 /* TODO: Remove. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3478 session->user_lookup_cb = g_hash_table_new_full(g_direct_hash,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3479 g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3480 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3481 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3482 they could be integers inside gpointers
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3483 or strings, so I don't freed them.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3484 Figure this out, once free cache. */
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
3485
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3486 /* Created in msim_process_server_info() */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3487 session->server_info = NULL;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3488
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3489 session->rxoff = 0;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3490 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3491 session->next_rid = 1;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3492 session->last_comm = time(NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3493 session->inbox_status = 0;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3494
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3495 return session;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3496 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3497
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3498 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3499 * Free a session.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3500 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3501 * @param session The session to destroy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3502 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3503 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3504 msim_session_destroy(MsimSession *session)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3505 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3506 g_return_if_fail(MSIM_SESSION_VALID(session));
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3507
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3508 session->magic = -1;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3509
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3510 g_free(session->rxbuf);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3511 g_free(session->username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3512
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3513 /* TODO: Remove. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3514 g_hash_table_destroy(session->user_lookup_cb);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3515 g_hash_table_destroy(session->user_lookup_cb_data);
18056
2c2d509ebe78 Add msim_process_server_info() to save the server information dictionary
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18055
diff changeset
3516
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3517 if (session->server_info) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3518 g_hash_table_destroy(session->server_info);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3519 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3520
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3521 g_free(session);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3522 }
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3523
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3524 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3525 * Close the connection.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3526 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3527 * @param gc The connection.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3528 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3529 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3530 msim_close(PurpleConnection *gc)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3531 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3532 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3533
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3534 if (gc == NULL) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3535 return;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3536 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3537
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3538 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3539 if (session == NULL)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3540 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3541
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3542 gc->proto_data = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3543
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3544 if (!MSIM_SESSION_VALID(session)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3545 return;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3546 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3547
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3548 if (session->gc->inpa) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3549 purple_input_remove(session->gc->inpa);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3550 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3551
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3552 msim_session_destroy(session);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3553 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3554
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3555
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3556 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3557 * Check if a string is a userid (all numeric).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3558 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3559 * @param user The user id, email, or name.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3560 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3561 * @return TRUE if is userid, FALSE if not.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3562 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3563 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3564 msim_is_userid(const gchar *user)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3565 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3566 g_return_val_if_fail(user != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3567
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3568 return strspn(user, "0123456789") == strlen(user);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3569 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3570
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3571 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3572 * Check if a string is an email address (contains an @).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3573 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3574 * @param user The user id, email, or name.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3575 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3576 * @return TRUE if is an email, FALSE if not.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3577 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3578 * This function is not intended to be used as a generic
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3579 * means of validating email addresses, but to distinguish
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3580 * between a user represented by an email address from
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3581 * other forms of identification.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3582 */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3583 static gboolean
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3584 msim_is_email(const gchar *user)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3585 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3586 g_return_val_if_fail(user != NULL, FALSE);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3587
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3588 return strchr(user, '@') != NULL;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3589 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3590
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3591
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3592 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3593 * Asynchronously lookup user information, calling callback when receive result.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3594 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3595 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3596 * @param user The user id, email address, or username. Not freed.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3597 * @param cb Callback, called with user information when available.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3598 * @param data An arbitray data pointer passed to the callback.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3599 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3600 /* TODO: change to not use callbacks */
18059
9dcbd6ed0b28 Make msimprpl-internal functions static.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18058
diff changeset
3601 static void
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3602 msim_lookup_user(MsimSession *session, const gchar *user,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3603 MSIM_USER_LOOKUP_CB cb, gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3604 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3605 MsimMessage *body;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3606 gchar *field_name;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3607 guint rid, cmd, dsn, lid;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3608
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3609 g_return_if_fail(MSIM_SESSION_VALID(session));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3610 g_return_if_fail(user != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3611 g_return_if_fail(cb != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3612
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3613 purple_debug_info("msim", "msim_lookup_userid: "
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3614 "asynchronously looking up <%s>\n", user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3615
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3616 msim_msg_dump("msim_lookup_user: data=%s\n", (MsimMessage *)data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3617
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3618 /* Setup callback. Response will be associated with request using 'rid'. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3619 rid = msim_new_reply_callback(session, cb, data);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3620
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3621 /* Send request */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3622
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3623 cmd = MSIM_CMD_GET;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3624
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3625 if (msim_is_userid(user)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3626 field_name = "UserID";
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3627 dsn = MG_MYSPACE_INFO_BY_ID_DSN;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3628 lid = MG_MYSPACE_INFO_BY_ID_LID;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3629 } else if (msim_is_email(user)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3630 field_name = "Email";
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3631 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3632 lid = MG_MYSPACE_INFO_BY_STRING_LID;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3633 } else {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3634 field_name = "UserName";
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3635 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3636 lid = MG_MYSPACE_INFO_BY_STRING_LID;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3637 }
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3638
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
3639 body = msim_msg_new(
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3640 field_name, MSIM_TYPE_STRING, g_strdup(user),
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3641 NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3642
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3643 g_return_if_fail(msim_send(session,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3644 "persist", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3645 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3646 "cmd", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3647 "dsn", MSIM_TYPE_INTEGER, dsn,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3648 "uid", MSIM_TYPE_INTEGER, session->userid,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3649 "lid", MSIM_TYPE_INTEGER, lid,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3650 "rid", MSIM_TYPE_INTEGER, rid,
19135
705302b2c7f7 Use the new dictionary data type when:
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19133
diff changeset
3651 "body", MSIM_TYPE_DICTIONARY, body,
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3652 NULL));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3653 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3654
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3655
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3656 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3657 * Obtain the status text for a buddy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3658 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3659 * @param buddy The buddy to obtain status text for.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3660 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3661 * @return Status text, or NULL if error. Caller g_free()'s.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3662 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3663 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3664 char *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3665 msim_status_text(PurpleBuddy *buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3666 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3667 MsimSession *session;
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3668 MsimUser *user;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3669 const gchar *display_name, *headline;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3670
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3671 g_return_val_if_fail(buddy != NULL, NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3672
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3673 user = msim_get_user_from_buddy(buddy);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3674
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3675 session = (MsimSession *)buddy->account->gc->proto_data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3676 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3677
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3678 display_name = headline = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3679
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3680 /* Retrieve display name and/or headline, depending on user preference. */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3681 if (purple_account_get_bool(session->account, "show_display_name", TRUE)) {
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3682 display_name = user->display_name;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3683 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3684
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3685 if (purple_account_get_bool(session->account, "show_headline", FALSE)) {
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3686 headline = user->headline;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3687 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3688
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3689 /* Return appropriate combination of display name and/or headline, or neither. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3690
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3691 if (display_name && headline) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3692 return g_strconcat(display_name, " ", headline, NULL);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3693 } else if (display_name) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3694 return g_strdup(display_name);
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3695 } else if (headline) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3696 return g_strdup(headline);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3697 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3698
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3699 return NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3700 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3701
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3702 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3703 * Obtain the tooltip text for a buddy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3704 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3705 * @param buddy Buddy to obtain tooltip text on.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3706 * @param user_info Variable modified to have the tooltip text.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3707 * @param full TRUE if should obtain full tooltip text.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3708 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3709 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3710 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3711 msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3712 gboolean full)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3713 {
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3714 MsimUser *user;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3715
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3716 g_return_if_fail(buddy != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3717 g_return_if_fail(user_info != NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3718
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3719 user = msim_get_user_from_buddy(buddy);
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3720
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3721 if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3722 MsimSession *session;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3723
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3724 session = (MsimSession *)buddy->account->gc->proto_data;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3725
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3726 g_return_if_fail(MSIM_SESSION_VALID(session));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3727
19166
d625520b98ac Use MsimUser structure for storing ephemeral information on users, instead
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19164
diff changeset
3728 /* TODO: if (full), do something different? */
19167
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3729
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3730 /* TODO: request information? have to figure out how to do
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3731 * the asynchronous lookup like oscar does (tooltip shows
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3732 * 'retrieving...' if not yet available, then changes when it is).
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3733 *
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3734 * Right now, only show what we have on hand.
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3735 */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3736
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3737 /* Show abbreviated user info. */
4ec67fc6d814 Refactor msim_tooltip_text() and msim_get_info_cb(), so that they now both use
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19166
diff changeset
3738 msim_append_user_info(session, user_info, user, FALSE);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3739 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3740 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3741
18055
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3742 /** Actions menu for account. */
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3743 GList *
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3744 msim_actions(PurplePlugin *plugin, gpointer context)
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3745 {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3746 PurpleConnection *gc;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3747 GList *menu;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3748 //PurplePluginAction *act;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3749
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3750 gc = (PurpleConnection *)context;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3751
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3752 menu = NULL;
18055
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3753
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3754 #if 0
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3755 /* TODO: find out how */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3756 act = purple_plugin_action_new(_("Find people..."), msim_);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3757 menu = g_list_append(menu, act);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3758
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3759 act = purple_plugin_action_new(_("Import friends..."), NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3760 menu = g_list_append(menu, act);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3761
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3762 act = purple_plugin_action_new(_("Change IM name..."), NULL);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3763 menu = g_list_append(menu, act);
18055
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3764 #endif
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3765
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3766 return menu;
18055
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3767 }
ed3a5b60eff6 Use MsimMessage's new list type for status messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18053
diff changeset
3768
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3769 /** Callbacks called by Purple, to access this plugin. */
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3770 PurplePluginProtocolInfo prpl_info = {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3771 /* options */
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3772 OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */
18038
4a904c0a564e Notify of new inbox messages (friend requests, inbox messages, comments),
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18037
diff changeset
3773 | OPT_PROTO_MAIL_CHECK,
4a904c0a564e Notify of new inbox messages (friend requests, inbox messages, comments),
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18037
diff changeset
3774
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3775 /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3776 NULL, /* user_splits */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3777 NULL, /* protocol_options */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3778 NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3779 msim_list_icon, /* list_icon */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3780 NULL, /* list_emblems */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3781 msim_status_text, /* status_text */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3782 msim_tooltip_text, /* tooltip_text */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3783 msim_status_types, /* status_types */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3784 msim_blist_node_menu, /* blist_node_menu */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3785 NULL, /* chat_info */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3786 NULL, /* chat_info_defaults */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3787 msim_login, /* login */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3788 msim_close, /* close */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3789 msim_send_im, /* send_im */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3790 NULL, /* set_info */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3791 msim_send_typing, /* send_typing */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3792 msim_get_info, /* get_info */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3793 msim_set_status, /* set_status */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3794 msim_set_idle, /* set_idle */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3795 NULL, /* change_passwd */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3796 msim_add_buddy, /* add_buddy */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3797 NULL, /* add_buddies */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3798 msim_remove_buddy, /* remove_buddy */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3799 NULL, /* remove_buddies */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3800 NULL, /* add_permit */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3801 NULL, /* add_deny */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3802 NULL, /* rem_permit */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3803 NULL, /* rem_deny */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3804 NULL, /* set_permit_deny */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3805 NULL, /* join_chat */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3806 NULL, /* reject chat invite */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3807 NULL, /* get_chat_name */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3808 NULL, /* chat_invite */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3809 NULL, /* chat_leave */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3810 NULL, /* chat_whisper */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3811 NULL, /* chat_send */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3812 NULL, /* keepalive */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3813 NULL, /* register_user */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3814 NULL, /* get_cb_info */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3815 NULL, /* get_cb_away */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3816 NULL, /* alias_buddy */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3817 NULL, /* group_buddy */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3818 NULL, /* rename_group */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3819 NULL, /* buddy_free */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3820 NULL, /* convo_closed */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3821 NULL, /* normalize */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3822 NULL, /* set_buddy_icon */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3823 NULL, /* remove_group */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3824 NULL, /* get_cb_real_name */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3825 NULL, /* set_chat_topic */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3826 NULL, /* find_blist_chat */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3827 NULL, /* roomlist_get_list */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3828 NULL, /* roomlist_cancel */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3829 NULL, /* roomlist_expand_category */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3830 NULL, /* can_receive_file */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3831 NULL, /* send_file */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3832 NULL, /* new_xfer */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3833 msim_offline_message, /* offline_message */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3834 NULL, /* whiteboard_prpl_ops */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3835 msim_send_really_raw, /* send_raw */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3836 NULL, /* roomlist_room_serialize */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3837 NULL, /* _purple_reserved1 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3838 NULL, /* _purple_reserved2 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3839 NULL, /* _purple_reserved3 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3840 NULL /* _purple_reserved4 */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3841 };
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3842
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3843
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3844
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3845 /** Based on MSN's plugin info comments. */
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3846 PurplePluginInfo info = {
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3847 PURPLE_PLUGIN_MAGIC,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3848 PURPLE_MAJOR_VERSION,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3849 PURPLE_MINOR_VERSION,
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3850 PURPLE_PLUGIN_PROTOCOL, /**< type */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3851 NULL, /**< ui_requirement */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3852 0, /**< flags */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3853 NULL, /**< dependencies */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3854 PURPLE_PRIORITY_DEFAULT, /**< priority */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3855
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3856 "prpl-myspace", /**< id */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3857 "MySpaceIM", /**< name */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3858 MSIM_PRPL_VERSION_STRING, /**< version */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3859 /** summary */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3860 "MySpaceIM Protocol Plugin",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3861 /** description */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3862 "MySpaceIM Protocol Plugin",
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3863 "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3864 "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3865
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3866 msim_load, /**< load */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3867 NULL, /**< unload */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3868 NULL, /**< destroy */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3869 NULL, /**< ui_info */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3870 &prpl_info, /**< extra_info */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3871 NULL, /**< prefs_info */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3872 msim_actions, /**< msim_actions */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3873 NULL, /**< reserved1 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3874 NULL, /**< reserved2 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3875 NULL, /**< reserved3 */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3876 NULL /**< reserved4 */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3877 };
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3878
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3879
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3880 #ifdef MSIM_SELF_TEST
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3881 /** Test functions.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3882 * Used to test or try out the internal workings of msimprpl. If you're reading
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3883 * this code for the first time, these functions can be instructive in learning
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3884 * how msimprpl is architected.
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3885 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3886 void
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3887 msim_test_all(void) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3888 guint failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3889
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3890
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3891 failures = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3892 failures += msim_test_msg();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3893 failures += msim_test_escaping();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3894
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3895 if (failures) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3896 purple_debug_info("msim", "msim_test_all HAD FAILURES: %d\n", failures);
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3897 } else {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3898 purple_debug_info("msim", "msim_test_all - all tests passed!\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3899 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3900 exit(0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3901 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3902
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3903 /** Test MsimMessage for basic functionality. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3904 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3905 msim_test_msg(void)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3906 {
19133
81e7c23bbb7f In msim_msg_pack_element_dict(), separate keys and values with '=' for
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18066
diff changeset
3907 MsimMessage *msg, *msg_cloned, *msg2;
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3908 GList *list;
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3909 gchar *packed, *packed_expected, *packed_cloned;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3910 guint failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3911
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3912 failures = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3913
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3914 purple_debug_info("msim", "\n\nTesting MsimMessage\n");
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
3915 msg = msim_msg_new(NULL); /* Create a new, empty message. */
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3916
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3917 /* Append some new elements. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3918 msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3919 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3920 msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3921 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3922 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v52/xxx\\yyy"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3923 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3924 msim_msg_dump("msg debug str=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3925 packed = msim_msg_pack(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3926
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3927 purple_debug_info("msim", "msg packed=%s\n", packed);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3928
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3929 packed_expected = "\\bx\\WFhY\\k1\\v1\\k1\\42\\k1"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3930 "\\v43\\k1\\v52/1xxx/2yyy\\k1\\v7\\final\\";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3931
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3932 if (0 != strcmp(packed, packed_expected)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3933 purple_debug_info("msim", "!!!(%d), msim_msg_pack not what expected: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3934 ++failures, packed, packed_expected);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3935 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3936
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3937
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3938 msg_cloned = msim_msg_clone(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3939 packed_cloned = msim_msg_pack(msg_cloned);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3940
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3941 purple_debug_info("msim", "msg cloned=%s\n", packed_cloned);
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3942 if (0 != strcmp(packed, packed_cloned)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3943 purple_debug_info("msim", "!!!(%d), msim_msg_pack on cloned message not equal to original: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3944 ++failures, packed_cloned, packed);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3945 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3946
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3947 g_free(packed);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3948 g_free(packed_cloned);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3949 msim_msg_free(msg_cloned);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3950 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3951
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3952 /* Try some of the more advanced functionality */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3953 list = NULL;
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3954
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3955 list = g_list_prepend(list, "item3");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3956 list = g_list_prepend(list, "item2");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3957 list = g_list_prepend(list, "item1");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3958 list = g_list_prepend(list, "item0");
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3959
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
3960 msg = msim_msg_new(NULL);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3961 msg = msim_msg_append(msg, "string", MSIM_TYPE_STRING, g_strdup("string value"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3962 msg = msim_msg_append(msg, "raw", MSIM_TYPE_RAW, g_strdup("raw value"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3963 msg = msim_msg_append(msg, "integer", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(3140));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3964 msg = msim_msg_append(msg, "boolean", MSIM_TYPE_BOOLEAN, GUINT_TO_POINTER(FALSE));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3965 msg = msim_msg_append(msg, "list", MSIM_TYPE_LIST, list);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3966
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3967 msim_msg_dump("msg with list=%s\n", msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3968 purple_debug_info("msim", "msg with list packed=%s\n", msim_msg_pack(msg));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3969
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
3970 msg2 = msim_msg_new(NULL);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3971 msg2 = msim_msg_append(msg2, "outer", MSIM_TYPE_STRING, g_strdup("outer value"));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3972 msg2 = msim_msg_append(msg2, "body", MSIM_TYPE_DICTIONARY, msg);
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3973 msim_msg_dump("msg with dict=%s\n", msg2); /* msg2 now 'owns' msg */
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3974 purple_debug_info("msim", "msg with dict packed=%s\n", msim_msg_pack(msg2));
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3975
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
3976 msim_msg_free(msg2);
19133
81e7c23bbb7f In msim_msg_pack_element_dict(), separate keys and values with '=' for
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18066
diff changeset
3977
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3978 return failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3979 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3980
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3981 /** Test protocol-level escaping/unescaping. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3982 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3983 msim_test_escaping(void)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3984 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3985 guint failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3986 gchar *raw, *escaped, *unescaped, *expected;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3987
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3988 failures = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3989
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3990 purple_debug_info("msim", "\n\nTesting escaping\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3991
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3992 raw = "hello/world\\hello/world";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3993
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3994 escaped = msim_escape(raw);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3995 purple_debug_info("msim", "msim_test_escaping: raw=%s, escaped=%s\n", raw, escaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3996 expected = "hello/1world/2hello/1world";
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
3997 if (0 != strcmp(escaped, expected)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3998 purple_debug_info("msim", "!!!(%d), msim_escape failed: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3999 ++failures, escaped, expected);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4000 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4001
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4002
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4003 unescaped = msim_unescape(escaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4004 g_free(escaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4005 purple_debug_info("msim", "msim_test_escaping: unescaped=%s\n", unescaped);
19144
3868ddc14400 Use cuddled if's etc. everywhere, to better match style of Pidgin/libpurple.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19139
diff changeset
4006 if (0 != strcmp(raw, unescaped)) {
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4007 purple_debug_info("msim", "!!!(%d), msim_unescape failed: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4008 ++failures, raw, unescaped);
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
4009 }
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4010
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4011 return failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4012 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4013 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4014
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4015 /** Initialize plugin. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4016 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4017 init_plugin(PurplePlugin *plugin)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4018 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4019 PurpleAccountOption *option;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4020 #ifdef MSIM_SELF_TEST
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4021 msim_test_all();
19159
31c6475e3ff1 Rewrite escaping so that it is more correct, in order to fix #2521. Test it.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19158
diff changeset
4022 exit(0);
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4023 #endif /* MSIM_SELF_TEST */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4024
19152
4cfa0cbe4cb8 Clarify password-too-long error (MySpace limits it, not us), and clean up
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19151
diff changeset
4025
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4026 /* TODO: default to automatically try different ports. Make the user be
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4027 * able to set the first port to try (like LastConnectedPort in Windows client). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4028 option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4029 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4030
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4031 option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4032 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4033
19168
e5a076b03a7a Conditionally compile out a few advanced configuration options (status text
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19167
diff changeset
4034 #ifdef MSIM_USER_WANTS_TO_CONFIGURE_STATUS_TEXT
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4035 option = purple_account_option_bool_new(_("Show display name in status text"), "show_display_name", TRUE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4036 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4037
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4038 option = purple_account_option_bool_new(_("Show headline in status text"), "show_headline", TRUE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4039 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
19168
e5a076b03a7a Conditionally compile out a few advanced configuration options (status text
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19167
diff changeset
4040 #endif
e5a076b03a7a Conditionally compile out a few advanced configuration options (status text
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19167
diff changeset
4041
e5a076b03a7a Conditionally compile out a few advanced configuration options (status text
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19167
diff changeset
4042 #ifdef MSIM_USER_WANTS_TO_DISABLE_EMOTICONS
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
4043 option = purple_account_option_bool_new(_("Send emoticons"), "emoticons", FALSE);
18048
c8f29e1916c2 Add account option to send emoticons, defaulting to off since can't currently
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18047
diff changeset
4044 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
19168
e5a076b03a7a Conditionally compile out a few advanced configuration options (status text
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19167
diff changeset
4045 #endif
18048
c8f29e1916c2 Add account option to send emoticons, defaulting to off since can't currently
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18047
diff changeset
4046
18057
77eb36712aca Update login process to more closely match official client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18056
diff changeset
4047 #ifdef MSIM_USER_REALLY_CARES_ABOUT_PRECISE_FONT_SIZES
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
4048 option = purple_account_option_int_new(_("Screen resolution (dots per inch)"), "dpi", MSIM_DEFAULT_DPI);
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
4049 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
4050
19149
b9e554509131 Change all code to better match the style of libpurple - use 8-space tabs
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19148
diff changeset
4051 option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
18042
390fbe2a4e87 Make DPI and base font point size configurable in account options. This
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18041
diff changeset
4052 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
18057
77eb36712aca Update login process to more closely match official client.
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18056
diff changeset
4053 #endif
19151
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4054
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4055 /* TODO: /zap command. Problem with this is that there are different kinds of zaps,
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4056 * and the selection is best made available in a drop-down menu, instead of forcing
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4057 * the user to type the kind of zap and memorizing available zaps (or putting it in the
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4058 * help menu). A new "attention" API, for zap/buzz/nudge (different protocols) will
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4059 * solve this. */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4060 #if 0
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4061 purple_cmd_register("zap", /* cmd */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4062 "w", /* args - accept a single word */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4063 PURPLE_CMD_P_PRPL, /* priority */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4064 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, /* flags */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4065 "prpl-myspace", /* prpl_id */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4066 msim_cmd_zap, /* func */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4067 _("zap: zap a user to get their attention"), /* helpstr */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4068 NULL); /* data */
6bf2cdffc98e Change msim_msg_new() and msim_msg_new_v() to accept the first key name as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 19149
diff changeset
4069 #endif
18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4070 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4071
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4072 PURPLE_INIT_PLUGIN(myspace, init_plugin, info);

mercurial