json.c
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 11 Oct 2012 21:30:48 +0000 (21:30 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Thu, 11 Oct 2012 21:30:48 +0000 (21:30 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@202 251d49ef-1d17-4917-a970-b30cf55b089b

json.c [new file with mode: 0644]

diff --git a/json.c b/json.c
new file mode 100644 (file)
index 0000000..abf8c4e
--- /dev/null
+++ b/json.c
@@ -0,0 +1,37 @@
+/* Modified by: xChaos, 20121011 */\r
+\r
+#include "cll1-0.6.2.h"\r
+#include "ipstruct.h"\r
+\r
+extern struct IP *ips, *ip;\r
+\r
+void write_json_traffic(char *json)\r
+{\r
+  FILE *f=fopen(json, "w");\r
+  if(f > 0)\r
+  {\r
+   int jsoncount=0;\r
+   fprintf(f, "{\n");\r
+   for_each(ip, ips)\r
+   {\r
+    if(      ip->lmsid > 0 \r
+        and (ip->traffic or ip->direct or ip->proxy or ip->upload))\r
+    {\r
+     if(jsoncount)\r
+     {\r
+      fprintf(f, ",\n");\r
+     }\r
+     fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d }",\r
+                ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload, ip->min, ip->desired, ip->max);\r
+     jsoncount++;\r
+    }\r
+   }\r
+   fprintf(f, "}\n");\r
+   fclose(f);\r
+   puts("done.");\r
+  }\r
+  else\r
+  {\r
+   perror(json);\r
+  }\r
+}
\ No newline at end of file
This page took 0.156432 seconds and 4 git commands to generate.