}
static gint
-rspamd_mailto_parse (struct http_parser_url *u, const gchar *str)
+rspamd_mailto_parse (struct http_parser_url *u, const gchar *str,
+ gchar const **end)
{
const gchar *p = str, *c = str;
gchar t;
+ gint ret = 1;
enum {
parse_mailto,
parse_slash,
st = parse_slash_slash;
}
else {
- return 1;
+ goto out;
}
p ++;
break;
st = parse_destination;
}
else {
- return 1;
+ goto out;
}
break;
case parse_destination:
case parse_user:
if (t == '@') {
if (p - c == 0) {
- return 1;
+ goto out;
}
u->field_set |= 1 << UF_USERINFO;
u->field_data[UF_USERINFO].len = p - c;
st = parse_at;
}
else if (!is_atom (t)) {
- return 1;
+ goto out;
}
p ++;
break;
st = parse_suffix_question;
}
else if (!is_domain (t) && t != '.' && t != '_') {
- return 1;
+ goto out;
}
p ++;
break;
break;
case parse_query:
if (!is_atom (t)) {
- return 1;
+ goto out;
}
p ++;
break;
}
if (st == parse_domain) {
- if (p - c == 0) {
- return 1;
- }
-
- u->field_set |= 1 << UF_HOST;
- u->field_data[UF_HOST].len = p - c;
- u->field_data[UF_HOST].off = c - str;
+ if (p - c != 0) {
+ u->field_set |= 1 << UF_HOST;
+ u->field_data[UF_HOST].len = p - c;
+ u->field_data[UF_HOST].off = c - str;
- return 0;
+ ret = 0;
+ }
}
else if (st == parse_query) {
if (p - c > 0) {
u->field_data[UF_QUERY].off = c - str;
}
- return 0;
+ ret = 0;
+ }
+
+out:
+ if (end != NULL) {
+ *end = p;
}
- return 1;
+ return ret;
}
static gint
-rspamd_web_parse (struct http_parser_url *u, const gchar *str)
+rspamd_web_parse (struct http_parser_url *u, const gchar *str, gchar const **end)
{
const gchar *p = str, *c = str;
gchar t;
st = parse_slash_slash;
}
else {
- return 1;
+ goto out;
}
p ++;
break;
case parse_user:
if (t == ':') {
if (p - c == 0) {
- return 1;
+ goto out;
}
u->field_set |= 1 << UF_USERINFO;
u->field_data[UF_USERINFO].len = p - c;
else if (t == '@') {
/* No password */
if (p - c == 0) {
- return 1;
+ goto out;
}
u->field_set |= 1 << UF_USERINFO;
u->field_data[UF_USERINFO].len = p - c;
st = parse_at;
}
else if (!is_atom (t)) {
- return 1;
+ goto out;
}
p ++;
break;
st = parse_at;
}
else if (!is_atom (t)) {
- return 1;
+ goto out;
}
p ++;
break;
case parse_domain:
if (t == '/' || t == ':') {
if (p - c == 0) {
- return 1;
+ goto out;
}
u->field_set |= 1 << UF_HOST;
u->field_data[UF_HOST].len = p - c;
if (uc == (gunichar)-1) {
/* Bad utf8 */
- return 1;
+ goto out;
}
if (!g_unichar_isalnum (uc)) {
/* Bad symbol */
- return 1;
+ goto out;
}
p = g_utf8_next_char (p);
if (t == '/') {
pt = strtoul (c, NULL, 10);
if (pt == 0 || pt > 65535) {
- return 1;
+ goto out;
}
u->port = pt;
st = parse_suffix_slash;
}
else if (!g_ascii_isdigit (t)) {
- return 1;
+ goto out;
}
p ++;
break;
switch (st) {
case parse_domain:
if (p - c == 0) {
- return 1;
+ goto out;
}
u->field_set |= 1 << UF_HOST;
u->field_data[UF_HOST].len = p - c;
case parse_port:
pt = strtoul (c, NULL, 10);
if (pt == 0 || pt > 65535) {
- return 1;
+ goto out;
}
u->port = pt;
ret = 0;
ret = 1;
break;
}
+out:
+ if (end != NULL) {
+ *end = p;
+ }
return ret;
}
if (len > sizeof ("mailto:") - 1) {
/* For mailto: urls we also need to add slashes to make it a valid URL */
if (g_ascii_strncasecmp (p, "mailto:", sizeof ("mailto:") - 1) == 0) {
- ret = rspamd_mailto_parse (&u, p);
+ ret = rspamd_mailto_parse (&u, p, NULL);
}
else {
- ret = rspamd_web_parse (&u, p);
+ ret = rspamd_web_parse (&u, p, NULL);
}
}
else {
- ret = rspamd_web_parse (&u, p);
+ ret = rspamd_web_parse (&u, p, NULL);
}
if (ret != 0) {