server/src/util/goodies.c

107 lines
2.3 KiB
C
Raw Normal View History

2010-08-08 10:06:34 +02:00
#include <platform.h>
#include "goodies.h"
/* libc includes */
#include <stdlib.h>
2015-05-18 09:04:05 +02:00
#include <string.h>
2010-08-08 10:06:34 +02:00
/* Simple Integer-Liste */
2011-03-07 08:02:35 +01:00
int *intlist_init(void)
2010-08-08 10:06:34 +02:00
{
return (calloc(1, sizeof(int)));
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
int *intlist_add(int *i_p, int i)
2010-08-08 10:06:34 +02:00
{
void *tmp;
i_p[0]++;
tmp = realloc(i_p, (i_p[0] + 1) * sizeof(int));
if (!tmp) abort();
i_p = (int *)tmp;
2011-03-07 08:02:35 +01:00
i_p[i_p[0]] = i;
return (i_p);
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
int *intlist_find(int *i_p, int fi)
2010-08-08 10:06:34 +02:00
{
int i;
2011-03-07 08:02:35 +01:00
for (i = 1; i <= i_p[0]; i++) {
if (i_p[i] == fi)
return (&i_p[i]);
}
return NULL;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static int spc_email_isvalid(const char *address)
2010-08-08 10:06:34 +02:00
{
int count = 0;
const char *c, *domain;
static const char *rfc822_specials = "()<>@,;:\\\"[]"; /* STATIC_CONST: contains a constant value */
/* first we validate the name portion (name@domain) */
for (c = address; *c; c++) {
if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) == '\"')) {
while (*++c) {
if (*c == '\"')
break;
if (*c == '\\' && (*++c == ' '))
continue;
if (*c <= ' ' || *c >= 127)
return 0;
}
if (!*c++)
return 0;
if (*c == '@')
break;
if (*c != '.')
return 0;
continue;
}
if (*c == '@')
break;
2011-03-07 08:02:35 +01:00
if (*c <= ' ' || *c >= 127)
return 0;
if (strchr(rfc822_specials, *c))
return 0;
2011-03-07 08:02:35 +01:00
}
if (*c!='@') {
/* no @ symbol */
return -1;
}
domain = ++c;
if (!*c) {
return -1;
}
if (c == address || *(c - 1) == '.')
return 0;
2010-08-08 10:06:34 +02:00
/* next we validate the domain portion (name@domain) */
do {
if (*c == '.') {
if (c == domain || *(c - 1) == '.')
return 0;
count++;
}
if (*c <= ' ' || *c >= 127)
return 0;
if (strchr(rfc822_specials, *c))
return 0;
} while (*++c);
2010-08-08 10:06:34 +02:00
return (count >= 1);
2010-08-08 10:06:34 +02:00
}
2017-11-14 16:20:31 +01:00
int check_email(const char *newmail)
2010-08-08 10:06:34 +02:00
{
if (newmail && *newmail) {
if (spc_email_isvalid(newmail) <= 0)
return -1;
2017-11-14 16:20:31 +01:00
} else {
return -1;
}
return 0;
2010-08-08 10:06:34 +02:00
}