Update coding style and make feedback module working
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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 */
|
||||
@@ -0,0 +1,51 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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 */
|
||||
+31
-19
@@ -17,11 +17,12 @@
|
||||
#include <string.h>
|
||||
#include <cStuff/string.h>
|
||||
#include <curl/curl.h>
|
||||
#include <components/log.h>
|
||||
#include "mail.h"
|
||||
|
||||
|
||||
struct payload {
|
||||
char now[40];
|
||||
char now[40];
|
||||
char *to;
|
||||
char *from;
|
||||
char *subject;
|
||||
@@ -30,8 +31,8 @@ struct payload {
|
||||
char *smtp_pass;
|
||||
char *smtp_url;
|
||||
char *data;
|
||||
size_t offset;
|
||||
size_t total;
|
||||
size_t offset;
|
||||
size_t total;
|
||||
};
|
||||
|
||||
|
||||
@@ -122,7 +123,7 @@ payload_free(struct payload *payload)
|
||||
|
||||
|
||||
static struct payload *
|
||||
payload_new(aislx_mail_t mail, const char *server)
|
||||
payload_new(AxMail mail, struct ax_mail_smtp *smtp)
|
||||
{
|
||||
size_t total;
|
||||
struct payload *payload;
|
||||
@@ -130,6 +131,7 @@ payload_new(aislx_mail_t mail, const char *server)
|
||||
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)
|
||||
@@ -138,10 +140,21 @@ payload_new(aislx_mail_t mail, const char *server)
|
||||
if (cstuff_strcpy(&payload->from, mail->from) == -1)
|
||||
goto e_cleanup;
|
||||
|
||||
if ( !(payload->msg_id = payload__get_id(mail->msg_id, server)) )
|
||||
if (cstuff_strcpy(&payload->smtp_user, smtp->user) == -1)
|
||||
goto e_cleanup;
|
||||
|
||||
total = cstuff_sprintf( &payload->data, AISLX_MAIL_FORMAT
|
||||
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
|
||||
, payload->now
|
||||
, payload->to
|
||||
, payload->from
|
||||
@@ -166,10 +179,10 @@ except:
|
||||
|
||||
|
||||
static void *
|
||||
aislx_mail_execute(void *p_ctx)
|
||||
ax_mail_execute(void *p_ctx)
|
||||
{
|
||||
struct payload * payload = (struct payload *)p_ctx;
|
||||
aisl_status_t status = AISL_MALLOC_ERROR;
|
||||
AislStatus status = AISL_MALLOC_ERROR;
|
||||
|
||||
CURL *curl;
|
||||
struct curl_slist *rcpts;
|
||||
@@ -180,6 +193,7 @@ aislx_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);
|
||||
@@ -190,6 +204,8 @@ aislx_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));
|
||||
@@ -206,20 +222,16 @@ aislx_mail_execute(void *p_ctx)
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
int rc;
|
||||
struct payload *payload;
|
||||
|
||||
if (!(payload = payload_new(mail, smtp_server)))
|
||||
if (!(payload = payload_new(mail, smtp)))
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
rc = pthread_create(&mail->thread, NULL, aislx_mail_execute, (void*)payload);
|
||||
rc = pthread_create(&mail->thread, NULL, ax_mail_execute, (void*)payload);
|
||||
if (rc) {
|
||||
payload_free(payload);
|
||||
return AISL_SYSCALL_ERROR;
|
||||
@@ -228,8 +240,8 @@ aislx_mail_send( aislx_mail_t mail,
|
||||
}
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_mail_get_status(aislx_mail_t mail)
|
||||
AislStatus
|
||||
ax_mail_get_status(AxMail mail)
|
||||
{
|
||||
int rc;
|
||||
void * retval;
|
||||
@@ -237,7 +249,7 @@ aislx_mail_get_status(aislx_mail_t mail)
|
||||
rc = pthread_tryjoin_np(mail->thread, &retval);
|
||||
|
||||
if (rc == 0) {
|
||||
rc = (aisl_status_t)retval;
|
||||
rc = (AislStatus)retval;
|
||||
return rc;
|
||||
} else {
|
||||
return AISL_IDLE;
|
||||
|
||||
+19
-16
@@ -13,8 +13,8 @@
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef AISLX_MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
#define AISLX_MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
#ifndef MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
#define MAIL_H_2738BEC4_CF82_4D77_A41F_0E2615848194
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
|
||||
#ifndef AISLX_MAIL_FORMAT
|
||||
#ifndef AX_MAIL_FORMAT
|
||||
|
||||
#define AISLX_MAIL_FORMAT \
|
||||
#define AX_MAIL_FORMAT \
|
||||
"Date: %s\r\n" \
|
||||
"To: %s\r\n" \
|
||||
"From: %s\r\n" \
|
||||
@@ -37,8 +37,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
struct aislx_mail
|
||||
{
|
||||
struct ax_mail {
|
||||
pthread_t thread;
|
||||
const char *to;
|
||||
const char *reply_to;
|
||||
@@ -48,19 +47,23 @@ struct aislx_mail
|
||||
uuid_t msg_id;
|
||||
};
|
||||
|
||||
typedef struct aislx_mail * aislx_mail_t;
|
||||
typedef struct ax_mail * AxMail;
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_mail_send( aislx_mail_t mail,
|
||||
const char *smtp_server,
|
||||
const char *smtp_user,
|
||||
const char *smtp_pass,
|
||||
int flags );
|
||||
struct ax_mail_smtp {
|
||||
const char *user;
|
||||
const char *pass;
|
||||
const char *host;
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_mail_get_status(aislx_mail_t mail);
|
||||
AislStatus
|
||||
ax_mail_send(AxMail mail, struct ax_mail_smtp *smtp, int flags);
|
||||
|
||||
|
||||
#endif /* !AISLX_MAIL_H */
|
||||
AislStatus
|
||||
ax_mail_get_status(AxMail mail);
|
||||
|
||||
|
||||
#endif /* !MAIL_H */
|
||||
|
||||
+15
-16
@@ -16,20 +16,18 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "log.h"
|
||||
#include "query.h"
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_query_init( aislx_query_t query,
|
||||
size_t total,
|
||||
aislx_query_on_var on_var,
|
||||
void * p_ctx )
|
||||
AislStatus
|
||||
ax_query_init(AxQuery query, size_t total, AxQueryHandler on_var, void *p_ctx)
|
||||
{
|
||||
query->on_var = on_var;
|
||||
query->p_ctx = p_ctx;
|
||||
query->data = NULL;
|
||||
query->size = 0;
|
||||
query->total = 0;
|
||||
query->total = total;
|
||||
query->separator = 0;
|
||||
|
||||
return AISL_SUCCESS;
|
||||
@@ -37,7 +35,7 @@ aislx_query_init( aislx_query_t query,
|
||||
|
||||
|
||||
void
|
||||
aislx_query_release(aislx_query_t query)
|
||||
ax_query_release(AxQuery query)
|
||||
{
|
||||
if (query->data)
|
||||
free(query->data);
|
||||
@@ -45,9 +43,9 @@ aislx_query_release(aislx_query_t query)
|
||||
|
||||
|
||||
static void
|
||||
aislx_query_notify(const char * key, uint32_t k_len,
|
||||
const char * val, uint32_t v_len,
|
||||
aislx_query_t query)
|
||||
ax_query_notify(const char *key, uint32_t k_len,
|
||||
const char *val, uint32_t v_len,
|
||||
AxQuery query)
|
||||
{
|
||||
if (query->on_var) {
|
||||
if (query->on_var(key, k_len, val, v_len, query->p_ctx) != 0)
|
||||
@@ -57,7 +55,7 @@ aislx_query_notify(const char * key, uint32_t k_len,
|
||||
|
||||
|
||||
static int32_t
|
||||
aislx_query_process(aislx_query_t query, const char * data, int32_t length)
|
||||
ax_query_process(AxQuery query, const char *data, int32_t length)
|
||||
{
|
||||
const char *i = data,
|
||||
*key = data,
|
||||
@@ -86,7 +84,7 @@ aislx_query_process(aislx_query_t query, const char * data, int32_t length)
|
||||
query->separator = c;
|
||||
|
||||
if (query->separator == c) {
|
||||
aislx_query_notify(key, k_len, val, i-val, query);
|
||||
ax_query_notify(key, k_len, val, i-val, query);
|
||||
/* reset parser */
|
||||
key = (c == ';') ? i+2 : i+1;
|
||||
k_len = 0;
|
||||
@@ -98,7 +96,7 @@ aislx_query_process(aislx_query_t query, const char * data, int32_t length)
|
||||
}
|
||||
|
||||
if (query->total == result) {
|
||||
aislx_query_notify(key, k_len, val, i-val, query);
|
||||
ax_query_notify(key, k_len, val, i-val, query);
|
||||
} else {
|
||||
result = (key > i) ? i - data : key - data;
|
||||
}
|
||||
@@ -109,8 +107,8 @@ aislx_query_process(aislx_query_t query, const char * data, int32_t length)
|
||||
}
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_query_feed(aislx_query_t query, const char *data, int32_t length)
|
||||
AislStatus
|
||||
ax_query_feed(AxQuery query, const char *data, int32_t length)
|
||||
{
|
||||
size_t processed;
|
||||
const char *source;
|
||||
@@ -128,7 +126,7 @@ aislx_query_feed(aislx_query_t query, const char *data, int32_t length)
|
||||
source = data;
|
||||
}
|
||||
|
||||
processed = aislx_query_process(query, source, length);
|
||||
processed = ax_query_process(query, source, length);
|
||||
|
||||
if (processed < 0)
|
||||
return AISL_INPUT_ERROR;
|
||||
@@ -137,6 +135,7 @@ aislx_query_feed(aislx_query_t query, const char *data, int32_t length)
|
||||
char *buffer;
|
||||
|
||||
length -= processed;
|
||||
|
||||
if (!(buffer = malloc(length)))
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
|
||||
+14
-18
@@ -13,8 +13,8 @@
|
||||
* @see https://lowenware.com/aisl
|
||||
*/
|
||||
|
||||
#ifndef AISLX_QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
#define AISLX_QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
#ifndef QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
#define QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
@@ -22,14 +22,13 @@
|
||||
|
||||
|
||||
typedef int
|
||||
(*aislx_query_on_var)( const char *key, uint32_t k_len,
|
||||
const char *val, uint32_t v_len,
|
||||
void *p_ctx );
|
||||
(*AxQueryHandler)(const char *key, uint32_t k_len,
|
||||
const char *val, uint32_t v_len,
|
||||
void *p_ctx );
|
||||
|
||||
|
||||
struct aislx_query
|
||||
{
|
||||
aislx_query_on_var on_var;
|
||||
struct ax_query {
|
||||
AxQueryHandler on_var;
|
||||
void *p_ctx;
|
||||
char *data;
|
||||
size_t size;
|
||||
@@ -37,22 +36,19 @@ struct aislx_query
|
||||
char separator;
|
||||
};
|
||||
|
||||
typedef struct aislx_query * aislx_query_t;
|
||||
typedef struct ax_query * AxQuery;
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_query_init( aislx_query_t query,
|
||||
size_t total,
|
||||
aislx_query_on_var on_var,
|
||||
void *p_ctx );
|
||||
AislStatus
|
||||
ax_query_init(AxQuery query, size_t total, AxQueryHandler on_var, void *p_ctx);
|
||||
|
||||
|
||||
void
|
||||
aislx_query_release(aislx_query_t query);
|
||||
ax_query_release(AxQuery query);
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_query_feed(aislx_query_t query, const char *data, int32_t length);
|
||||
AislStatus
|
||||
ax_query_feed(AxQuery query, const char *data, int32_t length);
|
||||
|
||||
|
||||
#endif /* !AISLX_QUERY_H */
|
||||
#endif /* !QUERY_H */
|
||||
|
||||
+3
-3
@@ -16,10 +16,10 @@
|
||||
#include "quick.h"
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_quick_response(aisl_stream_t stream, aisl_http_response_t http_response)
|
||||
AislStatus
|
||||
ax_quick_response(AislStream stream, AislHttpResponse http_response)
|
||||
{
|
||||
aisl_status_t result;
|
||||
AislStatus result;
|
||||
|
||||
result = aisl_response(stream, http_response, 0);
|
||||
|
||||
|
||||
+5
-5
@@ -13,12 +13,12 @@
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#ifndef AISLX_QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
#define AISLX_QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
#ifndef QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
#define QUICK_H_39A26EF5_2352_4D54_A10C_203CBBEDF1DF
|
||||
|
||||
#include <aisl/aisl.h>
|
||||
|
||||
aisl_status_t
|
||||
aislx_quick_response(aisl_stream_t stream, aisl_http_response_t http_response);
|
||||
AislStatus
|
||||
ax_quick_response(AislStream stream, AislHttpResponse http_response);
|
||||
|
||||
#endif /* !AISLX_QUICK_H */
|
||||
#endif /* !QUICK_H */
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
|
||||
int
|
||||
aislx_validate_email(const char *value)
|
||||
ax_validate_email(const char *value)
|
||||
{
|
||||
const char *at = NULL,
|
||||
*dot = NULL,
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* @see https://lowenware.com/
|
||||
*/
|
||||
|
||||
#ifndef AISLX_VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
#define AISLX_VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
#ifndef VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
#define VALIDATE_H_5EEF42FB_E99B_4768_AF28_E548CF72D2E6
|
||||
|
||||
|
||||
int
|
||||
aislx_validate_email(const char * value);
|
||||
ax_validate_email(const char *value);
|
||||
|
||||
#endif /* !AISLX_VALIDATE_H */
|
||||
#endif /* !AX_VALIDATE_H */
|
||||
|
||||
Reference in New Issue
Block a user