Add query parser component prototype
This commit is contained in:
+19
-18
@@ -12,17 +12,17 @@
|
||||
*
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
#include <component/query-stream.h>
|
||||
#include <component/mail.h>
|
||||
#include <component/validate.h>
|
||||
#include <component/quick.h>
|
||||
#include <components/query.h>
|
||||
#include <components/mail.h>
|
||||
#include <components/validate.h>
|
||||
#include <components/quick.h>
|
||||
#include "mod-feedback.h"
|
||||
|
||||
|
||||
struct context
|
||||
{
|
||||
struct aislx_mod_ctx root;
|
||||
struct aislx_query_stream qs;
|
||||
struct aislx_query qs;
|
||||
struct aislx_mail mail;
|
||||
|
||||
char * email;
|
||||
@@ -35,7 +35,7 @@ typedef struct context * context_t;
|
||||
static void
|
||||
context_free(context_t ctx)
|
||||
{
|
||||
aislx_query_stream_release(&ctx->qs);
|
||||
aislx_query_release(&ctx->qs);
|
||||
aislx_mail_release(&ctx->mail);
|
||||
|
||||
if (ctx->email)
|
||||
@@ -79,7 +79,7 @@ on_stream_open(aislx_mod_feedback_t mod, aisl_evt_stream_open_t const evt)
|
||||
aisl_stream_t s = (aisl_stream_t) (evt->evt.source);
|
||||
|
||||
if (!(ctx = (context_t)aislx_mod_ctx_new(mod)))
|
||||
goto e_malloc;
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
ctx->mail.from = mod->mail_from;
|
||||
ctx->mail.subject = mod->mail_subject;
|
||||
@@ -88,24 +88,25 @@ on_stream_open(aislx_mod_feedback_t mod, aisl_evt_stream_open_t const evt)
|
||||
ctx->mail.smtp_password = mod->smtp_password;
|
||||
ctx->mail.smtp_port = mod->smtp_port;
|
||||
|
||||
if(aislx_query_stream_init(&ctx->qs, on_input_var, NULL, (void*)ctx) != 0)
|
||||
goto release;
|
||||
|
||||
aisl_set_context(s, ctx);
|
||||
|
||||
return AISL_SUCCESS;
|
||||
|
||||
release:
|
||||
context_free(ctx);
|
||||
|
||||
e_malloc:
|
||||
return AISL_MALLOC_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static aisl_status_t
|
||||
on_stream_header(aislx_mod_feedback_t mod, aisl_evt_stream_header_t const evt)
|
||||
{
|
||||
if (strcmp(evt->key, "content-length")==0)
|
||||
{
|
||||
size_t total = strtoll(evt->value, NULL, 10);
|
||||
|
||||
if(aislx_query_init(&ctx->qs, total, on_input_var, (void*)ctx) != 0)
|
||||
{
|
||||
aisl_stream_t s = (aisl_stream_source_t)evt->source;
|
||||
aislx_quick_response(s, AISL_HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ on_stream_input(aislx_mod_feedback_t mod, aisl_evt_stream_input_t const evt)
|
||||
{
|
||||
context_t ctx = aisl_get_context((aisl_stream_t)evt->evt.source);
|
||||
|
||||
aislx_query_stream_feed(ctx->qs, evt->data, evt->size);
|
||||
aislx_query_feed(ctx->qs, evt->data, evt->size);
|
||||
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
@@ -128,7 +129,7 @@ on_stream_request(aislx_mod_feedback_t mod, aisl_evt_t const evt)
|
||||
aisl_stream_t s = (aisl_stream_t)evt->source;
|
||||
|
||||
/* finalize input */
|
||||
aislx_query_stream_flush(ctx->qs);
|
||||
aislx_query_flush(ctx->qs);
|
||||
|
||||
/* verify input */
|
||||
if (!ctx->email || !ctx->message || aislx_validate_email(ctx->email) != 0)
|
||||
|
||||
Reference in New Issue
Block a user