libpurple/protocols/gg/validator.c

Fri, 10 Mar 2023 01:16:40 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Fri, 10 Mar 2023 01:16:40 -0600
changeset 42135
1a89a067a0d5
parent 42124
472dc8caeda3
permissions
-rw-r--r--

Add a PurpleRequestFieldString subclass

This also does an `hg cp`, though with all the renaming of the parameter names, maybe that wasn't as useful for tracking the diff.

Note, I didn't bother re-indenting some of the blocks, because they'll all eventually be moved when everything is subclassed.

Testing Done:
Compiled and opened Request Fields from the Demo protocol.

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

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
42135
1a89a067a0d5 Add a PurpleRequestFieldString subclass
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42124
diff changeset
42 g_return_val_if_fail(PURPLE_IS_REQUEST_FIELD_STRING(field), FALSE);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
43
42135
1a89a067a0d5 Add a PurpleRequestFieldString subclass
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42124
diff changeset
44 value = purple_request_field_string_get_value(PURPLE_REQUEST_FIELD_STRING(field));
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
45
40538
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
46 if (value != NULL) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
47 size_t len = strlen(value);
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
48 if (6 <= len && len <= 15) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
49 if (g_regex_match_simple(
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
50 "^[ a-zA-Z0-9~`!@#$%^&*()_+=[\\]{};':\",./?<>\\\\|-]+$",
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
51 value, 0, 0)) {
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
52 return TRUE;
222423055d93 Cleanup some GG utility functions
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40439
diff changeset
53 }
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 }
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
56
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
57 if (errmsg)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
58 *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
59 return FALSE;
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
60 }
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 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
63 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
64 {
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
65 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
66 PurpleRequestField *field2 = field2_p;
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
67
42135
1a89a067a0d5 Add a PurpleRequestFieldString subclass
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42124
diff changeset
68 g_return_val_if_fail(PURPLE_IS_REQUEST_FIELD_STRING(field), FALSE);
1a89a067a0d5 Add a PurpleRequestFieldString subclass
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42124
diff changeset
69 g_return_val_if_fail(PURPLE_IS_REQUEST_FIELD_STRING(field2), FALSE);
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
70
42135
1a89a067a0d5 Add a PurpleRequestFieldString subclass
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42124
diff changeset
71 value1 = purple_request_field_string_get_value(PURPLE_REQUEST_FIELD_STRING(field));
1a89a067a0d5 Add a PurpleRequestFieldString subclass
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42124
diff changeset
72 value2 = purple_request_field_string_get_value(PURPLE_REQUEST_FIELD_STRING(field2));
35357
389e413e3414 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35305
diff changeset
73
33332
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
74 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
75 return TRUE;
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 if (errmsg)
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
78 *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
79 return FALSE;
3d3f0584edf6 Gadu-Gadu: let's use brand new validation for Request API (2)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80 }

mercurial