diff --git a/components/validate.c b/components/validate.c index 9cc6f20..a0b0c06 100644 --- a/components/validate.c +++ b/components/validate.c @@ -16,6 +16,7 @@ #include #include #include +#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; diff --git a/mods/feedback.c b/mods/feedback.c index 016e425..397ff2c 100644 --- a/mods/feedback.c +++ b/mods/feedback.c @@ -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; }