libpurple/protocols/gg/validator.c

Fri, 01 Oct 2021 05:09:16 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 01 Oct 2021 05:09:16 -0500
changeset 41071
f4f7d9f816f9
parent 40538
222423055d93
child 42085
a76f1668564c
permissions
-rw-r--r--

move the gadu-gadu protocol plugins icons to a resource in the plugin

Testing Done:
Ran in devenv with a logo inverted (which was reverted before committing).

Reviewed at https://reviews.imfreedom.org/r/976/

33348
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
1 /* purple
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
2 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
5 * source distribution.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
6 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
7 * Rewritten from scratch during Google Summer of Code 2012
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
8 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
9 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
10 * Previously implemented by:
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
11 * - Arkadiusz Miskiewicz <misiek@pld.org.pl> - first implementation (2001);
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
12 * - Bartosz Oler <bartosz@bzimage.us> - reimplemented during GSoC 2005;
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
13 * - Krzysztof Klinikowski <grommasher@gmail.com> - some parts (2009-2011).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
14 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
15 * This program is free software; you can redistribute it and/or modify
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
16 * it under the terms of the GNU General Public License as published by
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
17 * the Free Software Foundation; either version 2 of the License, or
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
18 * (at your option) any later version.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
19 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
20 * This program is distributed in the hope that it will be useful,
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
23 * GNU General Public License for more details.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
24 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
25 * You should have received a copy of the GNU General Public License
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
26 * along with this program; if not, write to the Free Software
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
28 */
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33332
diff changeset
29
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
30 #include "validator.h"
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
35305
056b8468d470 Manual merge for 07e827917960
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33348
diff changeset
32 #include "utils.h"
056b8468d470 Manual merge for 07e827917960
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33348
diff changeset
33
40439
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 38854
diff changeset
34 #include <glib/gi18n-lib.h>
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 38854
diff changeset
35
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
36 gboolean ggp_validator_password(PurpleRequestField *field, gchar **errmsg,
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
37 void *user_data)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38 {
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
39 const char *value;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
40
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
41 g_return_val_if_fail(field != NULL, FALSE);
35378
5d9e2581005b gtk-doc prep: *_get_type() functions are hidden as standard GType-returning funcs, so rename them.
Ankit Vani <a@nevitus.org>
parents: 35357
diff changeset
42 g_return_val_if_fail(purple_request_field_get_field_type(field) ==
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
43 PURPLE_REQUEST_FIELD_STRING, FALSE);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
44
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
45 value = purple_request_field_string_get_value(field);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
46
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
47 if (value != NULL) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
48 size_t len = strlen(value);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
49 if (6 <= len && len <= 15) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
50 if (g_regex_match_simple(
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
51 "^[ a-zA-Z0-9~`!@#$%^&*()_+=[\\]{};':\",./?<>\\\\|-]+$",
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
52 value, 0, 0)) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
53 return TRUE;
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
54 }
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
55 }
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
56 }
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
57
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
58 if (errmsg)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
59 *errmsg = g_strdup(_("Password can contain 6-15 alphanumeric characters"));
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
60 return FALSE;
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
61 }
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
62
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
63 gboolean ggp_validator_password_equal(PurpleRequestField *field, gchar **errmsg,
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
64 void *field2_p)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
65 {
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
66 const char *value1, *value2;
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67 PurpleRequestField *field2 = field2_p;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
68
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
69 g_return_val_if_fail(field != NULL, FALSE);
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
70 g_return_val_if_fail(field2 != NULL, FALSE);
35378
5d9e2581005b gtk-doc prep: *_get_type() functions are hidden as standard GType-returning funcs, so rename them.
Ankit Vani <a@nevitus.org>
parents: 35357
diff changeset
71 g_return_val_if_fail(purple_request_field_get_field_type(field) ==
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
72 PURPLE_REQUEST_FIELD_STRING, FALSE);
35378
5d9e2581005b gtk-doc prep: *_get_type() functions are hidden as standard GType-returning funcs, so rename them.
Ankit Vani <a@nevitus.org>
parents: 35357
diff changeset
73 g_return_val_if_fail(purple_request_field_get_field_type(field2) ==
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
74 PURPLE_REQUEST_FIELD_STRING, FALSE);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
75
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
76 value1 = purple_request_field_string_get_value(field);
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
77 value2 = purple_request_field_string_get_value(field2);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
78
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
79 if (g_strcmp0(value1, value2) == 0)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80 return TRUE;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
81
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
82 if (errmsg)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
83 *errmsg = g_strdup(_("Passwords do not match"));
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
84 return FALSE;
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
85 }

mercurial