Mercurial > pidgin.yaz
annotate src/protocols/gg/utils.c @ 12090:34390fe6eced
[gaim-migrate @ 14387]
Yes, rlaager, this change should be in ChangeLog.API
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 14 Nov 2005 22:49:30 +0000 |
parents | 8724718d387f |
children | cadda0024205 |
rev | line source |
---|---|
11414 | 1 /** |
2 * @file utils.c | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 | |
23 | |
24 #include "utils.h" | |
25 | |
26 | |
27 /* static uin_t ggp_str_to_uin(const char *text) {{{ */ | |
28 uin_t ggp_str_to_uin(const char *text) | |
29 { | |
30 char *tmp; | |
31 long num; | |
32 | |
33 if (!text) | |
34 return 0; | |
35 | |
36 errno = 0; | |
37 num = strtol(text, &tmp, 0); | |
38 | |
39 if (*text == '\0' || *tmp != '\0') | |
40 return 0; | |
41 | |
12007
8724718d387f
[gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11414
diff
changeset
|
42 if ((errno == ERANGE || (num == LONG_MAX || num == LONG_MIN)) |
8724718d387f
[gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11414
diff
changeset
|
43 || num > UINT_MAX || num < 0) |
11414 | 44 return 0; |
45 | |
46 return (uin_t) num; | |
47 } | |
48 /* }}} */ | |
49 | |
50 /* char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) {{{ */ | |
51 char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) | |
52 { | |
53 gchar *msg; | |
54 GError *err = NULL; | |
55 | |
56 if (locstr == NULL) | |
57 return NULL; | |
58 | |
12007
8724718d387f
[gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11414
diff
changeset
|
59 msg = g_convert_with_fallback(locstr, strlen(locstr), encdst, encsrc, |
8724718d387f
[gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11414
diff
changeset
|
60 "?", NULL, NULL, &err); |
11414 | 61 if (err != NULL) { |
62 gaim_debug_error("gg", "Error converting from %s to %s: %s\n", | |
12007
8724718d387f
[gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11414
diff
changeset
|
63 encsrc, encdst, err->message); |
11414 | 64 g_error_free(err); |
65 } | |
66 | |
67 /* Just in case? */ | |
68 if (msg == NULL) | |
69 msg = g_strdup(locstr); | |
70 | |
71 return msg; | |
72 } | |
73 /* }}} */ | |
74 | |
75 /* ggp_get_uin(GaimAccount *account) {{{ */ | |
76 uin_t ggp_get_uin(GaimAccount *account) | |
77 { | |
78 return ggp_str_to_uin(gaim_account_get_username(account)); | |
79 } | |
80 /* }}} */ | |
81 | |
82 /* const *char ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) {{{ */ | |
83 const char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) | |
84 { | |
85 GaimBuddy *buddy; | |
86 gchar *str_uin; | |
87 | |
88 str_uin = g_strdup_printf("%lu", (unsigned long int)uin); | |
89 | |
90 buddy = gaim_find_buddy(gaim_connection_get_account(gc), str_uin); | |
91 if (buddy != NULL) { | |
92 g_free(str_uin); | |
93 return gaim_buddy_get_alias(buddy); | |
94 } else { | |
95 return str_uin; | |
96 } | |
97 } | |
98 /* }}} */ | |
99 | |
100 | |
12007
8724718d387f
[gaim-migrate @ 14300]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11414
diff
changeset
|
101 /* vim: set ts=8 sts=0 sw=8 noet: */ |