aboutsummaryrefslogtreecommitdiffstats
path: root/src/webui.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2013-01-09 20:00:40 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2013-01-09 20:00:40 +0400
commit45a890e23bdca0d6e50f36bd74c19c5857fa883b (patch)
treeec5b37b318693e97f9a75e069897e16d57914275 /src/webui.c
parent3918004b4161414bf0471dd1691b8c25000d02e1 (diff)
downloadrspamd-45a890e23bdca0d6e50f36bd74c19c5857fa883b.tar.gz
rspamd-45a890e23bdca0d6e50f36bd74c19c5857fa883b.zip
Use temporary list to avoid stupid comma problems.
Diffstat (limited to 'src/webui.c')
-rw-r--r--src/webui.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/webui.c b/src/webui.c
index a86f9abe6..8666e76ca 100644
--- a/src/webui.c
+++ b/src/webui.c
@@ -686,10 +686,9 @@ http_handle_maps (struct evhttp_request *req, gpointer arg)
{
struct rspamd_webui_worker_ctx *ctx = arg;
struct evbuffer *evb;
- GList *cur;
- struct rspamd_map *map, *next;
+ GList *cur, *tmp = NULL;
+ struct rspamd_map *map;
gboolean editable;
- gchar *comma;
if (!http_check_password (ctx, req)) {
@@ -712,27 +711,25 @@ http_handle_maps (struct evhttp_request *req, gpointer arg)
map = cur->data;
if (map->protocol == MAP_PROTO_FILE && map->description != NULL) {
if (access (map->uri, R_OK) == 0) {
- editable = access (map->uri, W_OK) == 0;
- if (cur->next) {
- next = cur->next->data;
- if (next->protocol == MAP_PROTO_FILE && next->description != NULL &&
- access (next->uri, R_OK) == 0) {
- comma = "},";
- }
- else {
- comma = "}";
- }
- }
- else {
- comma = "}";
- }
- evbuffer_add_printf (evb, "{\"map\":%u,\"description\":\"%s\",\"editable\":%s%s",
- map->id, map->description, editable ? "true" : "false",
- comma);
+ tmp = g_list_prepend (tmp, map);
}
}
cur = g_list_next (cur);
}
+ /* Iterate over selected maps */
+ cur = tmp;
+ while (cur) {
+ map = cur->data;
+ editable = access (map->uri, W_OK) == 0;
+ evbuffer_add_printf (evb, "{\"map\":%u,\"description\":\"%s\",\"editable\":%s%s",
+ map->id, map->description, editable ? "true" : "false",
+ cur->next ? "}," : "}");
+ cur = g_list_next (cur);
+ }
+
+ if (tmp) {
+ g_list_free (tmp);
+ }
evbuffer_add (evb, "]" CRLF, 3);
evhttp_add_header (req->output_headers, "Connection", "close");