Sun, 17 Aug 2008 06:41:47 +0000
propagate from branch 'im.pidgin.pidgin' (head bae667a13f2ccb147e9f29eda6580be70c9b4ac2)
to branch 'im.pidgin.soc.2008.masterpassword' (head 5fcfc69be362961f0c3d36f1456f9139ebf493fe)
| 11414 | 1 | /** |
|
13627
44233a1064f9
[gaim-migrate @ 16013]
Evan Schoenberg <evands@pidgin.im>
parents:
12373
diff
changeset
|
2 | * @file gg-utils.c |
| 11414 | 3 | * |
| 15884 | 4 | * purple |
| 11414 | 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 11414 | 21 | */ |
| 22 | ||
| 23 | ||
|
13627
44233a1064f9
[gaim-migrate @ 16013]
Evan Schoenberg <evands@pidgin.im>
parents:
12373
diff
changeset
|
24 | #include "gg-utils.h" |
| 11414 | 25 | |
| 26 | ||
|
12224
bf547f7989a4
[gaim-migrate @ 14526]
Richard Laager <rlaager@pidgin.im>
parents:
12223
diff
changeset
|
27 | /* uin_t ggp_str_to_uin(const char *str) {{{ */ |
|
bf547f7989a4
[gaim-migrate @ 14526]
Richard Laager <rlaager@pidgin.im>
parents:
12223
diff
changeset
|
28 | uin_t ggp_str_to_uin(const char *str) |
| 11414 | 29 | { |
| 30 | char *tmp; | |
| 31 | long num; | |
| 32 | ||
|
12225
056e128413ef
[gaim-migrate @ 14527]
Richard Laager <rlaager@pidgin.im>
parents:
12224
diff
changeset
|
33 | if (!str) |
| 11414 | 34 | return 0; |
| 35 | ||
| 36 | errno = 0; | |
|
12225
056e128413ef
[gaim-migrate @ 14527]
Richard Laager <rlaager@pidgin.im>
parents:
12224
diff
changeset
|
37 | num = strtol(str, &tmp, 10); |
| 11414 | 38 | |
|
12225
056e128413ef
[gaim-migrate @ 14527]
Richard Laager <rlaager@pidgin.im>
parents:
12224
diff
changeset
|
39 | if (*str == '\0' || *tmp != '\0') |
| 11414 | 40 | return 0; |
| 41 | ||
| 12007 | 42 | if ((errno == ERANGE || (num == LONG_MAX || num == LONG_MIN)) |
|
12223
ae3a794b20e5
[gaim-migrate @ 14525]
Richard Laager <rlaager@pidgin.im>
parents:
12214
diff
changeset
|
43 | #if (LONG_MAX > UINT_MAX) |
|
ae3a794b20e5
[gaim-migrate @ 14525]
Richard Laager <rlaager@pidgin.im>
parents:
12214
diff
changeset
|
44 | || num > (long)UINT_MAX |
|
ae3a794b20e5
[gaim-migrate @ 14525]
Richard Laager <rlaager@pidgin.im>
parents:
12214
diff
changeset
|
45 | #endif |
|
ae3a794b20e5
[gaim-migrate @ 14525]
Richard Laager <rlaager@pidgin.im>
parents:
12214
diff
changeset
|
46 | || num < 0) |
| 11414 | 47 | return 0; |
| 48 | ||
| 49 | return (uin_t) num; | |
| 50 | } | |
| 51 | /* }}} */ | |
| 52 | ||
| 15288 | 53 | /* unsigned int ggp_array_size(char **array) {{{ */ |
| 54 | unsigned int ggp_array_size(char **array) | |
| 55 | { | |
| 56 | unsigned int i; | |
| 57 | ||
| 58 | for (i = 0; array[i] != NULL && i < UINT_MAX; i++) | |
| 59 | {} | |
| 60 | ||
| 61 | return i; | |
| 62 | } | |
| 63 | /* }}} */ | |
| 64 | ||
| 11414 | 65 | /* char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) {{{ */ |
| 66 | char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) | |
| 67 | { | |
| 68 | gchar *msg; | |
| 69 | GError *err = NULL; | |
| 70 | ||
| 71 | if (locstr == NULL) | |
| 72 | return NULL; | |
| 73 | ||
| 12007 | 74 | msg = g_convert_with_fallback(locstr, strlen(locstr), encdst, encsrc, |
| 75 | "?", NULL, NULL, &err); | |
| 11414 | 76 | if (err != NULL) { |
| 15884 | 77 | purple_debug_error("gg", "Error converting from %s to %s: %s\n", |
| 12007 | 78 | encsrc, encdst, err->message); |
| 11414 | 79 | g_error_free(err); |
| 80 | } | |
| 81 | ||
| 82 | /* Just in case? */ | |
| 83 | if (msg == NULL) | |
| 84 | msg = g_strdup(locstr); | |
| 85 | ||
| 86 | return msg; | |
| 87 | } | |
| 88 | /* }}} */ | |
| 89 | ||
| 15884 | 90 | /* ggp_get_uin(PurpleAccount *account) {{{ */ |
| 91 | uin_t ggp_get_uin(PurpleAccount *account) | |
| 11414 | 92 | { |
| 15884 | 93 | return ggp_str_to_uin(purple_account_get_username(account)); |
| 11414 | 94 | } |
| 95 | /* }}} */ | |
| 96 | ||
| 15884 | 97 | /* char *ggp_buddy_get_name(PurpleConnection *gc, const uin_t uin) {{{ */ |
| 98 | char *ggp_buddy_get_name(PurpleConnection *gc, const uin_t uin) | |
| 11414 | 99 | { |
| 15884 | 100 | PurpleBuddy *buddy; |
| 11414 | 101 | gchar *str_uin; |
| 102 | ||
| 103 | str_uin = g_strdup_printf("%lu", (unsigned long int)uin); | |
| 104 | ||
| 15884 | 105 | buddy = purple_find_buddy(purple_connection_get_account(gc), str_uin); |
| 11414 | 106 | if (buddy != NULL) { |
| 107 | g_free(str_uin); | |
| 15884 | 108 | return g_strdup(purple_buddy_get_alias(buddy)); |
| 11414 | 109 | } else { |
| 110 | return str_uin; | |
| 111 | } | |
| 112 | } | |
| 113 | /* }}} */ | |
| 114 | ||
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
115 | void ggp_status_fake_to_self(PurpleAccount *account) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
116 | { |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
117 | PurplePresence *presence; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
118 | PurpleStatus *status; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
119 | const char *status_id; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
120 | const char *msg; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
121 | |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
122 | if (! purple_find_buddy(account, purple_account_get_username(account))) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
123 | return; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
124 | |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
125 | presence = purple_account_get_presence(account); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
126 | status = purple_presence_get_active_status(presence); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
127 | msg = purple_status_get_attr_string(status, "message"); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
128 | if (msg && !*msg) |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
129 | msg = NULL; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
130 | |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
131 | status_id = purple_status_get_id(status); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
132 | if (strcmp(status_id, "invisible") == 0) { |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
133 | status_id = "offline"; |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
134 | } |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
135 | |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
136 | if (msg) { |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
137 | if (strlen(msg) > GG_STATUS_DESCR_MAXSIZE) { |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
138 | msg = purple_markup_slice(msg, 0, GG_STATUS_DESCR_MAXSIZE); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
139 | } |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
140 | } |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
141 | purple_prpl_got_user_status(account, purple_account_get_username(account), |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
142 | status_id, |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
143 | msg ? "message" : NULL, msg, NULL); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
144 | } |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
145 | |
| 11414 | 146 | |
| 12007 | 147 | /* vim: set ts=8 sts=0 sw=8 noet: */ |