~vish/ubuntu/maverick/pidgin/bug25979

« back to all changes in this revision

Viewing changes to libpurple/protocols/oscar/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-10-09 19:40:26 UTC
  • mfrom: (1.4.1 upstream) (46.1.10 karmic)
  • Revision ID: james.westby@ubuntu.com-20091009194026-wbqqh0bsbz19nx5q
Tags: 1:2.6.2-1ubuntu7
* Don't stick the buddy list window to all desktops as some
  window managers have trouble to properly unstick it (LP: #346840)
  - debian/patches/11_buddy_list_really_show.patch
* Always use default tray icon size on KDE (LP: #209440)
  - debian/patches/62_tray_icon_size_kde.patch
* Use scrollbars in the preferences dialog if the screen height is
  below 700 px instead of 600 px
  - debian/patches/60_1024x600_gtkprefs.c.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 */
27
27
 
28
28
#include "oscar.h"
 
29
 
 
30
#include "core.h"
 
31
 
29
32
#include <ctype.h>
30
33
 
31
34
#ifdef _WIN32
32
35
#include "win32dep.h"
33
36
#endif
34
37
 
 
38
int oscar_get_ui_info_int(const char *str, int default_value)
 
39
{
 
40
        GHashTable *ui_info;
 
41
 
 
42
        ui_info = purple_core_get_ui_info();
 
43
        if (ui_info != NULL) {
 
44
                gpointer value;
 
45
                if (g_hash_table_lookup_extended(ui_info, str, NULL, &value))
 
46
                        return GPOINTER_TO_INT(value);
 
47
        }
 
48
 
 
49
        return default_value;
 
50
}
 
51
 
 
52
const char *oscar_get_ui_info_string(const char *str, const char *default_value)
 
53
{
 
54
        GHashTable *ui_info;
 
55
        const char *value = NULL;
 
56
 
 
57
        ui_info = purple_core_get_ui_info();
 
58
        if (ui_info != NULL)
 
59
                value = g_hash_table_lookup(ui_info, str);
 
60
        if (value == NULL)
 
61
                value = default_value;
 
62
 
 
63
        return value;
 
64
}
 
65
 
 
66
gchar *oscar_get_clientstring(void)
 
67
{
 
68
        const char *name, *version;
 
69
 
 
70
        name = oscar_get_ui_info_string("name", "Purple");
 
71
        version = oscar_get_ui_info_string("version", VERSION);
 
72
 
 
73
        return g_strdup_printf("%s/%s", name, version);;
 
74
}
 
75
 
35
76
/*
36
77
 * Tokenizing functions.  Used to portably replace strtok/sep.
37
78
 *   -- DMP.
136
177
}
137
178
 
138
179
/**
139
 
 * Check if the given screen name is a valid AIM screen name.
 
180
 * Check if the given name is a valid AIM username.
140
181
 * Example: BobDole
141
182
 * Example: Henry_Ford@mac.com
142
183
 * Example: 1KrazyKat@example.com
143
184
 *
144
 
 * @return TRUE if the screen name is valid, FALSE if not.
 
185
 * @return TRUE if the name is valid, FALSE if not.
145
186
 */
146
187
static gboolean
147
 
aim_snvalid_aim(const char *sn)
 
188
oscar_util_valid_name_aim(const char *name)
148
189
{
149
190
        int i;
150
191
 
151
 
        if (purple_email_is_valid(sn))
 
192
        if (purple_email_is_valid(name))
152
193
                return TRUE;
153
194
 
154
 
        /* Normal AIM screen names can't start with a number */
155
 
        if (isdigit(sn[0]))
 
195
        /* Normal AIM usernames can't start with a number */
 
196
        if (isdigit(name[0]))
156
197
                return FALSE;
157
198
 
158
 
        for (i = 0; sn[i] != '\0'; i++) {
159
 
                if (!isalnum(sn[i]) && (sn[i] != ' '))
 
199
        for (i = 0; name[i] != '\0'; i++) {
 
200
                if (!isalnum(name[i]) && (name[i] != ' '))
160
201
                        return FALSE;
161
202
        }
162
203
 
164
205
}
165
206
 
166
207
/**
167
 
 * Check if the given screen name is a valid ICQ screen name.
 
208
 * Check if the given name is a valid ICQ username.
168
209
 * Example: 1234567
169
210
 *
170
 
 * @return TRUE if the screen name is valid, FALSE if not.
 
211
 * @return TRUE if the name is valid, FALSE if not.
171
212
 */
172
213
gboolean
173
 
aim_snvalid_icq(const char *sn)
 
214
oscar_util_valid_name_icq(const char *name)
174
215
{
175
216
        int i;
176
217
 
177
 
        for (i = 0; sn[i] != '\0'; i++) {
178
 
                if (!isdigit(sn[i]))
 
218
        for (i = 0; name[i] != '\0'; i++) {
 
219
                if (!isdigit(name[i]))
179
220
                        return FALSE;
180
221
        }
181
222
 
183
224
}
184
225
 
185
226
/**
186
 
 * Check if the given screen name is a valid SMS screen name.
 
227
 * Check if the given name is a valid SMS username.
187
228
 * Example: +19195551234
188
229
 *
189
 
 * @return TRUE if the screen name is valid, FALSE if not.
 
230
 * @return TRUE if the name is valid, FALSE if not.
190
231
 */
191
232
gboolean
192
 
aim_snvalid_sms(const char *sn)
 
233
oscar_util_valid_name_sms(const char *name)
193
234
{
194
235
        int i;
195
236
 
196
 
        if (sn[0] != '+')
 
237
        if (name[0] != '+')
197
238
                return FALSE;
198
239
 
199
 
        for (i = 1; sn[i] != '\0'; i++) {
200
 
                if (!isdigit(sn[i]))
 
240
        for (i = 1; name[i] != '\0'; i++) {
 
241
                if (!isdigit(name[i]))
201
242
                        return FALSE;
202
243
        }
203
244
 
205
246
}
206
247
 
207
248
/**
208
 
 * Check if the given screen name is a valid oscar screen name.
 
249
 * Check if the given name is a valid oscar username.
209
250
 *
210
 
 * @return TRUE if the screen name is valid, FALSE if not.
 
251
 * @return TRUE if the name is valid, FALSE if not.
211
252
 */
212
253
gboolean
213
 
aim_snvalid(const char *sn)
 
254
oscar_util_valid_name(const char *name)
214
255
{
215
 
        if ((sn == NULL) || (*sn == '\0'))
 
256
        if ((name == NULL) || (*name == '\0'))
216
257
                return FALSE;
217
258
 
218
 
        return aim_snvalid_icq(sn) || aim_snvalid_sms(sn) || aim_snvalid_aim(sn);
 
259
        return oscar_util_valid_name_icq(name)
 
260
                        || oscar_util_valid_name_sms(name)
 
261
                        || oscar_util_valid_name_aim(name);
219
262
}
220
263
 
221
264
/**
222
 
 * This takes two screen names and compares them using the rules
223
 
 * on screen names for AIM/AOL.  Mainly, this means case and space
 
265
 * This takes two names and compares them using the rules
 
266
 * on usernames for AIM/AOL.  Mainly, this means case and space
224
267
 * insensitivity (all case differences and spacing differences are
225
 
 * ignored, with the exception that screen names can not start with
 
268
 * ignored, with the exception that usernames can not start with
226
269
 * a space).
227
270
 *
228
271
 * @return 0 if equal, non-0 if different
229
272
 */
230
273
/* TODO: Do something different for email addresses. */
231
274
int
232
 
aim_sncmp(const char *sn1, const char *sn2)
 
275
oscar_util_name_compare(const char *name1, const char *name2)
233
276
{
234
277
 
235
 
        if ((sn1 == NULL) || (sn2 == NULL))
 
278
        if ((name1 == NULL) || (name2 == NULL))
236
279
                return -1;
237
280
 
238
281
        do {
239
 
                while (*sn2 == ' ')
240
 
                        sn2++;
241
 
                while (*sn1 == ' ')
242
 
                        sn1++;
243
 
                if (toupper(*sn1) != toupper(*sn2))
 
282
                while (*name2 == ' ')
 
283
                        name2++;
 
284
                while (*name1 == ' ')
 
285
                        name1++;
 
286
                if (toupper(*name1) != toupper(*name2))
244
287
                        return 1;
245
 
        } while ((*sn1 != '\0') && sn1++ && sn2++);
 
288
        } while ((*name1 != '\0') && name1++ && name2++);
246
289
 
247
290
        return 0;
248
291
}