return rspamd_dispatcher_write (d, buf, buflen, FALSE, FALSE);
}
else {
- if (!rspamd_dispatcher_write (d, hbuf, r, TRUE, TRUE)) {
+ if (!rspamd_dispatcher_write (d, hbuf, r, FALSE, TRUE)) {
return FALSE;
}
}
headern = separate_command (line, ':');
if (line == NULL || headern == NULL) {
+ msg_warn ("bad header: %V", line);
return FALSE;
}
/* Eat whitespaces */
if (in->len == 0) {
/* End of headers */
if (session->cmd == NULL && session->custom_handler == NULL) {
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "500 Bad command" CRLF);
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Bad command" CRLF CRLF);
if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
return FALSE;
}
/* Perform command */
else if (session->cmd != NULL) {
if (! process_command (session->cmd, NULL, session)) {
+ msg_debug ("process command failed");
destroy_session (session->s);
return FALSE;
}
}
if (session->state != STATE_LEARN && session->state != STATE_LEARN_SPAM_PRE
&& session->state != STATE_WEIGHTS && session->state != STATE_OTHER) {
+ msg_debug ("closing restful connection");
destroy_session (session->s);
return FALSE;
}
}
- if (!process_header (in, session)) {
- msg_debug ("'%V'", in);
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "500 Bad header" CRLF);
+ else if (!process_header (in, session)) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Bad header" CRLF CRLF);
if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
return FALSE;
}
msg_warn ("processing of message failed");
free_task (task, FALSE);
session->state = STATE_REPLY;
- r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+ if (session->restful) {
+ r = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Cannot process message" CRLF CRLF);
+ }
+ else {
+ r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+ }
if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
return FALSE;
}
}
if (!learn_task (session->learn_symbol, task, &err)) {
+ free_task (task, FALSE);
if (err) {
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, learn classifier error: %s" CRLF END, err->message);
+ if (session->restful) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Learn classifier error: %s" CRLF CRLF, err->message);
+ }
+ else {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, learn classifier error: %s" CRLF END, err->message);
+ }
g_error_free (err);
}
else {
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, unknown learn classifier error" CRLF END);
+ if (session->restful) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Learn classifier error: unknown" CRLF CRLF);
+ }
+ else {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, unknown learn classifier error" CRLF END);
+ }
}
- free_task (task, FALSE);
+
if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
return FALSE;
}
}
free_task (task, FALSE);
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn ok" CRLF END);
+ if (session->restful) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 200 Learn OK" CRLF CRLF);
+ }
+ else {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn ok" CRLF END);
+ }
session->state = STATE_REPLY;
if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
return FALSE;
if (r == -1) {
msg_warn ("processing of message failed");
session->state = STATE_REPLY;
- r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+ if (session->restful) {
+ r = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Cannot process message" CRLF CRLF);
+ }
+ else {
+ r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+ }
if (!session->restful) {
if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
return FALSE;
r = process_filters (task);
if (r == -1) {
session->state = STATE_REPLY;
- r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+ if (session->restful) {
+ r = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Cannot process message" CRLF CRLF);
+ }
+ else {
+ r = rspamd_snprintf (out_buf, sizeof (out_buf), "cannot process message" CRLF);
+ }
destroy_session (task->s);
if (!session->restful) {
if (! rspamd_dispatcher_write (session->dispatcher, out_buf, r, FALSE, FALSE)) {
else if (session->state == STATE_LEARN_SPAM) {
/* Perform actual learn here */
if (session->learn_classifier == NULL) {
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, learn classifier error: %s" CRLF END, "unknown classifier");
+ if (session->restful) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Learn classifier error: %s" CRLF CRLF, "unknown classifier");
+ }
+ else {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, learn classifier error: %s" CRLF END, "unknown classifier");
+ }
}
else {
if (! learn_task_spam (session->learn_classifier, session->learn_task, session->in_class, &err)) {
if (err) {
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, learn classifier error: %s" CRLF END, err->message);
+ if (session->restful) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Learn classifier error: %s" CRLF CRLF, err->message);
+ }
+ else {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, learn classifier error: %s" CRLF END, err->message);
+ }
g_error_free (err);
}
else {
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, unknown learn classifier error" CRLF END);
+ if (session->restful) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 500 Learn classifier error: unknown" CRLF CRLF);
+ }
+ else {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn failed, learn classifier error: unknown" CRLF END);
+ }
}
}
else {
- i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn ok" CRLF END);
+ if (session->restful) {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "HTTP/1.0 200 Learn OK" CRLF CRLF);
+ }
+ else {
+ i = rspamd_snprintf (out_buf, sizeof (out_buf), "learn ok" CRLF END);
+ }
}
}
session->learn_task->dispatcher = NULL;
destroy_session (session->learn_task->s);
session->state = STATE_REPLY;
- if (!session->restful) {
- if (! rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
- return FALSE;
- }
+ if (! rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
+ return FALSE;
}
- else {
- if (! restful_write_reply (500, out_buf, NULL, 0, session->dispatcher)) {
- return FALSE;
- }
+ if (session->restful) {
+ destroy_session (session->s);
+ return FALSE;
}
return TRUE;
}