json.c
[svn/Prometheus-QoS/.git] / json.c
1 /* Modified by: xChaos, 20121011 */
2
3 #include "cll1-0.6.2.h"
4 #include "ipstruct.h"
5
6 extern struct IP *ips, *ip;
7
8 void write_json_traffic(char *json)
9 {
10 FILE *f=fopen(json, "w");
11 if(f > 0)
12 {
13 int jsoncount=0;
14 fprintf(f, "{\n");
15 for_each(ip, ips)
16 {
17 if( ip->lmsid > 0
18 and (ip->traffic or ip->direct or ip->proxy or ip->upload))
19 {
20 if(jsoncount)
21 {
22 fprintf(f, ",\n");
23 }
24 fprintf(f, " \"%s\":{ \"lms\": %d, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d }",
25 ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload, ip->min, ip->desired, ip->max);
26 jsoncount++;
27 }
28 }
29 fprintf(f, "}\n");
30 fclose(f);
31 puts("done.");
32 }
33 else
34 {
35 perror(json);
36 }
37 }
This page took 0.264166 seconds and 5 git commands to generate.