libpurple/protocols/gg/validator.c

Thu, 23 Feb 2023 22:42:20 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 23 Feb 2023 22:42:20 -0600
changeset 42085
a76f1668564c
parent 40538
222423055d93
child 42124
472dc8caeda3
permissions
-rw-r--r--

Make the gadu gadu protocol plugin clean for warning level 2

Testing Done:
Touched all of the files, built, and verifed the warnings were gone.

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

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
42085
a76f1668564c Make the gadu gadu protocol plugin clean for warning level 2
Gary Kramlich <grim@reaperworld.com>
parents: 40538
diff changeset
36 gboolean
a76f1668564c Make the gadu gadu protocol plugin clean for warning level 2
Gary Kramlich <grim@reaperworld.com>
parents: 40538
diff changeset
37 ggp_validator_password(PurpleRequestField *field, gchar **errmsg,
a76f1668564c Make the gadu gadu protocol plugin clean for warning level 2
Gary Kramlich <grim@reaperworld.com>
parents: 40538
diff changeset
38 G_GNUC_UNUSED gpointer data)
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
39 {
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
40 const char *value;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
41
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
42 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
43 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
44 PURPLE_REQUEST_FIELD_STRING, FALSE);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
45
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
46 value = purple_request_field_string_get_value(field);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
47
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
48 if (value != NULL) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
49 size_t len = strlen(value);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
50 if (6 <= len && len <= 15) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
51 if (g_regex_match_simple(
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
52 "^[ a-zA-Z0-9~`!@#$%^&*()_+=[\\]{};':\",./?<>\\\\|-]+$",
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
53 value, 0, 0)) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
54 return TRUE;
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 }
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
57 }
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
58
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
59 if (errmsg)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
60 *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
61 return FALSE;
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
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
64 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
65 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
66 {
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67 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
68 PurpleRequestField *field2 = field2_p;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
69
33332
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(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
71 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
72 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
73 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
74 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
75 PURPLE_REQUEST_FIELD_STRING, FALSE);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
76
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
77 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
78 value2 = purple_request_field_string_get_value(field2);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
79
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80 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
81 return TRUE;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
82
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
83 if (errmsg)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
84 *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
85 return FALSE;
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
86 }

mercurial