diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-04-07 04:21:29 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-04-07 04:21:29 +0000 |
commit | fe1cc2f25ac9ddaad8213e6f34268f1329c3d865 (patch) | |
tree | 31e23dd04d1db2632626ebf960061c9c3885527c /src/common | |
parent | 6729808a6dd1e3760c3f8b5453d07f27f35dca45 (diff) | |
download | hercules-fe1cc2f25ac9ddaad8213e6f34268f1329c3d865.tar.gz hercules-fe1cc2f25ac9ddaad8213e6f34268f1329c3d865.tar.bz2 hercules-fe1cc2f25ac9ddaad8213e6f34268f1329c3d865.tar.xz hercules-fe1cc2f25ac9ddaad8213e6f34268f1329c3d865.zip |
- Moved e_mail_check() and config_switch() to strlib.h
- Synchronized the login servers a bit
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10174 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/strlib.c | 50 | ||||
-rw-r--r-- | src/common/strlib.h | 4 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c index 327b2daf1..0ad0575f7 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -207,3 +207,53 @@ size_t strnlen (const char* string, size_t maxlen) return end ? (size_t) (end - string) : maxlen; } #endif + +//---------------------------------------------------- +// E-mail check: return 0 (not correct) or 1 (valid). +//---------------------------------------------------- +int e_mail_check(char* email) +{ + char ch; + char* last_arobas; + int len = strlen(email); + + // athena limits + if (len < 3 || len > 39) + return 0; + + // part of RFC limits (official reference of e-mail description) + if (strchr(email, '@') == NULL || email[len-1] == '@') + return 0; + + if (email[len-1] == '.') + return 0; + + last_arobas = strrchr(email, '@'); + + if (strstr(last_arobas, "@.") != NULL || strstr(last_arobas, "..") != NULL) + return 0; + + for(ch = 1; ch < 32; ch++) + if (strchr(last_arobas, ch) != NULL) + return 0; + + if (strchr(last_arobas, ' ') != NULL || strchr(last_arobas, ';') != NULL) + return 0; + + // all correct + return 1; +} + +//-------------------------------------------------- +// Return numerical value of a switch configuration +// on/off, english, français, deutsch, español +//-------------------------------------------------- +int config_switch(const char* str) +{ + if (strcmpi(str, "on") == 0 || strcmpi(str, "yes") == 0 || strcmpi(str, "oui") == 0 || strcmpi(str, "ja") == 0 || strcmpi(str, "si") == 0) + return 1; + if (strcmpi(str, "off") == 0 || strcmpi(str, "no") == 0 || strcmpi(str, "non") == 0 || strcmpi(str, "nein") == 0) + return 0; + + return (int)strtol(str, NULL, 0); +} diff --git a/src/common/strlib.h b/src/common/strlib.h index 332e823b9..baaf244d7 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -22,4 +22,8 @@ char* _strtok_r(char* s1, const char* s2, char** lasts); size_t strnlen (const char* string, size_t maxlen); #endif +int e_mail_check(char* email); +int config_switch(const char* str); + + #endif /* _STRLIB_H_ */ |