Compare commits
No commits in common. "dc52c2009852c09ecd249867ed80e5ff6d9b8d38" and "db758cd938a3ee26f96377d304a3d7bc7f39fc26" have entirely different histories.
dc52c20098
...
db758cd938
|
@ -96,7 +96,6 @@ cstuff_vsprintf(char **out, const char *format, va_list args)
|
|||
if (!(s = malloc(result + 1)))
|
||||
return -1;
|
||||
|
||||
*out = s;
|
||||
result = vsnprintf(s, result+1, format, args);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file log.c
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
||||
#if AX_LOG_ENABLED == 1
|
||||
|
||||
struct cstuff_log axLog;
|
||||
|
||||
#endif /* AX_LOG_ENABLED == 1 */
|
|
@ -1,51 +0,0 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2017-2019 by Löwenware Ltd
|
||||
* Please, refer LICENSE file for legal information
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file log.h
|
||||
* @author Ilja Kartašov <ik@lowenware.com>
|
||||
* @brief Log macro wrapper header-only module
|
||||
*
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef LOG_H_97A757CA_02E8_4D9C_BE42_29A930928F49
|
||||
#define LOG_H_97A757CA_02E8_4D9C_BE42_29A930928F49
|
||||
|
||||
#include <cStuff/log.h>
|
||||
|
||||
#ifndef AX_LOG_ENABLED
|
||||
#define AX_LOG_ENABLED 1
|
||||
#endif
|
||||
|
||||
|
||||
#if AX_LOG_ENABLED == 1
|
||||
|
||||
extern struct cstuff_log axLog;
|
||||
|
||||
#define AX_LOG_INIT(LEVEL) cstuff_log_init(&axLog, LEVEL)
|
||||
#define AX_LOG_RELEASE() cstuff_log_release(&axLog)
|
||||
|
||||
#define AX_LOG_DEBUG(...) cstuff_log_printf(&axLog, CSTUFF_LOG_DEBUG, __VA_ARGS__)
|
||||
#define AX_LOG_STATE(...) cstuff_log_printf(&axLog, CSTUFF_LOG_STATE, __VA_ARGS__)
|
||||
#define AX_LOG_ALERT(...) cstuff_log_printf(&axLog, CSTUFF_LOG_ALERT, __VA_ARGS__)
|
||||
#define AX_LOG_ERROR(...) cstuff_log_printf(&axLog, CSTUFF_LOG_ERROR, __VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define AX_LOG_DECLARE()
|
||||
#define AX_LOG_INIT(TARGET)
|
||||
#define AX_LOG_RELEASE()
|
||||
|
||||
#define AX_LOG_DEBUG(...)
|
||||
#define AX_LOG_STATE(...)
|
||||
#define AX_LOG_ALERT(...)
|
||||
#define AX_LOG_ERROR(...)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* !LOG_H */
|
|
@ -17,7 +17,6 @@
|
|||
#include <string.h>
|
||||
#include <cStuff/string.h>
|
||||
#include <curl/curl.h>
|
||||
#include <components/log.h>
|
||||
#include "mail.h"
|
||||
|
||||
|
||||
|
@ -123,7 +122,7 @@ payload_free(struct payload *payload)
|
|||
|
||||
|
||||
static struct payload *
|
||||
payload_new(AxMail mail, struct ax_mail_smtp *smtp)
|
||||
payload_new(aislx_mail_t mail, const char *server)
|
||||
{
|
||||
size_t total;
|
||||
struct payload *payload;
|
||||
|
@ -131,7 +130,6 @@ payload_new(AxMail mail, struct ax_mail_smtp *smtp)
|
|||
if (!(payload = calloc(1, sizeof(struct payload))))
|
||||
goto except;
|
||||
|
||||
|
||||
payload__get_now(payload->now, sizeof(payload->now));
|
||||
|
||||
if (cstuff_strcpy(&payload->to, mail->to) == -1)
|
||||
|
@ -140,21 +138,10 @@ payload_new(AxMail mail, struct ax_mail_smtp *smtp)
|
|||
if (cstuff_strcpy(&payload->from, mail->from) == -1)
|
||||
goto e_cleanup;
|
||||
|
||||
if (cstuff_strcpy(&payload->smtp_user, smtp->user) == -1)
|
||||
if ( !(payload->msg_id = payload__get_id(mail->msg_id, server)) )
|
||||
goto e_cleanup;
|
||||
|
||||
if (cstuff_strcpy(&payload->smtp_pass, smtp->pass) == -1)
|
||||
goto e_cleanup;
|
||||
|
||||
if ( !(payload->msg_id = payload__get_id(mail->msg_id, smtp->host)) )
|
||||
goto e_cleanup;
|
||||
|
||||
if (cstuff_sprintf(&payload->smtp_url, "smtps://%s:%d/", smtp->host,
|
||||
smtp->port & 0xFFFF) == -1) {
|
||||
goto e_cleanup;
|
||||
}
|
||||
|
||||
total = cstuff_sprintf( &payload->data, AX_MAIL_FORMAT
|
||||
total = cstuff_sprintf( &payload->data, AISLX_MAIL_FORMAT
|
||||
, payload->now
|
||||
, payload->to
|
||||
, payload->from
|
||||
|
@ -179,10 +166,10 @@ except:
|
|||
|
||||
|
||||
static void *
|
||||
ax_mail_execute(void *p_ctx)
|
||||
aislx_mail_execute(void *p_ctx)
|
||||
{
|
||||
struct payload * payload = (struct payload *)p_ctx;
|
||||
AislStatus status = AISL_MALLOC_ERROR;
|
||||
aisl_status_t status = AISL_MALLOC_ERROR;
|
||||
|
||||
CURL *curl;
|
||||
struct curl_slist *rcpts;
|
||||
|
@ -193,7 +180,6 @@ ax_mail_execute(void *p_ctx)
|
|||
curl_easy_setopt(curl, CURLOPT_URL, payload->smtp_url);
|
||||
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long) CURLUSESSL_ALL);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_feed);
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, payload);
|
||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||
|
@ -204,8 +190,6 @@ ax_mail_execute(void *p_ctx)
|
|||
if ((rcpts = curl_slist_append(NULL, payload->to)) != NULL) {
|
||||
CURLcode res;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpts);
|
||||
|
||||
if ((res = curl_easy_perform(curl)) != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n"
|
||||
, curl_easy_strerror(res));
|
||||
|
@ -222,16 +206,20 @@ ax_mail_execute(void *p_ctx)
|
|||
}
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_mail_send(AxMail mail, struct ax_mail_smtp *smtp, int flags)
|
||||
aisl_status_t
|
||||
aislx_mail_send( aislx_mail_t mail,
|
||||
const char *smtp_server,
|
||||
const char *smtp_user,
|
||||
const char *smtp_pass,
|
||||
int flags )
|
||||
{
|
||||
int rc;
|
||||
struct payload *payload;
|
||||
|
||||
if (!(payload = payload_new(mail, smtp)))
|
||||
if (!(payload = payload_new(mail, smtp_server)))
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
rc = pthread_create(&mail->thread, NULL, ax_mail_execute, (void*)payload);
|
||||
rc = pthread_create(&mail->thread, NULL, aislx_mail_execute, (void*)payload);
|
||||
if (rc) {
|
||||
payload_free(payload);
|
||||
return AISL_SYSCALL_ERROR;
|
||||
|
@ -240,8 +228,8 @@ ax_mail_send(AxMail mail, struct ax_mail_smtp *smtp, int flags)
|
|||
}
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_mail_get_status(AxMail mail)
|
||||
aisl_status_t
|
||||
aislx_mail_get_status(aislx_mail_t mail)
|
||||
{
|
||||
int rc;
|
||||
void * retval;
|
||||
|
@ -249,7 +237,7 @@ ax_mail_get_status(AxMail mail)
|
|||
rc = pthread_tryjoin_np(mail->thread, &retval);
|
||||
|
||||
if (rc == 0) {
|
||||
rc = (AislStatus)retval;
|
||||
rc = (aisl_status_t)retval;
|
||||
return rc;
|
||||
} else {
|
||||
return AISL_IDLE;
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
#define MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
#ifndef AISLX_MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
#define AISLX_MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
@ -22,9 +22,9 @@
|
|||
#include <uuid/uuid.h>
|
||||
|
||||
|
||||
#ifndef AX_MAIL_FORMAT
|
||||
#ifndef AISLX_MAIL_FORMAT
|
||||
|
||||
#define AX_MAIL_FORMAT \
|
||||
#define AISLX_MAIL_FORMAT \
|
||||
"Date: %s\r\n" \
|
||||
"To: %s\r\n" \
|
||||
"From: %s\r\n" \
|
||||
|
@ -37,7 +37,8 @@
|
|||
|
||||
#endif
|
||||
|
||||
struct ax_mail {
|
||||
struct aislx_mail
|
||||
{
|
||||
pthread_t thread;
|
||||
const char *to;
|
||||
const char *reply_to;
|
||||
|
@ -47,23 +48,19 @@ struct ax_mail {
|
|||
uuid_t msg_id;
|
||||
};
|
||||
|
||||
typedef struct ax_mail * AxMail;
|
||||
typedef struct aislx_mail * aislx_mail_t;
|
||||
|
||||
|
||||
struct ax_mail_smtp {
|
||||
const char *user;
|
||||
const char *pass;
|
||||
const char *host;
|
||||
uint16_t port;
|
||||
};
|
||||
aisl_status_t
|
||||
aislx_mail_send( aislx_mail_t mail,
|
||||
const char *smtp_server,
|
||||
const char *smtp_user,
|
||||
const char *smtp_pass,
|
||||
int flags );
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_mail_send(AxMail mail, struct ax_mail_smtp *smtp, int flags);
|
||||
aisl_status_t
|
||||
aislx_mail_get_status(aislx_mail_t mail);
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_mail_get_status(AxMail mail);
|
||||
|
||||
|
||||
#endif /* !MAIL_H */
|
||||
#endif /* !AISLX_MAIL_H */
|
||||
|
|
|
@ -16,18 +16,20 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "log.h"
|
||||
#include "query.h"
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_query_init(AxQuery query, size_t total, AxQueryHandler on_var, void *p_ctx)
|
||||
aisl_status_t
|
||||
aislx_query_init( aislx_query_t query,
|
||||
size_t total,
|
||||
aislx_query_on_var on_var,
|
||||
void * p_ctx )
|
||||
{
|
||||
query->on_var = on_var;
|
||||
query->p_ctx = p_ctx;
|
||||
query->data = NULL;
|
||||
query->size = 0;
|
||||
query->total = total;
|
||||
query->total = 0;
|
||||
query->separator = 0;
|
||||
|
||||
return AISL_SUCCESS;
|
||||
|
@ -35,7 +37,7 @@ ax_query_init(AxQuery query, size_t total, AxQueryHandler on_var, void *p_ctx)
|
|||
|
||||
|
||||
void
|
||||
ax_query_release(AxQuery query)
|
||||
aislx_query_release(aislx_query_t query)
|
||||
{
|
||||
if (query->data)
|
||||
free(query->data);
|
||||
|
@ -43,9 +45,9 @@ ax_query_release(AxQuery query)
|
|||
|
||||
|
||||
static void
|
||||
ax_query_notify(const char *key, uint32_t k_len,
|
||||
aislx_query_notify(const char * key, uint32_t k_len,
|
||||
const char * val, uint32_t v_len,
|
||||
AxQuery query)
|
||||
aislx_query_t query)
|
||||
{
|
||||
if (query->on_var) {
|
||||
if (query->on_var(key, k_len, val, v_len, query->p_ctx) != 0)
|
||||
|
@ -55,7 +57,7 @@ ax_query_notify(const char *key, uint32_t k_len,
|
|||
|
||||
|
||||
static int32_t
|
||||
ax_query_process(AxQuery query, const char *data, int32_t length)
|
||||
aislx_query_process(aislx_query_t query, const char * data, int32_t length)
|
||||
{
|
||||
const char *i = data,
|
||||
*key = data,
|
||||
|
@ -84,7 +86,7 @@ ax_query_process(AxQuery query, const char *data, int32_t length)
|
|||
query->separator = c;
|
||||
|
||||
if (query->separator == c) {
|
||||
ax_query_notify(key, k_len, val, i-val, query);
|
||||
aislx_query_notify(key, k_len, val, i-val, query);
|
||||
/* reset parser */
|
||||
key = (c == ';') ? i+2 : i+1;
|
||||
k_len = 0;
|
||||
|
@ -96,7 +98,7 @@ ax_query_process(AxQuery query, const char *data, int32_t length)
|
|||
}
|
||||
|
||||
if (query->total == result) {
|
||||
ax_query_notify(key, k_len, val, i-val, query);
|
||||
aislx_query_notify(key, k_len, val, i-val, query);
|
||||
} else {
|
||||
result = (key > i) ? i - data : key - data;
|
||||
}
|
||||
|
@ -107,8 +109,8 @@ ax_query_process(AxQuery query, const char *data, int32_t length)
|
|||
}
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_query_feed(AxQuery query, const char *data, int32_t length)
|
||||
aisl_status_t
|
||||
aislx_query_feed(aislx_query_t query, const char *data, int32_t length)
|
||||
{
|
||||
size_t processed;
|
||||
const char *source;
|
||||
|
@ -126,7 +128,7 @@ ax_query_feed(AxQuery query, const char *data, int32_t length)
|
|||
source = data;
|
||||
}
|
||||
|
||||
processed = ax_query_process(query, source, length);
|
||||
processed = aislx_query_process(query, source, length);
|
||||
|
||||
if (processed < 0)
|
||||
return AISL_INPUT_ERROR;
|
||||
|
@ -135,7 +137,6 @@ ax_query_feed(AxQuery query, const char *data, int32_t length)
|
|||
char *buffer;
|
||||
|
||||
length -= processed;
|
||||
|
||||
if (!(buffer = malloc(length)))
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* @see https://lowenware.com/aisl
|
||||
*/
|
||||
|
||||
#ifndef QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
#define QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
#ifndef AISLX_QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
#define AISLX_QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
@ -22,13 +22,14 @@
|
|||
|
||||
|
||||
typedef int
|
||||
(*AxQueryHandler)(const char *key, uint32_t k_len,
|
||||
(*aislx_query_on_var)( const char *key, uint32_t k_len,
|
||||
const char *val, uint32_t v_len,
|
||||
void *p_ctx );
|
||||
|
||||
|
||||
struct ax_query {
|
||||
AxQueryHandler on_var;
|
||||
struct aislx_query
|
||||
{
|
||||
aislx_query_on_var on_var;
|
||||
void *p_ctx;
|
||||
char *data;
|
||||
size_t size;
|
||||
|
@ -36,19 +37,22 @@ struct ax_query {
|
|||
char separator;
|
||||
};
|
||||
|
||||
typedef struct ax_query * AxQuery;
|
||||
typedef struct aislx_query * aislx_query_t;
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_query_init(AxQuery query, size_t total, AxQueryHandler on_var, void *p_ctx);
|
||||
aisl_status_t
|
||||
aislx_query_init( aislx_query_t query,
|
||||
size_t total,
|
||||
aislx_query_on_var on_var,
|
||||
void *p_ctx );
|
||||
|
||||
|
||||
void
|
||||
ax_query_release(AxQuery query);
|
||||
aislx_query_release(aislx_query_t query);
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_query_feed(AxQuery query, const char *data, int32_t length);
|
||||
aisl_status_t
|
||||
aislx_query_feed(aislx_query_t query, const char *data, int32_t length);
|
||||
|
||||
|
||||
#endif /* !QUERY_H */
|
||||
#endif /* !AISLX_QUERY_H */
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
#include "quick.h"
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_quick_response(AislStream stream, AislHttpResponse http_response)
|
||||
aisl_status_t
|
||||
aislx_quick_response(aisl_stream_t stream, aisl_http_response_t http_response)
|
||||
{
|
||||
AislStatus result;
|
||||
aisl_status_t result;
|
||||
|
||||
result = aisl_response(stream, http_response, 0);
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
#define QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
#ifndef AISLX_QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
#define AISLX_QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
|
||||
#include <aisl/aisl.h>
|
||||
|
||||
AislStatus
|
||||
ax_quick_response(AislStream stream, AislHttpResponse http_response);
|
||||
aisl_status_t
|
||||
aislx_quick_response(aisl_stream_t stream, aisl_http_response_t http_response);
|
||||
|
||||
#endif /* !QUICK_H */
|
||||
#endif /* !AISLX_QUICK_H */
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
|
||||
int
|
||||
ax_validate_email(const char *value)
|
||||
aislx_validate_email(const char *value)
|
||||
{
|
||||
const char *at = NULL,
|
||||
*dot = NULL,
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
#define VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
#ifndef AISLX_VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
#define AISLX_VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
|
||||
|
||||
int
|
||||
ax_validate_email(const char *value);
|
||||
aislx_validate_email(const char * value);
|
||||
|
||||
#endif /* !AX_VALIDATE_H */
|
||||
#endif /* !AISLX_VALIDATE_H */
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#include "context.h"
|
||||
#include "ctx.h"
|
||||
|
||||
|
||||
AxContext
|
||||
ax_context_new(AxModule mod)
|
||||
aislx_ctx_t
|
||||
aislx_ctx_new(aislx_module_t mod)
|
||||
{
|
||||
AxContext ctx;
|
||||
aislx_ctx_t ctx;
|
||||
|
||||
if ((ctx = calloc(1, mod->ctx_size)) != NULL) {
|
||||
ctx->mod = mod;
|
||||
|
@ -30,7 +30,7 @@ ax_context_new(AxModule mod)
|
|||
|
||||
|
||||
void
|
||||
ax_context_free(AxContext ctx)
|
||||
aislx_ctx_free(aislx_ctx_t ctx)
|
||||
{
|
||||
free(ctx);
|
||||
}
|
|
@ -13,36 +13,36 @@
|
|||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef CONTEXT_H_683B0A86_2A15_483D_B0F9_7BFBB4BA068F
|
||||
#define CONTEXT_H_683B0A86_2A15_483D_B0F9_7BFBB4BA068F
|
||||
#ifndef AISLX_CTX_H_683B0A86_2A15_483D_B0F9_7BFBB4BA068F
|
||||
#define AISLX_CTX_H_683B0A86_2A15_483D_B0F9_7BFBB4BA068F
|
||||
|
||||
#define AX_CONTEXT(x) ((AxContext)x)
|
||||
#define AISLX_CTX(x) ((aislx_ctx_t)x)
|
||||
|
||||
#include <mods/module.h>
|
||||
|
||||
/** @brief Root level ASIL mod's context structure
|
||||
*/
|
||||
struct ax_context {
|
||||
AxModule mod; /**< Mod's pointer */
|
||||
struct aislx_ctx {
|
||||
aislx_module_t mod; /**< Mod's pointer */
|
||||
};
|
||||
|
||||
/** @brief Root level ASIL mod's context structure pointer
|
||||
*/
|
||||
typedef struct ax_context * AxContext;
|
||||
typedef struct aislx_ctx * aislx_ctx_t;
|
||||
|
||||
|
||||
/** @brief Allocates zeroed #aislx_t context
|
||||
* @param mod an instance of #aislx_t
|
||||
* @return pointer to newly allocated #aisl_mox_ctx_t
|
||||
*/
|
||||
AxContext
|
||||
ax_context_new(AxModule mod);
|
||||
aislx_ctx_t
|
||||
aislx_ctx_new(aislx_module_t mod);
|
||||
|
||||
|
||||
/** @brief Frees previosly allocated #aislx_ctx_t
|
||||
* @param ctx an instance of mod's context structure
|
||||
* */
|
||||
void
|
||||
ax_context_free(AxContext ctx);
|
||||
aislx_ctx_free(aislx_ctx_t ctx);
|
||||
|
||||
#endif /* !AISLX_CTX_H */
|
132
mods/feedback.c
132
mods/feedback.c
|
@ -18,27 +18,27 @@
|
|||
#include <components/mail.h>
|
||||
#include <components/validate.h>
|
||||
#include <components/quick.h>
|
||||
#include <components/log.h>
|
||||
#include <cStuff/string.h>
|
||||
#include "feedback.h"
|
||||
|
||||
|
||||
struct context
|
||||
{
|
||||
struct ax_context root;
|
||||
struct ax_query qs;
|
||||
struct ax_mail mail;
|
||||
struct aislx_ctx root;
|
||||
struct aislx_query qs;
|
||||
struct aislx_mail mail;
|
||||
|
||||
char * email;
|
||||
char * msg;
|
||||
};
|
||||
|
||||
typedef struct context * Context;
|
||||
typedef struct context * context_t;
|
||||
|
||||
|
||||
static void
|
||||
context_free(Context ctx)
|
||||
context_free(context_t ctx)
|
||||
{
|
||||
ax_query_release(&ctx->qs);
|
||||
aislx_query_release(&ctx->qs);
|
||||
|
||||
if (ctx->email)
|
||||
free(ctx->email);
|
||||
|
@ -46,7 +46,7 @@ context_free(Context ctx)
|
|||
if (ctx->msg)
|
||||
free(ctx->msg);
|
||||
|
||||
ax_context_free((AxContext)ctx);
|
||||
aislx_ctx_free((aislx_ctx_t)ctx);
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,30 +55,32 @@ on_input_var( const char *key, uint32_t k_len,
|
|||
const char *val, uint32_t v_len,
|
||||
void *p_ctx )
|
||||
{
|
||||
Context ctx = (Context) p_ctx;
|
||||
AxFeedback mod = (AxFeedback)((AxContext)ctx)->mod;
|
||||
context_t ctx = (context_t) p_ctx;
|
||||
aislx_feedback_t mod = (aislx_feedback_t)((aislx_ctx_t)ctx)->mod;
|
||||
|
||||
if (!ctx->email && k_len == mod->name_email_length) {
|
||||
if (!ctx->email && k_len == mod->name_email_length)
|
||||
{
|
||||
if (strncmp(key, mod->name_email, k_len)==0)
|
||||
return (cstuff_strncpy(&ctx->email, val, v_len) == -1);
|
||||
return cstuff_strncpy(&ctx->email, val, v_len);
|
||||
}
|
||||
|
||||
if (!ctx->msg && k_len == mod->name_msg_length) {
|
||||
if (!ctx->msg && k_len == mod->name_msg_length)
|
||||
{
|
||||
if (strncmp(key, mod->name_msg, k_len)==0)
|
||||
return (cstuff_strncpy(&ctx->msg, val, v_len) == -1);
|
||||
return cstuff_strncpy(&ctx->msg, val, v_len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static AislStatus
|
||||
on_stream_open(AxFeedback mod, const struct aisl_evt_open *evt)
|
||||
static aisl_status_t
|
||||
on_stream_open(aislx_feedback_t mod, aisl_evt_stream_open_t const evt)
|
||||
{
|
||||
Context ctx;
|
||||
AislStream s = (AislStream) (evt->evt.source);
|
||||
context_t ctx;
|
||||
aisl_stream_t s = (aisl_stream_t) (evt->evt.source);
|
||||
|
||||
if (!(ctx = (Context)ax_context_new(AX_MODULE(mod))))
|
||||
if (!(ctx = (context_t)aislx_ctx_new(AISLX_MODULE(mod))))
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
ctx->mail.from = mod->mail_from;
|
||||
|
@ -97,50 +99,60 @@ on_stream_open(AxFeedback mod, const struct aisl_evt_open *evt)
|
|||
}
|
||||
|
||||
|
||||
static AislStatus
|
||||
on_stream_header(AxFeedback mod, const struct aisl_evt_header *evt)
|
||||
static aisl_status_t
|
||||
on_stream_header(aislx_feedback_t mod, aisl_evt_stream_header_t const evt)
|
||||
{
|
||||
AislStream s = (AislStream)evt->evt.source;
|
||||
Context ctx = aisl_get_context(s);
|
||||
aisl_stream_t s = (aisl_stream_t)evt->evt.source;
|
||||
context_t ctx = aisl_get_context(s);
|
||||
|
||||
if (strcmp(evt->key, "content-length") == 0) {
|
||||
if (strcmp(evt->key, "content-length")==0)
|
||||
{
|
||||
size_t total = strtoll(evt->value, NULL, 10);
|
||||
|
||||
if(ax_query_init(&ctx->qs, total, on_input_var, (void*)ctx) != 0) {
|
||||
ax_quick_response(s, AISL_HTTP_INTERNAL_SERVER_ERROR);
|
||||
if(aislx_query_init(&ctx->qs, total, on_input_var, (void*)ctx) != 0)
|
||||
{
|
||||
aislx_quick_response(s, AISL_HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static AislStatus
|
||||
on_stream_input(AxFeedback mod, const struct aisl_evt_input *evt)
|
||||
static aisl_status_t
|
||||
on_stream_input(aislx_feedback_t mod, aisl_evt_stream_input_t const evt)
|
||||
{
|
||||
Context ctx = aisl_get_context((AislStream)evt->evt.source);
|
||||
context_t ctx = aisl_get_context((aisl_stream_t)evt->evt.source);
|
||||
|
||||
ax_query_feed(&ctx->qs, evt->data, evt->size);
|
||||
aislx_query_feed(&ctx->qs, evt->data, evt->size);
|
||||
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static AislStatus
|
||||
on_stream_request(AxFeedback mod, const struct aisl_evt *evt)
|
||||
static aisl_status_t
|
||||
on_stream_request(aislx_feedback_t mod, aisl_evt_t const evt)
|
||||
{
|
||||
Context ctx = aisl_get_context((AislStream)evt->source);
|
||||
AislStream s = (AislStream)evt->source;
|
||||
aisl_status_t status;
|
||||
context_t ctx = aisl_get_context((aisl_stream_t)evt->source);
|
||||
aisl_stream_t s = (aisl_stream_t)evt->source;
|
||||
|
||||
/* verify input */
|
||||
if (!ctx->email || !ctx->msg || ax_validate_email(ctx->email) != 0)
|
||||
ax_quick_response(s, AISL_HTTP_BAD_REQUEST);
|
||||
if (!ctx->email || !ctx->msg || aislx_validate_email(ctx->email) != 0)
|
||||
aislx_quick_response(s, AISL_HTTP_BAD_REQUEST);
|
||||
|
||||
ctx->mail.reply_to = ctx->email;
|
||||
ctx->mail.to = ctx->email;
|
||||
ctx->mail.msg = ctx->msg;
|
||||
uuid_generate(ctx->mail.msg_id);
|
||||
|
||||
if (ax_mail_send(&ctx->mail, &mod->smtp, 0) != AISL_SUCCESS)
|
||||
ax_quick_response(s, AISL_HTTP_INTERNAL_SERVER_ERROR);
|
||||
/* create thread */
|
||||
status = aislx_mail_send(&ctx->mail
|
||||
, mod->smtp_host
|
||||
, mod->smtp_user
|
||||
, mod->smtp_pass
|
||||
, 0);
|
||||
|
||||
if (status != AISL_SUCCESS)
|
||||
aislx_quick_response(s, AISL_HTTP_INTERNAL_SERVER_ERROR);
|
||||
|
||||
aisl_set_output_event(s, true); /**< enable output event */
|
||||
|
||||
|
@ -148,14 +160,15 @@ on_stream_request(AxFeedback mod, const struct aisl_evt *evt)
|
|||
}
|
||||
|
||||
|
||||
static AislStatus
|
||||
on_stream_output(AxFeedback mod, const struct aisl_evt *evt)
|
||||
static aisl_status_t
|
||||
on_stream_output(aislx_feedback_t mod, aisl_evt_t const evt)
|
||||
{
|
||||
Context ctx = aisl_get_context((AislStream)evt->source);
|
||||
context_t ctx = aisl_get_context((aisl_stream_t)evt->source);
|
||||
|
||||
AislHttpResponse rc = AISL_HTTP_OK;
|
||||
aisl_http_response_t rc = AISL_HTTP_OK;
|
||||
|
||||
switch (ax_mail_get_status(&ctx->mail)) {
|
||||
switch (aislx_mail_get_status(&ctx->mail))
|
||||
{
|
||||
case AISL_SUCCESS: break;
|
||||
case AISL_IDLE: return AISL_SUCCESS;
|
||||
|
||||
|
@ -163,33 +176,33 @@ on_stream_output(AxFeedback mod, const struct aisl_evt *evt)
|
|||
rc = AISL_HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
ax_quick_response((AislStream)evt->source, rc);
|
||||
aislx_quick_response((aisl_stream_t)evt->source, rc);
|
||||
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static AislStatus
|
||||
on_stream_close(AxFeedback mod, const struct aisl_evt *evt)
|
||||
static aisl_status_t
|
||||
on_stream_close(aislx_feedback_t mod, aisl_evt_t const evt)
|
||||
{
|
||||
context_free((Context)aisl_get_context((AislStream)evt->source));
|
||||
context_free((context_t)aisl_get_context((aisl_stream_t)evt->source));
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static AislStatus
|
||||
ax_feedback_on_event(AxFeedback mod, const struct aisl_evt *evt)
|
||||
static aisl_status_t
|
||||
aislx_feedback_on_event(aislx_feedback_t mod, aisl_evt_t const evt)
|
||||
{
|
||||
switch(evt->code)
|
||||
{
|
||||
case AISL_EVENT_STREAM_OPEN:
|
||||
return on_stream_open(mod, (const struct aisl_evt_open *)evt);
|
||||
return on_stream_open(mod, (aisl_evt_stream_open_t)evt);
|
||||
|
||||
case AISL_EVENT_STREAM_HEADER:
|
||||
return on_stream_header(mod, (const struct aisl_evt_header *)evt);
|
||||
return on_stream_header(mod, (aisl_evt_stream_header_t)evt);
|
||||
|
||||
case AISL_EVENT_STREAM_INPUT:
|
||||
return on_stream_input(mod, (const struct aisl_evt_input *)evt);
|
||||
return on_stream_input(mod, (aisl_evt_stream_input_t)evt);
|
||||
|
||||
case AISL_EVENT_STREAM_REQUEST:
|
||||
return on_stream_request(mod, evt);
|
||||
|
@ -206,17 +219,20 @@ ax_feedback_on_event(AxFeedback mod, const struct aisl_evt *evt)
|
|||
}
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_feedback_init(AxFeedback mod, const struct ax_feedback_cfg *cfg)
|
||||
aisl_status_t
|
||||
aislx_feedback_init(aislx_feedback_t mod, aislx_feedback_cfg_t cfg)
|
||||
{
|
||||
AX_MODULE_INIT(ax_feedback, cfg->end_point);
|
||||
AISLX_MODULE_INIT(aislx_feedback, cfg->end_point);
|
||||
|
||||
mod->mail_subject = cfg->mail_subject;
|
||||
mod->mail_from = cfg->mail_from;
|
||||
mod->mail_to = cfg->mail_to;
|
||||
mod->name_email = cfg->name_email;
|
||||
mod->name_msg = cfg->name_msg;
|
||||
memcpy(&mod->smtp, &cfg->smtp, sizeof (cfg->smtp));
|
||||
mod->smtp_host = cfg->smtp_host;
|
||||
mod->smtp_user = cfg->smtp_user;
|
||||
mod->smtp_pass = cfg->smtp_pass;
|
||||
mod->smtp_port = cfg->smtp_port;
|
||||
|
||||
mod->name_email_length = strlen(cfg->name_email);
|
||||
mod->name_msg_length = strlen(cfg->name_msg);
|
||||
|
@ -226,7 +242,7 @@ ax_feedback_init(AxFeedback mod, const struct ax_feedback_cfg *cfg)
|
|||
|
||||
|
||||
void
|
||||
ax_feedback_release(AxFeedback mod)
|
||||
aislx_feedback_release(aislx_feedback_t mod)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -13,45 +13,57 @@
|
|||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef FEEDBACK_H_6CC516E4_A7F2_4A9D_B467_75DCF6F58108
|
||||
#define FEEDBACK_H_6CC516E4_A7F2_4A9D_B467_75DCF6F58108
|
||||
#ifndef AISLX_MOD_FEEDBACK_H_6CC516E4_A7F2_4A9D_B467_75DCF6F58108
|
||||
#define AISLX_MOD_FEEDBACK_H_6CC516E4_A7F2_4A9D_B467_75DCF6F58108
|
||||
|
||||
#include <mods/context.h>
|
||||
#include <mods/ctx.h>
|
||||
#include <mods/module.h>
|
||||
#include <components/mail.h>
|
||||
|
||||
struct ax_feedback_cfg {
|
||||
struct ax_mail_smtp smtp;
|
||||
struct aislx_feedback_cfg
|
||||
{
|
||||
const char *end_point;
|
||||
const char *name_email;
|
||||
const char *name_msg;
|
||||
const char *mail_subject;
|
||||
const char *mail_from;
|
||||
const char *mail_to;
|
||||
const char *smtp_host;
|
||||
const char *smtp_user;
|
||||
const char *smtp_pass;
|
||||
uint16_t smtp_port;
|
||||
};
|
||||
|
||||
typedef struct aislx_feedback_cfg * aislx_feedback_cfg_t;
|
||||
|
||||
|
||||
struct aislx_feedback
|
||||
{
|
||||
struct aislx_module root;
|
||||
|
||||
struct ax_feedback {
|
||||
struct ax_module root;
|
||||
struct ax_mail_smtp smtp;
|
||||
const char *name_email;
|
||||
const char *name_msg;
|
||||
const char *mail_subject;
|
||||
const char *mail_from;
|
||||
const char *mail_to;
|
||||
const char *smtp_host;
|
||||
const char *smtp_user;
|
||||
const char *smtp_pass;
|
||||
uint16_t smtp_port;
|
||||
|
||||
uint16_t name_email_length;
|
||||
uint16_t name_msg_length;
|
||||
};
|
||||
|
||||
|
||||
typedef struct ax_feedback * AxFeedback;
|
||||
typedef struct aislx_feedback * aislx_feedback_t;
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_feedback_init(AxFeedback mod, const struct ax_feedback_cfg *cfg);
|
||||
aisl_status_t
|
||||
aislx_feedback_init(aislx_feedback_t mod,
|
||||
aislx_feedback_cfg_t cfg);
|
||||
|
||||
|
||||
void
|
||||
ax_feedback_release(AxFeedback mod);
|
||||
aislx_feedback_release(aislx_feedback_t mod);
|
||||
|
||||
#endif /* !FEEDBACK_H */
|
||||
#endif /* !AISLX_MOD_FEEDBACK_H */
|
||||
|
|
|
@ -14,21 +14,20 @@
|
|||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <components/log.h>
|
||||
#include "module.h"
|
||||
#include "context.h"
|
||||
#include "ctx.h"
|
||||
|
||||
|
||||
AislStatus
|
||||
ax_module_on_event(AxModule mod, const struct aisl_evt *evt)
|
||||
aisl_status_t
|
||||
aislx_module_on_event(aislx_module_t mod, aisl_evt_t const evt)
|
||||
{
|
||||
AxContext ctx;
|
||||
struct aisl_evt_open *so_evt;
|
||||
aislx_ctx_t ctx;
|
||||
aisl_evt_stream_open_t so_evt;
|
||||
|
||||
switch(evt->code)
|
||||
{
|
||||
case AISL_EVENT_STREAM_OPEN:
|
||||
so_evt = (struct aisl_evt_open *)evt;
|
||||
so_evt = (aisl_evt_stream_open_t)evt;
|
||||
|
||||
if (strncmp(so_evt->path, mod->end_point, mod->ep_length))
|
||||
return AISL_IDLE;
|
||||
|
@ -39,7 +38,7 @@ ax_module_on_event(AxModule mod, const struct aisl_evt *evt)
|
|||
case AISL_EVENT_STREAM_REQUEST:
|
||||
case AISL_EVENT_STREAM_OUTPUT:
|
||||
case AISL_EVENT_STREAM_CLOSE:
|
||||
if (!(ctx = aisl_get_context((AislStream)evt->source)))
|
||||
if (!(ctx = aisl_get_context((aisl_stream_t)evt->source)))
|
||||
return AISL_SUCCESS;
|
||||
|
||||
if (ctx->mod == mod)
|
||||
|
|
|
@ -13,50 +13,50 @@
|
|||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef MODULE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA
|
||||
#define MODULE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA
|
||||
#ifndef AISLX_MODULE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA
|
||||
#define AISLX_MODULE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA
|
||||
|
||||
#include <aisl/aisl.h>
|
||||
|
||||
#define AX_MODULE_INIT(MOD, END_POINT) \
|
||||
#define AISLX_MODULE_INIT(MOD, END_POINT) \
|
||||
do { \
|
||||
((AxModule) mod)->end_point = END_POINT; \
|
||||
((AxModule) mod)->ep_length = strlen(END_POINT); \
|
||||
((AxModule) mod)->on_event = (AxObserver)MOD##_on_event; \
|
||||
((AxModule) mod)->ctx_size = sizeof (struct context); \
|
||||
((aislx_module_t) mod)->end_point = END_POINT; \
|
||||
((aislx_module_t) mod)->ep_length = strlen(END_POINT); \
|
||||
((aislx_module_t) mod)->on_event = (aislx_observer_t)MOD##_on_event; \
|
||||
((aislx_module_t) mod)->ctx_size = sizeof(struct context); \
|
||||
} while(0) \
|
||||
|
||||
#define AX_MODULE(x) ((AxModule)x)
|
||||
#define AISLX_MODULE(x) ((aislx_module_t)x)
|
||||
|
||||
/** @brief AISL module structure pointer
|
||||
*/
|
||||
typedef struct ax_module * AxModule;
|
||||
typedef struct aislx_module * aislx_module_t;
|
||||
|
||||
|
||||
/** @brief Pointer to AISL stream event observer
|
||||
*/
|
||||
typedef AislStatus
|
||||
(* AxObserver)(AxModule mod, const struct aisl_evt *evt);
|
||||
typedef aisl_status_t
|
||||
(* aislx_observer_t)(aislx_module_t mod, aisl_evt_t const evt);
|
||||
|
||||
|
||||
|
||||
/** @brief Root level AISL mod's structure
|
||||
*/
|
||||
struct ax_module {
|
||||
struct aislx_module {
|
||||
const char *end_point; /**< Root mod's URL or NULL */
|
||||
AxObserver on_event; /**< Mod's stream event observer */
|
||||
aislx_observer_t on_event; /**< Mod's stream event observer */
|
||||
size_t ctx_size; /**< Mod's context size */
|
||||
uint8_t ep_length; /**< End-Point length */
|
||||
};
|
||||
|
||||
|
||||
/** @brief Wrapper function that calles mod's observer
|
||||
* @param mod an instance of AxModule#
|
||||
* @param mod an instance of #aislx_t
|
||||
* @param evt an AISL stream event
|
||||
* @return AISL_SUCCESS if event handled, AISL_IDLE if event not handled or an
|
||||
* error code
|
||||
*/
|
||||
AislStatus
|
||||
ax_module_on_event(AxModule mod, const struct aisl_evt *evt);
|
||||
aisl_status_t
|
||||
aislx_module_on_event(aislx_module_t mod, aisl_evt_t const evt);
|
||||
|
||||
#endif /* !MODULE;_H */
|
||||
#endif /* !AISLX_MODULE;_H */
|
||||
|
|
Loading…
Reference in New Issue