Fix email validation

This commit is contained in:
Ilja Kartašov 2019-04-25 15:04:45 +02:00
parent e3e84a0441
commit e623c0dce1
2 changed files with 26 additions and 4 deletions

View File

@ -16,6 +16,7 @@
#include <ctype.h> #include <ctype.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include "log.h"
#include "validate.h" #include "validate.h"
@ -100,8 +101,11 @@ ax_validate_email(const char *value)
continue; continue;
default: default:
if ( isalnum(c) == 0 ) if (isalnum(c))
{
i++;
continue; continue;
}
break; break;
} }
return (int)(i-value)+1; return (int)(i-value)+1;

View File

@ -34,6 +34,8 @@ struct context
typedef struct context * Context; typedef struct context * Context;
static const char modName[] = "feedback";
static void static void
context_free(Context ctx) context_free(Context ctx)
@ -128,13 +130,24 @@ on_stream_input(AxFeedback mod, const struct aisl_evt_input *evt)
static AislStatus static AislStatus
on_stream_request(AxFeedback mod, const struct aisl_evt *evt) on_stream_request(AxFeedback mod, const struct aisl_evt *evt)
{ {
int rc;
Context ctx = aisl_get_context((AislStream)evt->source); Context ctx = aisl_get_context((AislStream)evt->source);
AislStream s = (AislStream)evt->source; AislStream s = (AislStream)evt->source;
/* verify input */ /* verify input */
if (!ctx->email || !ctx->msg || ax_validate_email(ctx->email) != 0) { if (!ctx->email) {
ax_quick_response(s, AISL_HTTP_BAD_REQUEST); AX_LOG_ALERT("%s: email empty", modName);
goto finally; goto bad_request;
}
if (!ctx->msg) {
AX_LOG_ALERT("%s: msg empty", modName);
goto bad_request;
}
if ((rc = ax_validate_email(ctx->email))!= 0) {
AX_LOG_ALERT("%s: invalid email at %d", modName, rc);
goto bad_request;
} }
ctx->mail.reply_to = ctx->email; ctx->mail.reply_to = ctx->email;
@ -146,6 +159,11 @@ on_stream_request(AxFeedback mod, const struct aisl_evt *evt)
aisl_set_output_event(s, true); /**< enable output event */ aisl_set_output_event(s, true); /**< enable output event */
goto finally;
bad_request:
ax_quick_response(s, AISL_HTTP_BAD_REQUEST);
finally: finally:
return AISL_SUCCESS; return AISL_SUCCESS;
} }