Correct names and fix declaration issues
This commit is contained in:
+70
-59
@@ -13,17 +13,19 @@
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cStuff/string.h>
|
||||
#include <curl/curl.h>
|
||||
#include "mail.h"
|
||||
|
||||
|
||||
struct payload
|
||||
{
|
||||
struct payload {
|
||||
char now[40];
|
||||
char *to;
|
||||
char *from;
|
||||
char *subject;
|
||||
char *msg_id;
|
||||
char *smtp_user;
|
||||
char *smtp_pass;
|
||||
char *smtp_url;
|
||||
@@ -41,12 +43,11 @@ payload_feed(void *ptr, size_t size, size_t nmemb, void *userp)
|
||||
|
||||
left = payload->total - payload->offset;
|
||||
|
||||
if (left && (size = size*nmemb))
|
||||
{
|
||||
cf (size > left)
|
||||
if (left && (size = size*nmemb)) {
|
||||
if (size > left)
|
||||
size = left;
|
||||
|
||||
memcpy(ptr, payload->data[payload->offset], size);
|
||||
memcpy(ptr, &payload->data[payload->offset], size);
|
||||
payload->offset += size;
|
||||
|
||||
return size;
|
||||
@@ -57,25 +58,23 @@ payload_feed(void *ptr, size_t size, size_t nmemb, void *userp)
|
||||
|
||||
|
||||
static void
|
||||
payload__get_now(char * now, size_t size)
|
||||
payload__get_now(char *now, size_t size)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
time_t time_now = time(NULL);
|
||||
struct tm tm;
|
||||
|
||||
gmtime_r(&now, &tm);
|
||||
gmtime_r(&time_now, &tm);
|
||||
strftime(now, size, "%a, %d %b %Y %H:%M:%S GMT", &tm);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
payload__get_id(uuid_t uuid, char * server)
|
||||
payload__get_id(uuid_t uuid, const char *server)
|
||||
{
|
||||
size_t sz = strlen(server);
|
||||
char *result = malloc( sz + 3 + 36 + 1 );
|
||||
|
||||
char * result = malloc( sz + 3 + 36 + 1 );
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (result) {
|
||||
char * p =result;
|
||||
*(p++) = '<';
|
||||
uuid_unparse(uuid, p);
|
||||
@@ -91,8 +90,39 @@ payload__get_id(uuid_t uuid, char * server)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
payload_free(struct payload *payload)
|
||||
{
|
||||
if (payload->data)
|
||||
free(payload->data);
|
||||
|
||||
if (payload->to)
|
||||
free(payload->to);
|
||||
|
||||
if (payload->from)
|
||||
free(payload->from);
|
||||
|
||||
if (payload->subject)
|
||||
free(payload->subject);
|
||||
|
||||
if (payload->msg_id)
|
||||
free(payload->msg_id);
|
||||
|
||||
if (payload->smtp_user)
|
||||
free(payload->smtp_user);
|
||||
|
||||
if (payload->smtp_pass)
|
||||
free(payload->smtp_pass);
|
||||
|
||||
if (payload->smtp_url)
|
||||
free(payload->smtp_url);
|
||||
|
||||
free(payload);
|
||||
}
|
||||
|
||||
|
||||
static struct payload *
|
||||
payload_new(aislx_mail_t mail, const char * server)
|
||||
payload_new(aislx_mail_t mail, const char *server)
|
||||
{
|
||||
size_t total;
|
||||
struct payload *payload;
|
||||
@@ -108,17 +138,17 @@ payload_new(aislx_mail_t mail, const char * server)
|
||||
if (cstuff_strcpy(&payload->from, mail->from) == -1)
|
||||
goto e_cleanup;
|
||||
|
||||
if ( !(payload->message_id = payload__get_id(mail->msg_id, server)) )
|
||||
if ( !(payload->msg_id = payload__get_id(mail->msg_id, server)) )
|
||||
goto e_cleanup;
|
||||
|
||||
total = cstuff_sprintf( &payload->data, AISLX_MAIL_FORMAT
|
||||
, date
|
||||
, payload->to
|
||||
, payload->from
|
||||
, mail->reply_to
|
||||
, payload->message_id
|
||||
, mail->subject
|
||||
, mail->message );
|
||||
, payload->now
|
||||
, payload->to
|
||||
, payload->from
|
||||
, mail->reply_to
|
||||
, payload->msg_id
|
||||
, mail->subject
|
||||
, mail->msg );
|
||||
|
||||
if (!(total > 0))
|
||||
goto e_cleanup;
|
||||
@@ -135,28 +165,16 @@ except:
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
payload_free(struct payload *payload)
|
||||
{
|
||||
if (payload->data)
|
||||
free(payload->data);
|
||||
|
||||
free(payload);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
aislx_mail_execute(void * p_ctx)
|
||||
aislx_mail_execute(void *p_ctx)
|
||||
{
|
||||
void *result = NULL;
|
||||
struct payload * payload = (struct payload *)p_ctx;
|
||||
aisl_status_t status = AISL_MALLOC_ERROR;
|
||||
|
||||
CURL *curl;
|
||||
struct curl_slist *rcpts;
|
||||
|
||||
if ((curl = curl_easy_init()) != NULL)
|
||||
{
|
||||
if ((curl = curl_easy_init()) != NULL) {
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, payload->smtp_user);
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, payload->smtp_pass);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, payload->smtp_url);
|
||||
@@ -169,18 +187,14 @@ aislx_mail_execute(void * p_ctx)
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, payload->from);
|
||||
|
||||
if ((rcpts = curl_slist_append(NULL, payload->to)) != NULL)
|
||||
{
|
||||
if ((rcpts = curl_slist_append(NULL, payload->to)) != NULL) {
|
||||
CURLcode res;
|
||||
|
||||
if ((res = curl_easy_perform(curl)) != CURLE_OK)
|
||||
{
|
||||
if ((res = curl_easy_perform(curl)) != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n"
|
||||
, curl_easy_strerror(res));
|
||||
status = AISL_INPUT_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
status = AISL_SUCCESS;
|
||||
}
|
||||
curl_slist_free_all(rcpts);
|
||||
@@ -188,28 +202,28 @@ aislx_mail_execute(void * p_ctx)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return result + (int)status;
|
||||
return (void*)status;
|
||||
}
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_mail_send( aislx_mail_t mail,
|
||||
const char *smtp_server,
|
||||
const char *smtp_user,
|
||||
const char *smtp_pass,
|
||||
int flags )
|
||||
const char *smtp_server,
|
||||
const char *smtp_user,
|
||||
const char *smtp_pass,
|
||||
int flags )
|
||||
{
|
||||
struct payload * payload;
|
||||
int rc;
|
||||
struct payload *payload;
|
||||
|
||||
if (!(payload = payload_new(mail, smtp_server)))
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
if (pthread_create(&mail->thread, NULL, aislx_mail_execute, (void*)payload))
|
||||
{
|
||||
rc = pthread_create(&mail->thread, NULL, aislx_mail_execute, (void*)payload);
|
||||
if (rc) {
|
||||
payload_free(payload);
|
||||
return AISL_SYSCALL_ERROR;
|
||||
}
|
||||
|
||||
return AISL_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -222,13 +236,10 @@ aislx_mail_get_status(aislx_mail_t mail)
|
||||
|
||||
rc = pthread_tryjoin_np(mail->thread, &retval);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
rc = (int)(retval-0);
|
||||
if (rc == 0) {
|
||||
rc = (aisl_status_t)retval;
|
||||
return rc;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return AISL_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -39,8 +39,9 @@
|
||||
|
||||
struct aislx_mail
|
||||
{
|
||||
pthread_t pthread;
|
||||
pthread_t thread;
|
||||
const char *to;
|
||||
const char *reply_to;
|
||||
const char *from;
|
||||
const char *subject;
|
||||
const char *msg;
|
||||
|
||||
+49
-57
@@ -13,14 +13,17 @@
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.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 )
|
||||
size_t total,
|
||||
aislx_query_on_var on_var,
|
||||
void * p_ctx )
|
||||
{
|
||||
query->on_var = on_var;
|
||||
query->p_ctx = p_ctx;
|
||||
@@ -43,13 +46,12 @@ aislx_query_release(aislx_query_t query)
|
||||
|
||||
static void
|
||||
aislx_query_notify(const char * key, uint32_t k_len,
|
||||
const cahr * val, uint32_t v_len,
|
||||
aislx_query_t query)
|
||||
const char * val, uint32_t v_len,
|
||||
aislx_query_t query)
|
||||
{
|
||||
if (query->on_var)
|
||||
{
|
||||
if (query->on_var) {
|
||||
if (query->on_var(key, k_len, val, v_len, query->p_ctx) != 0)
|
||||
query->on_var == NULL;
|
||||
query->on_var = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,55 +59,47 @@ 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)
|
||||
{
|
||||
const char * i = data,
|
||||
* key = data,
|
||||
* val = NULL;
|
||||
|
||||
uint32_t k_len = 0;
|
||||
|
||||
const char *i = data,
|
||||
*key = data,
|
||||
*val = NULL;
|
||||
uint32_t k_len = 0;
|
||||
size_t result;
|
||||
|
||||
for (result=0; result < length; result++)
|
||||
{
|
||||
for (result=0; result < length; result++) {
|
||||
char c;
|
||||
|
||||
switch( (c = *i) )
|
||||
{
|
||||
case '=':
|
||||
if (val)
|
||||
return -1;
|
||||
switch( (c = *i) ) {
|
||||
case '=':
|
||||
if (val)
|
||||
return -1;
|
||||
|
||||
k_len = i-key;
|
||||
val = i+1;
|
||||
k_len = i-key;
|
||||
val = i+1;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
case ';':
|
||||
if (!val)
|
||||
return -1;
|
||||
|
||||
if (!query->separator)
|
||||
query->separator = c;
|
||||
|
||||
if (query->separator == c) {
|
||||
aislx_query_notify(key, k_len, val, i-val, query);
|
||||
/* reset parser */
|
||||
key = (c == ';') ? i+2 : i+1;
|
||||
k_len = 0;
|
||||
val = NULL;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
case ';'
|
||||
if (!val)
|
||||
return -1;
|
||||
|
||||
if (!query->separator)
|
||||
query->separator = c;
|
||||
|
||||
if (query->separator == c)
|
||||
{
|
||||
aislx_query_notify(key, k_len, val, i-val, query);
|
||||
/* reset parser */
|
||||
key = (c == ';') ? i+2 : i+1;
|
||||
k_len = 0;
|
||||
val = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (query->total == result)
|
||||
{
|
||||
if (query->total == result) {
|
||||
aislx_query_notify(key, k_len, val, i-val, query);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
result = (key > i) ? i - data : key - data;
|
||||
}
|
||||
|
||||
@@ -116,33 +110,31 @@ aislx_query_process(aislx_query_t query, const char * data, int32_t length)
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_query_feed(aislx_query_t query, char * data, int32_t length)
|
||||
aislx_query_feed(aislx_query_t query, const char *data, int32_t length)
|
||||
{
|
||||
size_t processed;
|
||||
char * source;
|
||||
const char *source;
|
||||
|
||||
if (query->data)
|
||||
{
|
||||
if (query->data) {
|
||||
if (!(source = realloc(query->data, length + query->size)))
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
length += query->size;
|
||||
query->data = source;
|
||||
query->data = (char*)source;
|
||||
query->size = length;
|
||||
|
||||
memcpy(&source[query->size], data, length);
|
||||
}
|
||||
else
|
||||
memcpy((char*)&source[query->size], data, length);
|
||||
} else {
|
||||
source = data;
|
||||
}
|
||||
|
||||
processed = aislx_query_process(query, source, length);
|
||||
|
||||
if (processed < 0)
|
||||
return AISL_INPUT_ERROR;
|
||||
|
||||
if (processed < length)
|
||||
{
|
||||
char * buffer;
|
||||
if (processed < length) {
|
||||
char *buffer;
|
||||
|
||||
length -= processed;
|
||||
if (!(buffer = malloc(length)))
|
||||
|
||||
+15
-14
@@ -17,33 +17,34 @@
|
||||
#define AISLX_QUERY_H_9306EAEB_6DFC_4936_934A_6472F00E490C
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <aisl/aisl.h>
|
||||
|
||||
|
||||
typedef int
|
||||
(*aislx_query_on_var)( const char * key, uint32_t k_len,
|
||||
const char * val, uint32_t v_len,
|
||||
void * p_ctx );
|
||||
(*aislx_query_on_var)( 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;
|
||||
|
||||
void * p_ctx;
|
||||
char * data;
|
||||
size_t size;
|
||||
size_t total;
|
||||
char separator;
|
||||
void *p_ctx;
|
||||
char *data;
|
||||
size_t size;
|
||||
size_t total;
|
||||
char separator;
|
||||
};
|
||||
|
||||
typedef struct aislx_query * aislx_query_t;
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_query_init( aislx_query_t query,
|
||||
size_t total,
|
||||
aislx_query_on_var on_var,
|
||||
void * p_ctx );
|
||||
aislx_query_init( aislx_query_t query,
|
||||
size_t total,
|
||||
aislx_query_on_var on_var,
|
||||
void *p_ctx );
|
||||
|
||||
|
||||
void
|
||||
@@ -51,7 +52,7 @@ aislx_query_release(aislx_query_t query);
|
||||
|
||||
|
||||
aisl_status_t
|
||||
aislx_query_feed(aislx_query_t query, char * data, uint32_t length);
|
||||
aislx_query_feed(aislx_query_t query, const char *data, int32_t length);
|
||||
|
||||
|
||||
#endif /* !AISLX_QUERY_H */
|
||||
|
||||
+3
-3
@@ -21,12 +21,12 @@ aislx_quick_response(aisl_stream_t stream, aisl_http_response_t http_response)
|
||||
{
|
||||
aisl_status_t result;
|
||||
|
||||
result = aisl_response(s, http_response, 0);
|
||||
result = aisl_response(stream, http_response, 0);
|
||||
|
||||
if (result == AISL_SUCCESS)
|
||||
aisl_flush(s);
|
||||
aisl_flush(stream);
|
||||
else
|
||||
aisl_reject(s);
|
||||
aisl_reject(stream);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+75
-80
@@ -13,101 +13,96 @@
|
||||
* @see https://lowenware.com/aisl/
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include "validate.h"
|
||||
|
||||
|
||||
int
|
||||
aislx_validate_email(const char * value)
|
||||
aislx_validate_email(const char *value)
|
||||
{
|
||||
const char * at = NULL,
|
||||
* dot = NULL,
|
||||
* i = value;
|
||||
|
||||
const char *at = NULL,
|
||||
*dot = NULL,
|
||||
*i = value;
|
||||
char c;
|
||||
|
||||
while ( (c = *i) != 0 )
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case '@':
|
||||
if (at || i == value) break;
|
||||
|
||||
at = i++;
|
||||
dot = NULL;
|
||||
continue;
|
||||
|
||||
case '"':
|
||||
case '(':
|
||||
case ')':
|
||||
case ',':
|
||||
case ';':
|
||||
case ':':
|
||||
case '<':
|
||||
case '>':
|
||||
case '[':
|
||||
case '\\':
|
||||
case ']':
|
||||
case ' ':
|
||||
/* These characters are allowed in double quotes only, but it is not
|
||||
* implemented in this validator, so we count them as forbidden
|
||||
*/
|
||||
while ( (c = *i) != 0 ) {
|
||||
switch(c) {
|
||||
case '@':
|
||||
if (at || i == value)
|
||||
break;
|
||||
|
||||
case '!':
|
||||
case '#':
|
||||
case '$':
|
||||
case '%':
|
||||
case '&':
|
||||
case '\'':
|
||||
case '*':
|
||||
case '+':
|
||||
case '/':
|
||||
case '=':
|
||||
case '?':
|
||||
case '^':
|
||||
case '_':
|
||||
case '`':
|
||||
case '{':
|
||||
case '|':
|
||||
case '}':
|
||||
case '~':
|
||||
/* Allowed special local-part characters */
|
||||
if (!at)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
at = i++;
|
||||
dot = NULL;
|
||||
continue;
|
||||
|
||||
case '-':
|
||||
/* Allowed characters */
|
||||
case '"':
|
||||
case '(':
|
||||
case ')':
|
||||
case ',':
|
||||
case ';':
|
||||
case ':':
|
||||
case '<':
|
||||
case '>':
|
||||
case '[':
|
||||
case '\\':
|
||||
case ']':
|
||||
case ' ':
|
||||
/* These characters are allowed in double quotes only, but it is not
|
||||
* implemented in this validator, so we count them as forbidden
|
||||
*/
|
||||
break;
|
||||
|
||||
case '!':
|
||||
case '#':
|
||||
case '$':
|
||||
case '%':
|
||||
case '&':
|
||||
case '\'':
|
||||
case '*':
|
||||
case '+':
|
||||
case '/':
|
||||
case '=':
|
||||
case '?':
|
||||
case '^':
|
||||
case '_':
|
||||
case '`':
|
||||
case '{':
|
||||
case '|':
|
||||
case '}':
|
||||
case '~':
|
||||
/* Allowed special local-part characters */
|
||||
if (!at) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case '.':
|
||||
if (dot && i == dot+1)
|
||||
break;
|
||||
|
||||
if (at)
|
||||
{
|
||||
if (i == at+1 || *(i+1) == 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i == value || *(i+1) == '@')
|
||||
break;
|
||||
}
|
||||
|
||||
dot = i++;
|
||||
continue;
|
||||
|
||||
default:
|
||||
if ( isalnum(c) == 0 )
|
||||
continue;
|
||||
case '-':
|
||||
/* Allowed characters */
|
||||
i++;
|
||||
continue;
|
||||
|
||||
case '.':
|
||||
if (dot && i == dot+1)
|
||||
break;
|
||||
|
||||
if (at) {
|
||||
if (i == at+1 || *(i+1) == 0)
|
||||
break;
|
||||
} else {
|
||||
if (i == value || *(i+1) == '@')
|
||||
break;
|
||||
}
|
||||
|
||||
dot = i++;
|
||||
continue;
|
||||
|
||||
default:
|
||||
if ( isalnum(c) == 0 )
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
return (int)(i-value)+1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user