Fix email validation
This commit is contained in:
parent
e3e84a0441
commit
e623c0dce1
|
@ -16,6 +16,7 @@
|
|||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include "log.h"
|
||||
#include "validate.h"
|
||||
|
||||
|
||||
|
@ -100,8 +101,11 @@ ax_validate_email(const char *value)
|
|||
continue;
|
||||
|
||||
default:
|
||||
if ( isalnum(c) == 0 )
|
||||
if (isalnum(c))
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (int)(i-value)+1;
|
||||
|
|
|
@ -34,6 +34,8 @@ struct context
|
|||
|
||||
typedef struct context * Context;
|
||||
|
||||
static const char modName[] = "feedback";
|
||||
|
||||
|
||||
static void
|
||||
context_free(Context ctx)
|
||||
|
@ -128,13 +130,24 @@ on_stream_input(AxFeedback mod, const struct aisl_evt_input *evt)
|
|||
static AislStatus
|
||||
on_stream_request(AxFeedback mod, const struct aisl_evt *evt)
|
||||
{
|
||||
int rc;
|
||||
Context ctx = aisl_get_context((AislStream)evt->source);
|
||||
AislStream s = (AislStream)evt->source;
|
||||
|
||||
/* verify input */
|
||||
if (!ctx->email || !ctx->msg || ax_validate_email(ctx->email) != 0) {
|
||||
ax_quick_response(s, AISL_HTTP_BAD_REQUEST);
|
||||
goto finally;
|
||||
if (!ctx->email) {
|
||||
AX_LOG_ALERT("%s: email empty", modName);
|
||||
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;
|
||||
|
@ -146,6 +159,11 @@ on_stream_request(AxFeedback mod, const struct aisl_evt *evt)
|
|||
|
||||
aisl_set_output_event(s, true); /**< enable output event */
|
||||
|
||||
goto finally;
|
||||
|
||||
bad_request:
|
||||
ax_quick_response(s, AISL_HTTP_BAD_REQUEST);
|
||||
|
||||
finally:
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue