summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-06 21:55:15 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-06 21:55:15 +0100
commitdaf929a743ad48149a9f81f3d54900971954ad77 (patch)
tree0e282177f464e50cc413512ca17aa2c7cb384094
parent4b86b2bbeeda5c4c56a0fb1b5add302835eca1b5 (diff)
downloadrspamd-daf929a743ad48149a9f81f3d54900971954ad77.tar.gz
rspamd-daf929a743ad48149a9f81f3d54900971954ad77.zip
Add compatibility output for rspamd 0.6 protocol.
-rw-r--r--src/http.c89
-rw-r--r--src/protocol.c4
2 files changed, 60 insertions, 33 deletions
diff --git a/src/http.c b/src/http.c
index 7184b1193..39ce4924a 100644
--- a/src/http.c
+++ b/src/http.c
@@ -729,45 +729,62 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn,
priv->header = NULL;
priv->buf = g_string_sized_new (128);
- if (msg->body == NULL || msg->body->len == 0) {
- pbody = NULL;
- bodylen = 0;
- priv->outlen = 2;
- msg->method = HTTP_GET;
+ if (msg->method < HTTP_SYMBOLS) {
+ if (msg->body == NULL || msg->body->len == 0) {
+ pbody = NULL;
+ bodylen = 0;
+ priv->outlen = 2;
+ msg->method = HTTP_GET;
+ }
+ else {
+ pbody = msg->body->str;
+ bodylen = msg->body->len;
+ priv->outlen = 3;
+ msg->method = HTTP_POST;
+ }
}
- else {
+ else if (msg->body != NULL) {
pbody = msg->body->str;
bodylen = msg->body->len;
- priv->outlen = 3;
- msg->method = HTTP_POST;
+ priv->outlen = 2;
+ }
+ else {
+ /* Invalid body for spamc method */
+ return;
}
if (conn->type == RSPAMD_HTTP_SERVER) {
/* Format reply */
- ptm = gmtime (&msg->date);
- t = *ptm;
- rspamd_snprintf (datebuf, sizeof (datebuf), "%s, %02d %s %4d %02d:%02d:%02d GMT",
- http_week[t.tm_wday],
- t.tm_mday,
- http_month[t.tm_mon],
- t.tm_year + 1900,
- t.tm_hour,
- t.tm_min,
- t.tm_sec);
- if (mime_type == NULL) {
- mime_type = "text/plain";
+ if (msg->method < HTTP_SYMBOLS) {
+ ptm = gmtime (&msg->date);
+ t = *ptm;
+ rspamd_snprintf (datebuf, sizeof (datebuf), "%s, %02d %s %4d %02d:%02d:%02d GMT",
+ http_week[t.tm_wday],
+ t.tm_mday,
+ http_month[t.tm_mon],
+ t.tm_year + 1900,
+ t.tm_hour,
+ t.tm_min,
+ t.tm_sec);
+ if (mime_type == NULL) {
+ mime_type = "text/plain";
+ }
+ rspamd_printf_gstring (priv->buf, "HTTP/1.1 %d %s\r\n"
+ "Connection: close\r\n"
+ "Server: %s\r\n"
+ "Date: %s\r\n"
+ "Content-Length: %z\r\n"
+ "Content-Type: %s\r\n",
+ msg->code, rspamd_http_code_to_str (msg->code),
+ "rspamd/" RVERSION,
+ datebuf,
+ msg->body->len,
+ mime_type);
+ }
+ else {
+ /* Legacy spamd reply */
+ rspamd_printf_gstring (priv->buf, "RSPAMD/1.3 0 EX_OK\r\n");
}
- rspamd_printf_gstring (priv->buf, "HTTP/1.1 %d %s\r\n"
- "Connection: close\r\n"
- "Server: %s\r\n"
- "Date: %s\r\n"
- "Content-Length: %z\r\n"
- "Content-Type: %s\r\n",
- msg->code, rspamd_http_code_to_str (msg->code),
- "rspamd/" RVERSION,
- datebuf,
- msg->body->len,
- mime_type);
}
else {
/* Format request */
@@ -809,8 +826,14 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn,
priv->out[i].iov_base = "\r\n";
priv->out[i++].iov_len = 2;
}
- priv->out[i].iov_base = "\r\n";
- priv->out[i++].iov_len = 2;
+ if (msg->method < HTTP_SYMBOLS) {
+ priv->out[i].iov_base = "\r\n";
+ priv->out[i++].iov_len = 2;
+ }
+ else {
+ /* No CRLF for compatibility reply */
+ priv->wr_total -= 2;
+ }
if (msg->body != NULL) {
priv->out[i].iov_base = pbody;
priv->out[i++].iov_len = bodylen;
diff --git a/src/protocol.c b/src/protocol.c
index a6e9f8d7d..65eb26b01 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -741,6 +741,10 @@ rspamd_protocol_write_reply (struct worker_task *task)
ucl_object_t *top = NULL;
msg = rspamd_http_new_message (HTTP_RESPONSE);
+ if (!task->is_json) {
+ /* Turn compatibility on */
+ msg->method = HTTP_SYMBOLS;
+ }
msg->date = time (NULL);
task->state = CLOSING_CONNECTION;