annotate libpurple/protocols/myspace/myspace.c @ 19353:af0e77c44667

MySpace added a new field, LastImageUpdated. Save it in MsimUser. Also, allow null session in msim_unrecognized, since sometimes the session is not conveniently available (such as in msim_store_user_info_each). Previously, LastImageUpdated was unrecognized and sent to msim_unrecognized with a null session, which was dereferenced and crashed. Fixed.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Fri, 24 Aug 2007 02:29:42 +0000
parents 93f01e37d9f1
children b22a33d3fc95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1 /* MySpaceIM Protocol Plugin
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3 * \author Jeff Connelly
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
6 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
7 * Based on Purple's "C Plugin HOWTO" hello world example.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
8 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
9 * Code also drawn from mockprpl:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
10 * http://snarfed.org/space/purple+mock+protocol+plugin
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
11 * Copyright (C) 2004-2007, Ryan Barrett <mockprpl@ryanb.org>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
12 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
13 * and some constructs also based on existing Purple plugins, which are:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
14 * Copyright (C) 2003, Robbert Haarman <purple@inglorion.net>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
15 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
16 * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
17 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
18 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
19 * This program is free software; you can redistribute it and/or modify
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
20 * it under the terms of the GNU General Public License as published by
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
21 * the Free Software Foundation; either version 2 of the License, or
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
22 * (at your option) any later version.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
23 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
24 * This program is distributed in the hope that it will be useful,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
27 * GNU General Public License for more details.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
28 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
29 * You should have received a copy of the GNU General Public License
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
30 * along with this program; if not, write to the Free Software
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
32 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
33
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
34 #define PURPLE_PLUGIN
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
35
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
36 #include "message.h"
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
37 #include "persist.h"
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
38 #include "myspace.h"
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
39
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
40 /* Globals */
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
41
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
42 /* The names in in emoticon_names (for <i n=whatever>) map to corresponding
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
43 * entries in emoticon_symbols (for the ASCII representation of the emoticon).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
44 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
45 * Multiple emoticon symbols in Pidgin can map to one name. List the
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
46 * canonical form, as inserted by the "Smile!" dialog, first. For example,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
47 * :) comes before :-), because although both are recognized as 'happy',
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
48 * the first is inserted by the smiley button (first symbol in theme).
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
49 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
50 * Note that symbols are case-sensitive in Pidgin -- :-X is not :-x. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
51 static struct MSIM_EMOTICON
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
52 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
53 gchar *name;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
54 gchar *symbol;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
55 } msim_emoticons[] = {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
56 /* Unfortunately, this list duplicates much of the file
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
57 * pidgin/pidgin/pixmaps/emotes/default/22/default.theme.in, because
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
58 * that file is part of Pidgin, but we're part of libpurple.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
59 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
60 { "bigsmile", ":D" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
61 { "bigsmile", ":-D" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
62 { "devil", "}:)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
63 { "frazzled", ":Z" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
64 { "geek", "B)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
65 { "googles", "%)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
66 { "growl", ":E" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
67 { "laugh", ":))" }, /* Must be before ':)' */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
68 { "happy", ":)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
69 { "happy", ":-)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
70 { "happi", ":)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
71 { "heart", ":X" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
72 { "mohawk", "-:" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
73 { "mad", "X(" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
74 { "messed", "X)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
75 { "nerd", "Q)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
76 { "oops", ":G" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
77 { "pirate", "P)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
78 { "scared", ":O" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
79 { "sidefrown", ":{" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
80 { "sinister", ":B" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
81 { "smirk", ":," },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
82 { "straight", ":|" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
83 { "tongue", ":P" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
84 { "tongue", ":p" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
85 { "tongy", ":P" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
86 { "upset", "B|" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
87 { "wink", ";-)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
88 { "wink", ";)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
89 { "winc", ";)" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
90 { "worried", ":[" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
91 { "kiss", ":x" },
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
92 { NULL, NULL }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
93 };
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
94
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
95 /* Internal functions */
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
96 static gboolean msim_send_zap(MsimSession *session, const gchar *username, guint code);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
97 static void msim_send_zap_from_menu(PurpleBlistNode *node, gpointer zap_num_ptr);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
98
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
99 #ifdef MSIM_DEBUG_MSG
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
100 static void print_hash_item(gpointer key, gpointer value, gpointer user_data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
101 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
102
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
103 static int msim_send_really_raw(PurpleConnection *gc, const char *buf,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
104 int total_bytes);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
105 static gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
106 static const gchar *msim_compute_login_response(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
107 const gchar nonce[2 * NONCE_SIZE], const gchar *email,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
108 const gchar *password, guint *response_len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
109 static gboolean msim_send_bm(MsimSession *session, const gchar *who,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
110 const gchar *text, int type);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
111
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
112 static guint msim_point_to_purple_size(MsimSession *session, guint point);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
113 static guint msim_purple_size_to_point(MsimSession *session, guint size);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
114 static guint msim_height_to_point(MsimSession *session, guint height);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
115 static guint msim_point_to_height(MsimSession *session, guint point);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
116
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
117 static void msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
118
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
119 static void msim_markup_tag_to_html(MsimSession *, xmlnode *root,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
120 gchar **begin, gchar **end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
121 static void html_tag_to_msim_markup(MsimSession *, xmlnode *root,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
122 gchar **begin, gchar **end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
123 static gchar *msim_convert_xml(MsimSession *, const gchar *raw,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
124 MSIM_XMLNODE_CONVERT f);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
125 static gchar *msim_convert_smileys_to_markup(gchar *before);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
126
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
127 /* High-level msim markup <=> html conversion functions. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
128 static gchar *msim_markup_to_html(MsimSession *, const gchar *raw);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
129 static gchar *html_to_msim_markup(MsimSession *, const gchar *raw);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
130
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
131 static MsimUser *msim_get_user_from_buddy(PurpleBuddy *buddy);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
132 static MsimUser *msim_find_user(MsimSession *session, const gchar *username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
133
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
134 static gboolean msim_incoming_bm_record_cv(MsimSession *session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
135 MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
136 static gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
137 static gboolean msim_incoming_status(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
138 static gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
139 static gboolean msim_incoming_zap(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
140 static gboolean msim_incoming_action(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
141 static gboolean msim_incoming_media(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
142 static gboolean msim_incoming_unofficial_client(MsimSession *session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
143 MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
144
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
145 #ifdef MSIM_SEND_CLIENT_VERSION
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
146 static gboolean msim_send_unofficial_client(MsimSession *session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
147 gchar *username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
148 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
149
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
150 static void msim_get_info_cb(MsimSession *session, MsimMessage *userinfo, gpointer data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
151 static gchar *msim_format_now_playing(gchar *band, gchar *song);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
152
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
153 static void msim_set_status_code(MsimSession *session, guint code,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
154 gchar *statstring);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
155
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
156 static void msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
157
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
158 static void msim_downloaded_buddy_icon(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
159 gsize len, const gchar *error_message);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
160
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
161 static void msim_store_user_info_each(const gchar *key_str, gchar *value_str, MsimUser *user);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
162 static gboolean msim_store_user_info(MsimSession *session, MsimMessage *msg, MsimUser *user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
163 static gboolean msim_process_server_info(MsimSession *session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
164 MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
165 static gboolean msim_web_challenge(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
166 static gboolean msim_process_reply(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
167
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
168 static gboolean msim_preprocess_incoming(MsimSession *session, MsimMessage *msg);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
169
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
170 #ifdef MSIM_USE_KEEPALIVE
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
171 static gboolean msim_check_alive(gpointer data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
172 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
173
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
174 static gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
175
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
176 static gboolean msim_process(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
177
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
178 static MsimMessage *msim_do_postprocessing(MsimMessage *msg,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
179 const gchar *uid_field_name, const gchar *uid_before, guint uid);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
180 static void msim_postprocess_outgoing_cb(MsimSession *session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
181 MsimMessage *userinfo, gpointer data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
182 static gboolean msim_postprocess_outgoing(MsimSession *session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
183 MsimMessage *msg, const gchar *username, const gchar *uid_field_name,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
184 const gchar *uid_before);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
185
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
186 static gboolean msim_error(MsimSession *session, MsimMessage *msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
187
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
188 static void msim_check_inbox_cb(MsimSession *session, MsimMessage *userinfo,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
189 gpointer data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
190 static gboolean msim_check_inbox(gpointer data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
191
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
192 static void msim_input_cb(gpointer gc_uncasted, gint source,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
193 PurpleInputCondition cond);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
194
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
195 static guint msim_new_reply_callback(MsimSession *session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
196 MSIM_USER_LOOKUP_CB cb, gpointer data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
197
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
198 static void msim_connect_cb(gpointer data, gint source,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
199 const gchar *error_message);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
200
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
201 static gboolean msim_is_userid(const gchar *user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
202 static gboolean msim_is_email(const gchar *user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
203
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
204 static void msim_lookup_user(MsimSession *session, const gchar *user,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
205 MSIM_USER_LOOKUP_CB cb, gpointer data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
206
19249
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
207 static void msim_import_friends(PurplePluginAction *action);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
208
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
209 double msim_round(double round);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
210
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
211 /* round is part of C99, but sometimes is unavailable before then.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
212 * Based on http://forums.belution.com/en/cpp/000/050/13.shtml
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
213 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
214 double msim_round(double value)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
215 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
216 if (value < 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
217 return -(floor(-value + 0.5));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
218 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
219 return floor( value + 0.5);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
220 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
221 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
222
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
223 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
224 * Load the plugin.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
225 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
226 gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
227 msim_load(PurplePlugin *plugin)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
228 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
229 /* If compiled to use RC4 from libpurple, check if it is really there. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
230 if (!purple_ciphers_find_cipher("rc4")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
231 purple_debug_error("msim", "rc4 not in libpurple, but it is required - not loading MySpaceIM plugin!\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
232 purple_notify_error(plugin, _("Missing Cipher"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
233 _("The RC4 cipher could not be found"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
234 _("Upgrade "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
235 "to a libpurple with RC4 support (>= 2.0.1). MySpaceIM "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
236 "plugin will not be loaded."));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
237 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
238 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
239 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
240 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
241
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
242 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
243 * Get possible user status types. Based on mockprpl.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
244 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
245 * @return GList of status types.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
246 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
247 GList *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
248 msim_status_types(PurpleAccount *acct)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
249 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
250 GList *types;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
251 PurpleStatusType *status;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
252
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
253 purple_debug_info("myspace", "returning status types\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
254
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
255 types = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
256
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
257 /* Statuses are almost all the same. Define a macro to reduce code repetition. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
258 #define _MSIM_ADD_NEW_STATUS(prim) status = \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
259 purple_status_type_new_with_attrs( \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
260 prim, /* PurpleStatusPrimitive */ \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
261 NULL, /* id - use default */ \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
262 NULL, /* name - use default */ \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
263 TRUE, /* savable */ \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
264 TRUE, /* user_settable */ \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
265 FALSE, /* not independent */ \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
266 \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
267 /* Attributes - each status can have a message. */ \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
268 "message", \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
269 _("Message"), \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
270 purple_value_new(PURPLE_TYPE_STRING), \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
271 NULL); \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
272 \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
273 \
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
274 types = g_list_append(types, status)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
275
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
276
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
277 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AVAILABLE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
278 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AWAY);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
279 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_OFFLINE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
280 _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_INVISIBLE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
281
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
282
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
283 return types;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
284 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
285
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
286 /** Get zap types. */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
287 GList *
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
288 msim_attention_types(PurpleAccount *acct)
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
289 {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
290 static GList *types = NULL;
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
291 MsimAttentionType* attn;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
292
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
293 if (!types) {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
294 #define _MSIM_ADD_NEW_ATTENTION(icn, des, incoming, outgoing) \
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
295 attn = g_new0(MsimAttentionType, 1); \
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
296 attn->icon = icn; \
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
297 attn->description = des; \
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
298 attn->incoming_description = incoming; \
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
299 attn->outgoing_description = outgoing; \
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
300 types = g_list_append(types, attn);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
301
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
302 /* TODO: icons for each zap */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
303 _MSIM_ADD_NEW_ATTENTION(NULL, _("zap"), _("zapped"), _("Zapping"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
304 _MSIM_ADD_NEW_ATTENTION(NULL, _("whack"), _("whacked"), _("Whacking"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
305 _MSIM_ADD_NEW_ATTENTION(NULL, _("torch"), _("torched"), _("Torching"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
306 _MSIM_ADD_NEW_ATTENTION(NULL, _("smooch"), _("smooched"), _("Smooching"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
307 _MSIM_ADD_NEW_ATTENTION(NULL, _("hug"), _("hugged"), _("Hugging"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
308 _MSIM_ADD_NEW_ATTENTION(NULL, _("bslap"), _("bslapped"), _("Bslapping"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
309 _MSIM_ADD_NEW_ATTENTION(NULL, _("goose"), _("goosed"), _("Goosing"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
310 _MSIM_ADD_NEW_ATTENTION(NULL, _("hi-five"), _("hi-fived"), _("Hi-fiving"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
311 _MSIM_ADD_NEW_ATTENTION(NULL, _("punk"), _("punk'd"), _("Punking"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
312 _MSIM_ADD_NEW_ATTENTION(NULL, _("raspberry"), _("raspberried"), _("Raspberry'ing"));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
313 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
314
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
315 return types;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
316 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
317
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
318 /** Send a zap */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
319 gboolean
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
320 msim_send_attention(PurpleConnection *gc, gchar *username, guint code)
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
321 {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
322 GList *types;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
323 MsimSession *session;
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
324 MsimAttentionType *attn;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
325 PurpleBuddy *buddy;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
326
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
327 session = (MsimSession *)gc->proto_data;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
328
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
329 /* Look for this attention type, by the code index given. */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
330 types = msim_attention_types(gc->account);
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
331 attn = (MsimAttentionType *)g_list_nth_data(types, code);
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
332
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
333 if (!attn) {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
334 purple_debug_info("msim_send_attention", "got invalid zap code %d\n", code);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
335 return FALSE;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
336 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
337
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
338 buddy = purple_find_buddy(session->account, username);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
339 if (!buddy) {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
340 return FALSE;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
341 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
342
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
343 /* TODO: make use of the MsimAttentionType we found, instead of
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
344 * doing it all over in msim_send_zap_from_menu. */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
345 msim_send_zap_from_menu(&buddy->node, GUINT_TO_POINTER(code));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
346
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
347 return TRUE;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
348 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
349
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
350 /** Send a zap to a user. */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
351 static gboolean
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
352 msim_send_zap(MsimSession *session, const gchar *username, guint code)
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
353 {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
354 gchar *zap_string;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
355 #ifndef MSIM_USE_ATTENTION_API
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
356 gchar *zap_description;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
357 #endif
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
358 GList *types;
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
359 MsimAttentionType *attn;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
360 gboolean rc;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
361
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
362 g_return_val_if_fail(session != NULL, FALSE);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
363 g_return_val_if_fail(username != NULL, FALSE);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
364
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
365 types = msim_attention_types(session->account);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
366
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
367 attn = g_list_nth_data(types, code);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
368 if (!attn) {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
369 return FALSE;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
370 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
371
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
372
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
373 #ifdef MSIM_USE_ATTENTION_API
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
374 serv_got_attention(session->gc, username, attn, FALSE);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
375 #else
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
376 zap_description = g_strdup_printf("*** Attention: %s %s ***", attn->outgoing_description,
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
377 username);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
378
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
379 serv_got_im(session->gc, username, zap_description,
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
380 PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_SYSTEM, time(NULL));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
381
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
382 g_free(zap_description);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
383 #endif
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
384
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
385 /* Construct and send the actual zap command. */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
386 zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", code);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
387
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
388 if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION)) {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
389 purple_debug_info("msim_send_zap_from_menu", "msim_send_bm failed: zapping %s with %s",
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
390 username, zap_string);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
391 rc = FALSE;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
392 } else {
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
393 rc = TRUE;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
394 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
395
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
396 g_free(zap_string);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
397
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
398 return rc;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
399
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
400 }
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
401
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
402 /** Zap someone. Callback from msim_blist_node_menu zap menu. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
403 static void
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
404 msim_send_zap_from_menu(PurpleBlistNode *node, gpointer zap_num_ptr)
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
405 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
406 PurpleBuddy *buddy;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
407 PurpleAccount *account;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
408 PurpleConnection *gc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
409 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
410 guint zap;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
411
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
412 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
413 /* Only know about buddies for now. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
414 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
415 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
416
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
417 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
418
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
419 buddy = (PurpleBuddy *)node;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
420
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
421 /* Find the session */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
422 account = buddy->account;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
423 gc = purple_account_get_connection(account);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
424 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
425
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
426 zap = GPOINTER_TO_INT(zap_num_ptr);
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
427
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
428 g_return_if_fail(msim_send_zap(session, buddy->name, zap));
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
429 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
430
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
431
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
432 /** Return menu, if any, for a buddy list node. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
433 GList *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
434 msim_blist_node_menu(PurpleBlistNode *node)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
435 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
436 GList *menu, *zap_menu;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
437 GList *types;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
438 PurpleMenuAction *act;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
439 /* Warning: hardcoded to match that in msim_attention_types. */
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
440 const gchar *zap_names[10];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
441 guint i;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
442
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
443 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
444 /* Only know about buddies for now. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
445 return NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
446 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
447
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
448 /* Names from official client. */
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
449 types = msim_attention_types(NULL);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
450 i = 0;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
451 do
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
452 {
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
453 MsimAttentionType *attn;
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
454
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
455 attn = (MsimAttentionType *)types->data;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
456 zap_names[i] = attn->description;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
457 ++i;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
458 } while ((types = g_list_next(types)));
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
459
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
460 menu = zap_menu = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
461
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
462 /* TODO: get rid of once is accessible directly in GUI */
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
463 for (i = 0; i < sizeof(zap_names) / sizeof(zap_names[0]); ++i) {
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
464 act = purple_menu_action_new(zap_names[i], PURPLE_CALLBACK(msim_send_zap_from_menu),
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
465 GUINT_TO_POINTER(i), NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
466 zap_menu = g_list_append(zap_menu, act);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
467 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
468
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
469 act = purple_menu_action_new(_("Zap"), NULL, NULL, zap_menu);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
470 menu = g_list_append(menu, act);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
471
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
472 return menu;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
473 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
474
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
475 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
476 * Return the icon name for a buddy and account.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
477 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
478 * @param acct The account to find the icon for, or NULL for protocol icon.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
479 * @param buddy The buddy to find the icon for, or NULL for the account icon.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
480 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
481 * @return The base icon name string.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
482 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
483 const gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
484 msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
485 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
486 /* Use a MySpace icon submitted by hbons at
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
487 * http://developer.pidgin.im/wiki/MySpaceIM. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
488 return "myspace";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
489 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
490
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
491 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
492 * Replace 'old' with 'new' in 'str'.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
493 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
494 * @param str The original string.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
495 * @param old The substring of 'str' to replace.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
496 * @param new The replacement for 'old' within 'str'.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
497 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
498 * @return A _new_ string, based on 'str', with 'old' replaced
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
499 * by 'new'. Must be g_free()'d by caller.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
500 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
501 * This string replace method is based on
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
502 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
503 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
504 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
505 gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
506 str_replace(const gchar *str, const gchar *old, const gchar *new)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
507 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
508 gchar **items;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
509 gchar *ret;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
510
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
511 items = g_strsplit(str, old, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
512 ret = g_strjoinv(new, items);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
513 g_free(items);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
514 return ret;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
515 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
516
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
517 #ifdef MSIM_DEBUG_MSG
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
518 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
519 print_hash_item(gpointer key, gpointer value, gpointer user_data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
520 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
521 purple_debug_info("msim", "%s=%s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
522 key ? (gchar *)key : "(NULL)",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
523 value ? (gchar *)value : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
524 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
525 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
526
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
527 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
528 * Send raw data (given as a NUL-terminated string) to the server.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
529 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
530 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
531 * @param msg The raw data to send, in a NUL-terminated string.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
532 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
533 * @return TRUE if succeeded, FALSE if not.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
534 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
535 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
536 gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
537 msim_send_raw(MsimSession *session, const gchar *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
538 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
539 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
540 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
541
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
542 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
543
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
544 return msim_send_really_raw(session->gc, msg, strlen(msg)) ==
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
545 strlen(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
546 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
547
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
548 /** Send raw data to the server, possibly with embedded NULs.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
549 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
550 * Used in prpl_info struct, so that plugins can have the most possible
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
551 * control of what is sent over the connection. Inside this prpl,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
552 * msim_send_raw() is used, since it sends NUL-terminated strings (easier).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
553 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
554 * @param gc PurpleConnection
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
555 * @param buf Buffer to send
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
556 * @param total_bytes Size of buffer to send
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
557 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
558 * @return Bytes successfully sent, or -1 on error.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
559 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
560 static int
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
561 msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
562 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
563 int total_bytes_sent;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
564 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
565
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
566 g_return_val_if_fail(gc != NULL, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
567 g_return_val_if_fail(buf != NULL, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
568 g_return_val_if_fail(total_bytes >= 0, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
569
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
570 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
571
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
572 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
573
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
574 /* Loop until all data is sent, or a failure occurs. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
575 total_bytes_sent = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
576 do {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
577 int bytes_sent;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
578
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
579 bytes_sent = send(session->fd, buf + total_bytes_sent,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
580 total_bytes - total_bytes_sent, 0);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
581
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
582 if (bytes_sent < 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
583 purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
584 buf, g_strerror(errno));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
585 return total_bytes_sent;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
586 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
587 total_bytes_sent += bytes_sent;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
588
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
589 } while(total_bytes_sent < total_bytes);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
590
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
591 return total_bytes_sent;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
592 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
593
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
594
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
595 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
596 * Start logging in to the MSIM servers.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
597 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
598 * @param acct Account information to use to login.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
599 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
600 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
601 msim_login(PurpleAccount *acct)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
602 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
603 PurpleConnection *gc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
604 const gchar *host;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
605 int port;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
606
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
607 g_return_if_fail(acct != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
608 g_return_if_fail(acct->username != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
609
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
610 purple_debug_info("msim", "logging in %s\n", acct->username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
611
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
612 gc = purple_account_get_connection(acct);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
613 gc->proto_data = msim_session_new(acct);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
614 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
615
19247
44b9e41bde2a No longer check the length of passwords - instead, pass the password to the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19246
diff changeset
616 #ifdef MSIM_MAX_PASSWORD_LENGTH
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
617 /* Passwords are limited in length. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
618 if (strlen(acct->password) > MSIM_MAX_PASSWORD_LENGTH) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
619 gchar *str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
620
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
621 str = g_strdup_printf(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
622 _("Sorry, passwords over %d characters in length (yours is "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
623 "%d) are not supported by MySpace."),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
624 MSIM_MAX_PASSWORD_LENGTH,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
625 (int)strlen(acct->password));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
626
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
627 /* Notify an error message also, because this is important! */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
628 purple_notify_error(acct, g_strdup(_("MySpaceIM Error")), str, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
629
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
630 purple_connection_error(gc, str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
631
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
632 g_free(str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
633 }
19247
44b9e41bde2a No longer check the length of passwords - instead, pass the password to the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19246
diff changeset
634 #endif
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
635
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
636 /* 1. connect to server */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
637 purple_connection_update_progress(gc, _("Connecting"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
638 0, /* which connection step this is */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
639 4); /* total number of steps */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
640
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
641 host = purple_account_get_string(acct, "server", MSIM_SERVER);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
642 port = purple_account_get_int(acct, "port", MSIM_PORT);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
643
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
644 /* From purple.sf.net/api:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
645 * """Note that this function name can be misleading--although it is called
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
646 * "proxy connect," it is used for establishing any outgoing TCP connection,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
647 * whether through a proxy or not.""" */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
648
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
649 /* Calls msim_connect_cb when connected. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
650 if (!purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
651 /* TODO: try other ports if in auto mode, then save
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
652 * working port and try that first next time. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
653 purple_connection_error(gc, _("Couldn't create socket"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
654 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
655 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
656 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
657
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
658 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
659 * Process a login challenge, sending a response.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
660 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
661 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
662 * @param msg Login challenge message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
663 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
664 * @return TRUE if successful, FALSE if not
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
665 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
666 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
667 msim_login_challenge(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
668 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
669 PurpleAccount *account;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
670 const gchar *response;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
671 guint response_len;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
672 gchar *nc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
673 gsize nc_len;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
674
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
675 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
676 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
677
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
678 g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
679
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
680 account = session->account;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
681
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
682 g_return_val_if_fail(account != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
683
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
684 purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
685
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
686 purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
687
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
688 if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
689 purple_debug_info("msim", "bad nc length: %x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
690 purple_connection_error(session->gc, _("Unexpected challenge length from server"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
691 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
692 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
693
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
694 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
695
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
696 response_len = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
697 response = msim_compute_login_response(nc, account->username, account->password, &response_len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
698
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
699 g_free(nc);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
700
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
701 return msim_send(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
702 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
703 /* This is actually user's email address. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
704 "username", MSIM_TYPE_STRING, g_strdup(account->username),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
705 /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
706 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
707 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
708 "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
709 "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
710 "reconn", MSIM_TYPE_INTEGER, 0,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
711 "status", MSIM_TYPE_INTEGER, 100,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
712 "id", MSIM_TYPE_INTEGER, 1,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
713 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
714 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
715
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
716 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
717 * Compute the base64'd login challenge response based on username, password, nonce, and IPs.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
718 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
719 * @param nonce The base64 encoded nonce ('nc') field from the server.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
720 * @param email User's email address (used as login name).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
721 * @param password User's cleartext password.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
722 * @param response_len Will be written with response length.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
723 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
724 * @return Binary login challenge response, ready to send to the server.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
725 * Must be g_free()'d when finished. NULL if error.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
726 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
727 static const gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
728 msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE],
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
729 const gchar *email, const gchar *password, guint *response_len)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
730 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
731 PurpleCipherContext *key_context;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
732 PurpleCipher *sha1;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
733 PurpleCipherContext *rc4;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
734
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
735 guchar hash_pw[HASH_SIZE];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
736 guchar key[HASH_SIZE];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
737 gchar *password_utf16le, *password_utf8_lc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
738 guchar *data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
739 guchar *data_out;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
740 size_t data_len, data_out_len;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
741 gsize conv_bytes_read, conv_bytes_written;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
742 GError *conv_error;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
743 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
744 int i;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
745 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
746
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
747 g_return_val_if_fail(nonce != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
748 g_return_val_if_fail(email != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
749 g_return_val_if_fail(password != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
750 g_return_val_if_fail(response_len != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
751
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
752 /* Convert password to lowercase (required for passwords containing
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
753 * uppercase characters). MySpace passwords are lowercase,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
754 * see ticket #2066. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
755 password_utf8_lc = g_utf8_strdown(password, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
756
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
757 /* Convert ASCII password to UTF16 little endian */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
758 purple_debug_info("msim", "converting password to UTF-16LE\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
759 conv_error = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
760 password_utf16le = g_convert(password_utf8_lc, -1, "UTF-16LE", "UTF-8",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
761 &conv_bytes_read, &conv_bytes_written, &conv_error);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
762 g_free(password_utf8_lc);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
763
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
764 g_return_val_if_fail(conv_bytes_read == strlen(password), NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
765
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
766 if (conv_error != NULL) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
767 purple_debug_error("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
768 "g_convert password UTF8->UTF16LE failed: %s",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
769 conv_error->message);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
770 g_error_free(conv_error);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
771 return NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
772 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
773
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
774 /* Compute password hash */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
775 purple_cipher_digest_region("sha1", (guchar *)password_utf16le,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
776 conv_bytes_written, sizeof(hash_pw), hash_pw, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
777 g_free(password_utf16le);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
778
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
779 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
780 purple_debug_info("msim", "pwhash = ");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
781 for (i = 0; i < sizeof(hash_pw); i++)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
782 purple_debug_info("msim", "%.2x ", hash_pw[i]);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
783 purple_debug_info("msim", "\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
784 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
785
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
786 /* key = sha1(sha1(pw) + nonce2) */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
787 sha1 = purple_ciphers_find_cipher("sha1");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
788 key_context = purple_cipher_context_new(sha1, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
789 purple_cipher_context_append(key_context, hash_pw, HASH_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
790 purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
791 purple_cipher_context_digest(key_context, sizeof(key), key, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
792
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
793 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
794 purple_debug_info("msim", "key = ");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
795 for (i = 0; i < sizeof(key); i++) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
796 purple_debug_info("msim", "%.2x ", key[i]);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
797 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
798 purple_debug_info("msim", "\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
799 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
800
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
801 rc4 = purple_cipher_context_new_by_name("rc4", NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
802
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
803 /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
804 * but only first 0x10 used for the RC4 key. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
805 purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
806 purple_cipher_context_set_key(rc4, key);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
807
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
808 /* TODO: obtain IPs of network interfaces */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
809
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
810 /* rc4 encrypt:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
811 * nonce1+email+IP list */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
812
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
813 data_len = NONCE_SIZE + strlen(email) + MSIM_LOGIN_IP_LIST_LEN;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
814 data = g_new0(guchar, data_len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
815 memcpy(data, nonce, NONCE_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
816 memcpy(data + NONCE_SIZE, email, strlen(email));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
817 memcpy(data + NONCE_SIZE + strlen(email), MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
818
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
819 data_out = g_new0(guchar, data_len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
820
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
821 purple_cipher_context_encrypt(rc4, (const guchar *)data,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
822 data_len, data_out, &data_out_len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
823 purple_cipher_context_destroy(rc4);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
824
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
825 g_assert(data_out_len == data_len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
826
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
827 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
828 purple_debug_info("msim", "response=<%s>\n", data_out);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
829 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
830
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
831 *response_len = data_out_len;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
832
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
833 return (const gchar *)data_out;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
834 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
835
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
836 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
837 * Schedule an IM to be sent once the user ID is looked up.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
838 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
839 * @param gc Connection.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
840 * @param who A user id, email, or username to send the message to.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
841 * @param message Instant message text to send.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
842 * @param flags Flags.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
843 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
844 * @return 1 if successful or postponed, -1 if failed
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
845 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
846 * Allows sending to a user by username, email address, or userid. If
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
847 * a username or email address is given, the userid must be looked up.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
848 * This function does that by calling msim_postprocess_outgoing().
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
849 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
850 int
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
851 msim_send_im(PurpleConnection *gc, const gchar *who, const gchar *message,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
852 PurpleMessageFlags flags)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
853 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
854 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
855 gchar *message_msim;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
856 int rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
857
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
858 g_return_val_if_fail(gc != NULL, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
859 g_return_val_if_fail(who != NULL, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
860 g_return_val_if_fail(message != NULL, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
861
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
862 /* 'flags' has many options, not used here. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
863
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
864 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
865
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
866 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
867
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
868 message_msim = html_to_msim_markup(session, message);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
869
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
870 if (msim_send_bm(session, who, message_msim, MSIM_BM_INSTANT)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
871 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
872 * return 1 even if the message could not be sent, since I don't know if
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
873 * it has failed yet--because the IM is only sent after the userid is
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
874 * retrieved from the server (which happens after this function returns).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
875 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
876 /* TODO: maybe if message is delayed, don't echo to conv window,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
877 * but do echo it to conv window manually once it is actually
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
878 * sent? Would be complicated. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
879 rc = 1;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
880 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
881 rc = -1;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
882 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
883
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
884 g_free(message_msim);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
885
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
886 /*
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
887 * In MySpace, you login with your email address, but don't talk to other
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
888 * users using their email address. So there is currently an asymmetry in the
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
889 * IM windows when using this plugin:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
890 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
891 * you@example.com: hello
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
892 * some_other_user: what's going on?
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
893 * you@example.com: just coding a prpl
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
894 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
895 * TODO: Make the sent IM's appear as from the user's username, instead of
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
896 * their email address. Purple uses the login (in MSIM, the email)--change this.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
897 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
898
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
899 return rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
900 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
901
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
902 /** Send a buddy message of a given type.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
903 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
904 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
905 * @param who Username to send message to.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
906 * @param text Message text to send. Not freed; will be copied.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
907 * @param type A MSIM_BM_* constant.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
908 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
909 * @return TRUE if success, FALSE if fail.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
910 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
911 * Buddy messages ('bm') include instant messages, action messages, status messages, etc.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
912 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
913 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
914 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
915 msim_send_bm(MsimSession *session, const gchar *who, const gchar *text,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
916 int type)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
917 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
918 gboolean rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
919 MsimMessage *msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
920 const gchar *from_username;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
921
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
922 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
923 g_return_val_if_fail(who != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
924 g_return_val_if_fail(text != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
925
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
926 from_username = session->account->username;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
927
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
928 g_return_val_if_fail(from_username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
929
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
930 purple_debug_info("msim", "sending %d message from %s to %s: %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
931 type, from_username, who, text);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
932
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
933 msg = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
934 "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
935 "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
936 /* 't' will be inserted here */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
937 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
938 "msg", MSIM_TYPE_STRING, g_strdup(text),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
939 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
940
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
941 rc = msim_postprocess_outgoing(session, msg, who, "t", "cv");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
942
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
943 msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
944
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
945 return rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
946 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
947
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
948 /* Indexes of this array + 1 map HTML font size to scale of normal font size. *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
949 * Based on _point_sizes from libpurple/gtkimhtml.c
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
950 * 1 2 3 4 5 6 7 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
951 static gdouble _font_scale[] = { .85, .95, 1, 1.2, 1.44, 1.728, 2.0736 };
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
952
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
953 #define MAX_FONT_SIZE 7 /* Purple maximum font size */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
954 #define POINTS_PER_INCH 72 /* How many pt's in an inch */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
955
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
956 /** Convert typographical font point size to HTML font size.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
957 * Based on libpurple/gtkimhtml.c */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
958 static guint
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
959 msim_point_to_purple_size(MsimSession *session, guint point)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
960 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
961 guint size, this_point, base;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
962 gdouble scale;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
963
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
964 base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
965
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
966 for (size = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
967 size < sizeof(_font_scale) / sizeof(_font_scale[0]);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
968 ++size) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
969 scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
970 this_point = (guint)msim_round(scale * base);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
971
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
972 if (this_point >= point) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
973 purple_debug_info("msim", "msim_point_to_purple_size: %d pt -> size=%d\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
974 point, size);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
975 return size;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
976 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
977 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
978
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
979 /* No HTML font size was this big; return largest possible. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
980 return this_point;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
981 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
982
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
983 /** Convert HTML font size to point size. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
984 static guint
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
985 msim_purple_size_to_point(MsimSession *session, guint size)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
986 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
987 gdouble scale;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
988 guint point;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
989 guint base;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
990
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
991 scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
992
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
993 base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
994
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
995 point = (guint)msim_round(scale * base);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
996
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
997 purple_debug_info("msim", "msim_purple_size_to_point: size=%d -> %d pt\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
998 size, point);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
999
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1000 return point;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1001 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1002
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1003 /** Convert a msim markup font pixel height to the more usual point size, for incoming messages. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1004 static guint
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1005 msim_height_to_point(MsimSession *session, guint height)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1006 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1007 guint dpi;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1008
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1009 dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1010
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1011 return (guint)msim_round((POINTS_PER_INCH * 1. / dpi) * height);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1012
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1013 /* See also: libpurple/protocols/bonjour/jabber.c
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1014 * _font_size_ichat_to_purple */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1015 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1016
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1017 /** Convert point size to msim pixel height font size specification, for outgoing messages. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1018 static guint
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1019 msim_point_to_height(MsimSession *session, guint point)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1020 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1021 guint dpi;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1022
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1023 dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1024
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1025 return (guint)msim_round((dpi * 1. / POINTS_PER_INCH) * point);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1026 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1027
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1028 /** Convert the msim markup <f> (font) tag into HTML. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1029 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1030 msim_markup_f_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1031 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1032 const gchar *face, *height_str, *decor_str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1033 GString *gs_end, *gs_begin;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1034 guint decor, height;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1035
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1036 face = xmlnode_get_attrib(root, "f");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1037 height_str = xmlnode_get_attrib(root, "h");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1038 decor_str = xmlnode_get_attrib(root, "s");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1039
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1040 if (height_str) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1041 height = atol(height_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1042 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1043 height = 12;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1044 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1045
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1046 if (decor_str) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1047 decor = atol(decor_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1048 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1049 decor = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1050 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1051
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1052 gs_begin = g_string_new("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1053 /* TODO: get font size working */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1054 if (height && !face) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1055 g_string_printf(gs_begin, "<font size='%d'>",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1056 msim_point_to_purple_size(session, msim_height_to_point(session, height)));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1057 } else if (height && face) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1058 g_string_printf(gs_begin, "<font face='%s' size='%d'>", face,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1059 msim_point_to_purple_size(session, msim_height_to_point(session, height)));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1060 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1061 g_string_printf(gs_begin, "<font>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1062 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1063
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1064 /* No support for font-size CSS? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1065 /* g_string_printf(gs_begin, "<span style='font-family: %s; font-size: %dpt'>", face,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1066 msim_height_to_point(height)); */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1067
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1068 gs_end = g_string_new("</font>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1069
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1070 if (decor & MSIM_TEXT_BOLD) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1071 g_string_append(gs_begin, "<b>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1072 g_string_prepend(gs_end, "</b>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1073 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1074
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1075 if (decor & MSIM_TEXT_ITALIC) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1076 g_string_append(gs_begin, "<i>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1077 g_string_append(gs_end, "</i>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1078 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1079
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1080 if (decor & MSIM_TEXT_UNDERLINE) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1081 g_string_append(gs_begin, "<u>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1082 g_string_append(gs_end, "</u>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1083 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1084
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1085
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1086 *begin = gs_begin->str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1087 *end = gs_end->str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1088 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1089
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1090 /** Convert a msim markup color to a color suitable for libpurple.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1091 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1092 * @param msim Either a color name, or an rgb(x,y,z) code.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1093 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1094 * @return A new string, either a color name or #rrggbb code. Must g_free().
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1095 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1096 static char *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1097 msim_color_to_purple(const char *msim)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1098 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1099 guint red, green, blue;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1100
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1101 if (!msim) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1102 return g_strdup("black");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1103 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1104
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1105 if (sscanf(msim, "rgb(%d,%d,%d)", &red, &green, &blue) != 3) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1106 /* Color name. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1107 return g_strdup(msim);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1108 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1109 /* TODO: rgba (alpha). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1110
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1111 return g_strdup_printf("#%.2x%.2x%.2x", red, green, blue);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1112 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1113
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1114 /** Convert the msim markup <a> (anchor) tag into HTML. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1115 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1116 msim_markup_a_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1117 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1118 const gchar *href;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1119
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1120 href = xmlnode_get_attrib(root, "h");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1121 if (!href) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1122 href = "";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1123 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1124
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1125 *begin = g_strdup_printf("<a href=\"%s\">%s", href, href);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1126 *end = g_strdup("</a>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1127 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1128
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1129 /** Convert the msim markup <p> (paragraph) tag into HTML. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1130 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1131 msim_markup_p_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1132 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1133 /* Just pass through unchanged.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1134 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1135 * Note: attributes currently aren't passed, if there are any. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1136 *begin = g_strdup("<p>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1137 *end = g_strdup("</p>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1138 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1139
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1140 /** Convert the msim markup <c> tag (text color) into HTML. TODO: Test */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1141 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1142 msim_markup_c_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1143 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1144 const gchar *color;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1145 gchar *purple_color;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1146
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1147 color = xmlnode_get_attrib(root, "v");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1148 if (!color) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1149 purple_debug_info("msim", "msim_markup_c_to_html: <c> tag w/o v attr");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1150 *begin = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1151 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1152 /* TODO: log as unrecognized */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1153 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1154 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1155
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1156 purple_color = msim_color_to_purple(color);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1157
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1158 *begin = g_strdup_printf("<font color='%s'>", purple_color);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1159
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1160 g_free(purple_color);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1161
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1162 /* *begin = g_strdup_printf("<span style='color: %s'>", color); */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1163 *end = g_strdup("</font>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1164 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1165
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1166 /** Convert the msim markup <b> tag (background color) into HTML. TODO: Test */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1167 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1168 msim_markup_b_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1169 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1170 const gchar *color;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1171 gchar *purple_color;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1172
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1173 color = xmlnode_get_attrib(root, "v");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1174 if (!color) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1175 *begin = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1176 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1177 purple_debug_info("msim", "msim_markup_b_to_html: <b> w/o v attr");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1178 /* TODO: log as unrecognized. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1179 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1180 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1181
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1182 purple_color = msim_color_to_purple(color);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1183
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1184 /* TODO: find out how to set background color. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1185 *begin = g_strdup_printf("<span style='background-color: %s'>",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1186 purple_color);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1187 g_free(purple_color);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1188
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1189 *end = g_strdup("</p>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1190 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1191
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1192 /** Convert the msim markup <i> tag (emoticon image) into HTML. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1193 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1194 msim_markup_i_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1195 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1196 const gchar *name;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1197 guint i;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1198 struct MSIM_EMOTICON *emote;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1199
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1200 name = xmlnode_get_attrib(root, "n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1201 if (!name) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1202 purple_debug_info("msim", "msim_markup_i_to_html: <i> w/o n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1203 *begin = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1204 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1205 /* TODO: log as unrecognized */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1206 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1207 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1208
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1209 /* Find and use canonical form of smiley symbol. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1210 for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1211 if (!strcmp(name, emote->name)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1212 *begin = g_strdup(emote->symbol);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1213 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1214 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1215 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1216 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1217
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1218 /* Couldn't find it, sorry. Try to degrade gracefully. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1219 *begin = g_strdup_printf("**%s**", name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1220 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1221 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1222
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1223 /** Convert an individual msim markup tag to HTML. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1224 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1225 msim_markup_tag_to_html(MsimSession *session, xmlnode *root, gchar **begin,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1226 gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1227 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1228 if (!strcmp(root->name, "f")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1229 msim_markup_f_to_html(session, root, begin, end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1230 } else if (!strcmp(root->name, "a")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1231 msim_markup_a_to_html(session, root, begin, end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1232 } else if (!strcmp(root->name, "p")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1233 msim_markup_p_to_html(session, root, begin, end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1234 } else if (!strcmp(root->name, "c")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1235 msim_markup_c_to_html(session, root, begin, end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1236 } else if (!strcmp(root->name, "b")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1237 msim_markup_b_to_html(session, root, begin, end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1238 } else if (!strcmp(root->name, "i")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1239 msim_markup_i_to_html(session, root, begin, end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1240 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1241 purple_debug_info("msim", "msim_markup_tag_to_html: "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1242 "unknown tag name=%s, ignoring",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1243 (root && root->name) ? root->name : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1244 *begin = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1245 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1246 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1247 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1248
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1249 /** Convert an individual HTML tag to msim markup. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1250 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1251 html_tag_to_msim_markup(MsimSession *session, xmlnode *root, gchar **begin,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1252 gchar **end)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1253 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1254 /* TODO: Coalesce nested tags into one <f> tag!
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1255 * Currently, the 's' value will be overwritten when b/i/u is nested
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1256 * within another one, and only the inner-most formatting will be
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1257 * applied to the text. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1258 if (!purple_utf8_strcasecmp(root->name, "root")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1259 *begin = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1260 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1261 } else if (!purple_utf8_strcasecmp(root->name, "b")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1262 *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_BOLD);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1263 *end = g_strdup("</f>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1264 } else if (!purple_utf8_strcasecmp(root->name, "i")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1265 *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_ITALIC);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1266 *end = g_strdup("</f>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1267 } else if (!purple_utf8_strcasecmp(root->name, "u")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1268 *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_UNDERLINE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1269 *end = g_strdup("</f>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1270 } else if (!purple_utf8_strcasecmp(root->name, "a")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1271 const gchar *href, *link_text;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1272
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1273 href = xmlnode_get_attrib(root, "href");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1274
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1275 if (!href) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1276 href = xmlnode_get_attrib(root, "HREF");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1277 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1278
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1279 link_text = xmlnode_get_data(root);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1280
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1281 if (href) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1282 if (!strcmp(link_text, href)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1283 /* Purple gives us: <a href="URL">URL</a>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1284 * Translate to <a h='URL' />
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1285 * Displayed as text of URL with link to URL
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1286 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1287 *begin = g_strdup_printf("<a h='%s' />", href);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1288 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1289 /* But if we get: <a href="URL">text</a>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1290 * Translate to: text: <a h='URL' />
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1291 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1292 * Because official client only supports self-closed <a>
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1293 * tags; you can't change the link text.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1294 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1295 *begin = g_strdup_printf("%s: <a h='%s' />", link_text, href);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1296 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1297 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1298 *begin = g_strdup("<a />");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1299 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1300
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1301 /* Sorry, kid. MySpace doesn't support you within <a> tags. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1302 xmlnode_free(root->child);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1303 root->child = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1304
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1305 *end = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1306 } else if (!purple_utf8_strcasecmp(root->name, "font")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1307 const gchar *size;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1308 const gchar *face;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1309
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1310 size = xmlnode_get_attrib(root, "size");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1311 face = xmlnode_get_attrib(root, "face");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1312
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1313 if (face && size) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1314 *begin = g_strdup_printf("<f f='%s' h='%d'>", face,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1315 msim_point_to_height(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1316 msim_purple_size_to_point(session, atoi(size))));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1317 } else if (face) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1318 *begin = g_strdup_printf("<f f='%s'>", face);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1319 } else if (size) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1320 *begin = g_strdup_printf("<f h='%d'>",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1321 msim_point_to_height(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1322 msim_purple_size_to_point(session, atoi(size))));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1323 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1324 *begin = g_strdup("<f>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1325 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1326
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1327 *end = g_strdup("</f>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1328
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1329 /* TODO: color (bg uses <body>), emoticons */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1330 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1331 *begin = g_strdup_printf("[%s]", root->name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1332 *end = g_strdup_printf("[/%s]", root->name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1333 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1334 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1335
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1336 /** Convert an xmlnode of msim markup or HTML to an HTML string or msim markup.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1337 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1338 * @param f Function to convert tags.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1339 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1340 * @return An HTML string. Caller frees.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1341 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1342 static gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1343 msim_convert_xmlnode(MsimSession *session, xmlnode *root, MSIM_XMLNODE_CONVERT f)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1344 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1345 xmlnode *node;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1346 gchar *begin, *inner, *end;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1347 GString *final;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1348
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1349 if (!root || !root->name) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1350 return g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1351 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1352
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1353 purple_debug_info("msim", "msim_convert_xmlnode: got root=%s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1354 root->name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1355
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1356 begin = inner = end = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1357
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1358 final = g_string_new("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1359
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1360 f(session, root, &begin, &end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1361
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1362 g_string_append(final, begin);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1363
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1364 /* Loop over all child nodes. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1365 for (node = root->child; node != NULL; node = node->next) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1366 switch (node->type) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1367 case XMLNODE_TYPE_ATTRIB:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1368 /* Attributes handled above. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1369 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1370
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1371 case XMLNODE_TYPE_TAG:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1372 /* A tag or tag with attributes. Recursively descend. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1373 inner = msim_convert_xmlnode(session, node, f);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1374 g_return_val_if_fail(inner != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1375
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1376 purple_debug_info("msim", " ** node name=%s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1377 (node && node->name) ? node->name : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1378 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1379
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1380 case XMLNODE_TYPE_DATA:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1381 /* Literal text. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1382 inner = g_new0(char, node->data_sz + 1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1383 strncpy(inner, node->data, node->data_sz);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1384 inner[node->data_sz] = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1385
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1386 purple_debug_info("msim", " ** node data=%s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1387 inner ? inner : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1388 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1389
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1390 default:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1391 purple_debug_info("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1392 "msim_convert_xmlnode: strange node\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1393 inner = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1394 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1395
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1396 if (inner) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1397 g_string_append(final, inner);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1398 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1399 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1400
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1401 /* TODO: Note that msim counts each piece of text enclosed by <f> as
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1402 * a paragraph and will display each on its own line. You actually have
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1403 * to _nest_ <f> tags to intersperse different text in one paragraph!
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1404 * Comment out this line below to see. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1405 g_string_append(final, end);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1406
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1407 purple_debug_info("msim", "msim_markup_xmlnode_to_gtkhtml: RETURNING %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1408 (final && final->str) ? final->str : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1409
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1410 return final->str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1411 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1412
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1413 /** Convert XML to something based on MSIM_XMLNODE_CONVERT. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1414 static gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1415 msim_convert_xml(MsimSession *session, const gchar *raw, MSIM_XMLNODE_CONVERT f)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1416 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1417 xmlnode *root;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1418 gchar *str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1419 gchar *enclosed_raw;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1420
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1421 g_return_val_if_fail(raw != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1422
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1423 /* Enclose text in one root tag, to try to make it valid XML for parsing. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1424 enclosed_raw = g_strconcat("<root>", raw, "</root>", NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1425
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1426 root = xmlnode_from_str(enclosed_raw, -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1427
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1428 if (!root) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1429 purple_debug_info("msim", "msim_markup_to_html: couldn't parse "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1430 "%s as XML, returning raw: %s\n", enclosed_raw, raw);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1431 /* TODO: msim_unrecognized */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1432 g_free(enclosed_raw);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1433 return g_strdup(raw);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1434 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1435
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1436 g_free(enclosed_raw);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1437
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1438 str = msim_convert_xmlnode(session, root, f);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1439 g_return_val_if_fail(str != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1440 purple_debug_info("msim", "msim_markup_to_html: returning %s\n", str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1441
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1442 xmlnode_free(root);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1443
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1444 return str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1445 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1446
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1447 /** Convert plaintext smileys to <i> markup tags.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1448 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1449 * @param before Original text with ASCII smileys. Will be freed.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1450 * @return A new string with <i> tags, if applicable. Must be g_free()'d.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1451 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1452 static gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1453 msim_convert_smileys_to_markup(gchar *before)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1454 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1455 gchar *old, *new, *replacement;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1456 guint i;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1457 struct MSIM_EMOTICON *emote;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1458
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1459 old = before;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1460 new = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1461
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1462 for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1463 gchar *name, *symbol;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1464
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1465 name = emote->name;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1466 symbol = emote->symbol;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1467
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1468 replacement = g_strdup_printf("<i n=\"%s\"/>", name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1469
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1470 purple_debug_info("msim", "msim_convert_smileys_to_markup: %s->%s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1471 symbol ? symbol : "(NULL)",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1472 replacement ? replacement : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1473 new = str_replace(old, symbol, replacement);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1474
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1475 g_free(replacement);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1476 g_free(old);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1477
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1478 old = new;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1479 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1480
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1481 return new;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1482 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1483
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1484
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1485 /** High-level function to convert MySpaceIM markup to Purple (HTML) markup.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1486 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1487 * @return Purple markup string, must be g_free()'d. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1488 static gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1489 msim_markup_to_html(MsimSession *session, const gchar *raw)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1490 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1491 return msim_convert_xml(session, raw,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1492 (MSIM_XMLNODE_CONVERT)(msim_markup_tag_to_html));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1493 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1494
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1495 /** High-level function to convert Purple (HTML) to MySpaceIM markup.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1496 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1497 * @return HTML markup string, must be g_free()'d. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1498 static gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1499 html_to_msim_markup(MsimSession *session, const gchar *raw)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1500 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1501 gchar *markup;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1502
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1503 markup = msim_convert_xml(session, raw,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1504 (MSIM_XMLNODE_CONVERT)(html_tag_to_msim_markup));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1505
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1506 if (purple_account_get_bool(session->account, "emoticons", TRUE)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1507 /* Frees markup and allocates a new one. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1508 markup = msim_convert_smileys_to_markup(markup);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1509 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1510
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1511 return markup;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1512 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1513
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1514 /** Get the MsimUser from a PurpleBuddy, creating it if needed. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1515 static MsimUser *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1516 msim_get_user_from_buddy(PurpleBuddy *buddy)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1517 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1518 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1519
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1520 if (!buddy) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1521 return NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1522 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1523
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1524 if (!buddy->proto_data) {
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
1525 /* No MsimUser for this buddy; make one. */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
1526
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1527 /* TODO: where is this freed? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1528 user = g_new0(MsimUser, 1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1529 user->buddy = buddy;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1530 buddy->proto_data = (gpointer)user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1531 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1532
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1533 user = (MsimUser *)(buddy->proto_data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1534
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1535 return user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1536 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1537
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1538 /** Find and return an MsimUser * representing a user on the buddy list, or NULL. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1539 static MsimUser *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1540 msim_find_user(MsimSession *session, const gchar *username)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1541 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1542 PurpleBuddy *buddy;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1543 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1544
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1545 buddy = purple_find_buddy(session->account, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1546 if (!buddy) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1547 return NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1548 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1549
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1550 user = msim_get_user_from_buddy(buddy);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1551
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1552 return user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1553 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1554
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1555
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1556 /** Record the client version in the buddy list, from an incoming message. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1557 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1558 msim_incoming_bm_record_cv(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1559 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1560 gchar *username, *cv;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1561 gboolean ret;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1562 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1563
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1564 username = msim_msg_get_string(msg, "_username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1565 cv = msim_msg_get_string(msg, "cv");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1566
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1567 g_return_val_if_fail(username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1568 if (!cv) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1569 /* No client version to record, don't worry about it. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1570 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1571 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1572
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1573 user = msim_find_user(session, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1574
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1575 if (user) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1576 user->client_cv = atol(cv);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1577 ret = TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1578 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1579 ret = FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1580 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1581
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1582 g_free(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1583 g_free(cv);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1584
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1585 return ret;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1586 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1587
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1588 /** Handle an incoming buddy message. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1589 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1590 msim_incoming_bm(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1591 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1592 guint bm;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1593
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1594 bm = msim_msg_get_integer(msg, "bm");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1595
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1596 msim_incoming_bm_record_cv(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1597
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1598 switch (bm) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1599 case MSIM_BM_STATUS:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1600 return msim_incoming_status(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1601 case MSIM_BM_INSTANT:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1602 return msim_incoming_im(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1603 case MSIM_BM_ACTION:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1604 return msim_incoming_action(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1605 case MSIM_BM_MEDIA:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1606 return msim_incoming_media(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1607 case MSIM_BM_UNOFFICIAL_CLIENT:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1608 return msim_incoming_unofficial_client(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1609 default:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1610 /* Not really an IM, but show it for informational
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1611 * purposes during development. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1612 return msim_incoming_im(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1613 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1614 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1615
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1616 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1617 * Handle an incoming instant message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1618 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1619 * @param session The session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1620 * @param msg Message from the server, containing 'f' (userid from) and 'msg'.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1621 * Should also contain username in _username from preprocessing.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1622 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1623 * @return TRUE if successful.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1624 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1625 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1626 msim_incoming_im(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1627 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1628 gchar *username, *msg_msim_markup, *msg_purple_markup;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1629
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1630 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1631 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1632
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1633 username = msim_msg_get_string(msg, "_username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1634 g_return_val_if_fail(username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1635
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1636 msg_msim_markup = msim_msg_get_string(msg, "msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1637 g_return_val_if_fail(msg_msim_markup != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1638
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1639 msg_purple_markup = msim_markup_to_html(session, msg_msim_markup);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1640 g_free(msg_msim_markup);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1641
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1642 serv_got_im(session->gc, username, msg_purple_markup,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1643 PURPLE_MESSAGE_RECV, time(NULL));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1644
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1645 g_free(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1646 g_free(msg_purple_markup);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1647
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1648 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1649 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1650
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1651 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1652 * Process unrecognized information.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1653 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1654 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1655 * @param msg An MsimMessage that was unrecognized, or NULL.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1656 * @param note Information on what was unrecognized, or NULL.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1657 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1658 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1659 msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1660 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1661 /* TODO: Some more context, outwardly equivalent to a backtrace,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1662 * for helping figure out what this msg is for. What was going on?
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1663 * But not too much information so that a user
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1664 * posting this dump reveals confidential information.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1665 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1666
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1667 /* TODO: dump unknown msgs to file, so user can send them to me
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1668 * if they wish, to help add support for new messages (inspired
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1669 * by Alexandr Shutko, who maintains OSCAR protocol documentation). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1670
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1671 purple_debug_info("msim", "Unrecognized data on account for %s\n",
19353
af0e77c44667 MySpace added a new field, LastImageUpdated. Save it in MsimUser.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19352
diff changeset
1672 (session && session->account && session->account->username) ?
af0e77c44667 MySpace added a new field, LastImageUpdated. Save it in MsimUser.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19352
diff changeset
1673 session->account->username : "(NULL)");
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1674 if (note) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1675 purple_debug_info("msim", "(Note: %s)\n", note);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1676 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1677
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1678 if (msg) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1679 msim_msg_dump("Unrecognized message dump: %s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1680 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1681 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1682
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1683 /** Process an incoming zap. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1684 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1685 msim_incoming_zap(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1686 {
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1687 gchar *msg_text, *username;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1688 gint zap;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1689 const gchar *zap_past_tense[10];
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1690 #ifdef MSIM_USE_ATTENTION_API
19244
b29788c6d269 Make msimprpl work without a libpurple attention API.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19243
diff changeset
1691 MsimAttentionType attn;
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1692 #else
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1693 gchar *zap_text;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1694 #endif
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1695
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1696 zap_past_tense[0] = _("zapped");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1697 zap_past_tense[1] = _("whacked");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1698 zap_past_tense[2] = _("torched");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1699 zap_past_tense[3] = _("smooched");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1700 zap_past_tense[4] = _("hugged");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1701 zap_past_tense[5] = _("bslapped");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1702 zap_past_tense[6] = _("goosed");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1703 zap_past_tense[7] = _("hi-fived");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1704 zap_past_tense[8] = _("punk'd");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1705 zap_past_tense[9] = _("raspberried");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1706
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1707 msg_text = msim_msg_get_string(msg, "msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1708 username = msim_msg_get_string(msg, "_username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1709
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1710 g_return_val_if_fail(msg_text != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1711 g_return_val_if_fail(username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1712
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1713 g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1714
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1715 zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0]));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1716
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1717 /* TODO:ZAP: use msim_attention_types */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1718 #ifdef MSIM_USE_ATTENTION_API
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1719 attn.incoming_description = zap_past_tense[zap];
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1720 attn.outgoing_description = NULL;
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1721 attn.icon = NULL; /* TODO: icon */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1722
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1723 serv_got_attention(session->gc, username, &attn, TRUE);
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1724 #else
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1725 zap_text = g_strdup_printf(_("*** You have been %s! ***"), zap_past_tense[zap]);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1726 serv_got_im(session->gc, username, zap_text,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1727 PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, time(NULL));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1728 g_free(zap_text);
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1729 #endif
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
1730
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1731 g_free(msg_text);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1732 g_free(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1733
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1734 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1735 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1736
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1737 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1738 * Handle an incoming action message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1739 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1740 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1741 * @param msg
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1742 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1743 * @return TRUE if successful.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1744 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1745 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1746 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1747 msim_incoming_action(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1748 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1749 gchar *msg_text, *username;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1750 gboolean rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1751
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1752 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1753 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1754
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1755 msg_text = msim_msg_get_string(msg, "msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1756 g_return_val_if_fail(msg_text != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1757
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1758 username = msim_msg_get_string(msg, "_username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1759 g_return_val_if_fail(username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1760
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1761 purple_debug_info("msim", "msim_incoming_action: action <%s> from <%d>\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1762 msg_text, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1763
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1764 if (strcmp(msg_text, "%typing%") == 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1765 /* TODO: find out if msim repeatedly sends typing messages, so we can
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1766 * give it a timeout. Right now, there does seem to be an inordinately
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1767 * amount of time between typing stopped-typing notifications. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1768 serv_got_typing(session->gc, username, 0, PURPLE_TYPING);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1769 rc = TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1770 } else if (strcmp(msg_text, "%stoptyping%") == 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1771 serv_got_typing_stopped(session->gc, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1772 rc = TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1773 } else if (strstr(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1774 rc = msim_incoming_zap(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1775 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1776 msim_unrecognized(session, msg,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1777 "got to msim_incoming_action but unrecognized value for 'msg'");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1778 rc = FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1779 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1780
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1781 g_free(msg_text);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1782 g_free(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1783
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1784 return rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1785 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1786
19351
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
1787 /* Process an incoming media (message background?) message. */
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1788 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1789 msim_incoming_media(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1790 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1791 gchar *username, *text;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1792
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1793 username = msim_msg_get_string(msg, "_username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1794 text = msim_msg_get_string(msg, "msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1795
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1796 g_return_val_if_fail(username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1797 g_return_val_if_fail(text != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1798
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1799 purple_debug_info("msim", "msim_incoming_media: from %s, got msg=%s\n", username, text);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1800
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1801 /* Media messages are sent when the user opens a window to someone.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1802 * Tell libpurple they started typing and stopped typing, to inform the Psychic
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1803 * Mode plugin so it too can open a window to the user. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1804 serv_got_typing(session->gc, username, 0, PURPLE_TYPING);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1805 serv_got_typing_stopped(session->gc, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1806
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1807 g_free(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1808
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1809 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1810 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1811
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1812 /* Process an incoming "unofficial client" message. The plugin for
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1813 * Miranda IM sends this message with the plugin information. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1814 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1815 msim_incoming_unofficial_client(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1816 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1817 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1818 gchar *username, *client_info;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1819
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1820 username = msim_msg_get_string(msg, "_username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1821 client_info = msim_msg_get_string(msg, "msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1822
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1823 g_return_val_if_fail(username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1824 g_return_val_if_fail(client_info != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1825
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1826 purple_debug_info("msim", "msim_incoming_unofficial_client: %s is using client %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1827 username, client_info);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1828
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1829 user = msim_find_user(session, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1830
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1831 g_return_val_if_fail(user != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1832
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1833 if (user->client_info) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1834 g_free(user->client_info);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1835 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1836 user->client_info = client_info;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1837
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1838 g_free(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1839 /* Do not free client_info - the MsimUser now owns it. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1840
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1841 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1842 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1843
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1844
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1845 #ifdef MSIM_SEND_CLIENT_VERSION
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1846 /** Send our client version to another unofficial client that understands it. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1847 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1848 msim_send_unofficial_client(MsimSession *session, gchar *username)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1849 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1850 gchar *our_info;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1851 gboolean ret;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1852
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1853 our_info = g_strdup_printf("Libpurple %d.%d.%d - msimprpl %s",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1854 PURPLE_MAJOR_VERSION,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1855 PURPLE_MINOR_VERSION,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1856 PURPLE_MICRO_VERSION,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1857 MSIM_PRPL_VERSION_STRING);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1858
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1859 ret = msim_send_bm(session, username, our_info, MSIM_BM_UNOFFICIAL_CLIENT);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1860
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1861 return ret;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1862 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1863 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1864
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1865 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1866 * Handle when our user starts or stops typing to another user.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1867 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1868 * @param gc
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1869 * @param name The buddy name to which our user is typing to
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1870 * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1871 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1872 * @return 0
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1873 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1874 unsigned int
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1875 msim_send_typing(PurpleConnection *gc, const gchar *name,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1876 PurpleTypingState state)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1877 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1878 const gchar *typing_str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1879 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1880
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1881 g_return_val_if_fail(gc != NULL, 0);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1882 g_return_val_if_fail(name != NULL, 0);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1883
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1884 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1885
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1886 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1887
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1888 switch (state) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1889 case PURPLE_TYPING:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1890 typing_str = "%typing%";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1891 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1892
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1893 case PURPLE_TYPED:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1894 case PURPLE_NOT_TYPING:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1895 default:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1896 typing_str = "%stoptyping%";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1897 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1898 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1899
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1900 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1901 msim_send_bm(session, name, typing_str, MSIM_BM_ACTION);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1902 return 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1903 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1904
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1905 /** Format the "now playing" indicator, showing the artist and song.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1906 * @return Return a new string (must be g_free()'d), or NULL.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1907 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1908 static gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1909 msim_format_now_playing(gchar *band, gchar *song)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1910 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1911 if ((band && strlen(band)) || (song && strlen(song))) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1912 return g_strdup_printf("%s - %s",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1913 (band && strlen(band)) ? band : "Unknown Artist",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1914 (song && strlen(song)) ? song : "Unknown Song");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1915 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1916 return NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1917 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1918 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1919
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1920 /** Append user information to a PurpleNotifyUserInfo, given an MsimUser.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1921 * Used by msim_tooltip_text() and msim_get_info_cb() to show a user's profile.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1922 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1923 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1924 msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1925 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1926 gchar *str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1927 guint uid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1928 guint cv;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1929
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1930 /* Useful to identify the account the tooltip refers to.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1931 * Other prpls show this. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1932 if (user->username) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1933 purple_notify_user_info_add_pair(user_info, _("User"), user->username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1934 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1935
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1936 uid = purple_blist_node_get_int(&user->buddy->node, "UserID");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1937
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1938 if (full) {
19246
335ebd202a7d Link to profile in get info.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19244
diff changeset
1939 /* TODO: link to username, if available */
335ebd202a7d Link to profile in get info.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19244
diff changeset
1940 purple_notify_user_info_add_pair(user_info, _("Profile"),
335ebd202a7d Link to profile in get info.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19244
diff changeset
1941 g_strdup_printf("<a href=\"http://myspace.com/%d\">http://myspace.com/%d</a>",
335ebd202a7d Link to profile in get info.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19244
diff changeset
1942 uid, uid));
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1943 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1944
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1945
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1946 /* a/s/l...the vitals */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1947 if (user->age) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1948 purple_notify_user_info_add_pair(user_info, _("Age"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1949 g_strdup_printf("%d", user->age));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1950 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1951
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1952 if (user->gender && strlen(user->gender)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1953 purple_notify_user_info_add_pair(user_info, _("Gender"), user->gender);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1954 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1955
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1956 if (user->location && strlen(user->location)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1957 purple_notify_user_info_add_pair(user_info, _("Location"), user->location);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1958 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1959
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1960 /* Other information */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1961 if (user->headline && strlen(user->headline)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1962 purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1963 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1964
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1965 str = msim_format_now_playing(user->band_name, user->song_name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1966 if (str && strlen(str)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1967 purple_notify_user_info_add_pair(user_info, _("Song"), str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1968 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1969
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1970 /* Note: total friends only available if looked up by uid, not username. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1971 if (user->total_friends) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1972 purple_notify_user_info_add_pair(user_info, _("Total Friends"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1973 g_strdup_printf("%d", user->total_friends));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1974 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1975
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1976 if (full) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1977 /* Client information */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1978
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1979 str = user->client_info;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1980 cv = user->client_cv;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1981
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1982 if (str && cv != 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1983 purple_notify_user_info_add_pair(user_info, _("Client Version"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1984 g_strdup_printf("%s (build %d)", str, cv));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1985 } else if (str) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1986 purple_notify_user_info_add_pair(user_info, _("Client Version"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1987 g_strdup(str));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1988 } else if (cv) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1989 purple_notify_user_info_add_pair(user_info, _("Client Version"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1990 g_strdup_printf("Build %d", cv));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1991 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1992 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1993 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1994
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1995 /** Callback for msim_get_info(), for when user info is received. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1996 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1997 msim_get_info_cb(MsimSession *session, MsimMessage *user_info_msg,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1998 gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
1999 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2000 MsimMessage *msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2001 gchar *username;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2002 PurpleNotifyUserInfo *user_info;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2003 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2004 gboolean temporary_user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2005
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2006 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2007
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2008 /* Get user{name,id} from msim_get_info, passed as an MsimMessage for
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2009 orthogonality. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2010 msg = (MsimMessage *)data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2011 g_return_if_fail(msg != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2012
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2013 username = msim_msg_get_string(msg, "user");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2014 if (!username) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2015 purple_debug_info("msim", "msim_get_info_cb: no 'user' in msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2016 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2017 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2018
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2019 msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2020 purple_debug_info("msim", "msim_get_info_cb: got for user: %s\n", username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2021
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2022 user = msim_find_user(session, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2023
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2024 if (!user) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2025 /* User isn't on blist, create a temporary user to store info. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2026 temporary_user = TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2027 user = g_new0(MsimUser, 1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2028 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2029 temporary_user = FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2030 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2031
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2032 /* Update user structure with new information */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2033 msim_store_user_info(session, user_info_msg, user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2034
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2035 user_info = purple_notify_user_info_new();
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2036
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2037 /* Append data from MsimUser to PurpleNotifyUserInfo for display, full */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2038 msim_append_user_info(session, user_info, user, TRUE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2039
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2040 purple_notify_userinfo(session->gc, username, user_info, NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2041 purple_debug_info("msim", "msim_get_info_cb: username=%s\n", username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2042
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2043 purple_notify_user_info_destroy(user_info);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2044 /* TODO: do not free username, since it will be used by user_info? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2045
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2046 if (temporary_user) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2047 g_free(user->client_info);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2048 g_free(user->gender);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2049 g_free(user->location);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2050 g_free(user->headline);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2051 g_free(user->display_name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2052 g_free(user->username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2053 g_free(user->band_name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2054 g_free(user->song_name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2055 g_free(user->image_url);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2056 g_free(user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2057 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2058
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2059 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2060
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2061 /** Retrieve a user's profile.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2062 * @param username Username, user ID, or email address to lookup.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2063 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2064 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2065 msim_get_info(PurpleConnection *gc, const gchar *username)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2066 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2067 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2068 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2069 guint uid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2070 gchar *user_to_lookup;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2071 MsimMessage *user_msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2072
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2073 g_return_if_fail(gc != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2074 g_return_if_fail(username != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2075
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2076 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2077
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2078 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2079
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2080 /* Obtain uid of buddy. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2081 user = msim_find_user(session, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2082
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2083 /* If is on buddy list, lookup by uid since it is faster. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2084 if (user && (uid = purple_blist_node_get_int(&user->buddy->node, "UserID"))) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2085 user_to_lookup = g_strdup_printf("%d", uid);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2086 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2087 /* Looking up buddy not on blist. Lookup by whatever user entered. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2088 user_to_lookup = g_strdup(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2089 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2090
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2091 /* Pass the username to msim_get_info_cb(), because since we lookup
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2092 * by userid, the userinfo message will only contain the uid (not
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2093 * the username) but it would be useful to display the username too.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2094 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2095 user_msg = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2096 "user", MSIM_TYPE_STRING, g_strdup(username),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2097 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2098 purple_debug_info("msim", "msim_get_info, setting up lookup, user=%s\n", username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2099
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2100 msim_lookup_user(session, user_to_lookup, msim_get_info_cb, user_msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2101
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2102 g_free(user_to_lookup);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2103 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2104
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2105 /** Set your status - callback for when user manually sets it. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2106 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2107 msim_set_status(PurpleAccount *account, PurpleStatus *status)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2108 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2109 PurpleStatusType *type;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2110 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2111 guint status_code;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2112 const gchar *statstring;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2113
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2114 session = (MsimSession *)account->gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2115
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2116 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2117
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2118 type = purple_status_get_type(status);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2119
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2120 switch (purple_status_type_get_primitive(type)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2121 case PURPLE_STATUS_AVAILABLE:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2122 purple_debug_info("msim", "msim_set_status: available (%d->%d)\n", PURPLE_STATUS_AVAILABLE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2123 MSIM_STATUS_CODE_ONLINE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2124 status_code = MSIM_STATUS_CODE_ONLINE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2125 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2126
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2127 case PURPLE_STATUS_INVISIBLE:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2128 purple_debug_info("msim", "msim_set_status: invisible (%d->%d)\n", PURPLE_STATUS_INVISIBLE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2129 MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2130 status_code = MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2131 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2132
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2133 case PURPLE_STATUS_AWAY:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2134 purple_debug_info("msim", "msim_set_status: away (%d->%d)\n", PURPLE_STATUS_AWAY,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2135 MSIM_STATUS_CODE_AWAY);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2136 status_code = MSIM_STATUS_CODE_AWAY;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2137 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2138
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2139 default:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2140 purple_debug_info("msim", "msim_set_status: unknown "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2141 "status interpreting as online");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2142 status_code = MSIM_STATUS_CODE_ONLINE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2143 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2144 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2145
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2146 statstring = purple_status_get_attr_string(status, "message");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2147
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2148 if (!statstring) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2149 statstring = g_strdup("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2150 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2151
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2152 msim_set_status_code(session, status_code, g_strdup(statstring));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2153 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2154
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2155 /** Go idle. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2156 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2157 msim_set_idle(PurpleConnection *gc, int time)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2158 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2159 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2160
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2161 g_return_if_fail(gc != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2162
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2163 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2164
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2165 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2166
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2167 if (time == 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2168 /* Going back from idle. In msim, idle is mutually exclusive
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2169 * from the other states (you can only be away or idle, but not
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2170 * both, for example), so by going non-idle I go online.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2171 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2172 /* TODO: find out how to keep old status string? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2173 msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE, g_strdup(""));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2174 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2175 /* msim doesn't support idle time, so just go idle */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2176 msim_set_status_code(session, MSIM_STATUS_CODE_IDLE, g_strdup(""));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2177 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2178 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2179
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2180 /** Set status using an MSIM_STATUS_CODE_* value.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2181 * @param status_code An MSIM_STATUS_CODE_* value.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2182 * @param statstring Status string, must be a dynamic string (will be freed by msim_send).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2183 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2184 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2185 msim_set_status_code(MsimSession *session, guint status_code, gchar *statstring)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2186 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2187 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2188 g_return_if_fail(statstring != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2189
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2190 purple_debug_info("msim", "msim_set_status_code: going to set status to code=%d,str=%s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2191 status_code, statstring);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2192
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2193 if (!msim_send(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2194 "status", MSIM_TYPE_INTEGER, status_code,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2195 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2196 "statstring", MSIM_TYPE_STRING, statstring,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2197 "locstring", MSIM_TYPE_STRING, g_strdup(""),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2198 NULL))
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2199 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2200 purple_debug_info("msim", "msim_set_status: failed to set status");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2201 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2202
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2203 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2204
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2205 /** After a uid is resolved to username, tag it with the username and submit for processing.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2206 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2207 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2208 * @param userinfo Response messsage to resolving request.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2209 * @param data MsimMessage *, the message to attach information to.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2210 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2211 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2212 msim_incoming_resolved(MsimSession *session, MsimMessage *userinfo,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2213 gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2214 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2215 gchar *username;
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2216 MsimMessage *msg, *body;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2217
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2218 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2219 g_return_if_fail(userinfo != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2220
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2221 body = msim_msg_get_dictionary(userinfo, "body");
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2222 g_return_if_fail(body != NULL);
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2223
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2224 username = msim_msg_get_string(body, "UserName");
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2225 g_return_if_fail(username != NULL);
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2226 /* Note: username will be owned by 'msg' below. */
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2227
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2228 msg = (MsimMessage *)data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2229 g_return_if_fail(msg != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2230
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2231 /* TODO: more elegant solution than below. attach whole message? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2232 /* Special elements name beginning with '_', we'll use internally within the
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2233 * program (did not come directly from the wire). */
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2234 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, username);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2235
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2236 /* TODO: attach more useful information, like ImageURL */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2237
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2238 msim_process(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2239
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2240 /* TODO: Free copy cloned from msim_preprocess_incoming(). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2241 //XXX msim_msg_free(msg);
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2242 msim_msg_free(body);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2243 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2244
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2245 /* Lookup a username by userid, from buddy list.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2246 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2247 * @param wanted_uid
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2248 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2249 * @return Username of wanted_uid, if on blist, or NULL. Static string.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2250 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2251 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2252 static const gchar *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2253 msim_uid2username_from_blist(MsimSession *session, guint wanted_uid)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2254 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2255 GSList *buddies, *cur;
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2256 gchar *ret;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2257
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2258 buddies = purple_find_buddies(session->account, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2259
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2260 if (!buddies)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2261 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2262 purple_debug_info("msim", "msim_uid2username_from_blist: no buddies?");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2263 return NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2264 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2265
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2266 ret = NULL;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2267
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2268 for (cur = buddies; cur != NULL; cur = g_slist_next(cur))
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2269 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2270 PurpleBuddy *buddy;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2271 guint uid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2272 const gchar *name;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2273
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2274 /* See finch/gnthistory.c */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2275 buddy = cur->data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2276
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2277 uid = purple_blist_node_get_int(&buddy->node, "UserID");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2278 name = purple_buddy_get_name(buddy);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2279
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2280 if (uid == wanted_uid)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2281 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2282 ret = g_strdup(name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2283 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2284 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2285 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2286
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2287 g_slist_free(buddies);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2288 return ret;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2289 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2290
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2291 /** Preprocess incoming messages, resolving as needed, calling msim_process() when ready to process.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2292 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2293 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2294 * @param msg MsimMessage *, freed by caller.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2295 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2296 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2297 msim_preprocess_incoming(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2298 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2299 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2300 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2301
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2302 if (msim_msg_get(msg, "bm") && msim_msg_get(msg, "f")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2303 guint uid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2304 const gchar *username;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2305
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2306 /* 'f' = userid message is from, in buddy messages */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2307 uid = msim_msg_get_integer(msg, "f");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2308
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2309 username = msim_uid2username_from_blist(session, uid);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2310
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2311 if (username) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2312 /* Know username already, use it. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2313 purple_debug_info("msim", "msim_preprocess_incoming: tagging with _username=%s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2314 username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2315 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2316 return msim_process(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2317
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2318 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2319 gchar *from;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2320
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2321 /* Send lookup request. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2322 /* XXX: where is msim_msg_get_string() freed? make _strdup and _nonstrdup. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2323 purple_debug_info("msim", "msim_incoming: sending lookup, setting up callback\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2324 from = msim_msg_get_string(msg, "f");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2325 msim_lookup_user(session, from, msim_incoming_resolved, msim_msg_clone(msg));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2326 g_free(from);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2327
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2328 /* indeterminate */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2329 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2330 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2331 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2332 /* Nothing to resolve - send directly to processing. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2333 return msim_process(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2334 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2335 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2336
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2337 #ifdef MSIM_USE_KEEPALIVE
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2338 /** Check if the connection is still alive, based on last communication. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2339 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2340 msim_check_alive(gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2341 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2342 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2343 time_t delta;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2344 gchar *errmsg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2345
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2346 session = (MsimSession *)data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2347
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2348 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2349
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2350 delta = time(NULL) - session->last_comm;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2351 //purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2352 if (delta >= MSIM_KEEPALIVE_INTERVAL) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2353 errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), (int)delta);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2354
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2355 purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2356 errmsg, MSIM_KEEPALIVE_INTERVAL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2357 purple_connection_error(session->gc, errmsg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2358
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2359 purple_notify_error(session->gc, NULL, errmsg, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2360
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2361 g_free(errmsg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2362
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2363 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2364 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2365
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2366 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2367 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2368 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2369
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2370 /** Handle mail reply checks. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2371 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2372 msim_check_inbox_cb(MsimSession *session, MsimMessage *reply, gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2373 {
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2374 MsimMessage *body;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2375 GString *notification;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2376 guint old_inbox_status;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2377 guint i, n;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2378 const gchar *froms[5], *tos[5], *urls[5], *subjects[5];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2379
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2380 /* Three parallel arrays for each new inbox message type. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2381 static const gchar *inbox_keys[] =
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2382 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2383 "Mail",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2384 "BlogComment",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2385 "ProfileComment",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2386 "FriendRequest",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2387 "PictureComment"
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2388 };
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2389
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2390 static const guint inbox_bits[] =
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2391 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2392 MSIM_INBOX_MAIL,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2393 MSIM_INBOX_BLOG_COMMENT,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2394 MSIM_INBOX_PROFILE_COMMENT,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2395 MSIM_INBOX_FRIEND_REQUEST,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2396 MSIM_INBOX_PICTURE_COMMENT
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2397 };
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2398
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2399 static const gchar *inbox_urls[] =
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2400 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2401 "http://messaging.myspace.com/index.cfm?fuseaction=mail.inbox",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2402 "http://blog.myspace.com/index.cfm?fuseaction=blog",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2403 "http://home.myspace.com/index.cfm?fuseaction=user",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2404 "http://messaging.myspace.com/index.cfm?fuseaction=mail.friendRequests",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2405 "http://home.myspace.com/index.cfm?fuseaction=user"
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2406 };
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2407
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2408 static const gchar *inbox_text[5];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2409
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2410 /* Can't write _()'d strings in array initializers. Workaround. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2411 inbox_text[0] = _("New mail messages");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2412 inbox_text[1] = _("New blog comments");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2413 inbox_text[2] = _("New profile comments");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2414 inbox_text[3] = _("New friend requests!");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2415 inbox_text[4] = _("New picture comments");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2416
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2417 g_return_if_fail(reply != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2418
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2419 msim_msg_dump("msim_check_inbox_cb: reply=%s\n", reply);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2420
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2421 body = msim_msg_get_dictionary(reply, "body");
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2422 g_return_if_fail(body != NULL);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2423
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2424 notification = g_string_new("");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2425
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2426 old_inbox_status = session->inbox_status;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2427
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2428 n = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2429
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2430 for (i = 0; i < sizeof(inbox_keys) / sizeof(inbox_keys[0]); ++i) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2431 const gchar *key;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2432 guint bit;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2433
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2434 key = inbox_keys[i];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2435 bit = inbox_bits[i];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2436
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2437 if (msim_msg_get(body, key)) {
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2438 /* Notify only on when _changes_ from no mail -> has mail
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2439 * (edge triggered) */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2440 if (!(session->inbox_status & bit)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2441 purple_debug_info("msim", "msim_check_inbox_cb: got %s, at %d\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2442 key ? key : "(NULL)", n);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2443
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2444 subjects[n] = inbox_text[i];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2445 froms[n] = _("MySpace");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2446 tos[n] = session->username;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2447 /* TODO: append token, web challenge, so automatically logs in.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2448 * Would also need to free strings because they won't be static
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2449 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2450 urls[n] = inbox_urls[i];
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2451
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2452 ++n;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2453 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2454 purple_debug_info("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2455 "msim_check_inbox_cb: already notified of %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2456 key ? key : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2457 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2458
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2459 session->inbox_status |= bit;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2460 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2461 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2462
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2463 if (n) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2464 purple_debug_info("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2465 "msim_check_inbox_cb: notifying of %d\n", n);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2466
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2467 /* TODO: free strings with callback _if_ change to dynamic (w/ token) */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2468 purple_notify_emails(session->gc, /* handle */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2469 n, /* count */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2470 TRUE, /* detailed */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2471 subjects, froms, tos, urls,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2472 NULL, /* PurpleNotifyCloseCallback cb */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2473 NULL); /* gpointer user_data */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2474
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2475 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2476
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2477 msim_msg_free(body);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2478 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2479
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2480 /* Send request to check if there is new mail. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2481 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2482 msim_check_inbox(gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2483 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2484 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2485
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2486 session = (MsimSession *)data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2487
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2488 purple_debug_info("msim", "msim_check_inbox: checking mail\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2489 g_return_val_if_fail(msim_send(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2490 "persist", MSIM_TYPE_INTEGER, 1,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2491 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2492 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_GET,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2493 "dsn", MSIM_TYPE_INTEGER, MG_CHECK_MAIL_DSN,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2494 "lid", MSIM_TYPE_INTEGER, MG_CHECK_MAIL_LID,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2495 "uid", MSIM_TYPE_INTEGER, session->userid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2496 "rid", MSIM_TYPE_INTEGER,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2497 msim_new_reply_callback(session, msim_check_inbox_cb, NULL),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2498 "body", MSIM_TYPE_STRING, g_strdup(""),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2499 NULL), TRUE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2500
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2501 /* Always return true, so that we keep checking for mail. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2502 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2503 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2504
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2505 /** Called when the session key arrives. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2506 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2507 msim_we_are_logged_on(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2508 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2509 MsimMessage *body;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2510
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2511 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2512 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2513
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2514 session->sesskey = msim_msg_get_integer(msg, "sesskey");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2515 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2516
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2517 /* What is proof? Used to be uid, but now is 52 base64'd bytes... */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2518
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2519 /* Comes with: proof,profileid,userid,uniquenick -- all same values
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2520 * some of the time, but can vary. This is our own user ID. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2521 session->userid = msim_msg_get_integer(msg, "userid");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2522
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2523 /* Not sure what profileid is used for. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2524 if (msim_msg_get_integer(msg, "profileid") != session->userid) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2525 msim_unrecognized(session, msg,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2526 "Profile ID didn't match user ID, don't know why");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2527 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2528
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2529 /* We now know are our own username, only after we're logged in..
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2530 * which is weird, but happens because you login with your email
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2531 * address and not username. Will be freed in msim_session_destroy(). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2532 session->username = msim_msg_get_string(msg, "uniquenick");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2533
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2534 /* The session is now set up, ready to be connected. This emits the
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2535 * signedOn signal, so clients can now do anything with msimprpl, and
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2536 * we're ready for it (session key, userid, username all setup). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2537 purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2538 purple_connection_set_state(session->gc, PURPLE_CONNECTED);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2539
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2540
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2541 /* Additional post-connect operations */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2542
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2543
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2544 if (msim_msg_get_integer(msg, "uniquenick") == session->userid) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2545 purple_debug_info("msim_we_are_logged_on", "TODO: pick username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2546 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2547
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2548 body = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2549 "UserID", MSIM_TYPE_INTEGER, session->userid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2550 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2551
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2552 /* Request IM info about ourself. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2553 msim_send(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2554 "persist", MSIM_TYPE_STRING, g_strdup("persist"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2555 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2556 "dsn", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_DSN,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2557 "uid", MSIM_TYPE_INTEGER, session->userid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2558 "lid", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_LID,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2559 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2560 "body", MSIM_TYPE_DICTIONARY, body,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2561 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2562
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2563 /* Request MySpace info about ourself. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2564 msim_send(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2565 "persist", MSIM_TYPE_STRING, g_strdup("persist"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2566 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2567 "dsn", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_DSN,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2568 "uid", MSIM_TYPE_INTEGER, session->userid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2569 "lid", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_LID,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2570 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2571 "body", MSIM_TYPE_STRING, g_strdup(""),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2572 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2573
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2574 /* TODO: set options (persist cmd=514,dsn=1,lid=10) */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2575 /* TODO: set blocklist */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2576
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2577 /* Notify servers of our current status. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2578 purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2579 msim_set_status(session->account,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2580 purple_account_get_active_status(session->account));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2581
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2582 /* TODO: setinfo */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2583 /*
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2584 body = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2585 "TotalFriends", MSIM_TYPE_INTEGER, 666,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2586 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2587 msim_send(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2588 "setinfo", MSIM_TYPE_BOOLEAN, TRUE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2589 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2590 "info", MSIM_TYPE_DICTIONARY, body,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2591 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2592 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2593
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2594 /* Disable due to problems with timeouts. TODO: fix. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2595 #ifdef MSIM_USE_KEEPALIVE
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2596 purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2597 (GSourceFunc)msim_check_alive, session);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2598 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2599
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2600 purple_timeout_add(MSIM_MAIL_INTERVAL_CHECK,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2601 (GSourceFunc)msim_check_inbox, session);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2602
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2603 msim_check_inbox(session);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2604
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2605 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2606 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2607
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2608 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2609 * Process a message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2610 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2611 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2612 * @param msg A message from the server, ready for processing (possibly with resolved username information attached). Caller frees.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2613 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2614 * @return TRUE if successful. FALSE if processing failed.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2615 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2616 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2617 msim_process(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2618 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2619 g_return_val_if_fail(session != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2620 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2621
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2622 #ifdef MSIM_DEBUG_MSG
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2623 msim_msg_dump("ready to process: %s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2624 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2625
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2626 if (msim_msg_get_integer(msg, "lc") == 1) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2627 return msim_login_challenge(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2628 } else if (msim_msg_get_integer(msg, "lc") == 2) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2629 return msim_we_are_logged_on(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2630 } else if (msim_msg_get(msg, "bm")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2631 return msim_incoming_bm(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2632 } else if (msim_msg_get(msg, "rid")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2633 return msim_process_reply(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2634 } else if (msim_msg_get(msg, "error")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2635 return msim_error(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2636 } else if (msim_msg_get(msg, "ka")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2637 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2638 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2639 msim_unrecognized(session, msg, "in msim_process");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2640 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2641 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2642 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2643
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2644 /** Callback for when a buddy icon finished being downloaded. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2645 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2646 msim_downloaded_buddy_icon(PurpleUtilFetchUrlData *url_data,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2647 gpointer user_data,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2648 const gchar *url_text,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2649 gsize len,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2650 const gchar *error_message)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2651 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2652 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2653
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2654 user = (MsimUser *)user_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2655
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2656 purple_debug_info("msim_downloaded_buddy_icon",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2657 "Downloaded %d bytes\n", len);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2658
19351
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2659 if (!url_text) {
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2660 purple_debug_info("msim_downloaded_buddy_icon",
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2661 "failed to download icon for %s",
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2662 user->buddy->name);
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2663 return;
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2664 }
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2665
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2666 purple_buddy_icons_set_for_user(user->buddy->account,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2667 user->buddy->name,
19351
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2668 g_memdup((gchar *)url_text, len), len,
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2669 /* Use URL itself as buddy icon "checksum" (TODO: ETag) */
5461821ac122 g_memdup() the icon data before setting it as the buddy icon.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19350
diff changeset
2670 user->image_url); /* checksum */
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2671 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2672
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2673 /** Store a field of information about a buddy. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2674 static void
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2675 msim_store_user_info_each(const gchar *key_str, gchar *value_str, MsimUser *user)
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2676 {
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2677 if (!strcmp(key_str, "UserID") || !strcmp(key_str, "ContactID")) {
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2678 /* Save to buddy list, if it exists, for quick cached uid lookup with msim_uid2username_from_blist(). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2679 if (user->buddy)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2680 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2681 purple_debug_info("msim", "associating uid %s with username %s\n", key_str, user->buddy->name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2682 purple_blist_node_set_int(&user->buddy->node, "UserID", atol(value_str));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2683 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2684 /* Need to store in MsimUser, too? What if not on blist? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2685 } else if (!strcmp(key_str, "Age")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2686 user->age = atol(value_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2687 } else if (!strcmp(key_str, "Gender")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2688 user->gender = g_strdup(value_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2689 } else if (!strcmp(key_str, "Location")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2690 user->location = g_strdup(value_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2691 } else if (!strcmp(key_str, "TotalFriends")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2692 user->total_friends = atol(value_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2693 } else if (!strcmp(key_str, "DisplayName")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2694 user->display_name = g_strdup(value_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2695 } else if (!strcmp(key_str, "BandName")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2696 user->band_name = g_strdup(value_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2697 } else if (!strcmp(key_str, "SongName")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2698 user->song_name = g_strdup(value_str);
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2699 } else if (!strcmp(key_str, "UserName") || !strcmp(key_str, "IMName") || !strcmp(key_str, "NickName")) {
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2700 /* Ignore because PurpleBuddy knows this already */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2701 ;
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2702 } else if (!strcmp(key_str, "ImageURL") || !strcmp(key_str, "AvatarURL")) {
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2703 const gchar *previous_url;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2704
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2705 user->image_url = g_strdup(value_str);
19352
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2706
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2707 /* Instead of showing 'no photo' picture, show nothing. */
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2708 if (!strcmp(user->image_url, "http://x.myspace.com/images/no_pic.gif"))
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2709 {
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2710 purple_buddy_icons_set_for_user(user->buddy->account,
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2711 user->buddy->name,
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2712 NULL, 0, NULL);
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2713 return;
93f01e37d9f1 If buddy doesn't have a picture, display no icon, instead of the "no photo" icon that MySpaceIM
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19351
diff changeset
2714 }
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2715
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2716 previous_url = purple_buddy_icons_get_checksum_for_user(user->buddy);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2717
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2718 /* Only download if URL changed */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2719 if (!previous_url || strcmp(previous_url, user->image_url)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2720 purple_util_fetch_url(user->image_url, TRUE, NULL, TRUE, msim_downloaded_buddy_icon, (gpointer)user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2721 }
19353
af0e77c44667 MySpace added a new field, LastImageUpdated. Save it in MsimUser.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19352
diff changeset
2722 } else if (!strcmp(key_str, "LastImageUpdated")) {
af0e77c44667 MySpace added a new field, LastImageUpdated. Save it in MsimUser.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19352
diff changeset
2723 /* TODO: use somewhere */
af0e77c44667 MySpace added a new field, LastImageUpdated. Save it in MsimUser.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19352
diff changeset
2724 user->last_image_updated = atol(value_str);
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2725 } else if (!strcmp(key_str, "Headline")) {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2726 user->headline = g_strdup(value_str);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2727 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2728 /* TODO: other fields in MsimUser */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2729 gchar *msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2730
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2731 msg = g_strdup_printf("msim_store_user_info_each: unknown field %s=%s",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2732 key_str, value_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2733
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2734 msim_unrecognized(NULL, NULL, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2735
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2736 g_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2737 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2738 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2739
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2740 /** Save buddy information to the buddy list from a user info reply message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2741 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2742 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2743 * @param msg The user information reply, with any amount of information.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2744 * @param user The structure to save to, or NULL to save in PurpleBuddy->proto_data.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2745 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2746 * Variable information is saved to the passed MsimUser structure. Permanent
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2747 * information (UserID) is stored in the blist node of the buddy list (and
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2748 * ends up in blist.xml, persisted to disk) if it exists.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2749 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2750 * If the function has no buddy information, this function
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2751 * is a no-op (and returns FALSE).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2752 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2753 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2754 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2755 msim_store_user_info(MsimSession *session, MsimMessage *msg, MsimUser *user)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2756 {
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2757 gchar *username;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2758 MsimMessage *body, *body_node;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2759
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2760 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2761 g_return_val_if_fail(msg != NULL, FALSE);
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2762
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2763 body = msim_msg_get_dictionary(msg, "body");
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2764 if (!body) {
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2765 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2766 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2767
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2768 username = msim_msg_get_string(body, "UserName");
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2769
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2770 if (!username) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2771 purple_debug_info("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2772 "msim_process_reply: not caching body, no UserName\n");
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2773 msim_msg_free(body);
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2774 g_free(username);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2775 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2776 }
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2777
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2778 /* Null user = find and store in PurpleBuddy's proto_data */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2779 if (!user) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2780 user = msim_find_user(session, username);
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2781 if (!user) {
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2782 msim_msg_free(body);
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2783 g_free(username);
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2784 return FALSE;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2785 }
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2786 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2787
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2788 /* TODO: make looping over MsimMessage's easier. */
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2789 for (body_node = body;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2790 body_node != NULL;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2791 body_node = msim_msg_get_next_element_node(body_node))
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2792 {
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2793 const gchar *key_str;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2794 gchar *value_str;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2795 MsimMessageElement *elem;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2796
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2797 elem = (MsimMessageElement *)body_node->data;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2798 key_str = elem->name;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2799
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2800 value_str = msim_msg_get_string_from_element(elem);
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2801 msim_store_user_info_each(key_str, value_str, user);
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2802 g_free(value_str);
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2803 }
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2804
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2805 if (msim_msg_get_integer(msg, "dsn") == MG_OWN_IM_INFO_DSN &&
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2806 msim_msg_get_integer(msg, "lid") == MG_OWN_IM_INFO_LID) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2807 /* TODO: do something with our own IM info, if we need it for some
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2808 * specific purpose. Otherwise it is available on the buddy list,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2809 * if the user has themselves as their own buddy.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2810 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2811 * However, much of the info is already available in MsimSession,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2812 * stored in msim_we_are_logged_on(). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2813 } else if (msim_msg_get_integer(msg, "dsn") == MG_OWN_MYSPACE_INFO_DSN &&
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2814 msim_msg_get_integer(msg, "lid") == MG_OWN_MYSPACE_INFO_LID) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2815 /* TODO: same as above, but for MySpace info. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2816 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2817
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2818 msim_msg_free(body);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2819
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2820 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2821 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2822
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2823 /** Process the initial server information from the server. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2824 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2825 msim_process_server_info(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2826 {
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2827 MsimMessage *body;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2828
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2829 body = msim_msg_get_dictionary(msg, "body");
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2830 g_return_val_if_fail(body != NULL, FALSE);
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2831
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2832 /* Example body:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2833 AdUnitRefreshInterval=10.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2834 AlertPollInterval=360.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2835 AllowChatRoomEmoticonSharing=False.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2836 ChatRoomUserIDs=78744676;163733130;1300326231;123521495;142663391.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2837 CurClientVersion=673.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2838 EnableIMBrowse=True.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2839 EnableIMStuffAvatars=False.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2840 EnableIMStuffZaps=False.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2841 MaxAddAllFriends=100.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2842 MaxContacts=1000.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2843 MinClientVersion=594.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2844 MySpaceIM_ENGLISH=78744676.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2845 MySpaceNowTimer=720.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2846 PersistenceDataTimeout=900.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2847 UseWebChallenge=1.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2848 WebTicketGoHome=False
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2849
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2850 Anything useful? TODO: use what is useful, and use it.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2851 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2852 purple_debug_info("msim_process_server_info",
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2853 "maximum contacts: %d\n",
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
2854 msim_msg_get_integer(body, "MaxContacts"));
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2855
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2856 session->server_info = body;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2857 /* session->server_info freed in msim_session_destroy */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2858
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2859 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2860 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2861
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2862 /** Process a web challenge, used to login to the web site. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2863 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2864 msim_web_challenge(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2865 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2866 /* TODO: web challenge, store token */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2867 return FALSE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2868 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2869
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2870 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2871 * Process a persistance message reply from the server.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2872 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2873 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2874 * @param msg Message reply from server.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2875 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2876 * @return TRUE if successful.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2877 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2878 * msim_lookup_user sets callback for here
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2879 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2880 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2881 msim_process_reply(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2882 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2883 MSIM_USER_LOOKUP_CB cb;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2884 gpointer data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2885 guint rid, cmd, dsn, lid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2886
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2887 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2888 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2889
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2890 msim_store_user_info(session, msg, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2891
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2892 rid = msim_msg_get_integer(msg, "rid");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2893 cmd = msim_msg_get_integer(msg, "cmd");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2894 dsn = msim_msg_get_integer(msg, "dsn");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2895 lid = msim_msg_get_integer(msg, "lid");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2896
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2897 /* Unsolicited messages */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2898 if (cmd == (MSIM_CMD_BIT_REPLY | MSIM_CMD_GET)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2899 if (dsn == MG_SERVER_INFO_DSN && lid == MG_SERVER_INFO_LID) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2900 return msim_process_server_info(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2901 } else if (dsn == MG_WEB_CHALLENGE_DSN && lid == MG_WEB_CHALLENGE_LID) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2902 return msim_web_challenge(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2903 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2904 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2905
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2906 /* If a callback is registered for this userid lookup, call it. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2907 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2908 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2909
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2910 if (cb) {
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2911 purple_debug_info("msim", "msim_process_reply: calling callback now\n");
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2912 msim_msg_dump("for msg=%s\n", msg);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2913 /* Clone message, so that the callback 'cb' can use it (needs to free it also). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2914 cb(session, msim_msg_clone(msg), data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2915 g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2916 g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2917 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2918 purple_debug_info("msim",
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
2919 "msim_process_reply: no callback for rid %d\n", rid);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2920 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2921
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2922 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2923 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2924
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2925 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2926 * Handle an error from the server.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2927 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2928 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2929 * @param msg The message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2930 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2931 * @return TRUE if successfully reported error.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2932 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2933 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2934 msim_error(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2935 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2936 gchar *errmsg, *full_errmsg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2937 guint err;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2938
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2939 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2940 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2941
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2942 err = msim_msg_get_integer(msg, "err");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2943 errmsg = msim_msg_get_string(msg, "errmsg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2944
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2945 full_errmsg = g_strdup_printf(_("Protocol error, code %d: %s"), err,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2946 errmsg ? errmsg : "no 'errmsg' given");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2947
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2948 g_free(errmsg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2949
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2950 purple_debug_info("msim", "msim_error (sesskey=%d): %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2951 session->sesskey, full_errmsg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2952
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2953 purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2954 full_errmsg, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2955
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2956 /* Destroy session if fatal. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2957 if (msim_msg_get(msg, "fatal")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2958 purple_debug_info("msim", "fatal error, closing\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2959 purple_connection_error(session->gc, full_errmsg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2960 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2961
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2962 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2963 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2964
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2965 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2966 * Process incoming status messages.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2967 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2968 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2969 * @param msg Status update message. Caller frees.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2970 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2971 * @return TRUE if successful.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2972 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2973 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2974 msim_incoming_status(MsimSession *session, MsimMessage *msg)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2975 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2976 PurpleBuddyList *blist;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2977 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2978 GList *list;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2979 gchar *status_headline;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2980 gint status_code, purple_status_code;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2981 gchar *username;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2982
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2983 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2984 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2985
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2986 msim_msg_dump("msim_status msg=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2987
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2988 /* Helpfully looked up by msim_incoming_resolve() for us. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2989 username = msim_msg_get_string(msg, "_username");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2990 g_return_val_if_fail(username != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2991
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2992 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2993 gchar *ss;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2994
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2995 ss = msim_msg_get_string(msg, "msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2996 purple_debug_info("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2997 "msim_status: updating status for <%s> to <%s>\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2998 username, ss ? ss : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
2999 g_free(ss);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3000 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3001
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3002 /* Example fields:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3003 * |s|0|ss|Offline
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3004 * |s|1|ss|:-)|ls||ip|0|p|0
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3005 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3006 list = msim_msg_get_list(msg, "msg");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3007
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3008 status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3009 purple_debug_info("msim", "msim_status: %s's status code = %d\n", username, status_code);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3010 status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3011
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3012 blist = purple_get_blist();
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3013
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3014 /* Add buddy if not found */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3015 user = msim_find_user(session, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3016 if (!user) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3017 PurpleBuddy *buddy;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3018
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3019 purple_debug_info("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3020 "msim_status: making new buddy for %s\n", username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3021 buddy = purple_buddy_new(session->account, username, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3022 purple_blist_add_buddy(buddy, NULL, NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3023
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3024 user = msim_get_user_from_buddy(buddy);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3025
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3026 /* All buddies on list should have 'uid' integer associated with them. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3027 purple_blist_node_set_int(&buddy->node, "UserID", msim_msg_get_integer(msg, "f"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3028
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3029 msim_store_user_info(session, msg, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3030 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3031 purple_debug_info("msim", "msim_status: found buddy %s\n", username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3032 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3033
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3034 user->headline = g_strdup(status_headline);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3035
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3036 /* Set user status */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3037 switch (status_code) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3038 case MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3039 purple_status_code = PURPLE_STATUS_OFFLINE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3040 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3041
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3042 case MSIM_STATUS_CODE_ONLINE:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3043 purple_status_code = PURPLE_STATUS_AVAILABLE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3044 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3045
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3046 case MSIM_STATUS_CODE_AWAY:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3047 purple_status_code = PURPLE_STATUS_AWAY;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3048 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3049
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3050 case MSIM_STATUS_CODE_IDLE:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3051 /* will be handled below */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3052 purple_status_code = -1;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3053 break;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3054
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3055 default:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3056 purple_debug_info("msim", "msim_status for %s, unknown status code %d, treating as available\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3057 username, status_code);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3058 purple_status_code = PURPLE_STATUS_AVAILABLE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3059 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3060
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3061 purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3062
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3063 if (status_code == MSIM_STATUS_CODE_IDLE) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3064 purple_debug_info("msim", "msim_status: got idle: %s\n", username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3065 purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3066 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3067 /* All other statuses indicate going back to non-idle. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3068 purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3069 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3070
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3071 #ifdef MSIM_SEND_CLIENT_VERSION
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3072 if (status_code == MSIM_STATUS_CODE_ONLINE) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3073 /* Secretly whisper to unofficial clients our own version as they come online */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3074 msim_send_unofficial_client(session, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3075 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3076 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3077
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3078 g_free(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3079 msim_msg_list_free(list);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3080
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3081 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3082 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3083
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3084 /** Add a buddy to user's buddy list. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3085 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3086 msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3087 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3088 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3089 MsimMessage *msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3090 /* MsimMessage *msg_persist; */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3091 MsimMessage *body;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3092
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3093 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3094 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3095 buddy->name, (group && group->name) ? group->name : "(no group)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3096
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3097 msg = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3098 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3099 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3100 /* "newprofileid" will be inserted here with uid. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3101 "reason", MSIM_TYPE_STRING, g_strdup(""),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3102 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3103
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3104 if (!msim_postprocess_outgoing(session, msg, buddy->name, "newprofileid", "reason")) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3105 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed."));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3106 msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3107 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3108 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3109 msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3110
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3111 /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3112 * buddy list since Purple adds it locally. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3113
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3114 body = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3115 "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3116 "GroupName", MSIM_TYPE_STRING, g_strdup(group->name),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3117 "Position", MSIM_TYPE_INTEGER, 1000,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3118 "Visibility", MSIM_TYPE_INTEGER, 1,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3119 "NickName", MSIM_TYPE_STRING, g_strdup(""),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3120 "NameSelect", MSIM_TYPE_INTEGER, 0,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3121 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3122
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3123 /* TODO: Update blocklist. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3124
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3125 #if 0
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3126 msg_persist = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3127 "persist", MSIM_TYPE_INTEGER, 1,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3128 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3129 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_PUT,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3130 "dsn", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_DSN,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3131 "lid", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_LID,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3132 /* TODO: Use msim_new_reply_callback to get rid. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3133 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3134 "body", MSIM_TYPE_DICTIONARY, body,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3135 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3136
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3137 if (!msim_postprocess_outgoing(session, msg_persist, buddy->name, "body", NULL))
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3138 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3139 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3140 msim_msg_free(msg_persist);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3141 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3142 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3143 msim_msg_free(msg_persist);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3144 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3145
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3146 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3147
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3148 /** Perform actual postprocessing on a message, adding userid as specified.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3149 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3150 * @param msg The message to postprocess.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3151 * @param uid_before Name of field where to insert new field before, or NULL for end.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3152 * @param uid_field_name Name of field to add uid to.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3153 * @param uid The userid to insert.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3154 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3155 * If the field named by uid_field_name already exists, then its string contents will
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3156 * be used for the field, except "<uid>" will be replaced by the userid.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3157 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3158 * If the field named by uid_field_name does not exist, it will be added before the
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3159 * field named by uid_before, as an integer, with the userid.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3160 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3161 * Does not handle sending, or scheduling userid lookup. For that, see msim_postprocess_outgoing().
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3162 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3163 static MsimMessage *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3164 msim_do_postprocessing(MsimMessage *msg, const gchar *uid_before,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3165 const gchar *uid_field_name, guint uid)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3166 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3167 msim_msg_dump("msim_do_postprocessing msg: %s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3168
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3169 /* First, check - if the field already exists, replace <uid> within it */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3170 if (msim_msg_get(msg, uid_field_name)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3171 MsimMessageElement *elem;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3172 gchar *fmt_string;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3173 gchar *uid_str, *new_str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3174
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3175 /* Warning: this is a delicate, but safe, operation */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3176
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3177 elem = msim_msg_get(msg, uid_field_name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3178
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3179 /* Get the packed element, flattening it. This allows <uid> to be
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3180 * replaced within nested data structures, since the replacement is done
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3181 * on the linear, packed data, not on a complicated data structure.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3182 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3183 * For example, if the field was originally a dictionary or a list, you
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3184 * would have to iterate over all the items in it to see what needs to
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3185 * be replaced. But by packing it first, the <uid> marker is easily replaced
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3186 * just by a string replacement.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3187 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3188 fmt_string = msim_msg_pack_element_data(elem);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3189
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3190 uid_str = g_strdup_printf("%d", uid);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3191 new_str = str_replace(fmt_string, "<uid>", uid_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3192 g_free(uid_str);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3193 g_free(fmt_string);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3194
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3195 /* Free the old element data */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3196 msim_msg_free_element_data(elem->data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3197
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3198 /* Replace it with our new data */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3199 elem->data = new_str;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3200 elem->type = MSIM_TYPE_RAW;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3201
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3202 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3203 /* Otherwise, insert new field into outgoing message. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3204 msg = msim_msg_insert_before(msg, uid_before, uid_field_name, MSIM_TYPE_INTEGER, GUINT_TO_POINTER(uid));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3205 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3206
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3207 msim_msg_dump("msim_postprocess_outgoing_cb: postprocessed msg=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3208
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3209 return msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3210 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3211
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3212 /** Callback for msim_postprocess_outgoing() to add a userid to a message, and send it (once receiving userid).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3213 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3214 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3215 * @param userinfo The user information reply message, containing the user ID
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3216 * @param data The message to postprocess and send.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3217 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3218 * The data message should contain these fields:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3219 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3220 * _uid_field_name: string, name of field to add with userid from userinfo message
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3221 * _uid_before: string, name of field before field to insert, or NULL for end
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3222 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3223 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3224 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3225 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3226 msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3227 gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3228 {
19350
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3229 gchar *uid_field_name, *uid_before, *username;
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3230 guint uid;
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3231 MsimMessage *msg, *body;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3232
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3233 msg = (MsimMessage *)data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3234
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3235 msim_msg_dump("msim_postprocess_outgoing_cb() got msg=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3236
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3237 /* Obtain userid from userinfo message. */
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3238 body = msim_msg_get_dictionary(userinfo, "body");
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3239 g_return_if_fail(body != NULL);
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3240
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3241 uid = msim_msg_get_integer(body, "UserID");
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3242 msim_msg_free(body);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3243
19350
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3244 username = msim_msg_get_string(msg, "_username");
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3245
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3246 if (!uid) {
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3247 gchar *msg;
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3248
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3249 msg = g_strdup_printf(_("No such user: %s"), username);
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3250 purple_notify_error(NULL, NULL, _("User lookup"), msg);
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3251 g_free(msg);
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3252 g_free(username);
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3253 //msim_msg_free(msg);
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3254 return;
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3255 }
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3256
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3257 uid_field_name = msim_msg_get_string(msg, "_uid_field_name");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3258 uid_before = msim_msg_get_string(msg, "_uid_before");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3259
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3260 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, uid);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3261
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3262 /* Send */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3263 if (!msim_msg_send(session, msg)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3264 msim_msg_dump("msim_postprocess_outgoing_cb: sending failed for message: %s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3265 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3266
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3267
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3268 /* Free field names AFTER sending message, because MsimMessage does NOT copy
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3269 * field names - instead, treats them as static strings (which they usually are).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3270 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3271 g_free(uid_field_name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3272 g_free(uid_before);
19350
8839775bad3e If a username cannot be looked up in postprocessing, throw up an error.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19256
diff changeset
3273 g_free(username);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3274 //msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3275 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3276
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3277 /** Postprocess and send a message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3278 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3279 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3280 * @param msg Message to postprocess. Will NOT be freed.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3281 * @param username Username to resolve. Assumed to be a static string (will not be freed or copied).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3282 * @param uid_field_name Name of new field to add, containing uid of username. Static string.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3283 * @param uid_before Name of existing field to insert username field before. Static string.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3284 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3285 * @return TRUE if successful.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3286 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3287 gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3288 msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3289 const gchar *username, const gchar *uid_field_name,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3290 const gchar *uid_before)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3291 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3292 PurpleBuddy *buddy;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3293 guint uid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3294 gboolean rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3295
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3296 g_return_val_if_fail(msg != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3297
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3298 /* Store information for msim_postprocess_outgoing_cb(). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3299 msim_msg_dump("msim_postprocess_outgoing: msg before=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3300 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3301 msg = msim_msg_append(msg, "_uid_field_name", MSIM_TYPE_STRING, g_strdup(uid_field_name));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3302 msg = msim_msg_append(msg, "_uid_before", MSIM_TYPE_STRING, g_strdup(uid_before));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3303
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3304 /* First, try the most obvious. If numeric userid is given, use that directly. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3305 if (msim_is_userid(username)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3306 uid = atol(username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3307 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3308 /* Next, see if on buddy list and know uid. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3309 buddy = purple_find_buddy(session->account, username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3310 if (buddy) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3311 uid = purple_blist_node_get_int(&buddy->node, "UserID");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3312 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3313 uid = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3314 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3315
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3316 if (!buddy || !uid)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3317 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3318 /* Don't have uid offhand - need to ask for it, and wait until hear back before sending. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3319 purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3320 username ? username : "(NULL)");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3321 msim_msg_dump("msim_postprocess_outgoing - scheduling lookup, msg=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3322 /* TODO: where is cloned message freed? Should be in _cb. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3323 msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3324 return TRUE; /* not sure of status yet - haven't sent! */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3325 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3326 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3327
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3328 /* Already have uid, postprocess and send msg immediately. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3329 purple_debug_info("msim", "msim_postprocess_outgoing: found username %s has uid %d\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3330 username ? username : "(NULL)", uid);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3331
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3332 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, uid);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3333
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3334 msim_msg_dump("msim_postprocess_outgoing: msg after (uid immediate)=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3335
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3336 rc = msim_msg_send(session, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3337
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3338 //msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3339
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3340 return rc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3341 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3342
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3343 /** Remove a buddy from the user's buddy list. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3344 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3345 msim_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3346 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3347 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3348 MsimMessage *delbuddy_msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3349 MsimMessage *persist_msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3350 MsimMessage *blocklist_msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3351 GList *blocklist_updates;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3352
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3353 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3354
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3355 delbuddy_msg = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3356 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3357 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3358 /* 'delprofileid' with uid will be inserted here. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3359 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3360
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3361 if (!msim_postprocess_outgoing(session, delbuddy_msg, buddy->name, "delprofileid", NULL)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3362 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3363 msim_msg_free(delbuddy_msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3364 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3365 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3366 msim_msg_free(delbuddy_msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3367
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3368 persist_msg = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3369 "persist", MSIM_TYPE_INTEGER, 1,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3370 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3371 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_DELETE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3372 "dsn", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_DSN,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3373 "lid", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_LID,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3374 "uid", MSIM_TYPE_INTEGER, session->userid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3375 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3376 /* <uid> will be replaced by postprocessing */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3377 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3378 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3379
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3380 if (!msim_postprocess_outgoing(session, persist_msg, buddy->name, "body", NULL)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3381 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3382 msim_msg_free(persist_msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3383 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3384 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3385 msim_msg_free(persist_msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3386
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3387 blocklist_updates = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3388 blocklist_updates = g_list_prepend(blocklist_updates, "a-");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3389 blocklist_updates = g_list_prepend(blocklist_updates, "<uid>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3390 blocklist_updates = g_list_prepend(blocklist_updates, "b-");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3391 blocklist_updates = g_list_prepend(blocklist_updates, "<uid>");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3392 blocklist_updates = g_list_reverse(blocklist_updates);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3393
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3394 blocklist_msg = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3395 "blocklist", MSIM_TYPE_BOOLEAN, TRUE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3396 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3397 /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3398 //"idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3399 "idlist", MSIM_TYPE_LIST, blocklist_updates,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3400 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3401
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3402 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3403 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3404 msim_msg_free(blocklist_msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3405 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3406 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3407 msim_msg_free(blocklist_msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3408 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3409
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3410 /** Return whether the buddy can be messaged while offline.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3411 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3412 * The protocol supports offline messages in just the same way as online
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3413 * messages.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3414 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3415 gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3416 msim_offline_message(const PurpleBuddy *buddy)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3417 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3418 return TRUE;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3419 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3420
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3421 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3422 * Callback when input available.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3423 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3424 * @param gc_uncasted A PurpleConnection pointer.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3425 * @param source File descriptor.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3426 * @param cond PURPLE_INPUT_READ
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3427 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3428 * Reads the input, and calls msim_preprocess_incoming() to handle it.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3429 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3430 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3431 msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3432 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3433 PurpleConnection *gc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3434 PurpleAccount *account;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3435 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3436 gchar *end;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3437 int n;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3438
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3439 g_return_if_fail(gc_uncasted != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3440 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3441
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3442 gc = (PurpleConnection *)(gc_uncasted);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3443 account = purple_connection_get_account(gc);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3444 session = gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3445
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3446 /* libpurple/eventloop.h only defines these two */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3447 if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3448 purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3449 purple_connection_error(gc, _("Invalid input condition"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3450 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3451 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3452
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3453 g_return_if_fail(cond == PURPLE_INPUT_READ);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3454 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3455
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3456 /* Mark down that we got data, so don't timeout. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3457 session->last_comm = time(NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3458
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3459 /* Only can handle so much data at once...
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3460 * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3461 * Should be large enough to hold the largest protocol message.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3462 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3463 if (session->rxoff >= MSIM_READ_BUF_SIZE) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3464 purple_debug_error("msim",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3465 "msim_input_cb: %d-byte read buffer full! rxoff=%d\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3466 MSIM_READ_BUF_SIZE, session->rxoff);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3467 purple_connection_error(gc, _("Read buffer full"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3468 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3469 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3470
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3471 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3472 session->rxoff, MSIM_READ_BUF_SIZE,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3473 MSIM_READ_BUF_SIZE - session->rxoff);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3474
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3475 /* Read into buffer. On Win32, need recv() not read(). session->fd also holds
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3476 * the file descriptor, but it sometimes differs from the 'source' parameter.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3477 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3478 n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3479
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3480 if (n < 0 && errno == EAGAIN) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3481 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3482 } else if (n < 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3483 purple_debug_error("msim", "msim_input_cb: read error, ret=%d, "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3484 "error=%s, source=%d, fd=%d (%X))\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3485 n, strerror(errno), source, session->fd, session->fd);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3486 purple_connection_error(gc, _("Read error"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3487 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3488 } else if (n == 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3489 purple_debug_info("msim", "msim_input_cb: server disconnected\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3490 purple_connection_error(gc, _("Server has disconnected"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3491 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3492 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3493
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3494 if (n + session->rxoff >= MSIM_READ_BUF_SIZE) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3495 purple_debug_info("msim_input_cb", "received %d bytes, pushing rxoff to %d, over buffer size of %d\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3496 n, n + session->rxoff, MSIM_READ_BUF_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3497 /* TODO: g_realloc like msn, yahoo, irc, jabber? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3498 purple_connection_error(gc, _("Read buffer full"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3499 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3500
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3501 /* Null terminate */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3502 purple_debug_info("msim", "msim_input_cb: going to null terminate "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3503 "at n=%d\n", n);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3504 session->rxbuf[session->rxoff + n] = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3505
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3506 #ifdef MSIM_CHECK_EMBEDDED_NULLS
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3507 /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3508 if (strlen(session->rxbuf + session->rxoff) != n) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3509 /* Occurs after login, but it is not a null byte. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3510 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes"
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3511 "--null byte encountered?\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3512 strlen(session->rxbuf + session->rxoff), n);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3513 //purple_connection_error(gc, "Invalid message - null byte on input");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3514 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3515 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3516 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3517
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3518 session->rxoff += n;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3519 purple_debug_info("msim", "msim_input_cb: read=%d\n", n);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3520
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3521 #ifdef MSIM_DEBUG_RXBUF
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3522 purple_debug_info("msim", "buf=<%s>\n", session->rxbuf);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3523 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3524
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3525 /* Look for \\final\\ end markers. If found, process message. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3526 while((end = strstr(session->rxbuf, MSIM_FINAL_STRING))) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3527 MsimMessage *msg;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3528
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3529 #ifdef MSIM_DEBUG_RXBUF
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3530 purple_debug_info("msim", "in loop: buf=<%s>\n", session->rxbuf);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3531 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3532 *end = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3533 msg = msim_parse(g_strdup(session->rxbuf));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3534 if (!msg) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3535 purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3536 purple_connection_error(gc, _("Unparseable message"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3537 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3538 /* Process message and then free it (processing function should
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3539 * clone message if it wants to keep it afterwards.) */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3540 if (!msim_preprocess_incoming(session, msg)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3541 msim_msg_dump("msim_input_cb: preprocessing message failed on msg: %s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3542 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3543 msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3544 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3545
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3546 /* Move remaining part of buffer to beginning. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3547 session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3548 memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3549 MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3550
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3551 /* Clear end of buffer */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3552 //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3553 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3554 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3555
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3556 /* Setup a callback, to be called when a reply is received with the returned rid.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3557 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3558 * @param cb The callback, an MSIM_USER_LOOKUP_CB.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3559 * @param data Arbitrary user data to be passed to callback (probably an MsimMessage *).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3560 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3561 * @return The request/reply ID, used to link replies with requests, or -1.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3562 * Put the rid in your request, 'rid' field.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3563 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3564 * TODO: Make more generic and more specific:
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3565 * 1) MSIM_USER_LOOKUP_CB - make it for PERSIST_REPLY, not just user lookup
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3566 * 2) data - make it an MsimMessage?
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3567 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3568 static guint
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3569 msim_new_reply_callback(MsimSession *session, MSIM_USER_LOOKUP_CB cb,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3570 gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3571 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3572 guint rid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3573
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3574 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3575
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3576 rid = session->next_rid++;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3577
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3578 g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3579 g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3580
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3581 return rid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3582 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3583
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3584 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3585 * Callback when connected. Sets up input handlers.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3586 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3587 * @param data A PurpleConnection pointer.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3588 * @param source File descriptor.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3589 * @param error_message
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3590 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3591 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3592 msim_connect_cb(gpointer data, gint source, const gchar *error_message)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3593 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3594 PurpleConnection *gc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3595 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3596
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3597 g_return_if_fail(data != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3598
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3599 gc = (PurpleConnection *)data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3600 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3601
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3602 if (source < 0) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3603 purple_connection_error(gc, _("Couldn't connect to host"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3604 purple_connection_error(gc, g_strdup_printf(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3605 _("Couldn't connect to host: %s (%d)"),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3606 error_message ? error_message : "no message given",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3607 source));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3608 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3609 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3610
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3611 session->fd = source;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3612
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3613 gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3614 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3615
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3616 /* Session methods */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3617
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3618 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3619 * Create a new MSIM session.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3620 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3621 * @param acct The account to create the session from.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3622 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3623 * @return Pointer to a new session. Free with msim_session_destroy.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3624 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3625 MsimSession *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3626 msim_session_new(PurpleAccount *acct)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3627 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3628 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3629
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3630 g_return_val_if_fail(acct != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3631
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3632 session = g_new0(MsimSession, 1);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3633
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3634 session->magic = MSIM_SESSION_STRUCT_MAGIC;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3635 session->account = acct;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3636 session->gc = purple_account_get_connection(acct);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3637 session->sesskey = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3638 session->userid = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3639 session->username = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3640 session->fd = -1;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3641
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3642 /* TODO: Remove. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3643 session->user_lookup_cb = g_hash_table_new_full(g_direct_hash,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3644 g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3645 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3646 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3647 they could be integers inside gpointers
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3648 or strings, so I don't freed them.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3649 Figure this out, once free cache. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3650
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3651 /* Created in msim_process_server_info() */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3652 session->server_info = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3653
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3654 session->rxoff = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3655 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3656 session->next_rid = 1;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3657 session->last_comm = time(NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3658 session->inbox_status = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3659
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3660 return session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3661 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3662
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3663 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3664 * Free a session.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3665 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3666 * @param session The session to destroy.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3667 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3668 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3669 msim_session_destroy(MsimSession *session)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3670 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3671 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3672
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3673 session->magic = -1;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3674
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3675 g_free(session->rxbuf);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3676 g_free(session->username);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3677
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3678 /* TODO: Remove. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3679 g_hash_table_destroy(session->user_lookup_cb);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3680 g_hash_table_destroy(session->user_lookup_cb_data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3681
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3682 if (session->server_info) {
19251
78558930d9f3 Replace msim_parse_body(), which returns a GHashTable * and takes a gchar *,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19249
diff changeset
3683 msim_msg_free(session->server_info);
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3684 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3685
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3686 g_free(session);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3687 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3688
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3689 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3690 * Close the connection.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3691 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3692 * @param gc The connection.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3693 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3694 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3695 msim_close(PurpleConnection *gc)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3696 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3697 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3698
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3699 if (gc == NULL) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3700 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3701 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3702
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3703 session = (MsimSession *)gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3704 if (session == NULL)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3705 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3706
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3707 gc->proto_data = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3708
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3709 if (!MSIM_SESSION_VALID(session)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3710 return;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3711 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3712
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3713 if (session->gc->inpa) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3714 purple_input_remove(session->gc->inpa);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3715 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3716
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3717 msim_session_destroy(session);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3718 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3719
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3720
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3721 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3722 * Check if a string is a userid (all numeric).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3723 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3724 * @param user The user id, email, or name.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3725 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3726 * @return TRUE if is userid, FALSE if not.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3727 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3728 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3729 msim_is_userid(const gchar *user)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3730 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3731 g_return_val_if_fail(user != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3732
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3733 return strspn(user, "0123456789") == strlen(user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3734 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3735
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3736 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3737 * Check if a string is an email address (contains an @).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3738 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3739 * @param user The user id, email, or name.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3740 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3741 * @return TRUE if is an email, FALSE if not.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3742 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3743 * This function is not intended to be used as a generic
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3744 * means of validating email addresses, but to distinguish
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3745 * between a user represented by an email address from
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3746 * other forms of identification.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3747 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3748 static gboolean
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3749 msim_is_email(const gchar *user)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3750 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3751 g_return_val_if_fail(user != NULL, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3752
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3753 return strchr(user, '@') != NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3754 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3755
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3756
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3757 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3758 * Asynchronously lookup user information, calling callback when receive result.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3759 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3760 * @param session
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3761 * @param user The user id, email address, or username. Not freed.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3762 * @param cb Callback, called with user information when available.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3763 * @param data An arbitray data pointer passed to the callback.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3764 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3765 /* TODO: change to not use callbacks */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3766 static void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3767 msim_lookup_user(MsimSession *session, const gchar *user,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3768 MSIM_USER_LOOKUP_CB cb, gpointer data)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3769 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3770 MsimMessage *body;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3771 gchar *field_name;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3772 guint rid, cmd, dsn, lid;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3773
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3774 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3775 g_return_if_fail(user != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3776 g_return_if_fail(cb != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3777
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3778 purple_debug_info("msim", "msim_lookup_userid: "
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3779 "asynchronously looking up <%s>\n", user);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3780
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3781 msim_msg_dump("msim_lookup_user: data=%s\n", (MsimMessage *)data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3782
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3783 /* Setup callback. Response will be associated with request using 'rid'. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3784 rid = msim_new_reply_callback(session, cb, data);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3785
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3786 /* Send request */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3787
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3788 cmd = MSIM_CMD_GET;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3789
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3790 if (msim_is_userid(user)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3791 field_name = "UserID";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3792 dsn = MG_MYSPACE_INFO_BY_ID_DSN;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3793 lid = MG_MYSPACE_INFO_BY_ID_LID;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3794 } else if (msim_is_email(user)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3795 field_name = "Email";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3796 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3797 lid = MG_MYSPACE_INFO_BY_STRING_LID;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3798 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3799 field_name = "UserName";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3800 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3801 lid = MG_MYSPACE_INFO_BY_STRING_LID;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3802 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3803
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3804 body = msim_msg_new(
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3805 field_name, MSIM_TYPE_STRING, g_strdup(user),
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3806 NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3807
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3808 g_return_if_fail(msim_send(session,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3809 "persist", MSIM_TYPE_INTEGER, 1,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3810 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3811 "cmd", MSIM_TYPE_INTEGER, 1,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3812 "dsn", MSIM_TYPE_INTEGER, dsn,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3813 "uid", MSIM_TYPE_INTEGER, session->userid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3814 "lid", MSIM_TYPE_INTEGER, lid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3815 "rid", MSIM_TYPE_INTEGER, rid,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3816 "body", MSIM_TYPE_DICTIONARY, body,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3817 NULL));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3818 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3819
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3820
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3821 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3822 * Obtain the status text for a buddy.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3823 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3824 * @param buddy The buddy to obtain status text for.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3825 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3826 * @return Status text, or NULL if error. Caller g_free()'s.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3827 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3828 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3829 char *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3830 msim_status_text(PurpleBuddy *buddy)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3831 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3832 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3833 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3834 const gchar *display_name, *headline;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3835
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3836 g_return_val_if_fail(buddy != NULL, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3837
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3838 user = msim_get_user_from_buddy(buddy);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3839
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3840 session = (MsimSession *)buddy->account->gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3841 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3842
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3843 display_name = headline = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3844
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3845 /* Retrieve display name and/or headline, depending on user preference. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3846 if (purple_account_get_bool(session->account, "show_display_name", TRUE)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3847 display_name = user->display_name;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3848 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3849
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3850 if (purple_account_get_bool(session->account, "show_headline", FALSE)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3851 headline = user->headline;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3852 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3853
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3854 /* Return appropriate combination of display name and/or headline, or neither. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3855
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3856 if (display_name && headline) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3857 return g_strconcat(display_name, " ", headline, NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3858 } else if (display_name) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3859 return g_strdup(display_name);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3860 } else if (headline) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3861 return g_strdup(headline);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3862 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3863
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3864 return NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3865 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3866
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3867 /**
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3868 * Obtain the tooltip text for a buddy.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3869 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3870 * @param buddy Buddy to obtain tooltip text on.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3871 * @param user_info Variable modified to have the tooltip text.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3872 * @param full TRUE if should obtain full tooltip text.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3873 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3874 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3875 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3876 msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3877 gboolean full)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3878 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3879 MsimUser *user;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3880
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3881 g_return_if_fail(buddy != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3882 g_return_if_fail(user_info != NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3883
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3884 user = msim_get_user_from_buddy(buddy);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3885
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3886 if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3887 MsimSession *session;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3888
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3889 session = (MsimSession *)buddy->account->gc->proto_data;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3890
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3891 g_return_if_fail(MSIM_SESSION_VALID(session));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3892
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3893 /* TODO: if (full), do something different? */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3894
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3895 /* TODO: request information? have to figure out how to do
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3896 * the asynchronous lookup like oscar does (tooltip shows
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3897 * 'retrieving...' if not yet available, then changes when it is).
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3898 *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3899 * Right now, only show what we have on hand.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3900 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3901
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3902 /* Show abbreviated user info. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3903 msim_append_user_info(session, user_info, user, FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3904 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3905 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
3906
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3907 /** Add contact from server to buddy list, after looking up username.
19256
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3908 * Callback from msim_add_contact_from_server().
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3909 *
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3910 * @param data An MsimMessage * of the contact information. Will be freed.
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3911 */
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3912 static void
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3913 msim_add_contact_from_server_cb(MsimSession *session, MsimMessage *user_lookup_info, gpointer data)
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3914 {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3915 MsimMessage *contact_info, *user_lookup_info_body;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3916 PurpleGroup *group;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3917 PurpleBuddy *buddy;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3918 MsimUser *user;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3919 gchar *username, *group_name;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3920 guint uid;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3921
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3922 contact_info = (MsimMessage *)data;
19256
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3923 purple_debug_info("msim_add_contact_from_server_cb", "contact_info addr=%X\n", contact_info);
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3924 uid = msim_msg_get_integer(contact_info, "ContactID");
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3925
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3926 if (!user_lookup_info) {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3927 username = g_strdup(msim_uid2username_from_blist(session, uid));
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3928 g_return_if_fail(username != NULL);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3929 } else {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3930 user_lookup_info_body = msim_msg_get_dictionary(user_lookup_info, "body");
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3931 username = msim_msg_get_string(user_lookup_info_body, "UserName");
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3932 msim_msg_free(user_lookup_info_body);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3933 g_return_if_fail(username != NULL);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3934 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3935
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3936 purple_debug_info("msim_add_contact_from_server_cb",
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3937 "*** about to add/update username=%s\n", username);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3938
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3939 /* 1. Creates a new group, or gets existing group if it exists (or so
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3940 * the documentation claims). */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3941 group_name = msim_msg_get_string(contact_info, "GroupName");
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3942 if (group_name) {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3943 group = purple_group_new(group_name);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3944 g_free(group_name);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3945 } else {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3946 group = purple_group_new(_("IM Friends"));
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3947 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3948
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3949 /* 2. Get or create buddy */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3950 buddy = purple_find_buddy(session->account, username);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3951 if (!buddy) {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3952 buddy = purple_buddy_new(session->account, username, NULL);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3953 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3954
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3955 /* TODO: use 'Position' in contact_info to take into account where buddy is */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3956 purple_blist_add_buddy(buddy, NULL, group, NULL /* insertion point */);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3957
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3958
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3959 /* 3. Update buddy information */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3960 user = msim_get_user_from_buddy(buddy);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3961
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3962 /* All buddies on list should have 'uid' integer associated with them. */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3963 purple_blist_node_set_int(&buddy->node, "UserID", uid);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3964
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3965 /* Stores a few fields in the MsimUser, relevant to the buddy itself.
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3966 * AvatarURL, Headline, ContactID. */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3967 msim_store_user_info(session, contact_info, NULL);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3968
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3969 /* TODO: other fields, store in 'user' */
19256
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3970
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3971 msim_msg_free(contact_info);
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3972 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3973
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3974 /** Add first ContactID in contact_info to buddy's list. Used to add
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3975 * server-side buddies to client-side list.
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3976 *
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3977 * @return TRUE if added.
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3978 * */
19256
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3979 static void
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3980 msim_add_contact_from_server(MsimSession *session, MsimMessage *contact_info)
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3981 {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3982 guint uid;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3983 const gchar *username;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3984
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3985 uid = msim_msg_get_integer(contact_info, "ContactID");
19256
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3986 g_return_if_fail(uid != 0);
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3987
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3988 /* Lookup the username, since NickName and IMName is unreliable */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3989 username = msim_uid2username_from_blist(session, uid);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3990 if (!username) {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3991 gchar *uid_str;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3992
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3993 uid_str = g_strdup_printf("%d", uid);
19256
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3994 purple_debug_info("msim_add_contact_from_server",
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3995 "contact_info addr=%X\n", contact_info);
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3996 msim_lookup_user(session, uid_str, msim_add_contact_from_server_cb, (gpointer)msim_msg_clone(contact_info));
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3997 g_free(uid_str);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
3998 } else {
19256
34a1957de14b Fix crashes. In myspace.c, clone the contact_info message before sending it to
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19255
diff changeset
3999 msim_add_contact_from_server_cb(session, NULL, (gpointer)msim_msg_clone(contact_info));
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4000 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4001 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4002
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4003 /** Called when contact list is received from server. */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4004 static void
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4005 msim_got_contact_list(MsimSession *session, MsimMessage *reply, gpointer user_data)
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4006 {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4007 MsimMessage *body, *body_node;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4008
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4009 msim_msg_dump("msim_got_contact_list: reply=%s", reply);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4010
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4011 body = msim_msg_get_dictionary(reply, "body");
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4012 g_return_if_fail(body != NULL);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4013
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4014 for (body_node = body;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4015 body_node != NULL;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4016 body_node = msim_msg_get_next_element_node(body_node))
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4017 {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4018 MsimMessageElement *elem;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4019
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4020 elem = (MsimMessageElement *)body_node->data;
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4021
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4022 if (!strcmp(elem->name, "ContactID"))
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4023 {
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4024 /* Will look for first contact in body_node */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4025 msim_add_contact_from_server(session, body_node);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4026 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4027 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4028
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4029 msim_msg_free(body);
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4030 }
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4031
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4032 /** Called when friends have been imported to buddy list on server. */
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4033 static void
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4034 msim_import_friends_cb(MsimSession *session, MsimMessage *reply, gpointer user_data)
19249
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4035 {
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4036 MsimMessage *body;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4037 gchar *completed;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4038 msim_msg_dump("msim_import_friends_cb=%s", reply);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4039
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4040 /* Check if the friends were imported successfully. */
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4041 body = msim_msg_get_dictionary(reply, "body");
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4042 g_return_if_fail(body != NULL);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4043 completed = msim_msg_get_string(body, "Completed");
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4044 g_return_if_fail(body != NULL);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4045 msim_msg_free(body);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4046 if (strcmp(completed, "True"))
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4047 {
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4048 purple_debug_info("msim_import_friends_cb",
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4049 "failed to import friends: %s", completed);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4050 purple_notify_error(session->account, _("Add friends from MySpace.com"),
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4051 _("Importing friends failed"), NULL);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4052 g_free(completed);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4053 return;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4054 }
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4055 g_free(completed);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4056
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4057 purple_debug_info("msim_import_friends_cb",
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4058 "added friends to server-side buddy list, requesting new contacts from server");
19249
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4059
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4060 g_return_if_fail(msim_send(session,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4061 "persist", MSIM_TYPE_INTEGER, 1,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4062 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4063 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_GET,
19255
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4064 "dsn", MSIM_TYPE_INTEGER, MG_LIST_ALL_CONTACTS_DSN,
1ea47b06f1a6 Initial implementation of friend importing. Not well tested.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19251
diff changeset
4065 "lid", MSIM_TYPE_INTEGER, MG_LIST_ALL_CONTACTS_LID,
19249
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4066 "uid", MSIM_TYPE_INTEGER, session->userid,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4067 "rid", MSIM_TYPE_INTEGER,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4068 msim_new_reply_callback(session, msim_got_contact_list, NULL),
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4069 "body", MSIM_TYPE_STRING, g_strdup(""),
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4070 NULL));
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4071
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4072 /* TODO: show, X friends have been added */
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4073 }
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4074
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4075 /** Import friends from myspace.com. */
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4076 static void msim_import_friends(PurplePluginAction *action)
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4077 {
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4078 PurpleConnection *gc;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4079 MsimSession *session;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4080 gchar *group_name;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4081
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4082 gc = (PurpleConnection *)action->context;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4083 session = (MsimSession *)gc->proto_data;
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4084
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4085 group_name = "MySpace Friends";
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4086
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4087 g_return_if_fail(msim_send(session,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4088 "persist", MSIM_TYPE_INTEGER, 1,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4089 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4090 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_PUT,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4091 "dsn", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_DSN,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4092 "lid", MSIM_TYPE_INTEGER, MC_IMPORT_ALL_FRIENDS_LID,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4093 "uid", MSIM_TYPE_INTEGER, session->userid,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4094 "rid", MSIM_TYPE_INTEGER,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4095 msim_new_reply_callback(session, msim_import_friends_cb, NULL),
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4096 "body", MSIM_TYPE_STRING,
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4097 g_strdup_printf("GroupName=%s", group_name),
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4098 NULL));
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4099
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4100
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4101 }
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4102
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4103 /** Actions menu for account. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4104 GList *
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4105 msim_actions(PurplePlugin *plugin, gpointer context)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4106 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4107 PurpleConnection *gc;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4108 GList *menu;
19249
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4109 PurplePluginAction *act;
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4110
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4111 gc = (PurpleConnection *)context;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4112
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4113 menu = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4114
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4115 #if 0
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4116 /* TODO: find out how */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4117 act = purple_plugin_action_new(_("Find people..."), msim_);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4118 menu = g_list_append(menu, act);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4119
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4120 act = purple_plugin_action_new(_("Change IM name..."), NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4121 menu = g_list_append(menu, act);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4122 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4123
19249
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4124 act = purple_plugin_action_new(g_strdup_printf("%s",
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4125 _("Add friends from MySpace.com")), msim_import_friends);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4126 menu = g_list_append(menu, act);
9d921dde9d9f First half of "Add friends from MySpace.com" support: add msim_import_friends(),
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19247
diff changeset
4127
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4128 return menu;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4129 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4130
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4131 /** Callbacks called by Purple, to access this plugin. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4132 PurplePluginProtocolInfo prpl_info = {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4133 /* options */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4134 OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4135 | OPT_PROTO_MAIL_CHECK,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4136
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4137 /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4138 NULL, /* user_splits */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4139 NULL, /* protocol_options */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4140 NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4141 msim_list_icon, /* list_icon */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4142 NULL, /* list_emblems */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4143 msim_status_text, /* status_text */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4144 msim_tooltip_text, /* tooltip_text */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4145 msim_status_types, /* status_types */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4146 msim_blist_node_menu, /* blist_node_menu */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4147 NULL, /* chat_info */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4148 NULL, /* chat_info_defaults */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4149 msim_login, /* login */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4150 msim_close, /* close */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4151 msim_send_im, /* send_im */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4152 NULL, /* set_info */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4153 msim_send_typing, /* send_typing */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4154 msim_get_info, /* get_info */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4155 msim_set_status, /* set_status */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4156 msim_set_idle, /* set_idle */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4157 NULL, /* change_passwd */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4158 msim_add_buddy, /* add_buddy */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4159 NULL, /* add_buddies */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4160 msim_remove_buddy, /* remove_buddy */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4161 NULL, /* remove_buddies */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4162 NULL, /* add_permit */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4163 NULL, /* add_deny */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4164 NULL, /* rem_permit */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4165 NULL, /* rem_deny */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4166 NULL, /* set_permit_deny */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4167 NULL, /* join_chat */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4168 NULL, /* reject chat invite */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4169 NULL, /* get_chat_name */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4170 NULL, /* chat_invite */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4171 NULL, /* chat_leave */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4172 NULL, /* chat_whisper */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4173 NULL, /* chat_send */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4174 NULL, /* keepalive */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4175 NULL, /* register_user */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4176 NULL, /* get_cb_info */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4177 NULL, /* get_cb_away */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4178 NULL, /* alias_buddy */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4179 NULL, /* group_buddy */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4180 NULL, /* rename_group */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4181 NULL, /* buddy_free */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4182 NULL, /* convo_closed */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4183 NULL, /* normalize */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4184 NULL, /* set_buddy_icon */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4185 NULL, /* remove_group */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4186 NULL, /* get_cb_real_name */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4187 NULL, /* set_chat_topic */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4188 NULL, /* find_blist_chat */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4189 NULL, /* roomlist_get_list */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4190 NULL, /* roomlist_cancel */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4191 NULL, /* roomlist_expand_category */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4192 NULL, /* can_receive_file */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4193 NULL, /* send_file */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4194 NULL, /* new_xfer */
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4195 msim_offline_message, /* offline_message */
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4196 NULL, /* whiteboard_prpl_ops */
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4197 msim_send_really_raw, /* send_raw */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4198 NULL, /* roomlist_room_serialize */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4199 #ifdef MSIM_USE_ATTENTION_API
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4200 msim_send_attention, /* send_attention */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4201 msim_attention_types, /* attention_types */
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4202 #else
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4203 NULL, /* _purple_reserved1 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4204 NULL, /* _purple_reserved2 */
19243
a242e014ab8c Re-apply the msimprpl-specific parts of revision
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 19242
diff changeset
4205 #endif
19242
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4206 NULL, /* _purple_reserved3 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4207 NULL /* _purple_reserved4 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4208 };
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4209
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4210
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4211
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4212 /** Based on MSN's plugin info comments. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4213 PurplePluginInfo info = {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4214 PURPLE_PLUGIN_MAGIC,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4215 PURPLE_MAJOR_VERSION,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4216 PURPLE_MINOR_VERSION,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4217 PURPLE_PLUGIN_PROTOCOL, /**< type */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4218 NULL, /**< ui_requirement */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4219 0, /**< flags */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4220 NULL, /**< dependencies */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4221 PURPLE_PRIORITY_DEFAULT, /**< priority */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4222
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4223 "prpl-myspace", /**< id */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4224 "MySpaceIM", /**< name */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4225 MSIM_PRPL_VERSION_STRING, /**< version */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4226 /** summary */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4227 "MySpaceIM Protocol Plugin",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4228 /** description */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4229 "MySpaceIM Protocol Plugin",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4230 "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4231 "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4232
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4233 msim_load, /**< load */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4234 NULL, /**< unload */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4235 NULL, /**< destroy */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4236 NULL, /**< ui_info */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4237 &prpl_info, /**< extra_info */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4238 NULL, /**< prefs_info */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4239 msim_actions, /**< msim_actions */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4240 NULL, /**< reserved1 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4241 NULL, /**< reserved2 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4242 NULL, /**< reserved3 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4243 NULL /**< reserved4 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4244 };
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4245
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4246
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4247 #ifdef MSIM_SELF_TEST
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4248 /** Test functions.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4249 * Used to test or try out the internal workings of msimprpl. If you're reading
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4250 * this code for the first time, these functions can be instructive in learning
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4251 * how msimprpl is architected.
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4252 */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4253 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4254 msim_test_all(void) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4255 guint failures;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4256
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4257
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4258 failures = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4259 failures += msim_test_msg();
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4260 failures += msim_test_escaping();
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4261
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4262 if (failures) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4263 purple_debug_info("msim", "msim_test_all HAD FAILURES: %d\n", failures);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4264 } else {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4265 purple_debug_info("msim", "msim_test_all - all tests passed!\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4266 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4267 exit(0);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4268 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4269
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4270 /** Test MsimMessage for basic functionality. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4271 int
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4272 msim_test_msg(void)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4273 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4274 MsimMessage *msg, *msg_cloned, *msg2;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4275 GList *list;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4276 gchar *packed, *packed_expected, *packed_cloned;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4277 guint failures;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4278
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4279 failures = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4280
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4281 purple_debug_info("msim", "\n\nTesting MsimMessage\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4282 msg = msim_msg_new(NULL); /* Create a new, empty message. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4283
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4284 /* Append some new elements. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4285 msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4286 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4287 msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4288 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4289 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v52/xxx\\yyy"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4290 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4291 msim_msg_dump("msg debug str=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4292 packed = msim_msg_pack(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4293
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4294 purple_debug_info("msim", "msg packed=%s\n", packed);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4295
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4296 packed_expected = "\\bx\\WFhY\\k1\\v1\\k1\\42\\k1"
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4297 "\\v43\\k1\\v52/1xxx/2yyy\\k1\\v7\\final\\";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4298
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4299 if (0 != strcmp(packed, packed_expected)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4300 purple_debug_info("msim", "!!!(%d), msim_msg_pack not what expected: %s != %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4301 ++failures, packed, packed_expected);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4302 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4303
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4304
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4305 msg_cloned = msim_msg_clone(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4306 packed_cloned = msim_msg_pack(msg_cloned);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4307
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4308 purple_debug_info("msim", "msg cloned=%s\n", packed_cloned);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4309 if (0 != strcmp(packed, packed_cloned)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4310 purple_debug_info("msim", "!!!(%d), msim_msg_pack on cloned message not equal to original: %s != %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4311 ++failures, packed_cloned, packed);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4312 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4313
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4314 g_free(packed);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4315 g_free(packed_cloned);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4316 msim_msg_free(msg_cloned);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4317 msim_msg_free(msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4318
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4319 /* Try some of the more advanced functionality */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4320 list = NULL;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4321
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4322 list = g_list_prepend(list, "item3");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4323 list = g_list_prepend(list, "item2");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4324 list = g_list_prepend(list, "item1");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4325 list = g_list_prepend(list, "item0");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4326
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4327 msg = msim_msg_new(NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4328 msg = msim_msg_append(msg, "string", MSIM_TYPE_STRING, g_strdup("string value"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4329 msg = msim_msg_append(msg, "raw", MSIM_TYPE_RAW, g_strdup("raw value"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4330 msg = msim_msg_append(msg, "integer", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(3140));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4331 msg = msim_msg_append(msg, "boolean", MSIM_TYPE_BOOLEAN, GUINT_TO_POINTER(FALSE));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4332 msg = msim_msg_append(msg, "list", MSIM_TYPE_LIST, list);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4333
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4334 msim_msg_dump("msg with list=%s\n", msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4335 purple_debug_info("msim", "msg with list packed=%s\n", msim_msg_pack(msg));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4336
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4337 msg2 = msim_msg_new(NULL);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4338 msg2 = msim_msg_append(msg2, "outer", MSIM_TYPE_STRING, g_strdup("outer value"));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4339 msg2 = msim_msg_append(msg2, "body", MSIM_TYPE_DICTIONARY, msg);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4340 msim_msg_dump("msg with dict=%s\n", msg2); /* msg2 now 'owns' msg */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4341 purple_debug_info("msim", "msg with dict packed=%s\n", msim_msg_pack(msg2));
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4342
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4343 msim_msg_free(msg2);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4344
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4345 return failures;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4346 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4347
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4348 /** Test protocol-level escaping/unescaping. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4349 int
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4350 msim_test_escaping(void)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4351 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4352 guint failures;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4353 gchar *raw, *escaped, *unescaped, *expected;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4354
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4355 failures = 0;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4356
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4357 purple_debug_info("msim", "\n\nTesting escaping\n");
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4358
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4359 raw = "hello/world\\hello/world";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4360
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4361 escaped = msim_escape(raw);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4362 purple_debug_info("msim", "msim_test_escaping: raw=%s, escaped=%s\n", raw, escaped);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4363 expected = "hello/1world/2hello/1world";
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4364 if (0 != strcmp(escaped, expected)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4365 purple_debug_info("msim", "!!!(%d), msim_escape failed: %s != %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4366 ++failures, escaped, expected);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4367 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4368
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4369
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4370 unescaped = msim_unescape(escaped);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4371 g_free(escaped);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4372 purple_debug_info("msim", "msim_test_escaping: unescaped=%s\n", unescaped);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4373 if (0 != strcmp(raw, unescaped)) {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4374 purple_debug_info("msim", "!!!(%d), msim_unescape failed: %s != %s\n",
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4375 ++failures, raw, unescaped);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4376 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4377
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4378 return failures;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4379 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4380 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4381
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4382 /** Initialize plugin. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4383 void
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4384 init_plugin(PurplePlugin *plugin)
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4385 {
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4386 PurpleAccountOption *option;
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4387 #ifdef MSIM_SELF_TEST
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4388 msim_test_all();
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4389 exit(0);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4390 #endif /* MSIM_SELF_TEST */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4391
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4392
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4393 /* TODO: default to automatically try different ports. Make the user be
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4394 * able to set the first port to try (like LastConnectedPort in Windows client). */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4395 option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4396 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4397
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4398 option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4399 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4400
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4401 #ifdef MSIM_USER_WANTS_TO_CONFIGURE_STATUS_TEXT
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4402 option = purple_account_option_bool_new(_("Show display name in status text"), "show_display_name", TRUE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4403 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4404
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4405 option = purple_account_option_bool_new(_("Show headline in status text"), "show_headline", TRUE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4406 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4407 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4408
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4409 #ifdef MSIM_USER_WANTS_TO_DISABLE_EMOTICONS
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4410 option = purple_account_option_bool_new(_("Send emoticons"), "emoticons", FALSE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4411 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4412 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4413
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4414 #ifdef MSIM_USER_REALLY_CARES_ABOUT_PRECISE_FONT_SIZES
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4415 option = purple_account_option_int_new(_("Screen resolution (dots per inch)"), "dpi", MSIM_DEFAULT_DPI);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4416 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4417
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4418 option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4419 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4420 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4421
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4422 /* TODO: /zap command. Problem with this is that there are different kinds of zaps,
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4423 * and the selection is best made available in a drop-down menu, instead of forcing
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4424 * the user to type the kind of zap and memorizing available zaps (or putting it in the
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4425 * help menu). A new "attention" API, for zap/buzz/nudge (different protocols) will
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4426 * solve this. */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4427 #if 0
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4428 purple_cmd_register("zap", /* cmd */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4429 "w", /* args - accept a single word */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4430 PURPLE_CMD_P_PRPL, /* priority */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4431 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, /* flags */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4432 "prpl-myspace", /* prpl_id */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4433 msim_cmd_zap, /* func */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4434 _("zap: zap a user to get their attention"), /* helpstr */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4435 NULL); /* data */
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4436 #endif
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4437 }
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4438
f60192409e7f merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 18918 18917
diff changeset
4439 PURPLE_INIT_PLUGIN(myspace, init_plugin, info);