static gboolean
rspamd_check_encrypted_password (struct rspamd_controller_worker_ctx *ctx,
- const GString * password, const gchar * check,
+ const rspamd_ftok_t * password, const gchar * check,
const struct rspamd_controller_pbkdf *pbkdf,
gboolean is_enable)
{
/* First of all check cached versions to save resources */
if (is_enable && ctx->cached_enable_password.len != 0) {
if (password->len != ctx->cached_enable_password.len ||
- !rspamd_constant_memcmp (password->str,
+ !rspamd_constant_memcmp (password->begin,
ctx->cached_enable_password.begin, password->len)) {
msg_info_ctx ("incorrect or absent enable password has been specified");
return FALSE;
}
else if (!is_enable && ctx->cached_password.len != 0) {
if (password->len != ctx->cached_password.len ||
- !rspamd_constant_memcmp (password->str,
+ !rspamd_constant_memcmp (password->begin,
ctx->cached_password.begin, password->len)) {
msg_info_ctx ("incorrect or absent password has been specified");
return FALSE;
}
local_key = g_alloca (pbkdf->key_len);
- rspamd_cryptobox_pbkdf (password->str, password->len,
+ rspamd_cryptobox_pbkdf (password->begin, password->len,
salt_decoded, salt_len,
local_key, pbkdf->key_len, pbkdf->rounds);
/* Mmap region */
m = mmap (NULL, password->len, PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
- memcpy (m, password->str, password->len);
+ memcpy (m, password->begin, password->len);
(void)mprotect (m, password->len, PROT_READ);
(void)mlock (m, password->len);
cache->begin = m;
struct rspamd_http_message *msg, gboolean is_enable)
{
const gchar *check;
- const GString *password;
- GString lookup;
+ const rspamd_ftok_t *password;
+ rspamd_ftok_t lookup;
GHashTable *query_args = NULL;
struct rspamd_controller_worker_ctx *ctx = session->ctx;
gboolean check_normal = TRUE, check_enable = TRUE, ret = TRUE,
/* Try to get password from query args */
query_args = rspamd_http_message_parse_query (msg);
- lookup.str = (gchar *)"password";
+ lookup.begin = (gchar *)"password";
lookup.len = sizeof ("password") - 1;
password = g_hash_table_lookup (query_args, &lookup);
}
if (check != NULL) {
if (!rspamd_is_encrypted_password (check, &pbkdf)) {
- ret = rspamd_constant_memcmp (password->str, check, password->len);
+ ret = rspamd_constant_memcmp (password->begin, check, password->len);
}
else {
ret = rspamd_check_encrypted_password (ctx, password, check,
if (ctx->password != NULL) {
check = ctx->password;
if (!rspamd_is_encrypted_password (check, &pbkdf)) {
- check_normal = rspamd_constant_memcmp (password->str, check,
+ check_normal = rspamd_constant_memcmp (password->begin, check,
password->len);
}
else {
if (ctx->enable_password != NULL) {
check = ctx->enable_password;
if (!rspamd_is_encrypted_password (check, &pbkdf)) {
- check_enable = rspamd_constant_memcmp (password->str, check,
+ check_enable = rspamd_constant_memcmp (password->begin, check,
password->len);
}
else {
struct rspamd_controller_session *session = conn_ent->ud;
GList *cur;
struct rspamd_map *map;
- const GString *idstr;
- gchar *errstr;
+ const rspamd_ftok_t *idstr;
struct stat st;
gint fd;
- guint32 id;
+ gulong id;
gboolean found = FALSE;
struct rspamd_http_message *reply;
return 0;
}
- id = strtoul (idstr->str, &errstr, 10);
- if (*errstr != '\0' && !g_ascii_isspace (*errstr)) {
+ if (!rspamd_strtoul (idstr->begin, idstr->len, &id)) {
msg_info_session ("invalid map id");
rspamd_controller_send_error (conn_ent, 400, "400 invalid map id");
return 0;
reply = rspamd_http_new_message (HTTP_RESPONSE);
reply->date = time (NULL);
reply->code = 200;
- reply->body = g_string_sized_new (st.st_size);
+ reply->body = rspamd_fstring_sized_new (st.st_size);
/* Read the whole buffer */
if (read (fd, reply->body->str, st.st_size) == -1) {
}
reply->body->len = st.st_size;
- reply->body->str[reply->body->len] = '\0';
close (fd);
GHashTable *query;
struct rspamd_controller_session *session = conn_ent->ud;
struct rspamd_controller_worker_ctx *ctx;
- GString srch, *value;
+ rspamd_ftok_t srch, *value;
struct rspamd_rrd_query_result *rrd_result;
gulong i, j, ts, start_row, cnt, t;
ucl_object_t *res, *elt[4], *data_elt;
}
query = rspamd_http_message_parse_query (msg);
- srch.str = (gchar *)"type";
+ srch.begin = (gchar *)"type";
srch.len = 4;
if (query == NULL || (value = g_hash_table_lookup (query, &srch)) == NULL) {
return 0;
}
- if (strncmp (value->str, "hourly", value->len) == 0) {
+ if (strncmp (value->begin, "hourly", value->len) == 0) {
rra_num = rra_hourly;
}
- else if (strncmp (value->str, "daily", value->len) == 0) {
+ else if (strncmp (value->begin, "daily", value->len) == 0) {
rra_num = rra_hourly;
}
- else if (strncmp (value->str, "weekly", value->len) == 0) {
+ else if (strncmp (value->begin, "weekly", value->len) == 0) {
rra_num = rra_hourly;
}
- else if (strncmp (value->str, "monthly", value->len) == 0) {
+ else if (strncmp (value->begin, "monthly", value->len) == 0) {
rra_num = rra_monthly;
}
GList *cur;
struct rspamd_map *map;
struct rspamd_controller_worker_ctx *ctx;
- const GString *idstr;
- gchar *errstr;
- guint32 id;
+ const rspamd_ftok_t *idstr;
+ gulong id;
gboolean found = FALSE;
gint fd;
return 0;
}
- id = strtoul (idstr->str, &errstr, 10);
- if (*errstr != '\0' && !g_ascii_isspace (*errstr)) {
- msg_info_session ("invalid map id: %v", idstr);
+ if (!rspamd_strtoul (idstr->begin, idstr->len, &id)) {
+ msg_info_session ("invalid map id: %T", idstr);
rspamd_controller_send_error (conn_ent, 400, "Map id is invalid");
return 0;
}
cmd = g_hash_table_lookup (session->ctx->custom_commands, msg->url->str);
if (cmd == NULL || cmd->handler == NULL) {
- msg_err_session ("custom command %v has not been found", msg->url);
+ msg_err_session ("custom command %V has not been found", msg->url);
rspamd_controller_send_error (conn_ent, 404, "No command associated");
return 0;
}
{
struct http_proxy_session *session = conn->ud;
struct rspamd_http_upstream *backend = NULL;
- const GString *host;
+ const rspamd_ftok_t *host;
gchar hostbuf[512];
if (!session->replied) {
backend = session->ctx->default_upstream;
}
else {
- rspamd_strlcpy (hostbuf, host->str, sizeof (hostbuf));
+ rspamd_strlcpy (hostbuf, host->begin, MIN(host->len + 1, sizeof (hostbuf)));
backend = g_hash_table_lookup (session->ctx->upstreams, hostbuf);
if (backend == NULL) {
task->deliver_to);
}
else {
- debug_task ("wrong header: %v", hn);
+ debug_task ("wrong header: %V", hn);
validh = FALSE;
}
break;
debug_task ("read hostname header, value: %s", task->hostname);
}
else {
- debug_task ("wrong header: %v", hn);
+ debug_task ("wrong header: %V", hn);
validh = FALSE;
}
break;
case 'F':
if (g_ascii_strncasecmp (headern, FROM_HEADER, hlen) == 0) {
if (!rspamd_task_add_sender (task, hv->str)) {
- msg_err_task ("bad from header: '%v'", hv);
+ msg_err_task ("bad from header: '%V'", hv);
validh = FALSE;
}
}
else {
- debug_task ("wrong header: %v", hn);
+ debug_task ("wrong header: %V", hn);
validh = FALSE;
}
break;
}
}
else {
- debug_task ("wrong header: %v", hn);
+ debug_task ("wrong header: %V", hn);
validh = FALSE;
}
break;
debug_task ("read queue_id header, value: %s", task->queue_id);
}
else {
- debug_task ("wrong header: %v", hn);
+ debug_task ("wrong header: %V", hn);
validh = FALSE;
}
break;
case 'R':
if (g_ascii_strncasecmp (headern, RCPT_HEADER, hlen) == 0) {
if (!rspamd_task_add_recipient (task, hv->str)) {
- msg_err_task ("bad from header: '%v'", h->value);
+ msg_err_task ("bad from header: '%V'", h->value);
validh = FALSE;
}
- debug_task ("read rcpt header, value: %v", hv);
+ debug_task ("read rcpt header, value: %V", hv);
}
else {
- debug_task ("wrong header: %v", hn);
+ debug_task ("wrong header: %V", hn);
validh = FALSE;
}
break;
case 'I':
if (g_ascii_strncasecmp (headern, IP_ADDR_HEADER, hlen) == 0) {
if (!rspamd_parse_inet_address (&task->from_addr, hv->str)) {
- msg_err_task ("bad ip header: '%v'", hv);
+ msg_err_task ("bad ip header: '%V'", hv);
return FALSE;
}
- debug_task ("read IP header, value: %v", hv);
+ debug_task ("read IP header, value: %V", hv);
has_ip = TRUE;
}
else {
- debug_task ("wrong header: %v", hn);
+ debug_task ("wrong header: %V", hn);
validh = FALSE;
}
break;
task->message_len = strtoul (hv->str, NULL, 10);
if (task->message_len == 0) {
- msg_err_task ("Invalid message length header: %v", hv);
+ msg_err_task ("Invalid message length header: %V", hv);
validh = FALSE;
}
else {
}
break;
default:
- debug_task ("unknown header: %v", hn);
+ debug_task ("unknown header: %V", hn);
validh = FALSE;
break;
}
new_task->re_cache);
new_task->raw_headers = g_hash_table_new (rspamd_strcase_hash,
rspamd_strcase_equal);
- new_task->request_headers = g_hash_table_new_full (rspamd_gstring_icase_hash,
- rspamd_gstring_icase_equal, rspamd_gstring_free_hard,
- rspamd_gstring_free_hard);
+ new_task->request_headers = g_hash_table_new_full (rspamd_ftok_icase_hash,
+ rspamd_ftok_icase_equal, rspamd_fstring_mapped_ftok_free,
+ rspamd_fstring_mapped_ftok_free);
rspamd_mempool_add_destructor (new_task->task_pool,
(rspamd_mempool_destruct_t) g_hash_table_unref,
new_task->request_headers);
- new_task->reply_headers = g_hash_table_new_full (rspamd_gstring_icase_hash,
- rspamd_gstring_icase_equal, rspamd_gstring_free_hard,
- rspamd_gstring_free_hard);
+ new_task->reply_headers = g_hash_table_new_full (rspamd_ftok_icase_hash,
+ rspamd_ftok_icase_equal, rspamd_fstring_mapped_ftok_free,
+ rspamd_fstring_mapped_ftok_free);
rspamd_mempool_add_destructor (new_task->task_pool,
(rspamd_mempool_destruct_t) g_hash_table_unref,
new_task->reply_headers);
ucl_object_t *control_obj;
gchar filepath[PATH_MAX], *fp;
gint fd, flen;
+ rspamd_ftok_t srch, *tok;
gpointer map;
struct stat st;
rspamd_protocol_handle_headers (task, msg);
}
- if (task->flags & RSPAMD_TASK_FLAG_FILE) {
- g_assert (task->msg.len > 0);
+ srch.begin = "file";
+ srch.len = 4;
+ tok = g_hash_table_lookup (task->request_headers, &srch);
- r = rspamd_strlcpy (filepath, task->msg.begin,
- MIN (sizeof (filepath), task->msg.len + 1));
+ if (tok == NULL) {
+ srch.begin = "path";
+ srch.len = 4;
+ tok = g_hash_table_lookup (task->request_headers, &srch);
+ }
+
+ if (tok) {
+ r = rspamd_strlcpy (filepath, tok->begin,
+ MIN (sizeof (filepath), tok->len + 1));
rspamd_decode_url (filepath, filepath, r + 1);
flen = strlen (filepath);
msg = rspamd_http_new_message (HTTP_RESPONSE);
va_start (args, error_msg);
- msg->status = g_string_sized_new (128);
- rspamd_vprintf_gstring (msg->status, error_msg, args);
+ msg->status = rspamd_fstring_sized_new (128);
+ rspamd_vprintf_fstring (&msg->status, error_msg, args);
va_end (args);
msg->date = time (NULL);
msg->code = code;
- msg->body = g_string_sized_new (128);
- rspamd_printf_gstring (msg->body, "{\"error\":\"%v\"}", msg->status);
+ msg->body = rspamd_fstring_sized_new (128);
+ rspamd_printf_fstring (&msg->body, "{\"error\":\"%V\"}", msg->status);
rspamd_http_connection_reset (entry->conn);
rspamd_http_connection_write_message (entry->conn,
msg,
msg = rspamd_http_new_message (HTTP_RESPONSE);
msg->date = time (NULL);
msg->code = 200;
- msg->body = g_string_new (str);
+ msg->body = rspamd_fstring_new_init (str, strlen (str));
rspamd_http_connection_reset (entry->conn);
rspamd_http_connection_write_message (entry->conn,
msg,
msg = rspamd_http_new_message (HTTP_RESPONSE);
msg->date = time (NULL);
msg->code = 200;
- msg->body = g_string_sized_new (BUFSIZ);
- rspamd_ucl_emit_gstring (obj, UCL_EMIT_JSON_COMPACT, msg->body);
+ msg->body = rspamd_fstring_sized_new (BUFSIZ);
+ rspamd_ucl_emit_fstring (obj, UCL_EMIT_JSON_COMPACT, &msg->body);
rspamd_http_connection_reset (entry->conn);
rspamd_http_connection_write_message (entry->conn,
msg,
fuzzy_controller_handler (struct rspamd_http_connection_entry *conn_ent,
struct rspamd_http_message *msg, struct module_ctx *ctx, gint cmd)
{
- const GString *arg;
- gchar *err_str;
- gint value = 1, flag = 0;
+ const rspamd_ftok_t *arg;
+ glong value = 1, flag = 0;
/* Get size */
arg = rspamd_http_message_find_header (msg, "Weight");
if (arg) {
errno = 0;
- value = strtol (arg->str, &err_str, 10);
- if (*err_str != '\0' && *err_str != '\r') {
- msg_info ("error converting numeric argument %v", arg);
- value = 0;
+
+ if (!rspamd_strtol (arg->begin, arg->len, &value)) {
+ msg_info ("error converting numeric argument %T", arg);
}
}
arg = rspamd_http_message_find_header (msg, "Flag");
if (arg) {
errno = 0;
- flag = strtol (arg->str, &err_str, 10);
- if (*err_str != '\0' && *err_str != '\r') {
- msg_info ("error converting numeric argument %v", arg);
+ if (!rspamd_strtol (arg->begin, arg->len, &flag)) {
+ msg_info ("error converting numeric argument %T", arg);
flag = 0;
}
}
struct redirector_param *param = (struct redirector_param *)conn->ud;
struct rspamd_task *task;
gint r, urllen;
- const GString *hdr;
+ const rspamd_ftok_t *hdr;
gchar *urlstr;
task = param->task;
urllen = hdr->len;
urlstr = rspamd_mempool_alloc (param->task->task_pool,
urllen + 1);
- rspamd_strlcpy (urlstr, hdr->str, urllen + 1);
+ rspamd_strlcpy (urlstr, hdr->begin, urllen + 1);
r = rspamd_url_parse (param->url, urlstr, urllen,
param->task->task_pool);
RSPAMD_HTTP_CLIENT_SIMPLE,
RSPAMD_HTTP_CLIENT, NULL);
msg = rspamd_http_new_message (HTTP_REQUEST);
- g_string_assign (msg->url, struri (url));
+ msg->url = rspamd_fstring_assign (msg->url, struri (url), strlen (struri (url)));
param->sock = s;
param->suffix = suffix;
param->redirector = selected;