#include "whowas.h"
#include "watch.h"
#include "httpd.h"
+#include "ircd.h"
+#include "s_serv.h"
#ifdef HAVE_LIBJANSSON
#ifdef HAVE_LIBMICROHTTPD
return ret;
}
+static int
+http_stats_links(struct MHD_Connection *connection, const char *url,
+ const char *method, const char *version, const char *upload_data,
+ size_t *upload_data_size)
+{
+ dlink_node *ptr = NULL;
+
+ json_t *root = json_array();
+
+ DLINK_FOREACH(ptr, serv_list.head)
+ {
+ struct Client *target_p = ptr->data;
+
+ json_t *link = json_object();
+ json_object_set_new(link, "name", json_string(target_p->name));
+ json_object_set_new(link, "sendq length", json_integer(dbuf_length(&target_p->localClient->buf_sendq)));
+ json_object_set_new(link, "sent messages", json_integer(target_p->localClient->send.messages));
+ json_object_set_new(link, "sent bytes", json_integer(target_p->localClient->send.messages));
+ json_object_set_new(link, "recv messages", json_integer(target_p->localClient->recv.messages));
+ json_object_set_new(link, "recv bytes", json_integer(target_p->localClient->recv.messages));
+ json_object_set_new(link, "connected for", json_integer(CurrentTime - target_p->localClient->firsttime));
+ json_object_set_new(link, "since", json_integer(CurrentTime - target_p->localClient->since));
+ json_object_set_new(link, "capabilities", json_string(show_capabilities(target_p)));
+ json_array_append(root, link);
+ }
+
+ const char *dump = json_dumps(root, JSON_INDENT(2));
+ if (dump == NULL)
+ return MHD_NO;
+
+ json_decref(root);
+ root = NULL;
+
+ struct MHD_Response *response = MHD_create_response_from_buffer(strlen(dump), (void *) dump, MHD_RESPMEM_MUST_FREE);
+ int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
+ MHD_destroy_response(response);
+
+ return ret;
+}
+
static struct HttpResource stats_http_memory =
{
.method = MHD_HTTP_METHOD_GET,
.handler = http_stats_memory
};
+static struct HttpResource stats_http_links =
+{
+ .method = MHD_HTTP_METHOD_GET,
+ .url = "/stats/links",
+ .handler = http_stats_links
+};
+
#endif
#endif
#ifdef HAVE_LIBJANSSON
#ifdef HAVE_LIBMICROHTTPD
httpd_register(&stats_http_memory);
+ httpd_register(&stats_http_links);
#endif
#endif
}
#ifdef HAVE_LIBJANSSON
#ifdef HAVE_LIBMICROHTTPD
httpd_unregister(&stats_http_memory);
+ httpd_unregister(&stats_http_links);
#endif
#endif
}