Browse Source

Fix keys initialization.

tags/0.9.0
Vsevolod Stakhov 9 years ago
parent
commit
9bcf7906ee
7 changed files with 35 additions and 4 deletions
  1. 1
    1
      src/client/rspamdclient.c
  2. 5
    0
      src/libserver/protocol.c
  3. 3
    0
      src/libserver/task.c
  4. 1
    0
      src/libserver/task.h
  5. 13
    1
      src/libutil/http.c
  6. 7
    1
      src/libutil/http.h
  7. 5
    1
      src/worker.c

+ 1
- 1
src/client/rspamdclient.c View File

@@ -251,7 +251,7 @@ rspamd_client_destroy (struct rspamd_client_connection *conn)
g_string_free (conn->key, TRUE);
}
if (conn->keypair) {
rspamd_http_connection_key_destroy (conn->keypair);
rspamd_http_connection_key_unref (conn->keypair);
}
g_string_free (conn->server_name, TRUE);
g_slice_free1 (sizeof (struct rspamd_client_connection), conn);

+ 5
- 0
src/libserver/protocol.c View File

@@ -905,6 +905,11 @@ rspamd_protocol_write_reply (struct rspamd_task *task)
const gchar *ctype = "application/json";

msg = rspamd_http_new_message (HTTP_RESPONSE);

if (task->peer_key) {
msg->peer_key = g_string_new (task->peer_key->str);
msg_info ("<%s> writing encrypted reply", task->message_id);
}
if (!task->is_json) {
/* Turn compatibility on */
msg->method = HTTP_SYMBOLS;

+ 3
- 0
src/libserver/task.c View File

@@ -266,6 +266,9 @@ rspamd_task_free (struct rspamd_task *task, gboolean is_soft)
if (task->settings != NULL) {
ucl_object_unref (task->settings);
}
if (task->peer_key != NULL) {
g_string_free (task->peer_key, TRUE);
}
rspamd_mempool_delete (task->task_pool);
g_slice_free1 (sizeof (struct rspamd_task), task);
}

+ 1
- 0
src/libserver/task.h View File

@@ -147,6 +147,7 @@ struct rspamd_task {
} pre_result; /**< Result of pre-filters */

ucl_object_t *settings; /**< Settings applied to task */
GString *peer_key; /**< Peer's pubkey */
};

/**

+ 13
- 1
src/libutil/http.c View File

@@ -1197,6 +1197,7 @@ rspamd_http_new_message (enum http_parser_type type)
new->port = 80;
new->type = type;
new->method = HTTP_GET;
new->peer_key = NULL;

return new;
}
@@ -1761,7 +1762,7 @@ rspamd_http_connection_set_key (struct rspamd_http_connection *conn,
}

void
rspamd_http_connection_key_destroy (gpointer key)
rspamd_http_connection_key_unref (gpointer key)
{
struct rspamd_http_keypair *kp = (struct rspamd_http_keypair *)key;

@@ -1769,6 +1770,17 @@ rspamd_http_connection_key_destroy (gpointer key)
REF_RELEASE (kp);
}

gpointer
rspamd_http_connection_key_ref (gpointer key)
{
struct rspamd_http_keypair *kp = (struct rspamd_http_keypair *)key;

g_assert (key != NULL);
REF_RETAIN (kp);

return kp;
}

GString *
rspamd_http_connection_make_peer_key (const gchar *key)
{

+ 7
- 1
src/libutil/http.h View File

@@ -193,7 +193,13 @@ GString *rspamd_http_connection_print_key (gpointer key, guint how);
* Release key pointed by an opaque pointer
* @param key opaque key structure
*/
void rspamd_http_connection_key_destroy (gpointer key);
void rspamd_http_connection_key_unref (gpointer key);

/**
* Increase refcount for a key pointed by an opaque pointer
* @param key opaque key structure
*/
gpointer rspamd_http_connection_key_ref (gpointer key);

GString *rspamd_http_connection_make_peer_key (const gchar *key);


+ 5
- 1
src/worker.c View File

@@ -129,6 +129,10 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
return 0;
}

if (msg->peer_key) {
task->peer_key = g_string_new (msg->peer_key->str);
}

if (!rspamd_task_process (task, msg, ctx->classify_pool, TRUE)) {
task->state = WRITE_REPLY;
}
@@ -354,7 +358,7 @@ start_worker (struct rspamd_worker *worker)
rspamd_log_close (rspamd_main->logger);

if (ctx->key) {
rspamd_http_connection_key_destroy (ctx->key);
rspamd_http_connection_key_unref (ctx->key);
}

exit (EXIT_SUCCESS);

Loading…
Cancel
Save