annotate libpurple/protocols/oscar/util.c @ 32770:1e0ded0cb2ee

Fix typo that was breaking compilation for me "HAVE_FARSTREAM" isn't a valid define. "HAVE_FARSIGHT" is
author Mark Doliner <mark@kingant.net>
date Fri, 13 Apr 2012 07:38:01 +0000
parents b441fd23e5bb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
2 * Purple's oscar protocol plugin
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * This file is the legal property of its developers.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 * Please see the AUTHORS file distributed alongside this file.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * Lesser General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19642
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * A little bit of this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * A little bit of that
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 * It started with a kiss
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 * Now we're up to bat
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 #include "oscar.h"
27427
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
29
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
30 #include "core.h"
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
31
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include <ctype.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 #include "win32dep.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37
29986
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
38 static const char * const msgerrreason[] = {
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
39 N_("Invalid error"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
40 N_("Invalid SNAC"),
30229
e5575248ca82 *** Plucked rev 16e7d9f71db071e6d043c456869b8f860bcc8d45 (ivan.komarov@soc.pidgin.im):
Paul Aurich <paul@darkrain42.org>
parents: 29986
diff changeset
41 N_("Server rate limit exceeded"),
30230
831634f28e76 *** Plucked rev 6290e1fa3bfba05e59462968ebbff460342c48dd (ivan.komarov@soc.pidgin.im):
Paul Aurich <paul@darkrain42.org>
parents: 30229
diff changeset
42 N_("Client rate limit exceeded"),
29986
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
43 N_("Not logged in"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
44 N_("Service unavailable"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
45 N_("Service not defined"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
46 N_("Obsolete SNAC"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
47 N_("Not supported by host"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
48 N_("Not supported by client"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
49 N_("Refused by client"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
50 N_("Reply too big"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
51 N_("Responses lost"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
52 N_("Request denied"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
53 N_("Busted SNAC payload"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
54 N_("Insufficient rights"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
55 N_("In local permit/deny"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
56 N_("Warning level too high (sender)"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
57 N_("Warning level too high (receiver)"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
58 N_("User temporarily unavailable"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
59 N_("No match"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
60 N_("List overflow"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
61 N_("Request ambiguous"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
62 N_("Queue full"),
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
63 N_("Not while on AOL")
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
64 };
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
65 static const int msgerrreasonlen = G_N_ELEMENTS(msgerrreason);
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
66
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
67 const char *oscar_get_msgerr_reason(size_t reason)
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
68 {
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
69 return (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Unknown reason");
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
70 }
f18b6eb0ed02 Cleanup, basically. Move the icbm snac error handling from oscar.c to
Mark Doliner <mark@kingant.net>
parents: 27429
diff changeset
71
27428
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
72 int oscar_get_ui_info_int(const char *str, int default_value)
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
73 {
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
74 GHashTable *ui_info;
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
75
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
76 ui_info = purple_core_get_ui_info();
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
77 if (ui_info != NULL) {
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
78 gpointer value;
27429
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
79 if (g_hash_table_lookup_extended(ui_info, str, NULL, &value))
27428
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
80 return GPOINTER_TO_INT(value);
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
81 }
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
82
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
83 return default_value;
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
84 }
5048054d319a Use the ui_info hash table instead of prefs when passing the clientstring
Mark Doliner <mark@kingant.net>
parents: 27427
diff changeset
85
27427
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
86 const char *oscar_get_ui_info_string(const char *str, const char *default_value)
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
87 {
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
88 GHashTable *ui_info;
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
89 const char *value = NULL;
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
90
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
91 ui_info = purple_core_get_ui_info();
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
92 if (ui_info != NULL)
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
93 value = g_hash_table_lookup(ui_info, str);
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
94 if (value == NULL)
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
95 value = default_value;
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
96
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
97 return value;
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
98 }
4f24d5da4cb3 Create a oscar_get_ui_info_string() function that looks up a value in the
Mark Doliner <mark@kingant.net>
parents: 25925
diff changeset
99
27429
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
100 gchar *oscar_get_clientstring(void)
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
101 {
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
102 const char *name, *version;
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
103
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
104 name = oscar_get_ui_info_string("name", "Purple");
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
105 version = oscar_get_ui_info_string("version", VERSION);
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
106
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
107 return g_strdup_printf("%s/%s", name, version);;
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
108 }
74e487f82f39 Oh, we don't need a special ui_info field for the AIM clientstring
Mark Doliner <mark@kingant.net>
parents: 27428
diff changeset
109
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 * Calculate the checksum of a given icon.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 guint16
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 aimutil_iconsum(const guint8 *buf, int buflen)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 guint32 sum;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 for (i=0, sum=0; i+1<buflen; i+=2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 sum += (buf[i+1] << 8) + buf[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 if (i < buflen)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 sum += buf[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 return sum;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 /**
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
129 * Check if the given name is a valid AIM username.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 * Example: BobDole
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 * Example: Henry_Ford@mac.com
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
132 * Example: 1KrazyKat@example.com
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 *
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
134 * @return TRUE if the name is valid, FALSE if not.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 static gboolean
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
137 oscar_util_valid_name_aim(const char *name)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
141 if (purple_email_is_valid(name))
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
142 return TRUE;
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
143
32510
b441fd23e5bb *** Plucked rev 13d6e924c9257b20e21050646cab88043bdb2e15 (markdoliner@pidgin.im):
Mark Doliner <mark@kingant.net>
parents: 30404
diff changeset
144 /* Normal AIM usernames can't start with a number, period or underscore */
b441fd23e5bb *** Plucked rev 13d6e924c9257b20e21050646cab88043bdb2e15 (markdoliner@pidgin.im):
Mark Doliner <mark@kingant.net>
parents: 30404
diff changeset
145 if (isalnum(name[0]) == 0)
18281
c298830e237f Make sure we still don't allow screen names of the form "1whatever"
Mark Doliner <mark@kingant.net>
parents: 18279
diff changeset
146 return FALSE;
c298830e237f Make sure we still don't allow screen names of the form "1whatever"
Mark Doliner <mark@kingant.net>
parents: 18279
diff changeset
147
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
148 for (i = 0; name[i] != '\0'; i++) {
32510
b441fd23e5bb *** Plucked rev 13d6e924c9257b20e21050646cab88043bdb2e15 (markdoliner@pidgin.im):
Mark Doliner <mark@kingant.net>
parents: 30404
diff changeset
149 if (!isalnum(name[i]) && name[i] != ' ' && name[i] != '.' && name[i] != '_')
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 /**
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
157 * Check if the given name is a valid ICQ username.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 * Example: 1234567
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 *
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
160 * @return TRUE if the name is valid, FALSE if not.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 */
19642
c0f503c18f7e A little function name shuffling.
Mark Doliner <mark@kingant.net>
parents: 18281
diff changeset
162 gboolean
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
163 oscar_util_valid_name_icq(const char *name)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
167 for (i = 0; name[i] != '\0'; i++) {
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
168 if (!isdigit(name[i]))
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
169 return FALSE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
172 return TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 /**
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
176 * Check if the given name is a valid SMS username.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 * Example: +19195551234
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 *
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
179 * @return TRUE if the name is valid, FALSE if not.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 */
19642
c0f503c18f7e A little function name shuffling.
Mark Doliner <mark@kingant.net>
parents: 18281
diff changeset
181 gboolean
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
182 oscar_util_valid_name_sms(const char *name)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
186 if (name[0] != '+')
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
187 return FALSE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
189 for (i = 1; name[i] != '\0'; i++) {
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
190 if (!isdigit(name[i]))
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
191 return FALSE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
194 return TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 /**
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
198 * Check if the given name is a valid oscar username.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 *
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
200 * @return TRUE if the name is valid, FALSE if not.
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 gboolean
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
203 oscar_util_valid_name(const char *name)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 {
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
205 if ((name == NULL) || (*name == '\0'))
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
206 return FALSE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
208 return oscar_util_valid_name_icq(name)
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
209 || oscar_util_valid_name_sms(name)
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
210 || oscar_util_valid_name_aim(name);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 /**
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
214 * This takes two names and compares them using the rules
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
215 * on usernames for AIM/AOL. Mainly, this means case and space
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 * insensitivity (all case differences and spacing differences are
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
217 * ignored, with the exception that usernames can not start with
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 * a space).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 *
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
220 * @return 0 if equal, non-0 if different
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 */
18279
48d2c9dbfcc2 Allow AIM screen names of the form "1abc@example.com" In most places
Mark Doliner <mark@kingant.net>
parents: 17191
diff changeset
222 /* TODO: Do something different for email addresses. */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 int
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
224 oscar_util_name_compare(const char *name1, const char *name2)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
227 if ((name1 == NULL) || (name2 == NULL))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 do {
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
231 while (*name2 == ' ')
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
232 name2++;
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
233 while (*name1 == ' ')
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
234 name1++;
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
235 if (toupper(*name1) != toupper(*name2))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 return 1;
25925
6e1967b0f90b Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <mark@kingant.net>
parents: 22752
diff changeset
237 } while ((*name1 != '\0') && name1++ && name2++);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 }
30361
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
241
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
242 /**
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
243 * Looks for %n, %d, or %t in a string, and replaces them with the
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
244 * specified name, date, and time, respectively.
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
245 *
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
246 * @param str The string that may contain the special variables.
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
247 * @param name The sender name.
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
248 *
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
249 * @return A newly allocated string where the special variables are
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
250 * expanded. This should be g_free'd by the caller.
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
251 */
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
252 gchar *
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
253 oscar_util_format_string(const char *str, const char *name)
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
254 {
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
255 char *c;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
256 GString *cpy;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
257 time_t t;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
258 struct tm *tme;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
259
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
260 g_return_val_if_fail(str != NULL, NULL);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
261 g_return_val_if_fail(name != NULL, NULL);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
262
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
263 /* Create an empty GString that is hopefully big enough for most messages */
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
264 cpy = g_string_sized_new(1024);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
265
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
266 t = time(NULL);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
267 tme = localtime(&t);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
268
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
269 c = (char *)str;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
270 while (*c) {
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
271 switch (*c) {
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
272 case '%':
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
273 if (*(c + 1)) {
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
274 switch (*(c + 1)) {
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
275 case 'n':
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
276 /* append name */
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
277 g_string_append(cpy, name);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
278 c++;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
279 break;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
280 case 'd':
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
281 /* append date */
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
282 g_string_append(cpy, purple_date_format_short(tme));
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
283 c++;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
284 break;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
285 case 't':
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
286 /* append time */
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
287 g_string_append(cpy, purple_time_format(tme));
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
288 c++;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
289 break;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
290 default:
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
291 g_string_append_c(cpy, *c);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
292 }
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
293 } else {
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
294 g_string_append_c(cpy, *c);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
295 }
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
296 break;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
297 default:
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
298 g_string_append_c(cpy, *c);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
299 }
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
300 c++;
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
301 }
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
302
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
303 return g_string_free(cpy, FALSE);
9881f18b95b1 Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible
ivan.komarov@soc.pidgin.im
parents: 29986
diff changeset
304 }
30373
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
305
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
306 gchar *
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
307 oscar_format_buddies(GSList *buddies, const gchar *no_buddies_message)
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
308 {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
309 GSList *cur;
30380
2d4dd38c5db5 Two small fixes Mark suggested:
ivan.komarov@soc.pidgin.im
parents: 30373
diff changeset
310 GString *result;
30373
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
311 if (!buddies) {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
312 return g_strdup_printf("<i>%s</i>", no_buddies_message);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
313 }
30380
2d4dd38c5db5 Two small fixes Mark suggested:
ivan.komarov@soc.pidgin.im
parents: 30373
diff changeset
314 result = g_string_new("");
30373
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
315 for (cur = buddies; cur != NULL; cur = cur->next) {
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
316 PurpleBuddy *buddy = cur->data;
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
317 const gchar *bname = purple_buddy_get_name(buddy);
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
318 const gchar *alias = purple_buddy_get_alias_only(buddy);
30380
2d4dd38c5db5 Two small fixes Mark suggested:
ivan.komarov@soc.pidgin.im
parents: 30373
diff changeset
319 g_string_append(result, bname);
30373
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
320 if (alias) {
30380
2d4dd38c5db5 Two small fixes Mark suggested:
ivan.komarov@soc.pidgin.im
parents: 30373
diff changeset
321 g_string_append_printf(result, " (%s)", alias);
30373
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
322 }
30380
2d4dd38c5db5 Two small fixes Mark suggested:
ivan.komarov@soc.pidgin.im
parents: 30373
diff changeset
323 g_string_append(result, "<br>");
30373
4e804413b12b Added a way to view the Visible/Invisible lists.
ivan.komarov@soc.pidgin.im
parents: 30365
diff changeset
324 }
30380
2d4dd38c5db5 Two small fixes Mark suggested:
ivan.komarov@soc.pidgin.im
parents: 30373
diff changeset
325 return g_string_free(result, FALSE);
30404
8e9b04071e79 propagate from branch 'im.pidgin.pidgin' (head 9166d0ffe82472b17cee09aabbef61d8ec6e3e44)
Mark Doliner <mark@kingant.net>
parents: 30388 30230
diff changeset
326 }