ref_entry_t ref;
};
+enum rspamd_http_priv_flags {
+ RSPAMD_HTTP_CONN_FLAG_ENCRYPTED = 1 << 0,
+ RSPAMD_HTTP_CONN_FLAG_NEW_HEADER = 1 << 1,
+ RSPAMD_HTTP_CONN_FLAG_RESETED = 1 << 2
+};
+
+#define IS_CONN_ENCRYPTED(c) ((c)->flags & RSPAMD_HTTP_CONN_FLAG_ENCRYPTED)
+#define IS_CONN_RESETED(c) ((c)->flags & RSPAMD_HTTP_CONN_FLAG_RESETED)
+
struct rspamd_http_connection_private {
struct _rspamd_http_privbuf *buf;
- gboolean new_header;
- gboolean encrypted;
struct rspamd_cryptobox_pubkey *peer_key;
struct rspamd_cryptobox_keypair *local_key;
struct rspamd_http_header *header;
struct rspamd_http_message *msg;
struct iovec *out;
guint outlen;
+ enum rspamd_http_priv_flags flags;
gsize wr_pos;
gsize wr_total;
};
if (priv->local_key == NULL) {
/* In this case we cannot do anything, e.g. we cannot decrypt payload */
- priv->encrypted = TRUE;
+ priv->flags |= RSPAMD_HTTP_CONN_FLAG_ENCRYPTED;
}
else {
/* Check sanity of what we have */
}
}
- priv->encrypted = TRUE;
+ priv->flags |= RSPAMD_HTTP_CONN_FLAG_ENCRYPTED;
g_free (decoded_id);
}
}
if (priv->header == NULL) {
rspamd_http_init_header (priv);
}
- else if (priv->new_header) {
+ else if (priv->flags & RSPAMD_HTTP_CONN_FLAG_NEW_HEADER) {
rspamd_http_finish_header (conn, priv);
rspamd_http_init_header (priv);
}
- priv->new_header = FALSE;
+ priv->flags &= ~RSPAMD_HTTP_CONN_FLAG_NEW_HEADER;
priv->header->combined = rspamd_fstring_append (priv->header->combined,
at, length);
return -1;
}
- if (!priv->new_header) {
- priv->new_header = TRUE;
+ if (!(priv->flags & RSPAMD_HTTP_CONN_FLAG_NEW_HEADER)) {
+ priv->flags |= RSPAMD_HTTP_CONN_FLAG_NEW_HEADER;
priv->header->combined = rspamd_fstring_append (priv->header->combined,
": ", 2);
priv->header->name->len = priv->header->combined->len - 2;
rspamd_http_finish_header (conn, priv);
priv->header = NULL;
- priv->new_header = FALSE;
+ priv->flags &= ~RSPAMD_HTTP_CONN_FLAG_NEW_HEADER;
}
if (parser->content_length != 0 && parser->content_length != ULLONG_MAX) {
priv->msg->body_buf.begin = priv->msg->body->str;
priv->msg->body_buf.len = priv->msg->body->len;
- if ((conn->opts & RSPAMD_HTTP_BODY_PARTIAL) && !priv->encrypted) {
+ if ((conn->opts & RSPAMD_HTTP_BODY_PARTIAL) && !IS_CONN_ENCRYPTED (priv)) {
/* Incremental update is impossible for encrypted requests so far */
return (conn->body_handler (conn, priv->msg, at, length));
}
rspamd_http_finish_header (conn, priv);
priv->header = NULL;
- priv->new_header = FALSE;
+ priv->flags &= ~RSPAMD_HTTP_CONN_FLAG_NEW_HEADER;
}
if (parser->flags & F_SPAMC) {
priv = conn->priv;
- if ((conn->opts & RSPAMD_HTTP_BODY_PARTIAL) == 0 && priv->encrypted) {
+ if ((conn->opts & RSPAMD_HTTP_BODY_PARTIAL) == 0 && IS_CONN_ENCRYPTED (priv)) {
mode = rspamd_keypair_alg (priv->local_key);
if (priv->local_key == NULL || priv->msg->peer_key == NULL ||
}
else {
/* Want to write more */
+ priv->flags &= ~RSPAMD_HTTP_CONN_FLAG_RESETED;
event_add (&priv->ev, priv->ptv);
}
conn->finished = FALSE;
/* Clear priv */
- event_del (&priv->ev);
+
+ if (!(priv->flags & RSPAMD_HTTP_CONN_FLAG_RESETED)) {
+ event_del (&priv->ev);
+ rspamd_http_parser_reset (conn);
+ }
if (priv->buf != NULL) {
REF_RELEASE (priv->buf);
priv->buf = NULL;
}
- rspamd_http_parser_reset (conn);
-
if (priv->out != NULL) {
g_slice_free1 (sizeof (struct iovec) * priv->outlen, priv->out);
priv->out = NULL;
}
+
+ priv->flags |= RSPAMD_HTTP_CONN_FLAG_RESETED;
}
struct rspamd_http_message *
if (priv->peer_key) {
priv->msg->peer_key = priv->peer_key;
priv->peer_key = NULL;
- priv->encrypted = TRUE;
+ priv->flags |= RSPAMD_HTTP_CONN_FLAG_ENCRYPTED;
}
if (timeout == NULL) {
priv->buf = g_slice_alloc0 (sizeof (*priv->buf));
REF_INIT_RETAIN (priv->buf, rspamd_http_privbuf_dtor);
priv->buf->data = rspamd_fstring_sized_new (8192);
- priv->new_header = TRUE;
+ priv->flags |= RSPAMD_HTTP_CONN_FLAG_NEW_HEADER;
event_set (&priv->ev,
fd,
if (base != NULL) {
event_base_set (base, &priv->ev);
}
+
+ priv->flags &= ~RSPAMD_HTTP_CONN_FLAG_RESETED;
event_add (&priv->ev, priv->ptv);
}
if (priv->peer_key && priv->local_key) {
priv->msg->peer_key = priv->peer_key;
priv->peer_key = NULL;
- priv->encrypted = TRUE;
+ priv->flags |= RSPAMD_HTTP_CONN_FLAG_ENCRYPTED;
}
if (priv->local_key != NULL && msg->peer_key != NULL) {
event_base_set (base, &priv->ev);
}
+ priv->flags &= ~RSPAMD_HTTP_CONN_FLAG_RESETED;
event_add (&priv->ev, priv->ptv);
}