diff options
author | Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im> | 2012-08-06 21:26:07 +0200 |
---|---|---|
committer | Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im> | 2012-08-06 21:26:07 +0200 |
commit | 121df0b15f1aab856979b15d07b18c90ef48869a (patch) | |
tree | 351d66264cb0255a45effefd6f616f1e56017e78 | |
parent | 83bb036abde4e87dc1f12a1ecad4dca1e1a64ed5 (diff) | |
download | pidgin-121df0b15f1aab856979b15d07b18c90ef48869a.tar.gz |
Gadu-Gadu: let's use brand new validation for Request API (2)
-rw-r--r-- | libpurple/protocols/gg/validator.c | 66 | ||||
-rw-r--r-- | libpurple/protocols/gg/validator.h | 16 |
2 files changed, 82 insertions, 0 deletions
diff --git a/libpurple/protocols/gg/validator.c b/libpurple/protocols/gg/validator.c new file mode 100644 index 0000000000..5bb8686c3a --- /dev/null +++ b/libpurple/protocols/gg/validator.c @@ -0,0 +1,66 @@ +#include "validator.h" + +#include "account.h" +#include "utils.h" + +gboolean ggp_validator_token(PurpleRequestField *field, gchar **errmsg, + void *token) +{ + const char *value; + + g_return_val_if_fail(field != NULL, FALSE); + g_return_val_if_fail(purple_request_field_get_type(field) == + PURPLE_REQUEST_FIELD_STRING, FALSE); + + value = purple_request_field_string_get_value(field); + + if (value != NULL && ggp_account_token_validate(token, value)) + return TRUE; + + if (errmsg) + *errmsg = g_strdup(_("Captcha validation failed")); + return FALSE; +} + +gboolean ggp_validator_password(PurpleRequestField *field, gchar **errmsg, + void *user_data) +{ + const char *value; + + g_return_val_if_fail(field != NULL, FALSE); + g_return_val_if_fail(purple_request_field_get_type(field) == + PURPLE_REQUEST_FIELD_STRING, FALSE); + + value = purple_request_field_string_get_value(field); + + if (value != NULL && ggp_password_validate(value)) + return TRUE; + + if (errmsg) + *errmsg = g_strdup(_("Password can contain 6-15 alphanumeric characters")); + return FALSE; +} + +gboolean ggp_validator_password_equal(PurpleRequestField *field, gchar **errmsg, + void *field2_p) +{ + const char *value1, *value2; + PurpleRequestField *field2 = field2_p; + + g_return_val_if_fail(field != NULL, FALSE); + g_return_val_if_fail(field2 != NULL, FALSE); + g_return_val_if_fail(purple_request_field_get_type(field) == + PURPLE_REQUEST_FIELD_STRING, FALSE); + g_return_val_if_fail(purple_request_field_get_type(field2) == + PURPLE_REQUEST_FIELD_STRING, FALSE); + + value1 = purple_request_field_string_get_value(field); + value2 = purple_request_field_string_get_value(field2); + + if (g_strcmp0(value1, value2) == 0) + return TRUE; + + if (errmsg) + *errmsg = g_strdup(_("Passwords do not match")); + return FALSE; +} diff --git a/libpurple/protocols/gg/validator.h b/libpurple/protocols/gg/validator.h new file mode 100644 index 0000000000..0be0fb1eee --- /dev/null +++ b/libpurple/protocols/gg/validator.h @@ -0,0 +1,16 @@ +#ifndef _GGP_VALIDATOR_H +#define _GGP_VALIDATOR_H + +#include <internal.h> +#include <request.h> + +gboolean ggp_validator_token(PurpleRequestField *field, gchar **errmsg, + void *token); + +gboolean ggp_validator_password(PurpleRequestField *field, gchar **errmsg, + void *user_data); + +gboolean ggp_validator_password_equal(PurpleRequestField *field, gchar **errmsg, + void *field2); + +#endif /* _GGP_VALIDATOR_H */ |