X-Git-Url: http://git.harvie.cz/?p=svn%2FPrometheus-QoS%2F.git;a=blobdiff_plain;f=json.c;fp=json.c;h=abf8c4ef34c81f8549a738ed037473528a3ae058;hp=0000000000000000000000000000000000000000;hb=05a9080997b372eb6003e407fc20b8ec80b8c085;hpb=1ab008b9af1556f1bcba85b2d262fa83b617f01e 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