Tue, 07 Aug 2012 00:12:39 +0200
Gadu-Gadu: setting own buddy icon
| 11414 | 1 | /** |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
2 | * @file 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 | ||
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
23 | #include "utils.h" |
| 11414 | 24 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
25 | #include "gg.h" |
| 11414 | 26 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
27 | #include <debug.h> |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
28 | |
|
12224
bf547f7989a4
[gaim-migrate @ 14526]
Richard Laager <rlaager@pidgin.im>
parents:
12223
diff
changeset
|
29 | uin_t ggp_str_to_uin(const char *str) |
| 11414 | 30 | { |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
31 | char *endptr; |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
32 | uin_t uin; |
| 11414 | 33 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
34 | if (!str || str[0] < '0' || str[0] > '9') |
| 11414 | 35 | return 0; |
| 36 | ||
| 37 | errno = 0; | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
38 | uin = strtoul(str, &endptr, 10); |
| 11414 | 39 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
40 | if (errno == ERANGE || endptr[0] != '\0') |
| 11414 | 41 | return 0; |
| 42 | ||
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
43 | return uin; |
| 11414 | 44 | } |
| 45 | ||
|
33298
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
46 | const char * ggp_uin_to_str(uin_t uin) |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
47 | { |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
48 | static char buff[GGP_UIN_LEN_MAX + 1]; |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
49 | |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
50 | g_snprintf(buff, GGP_UIN_LEN_MAX + 1, "%u", uin); |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
51 | |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
52 | return buff; |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
53 | } |
|
519acf37d16e
Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32438
diff
changeset
|
54 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
55 | static gchar * ggp_convert(const gchar *src, const char *srcenc, |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
56 | const char *dstenc) |
| 15288 | 57 | { |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
58 | gchar *dst; |
| 11414 | 59 | GError *err = NULL; |
| 60 | ||
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
61 | if (src == NULL) |
| 11414 | 62 | return NULL; |
| 63 | ||
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
64 | dst = g_convert_with_fallback(src, strlen(src), dstenc, srcenc, "?", |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
65 | NULL, NULL, &err); |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
66 | if (err != NULL) |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
67 | { |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
68 | purple_debug_error("gg", "error converting from %s to %s: %s\n", |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
69 | srcenc, dstenc, err->message); |
| 11414 | 70 | g_error_free(err); |
| 71 | } | |
| 72 | ||
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
73 | if (dst == NULL) |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
74 | dst = g_strdup(src); |
| 11414 | 75 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
76 | return dst; |
| 11414 | 77 | } |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
78 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
79 | gchar * ggp_convert_to_cp1250(const gchar *src) |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
80 | { |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
81 | return ggp_convert(src, "UTF-8", "CP1250"); |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
82 | } |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
83 | |
|
33299
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
84 | gchar * ggp_convert_from_cp1250(const gchar *src) |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
85 | { |
|
b3c4ab3aeb7f
Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33298
diff
changeset
|
86 | return ggp_convert(src, "CP1250", "UTF-8"); |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
87 | } |
|
33309
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
88 | |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
89 | gboolean ggp_password_validate(const gchar *password) |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
90 | { |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
91 | const int len = strlen(password); |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
92 | if (len < 6 || len > 15) |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
93 | return FALSE; |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
94 | return g_regex_match_simple("^[ a-zA-Z0-9~`!@#$%^&*()_+=[\\]{};':\",./?" |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
95 | "<>\\\\|-]+$", password, 0, 0); |
|
bc2f2ea7b5ab
Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33305
diff
changeset
|
96 | } |