From: xchaos Date: Thu, 11 Oct 2012 21:30:48 +0000 (+0000) Subject: json.c X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=05a9080997b372eb6003e407fc20b8ec80b8c085;p=svn%2FPrometheus-QoS%2F.git json.c git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@202 251d49ef-1d17-4917-a970-b30cf55b089b --- diff --git a/json.c b/json.c new file mode 100644 index 0000000..abf8c4e --- /dev/null +++ b/json.c @@ -0,0 +1,37 @@ +/* Modified by: xChaos, 20121011 */ + +#include "cll1-0.6.2.h" +#include "ipstruct.h" + +extern struct IP *ips, *ip; + +void write_json_traffic(char *json) +{ + FILE *f=fopen(json, "w"); + if(f > 0) + { + int jsoncount=0; + fprintf(f, "{\n"); + for_each(ip, ips) + { + if( ip->lmsid > 0 + and (ip->traffic or ip->direct or ip->proxy or ip->upload)) + { + if(jsoncount) + { + fprintf(f, ",\n"); + } + fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d }", + ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload, ip->min, ip->desired, ip->max); + jsoncount++; + } + } + fprintf(f, "}\n"); + fclose(f); + puts("done."); + } + else + { + perror(json); + } +} \ No newline at end of file