c9c63f0eb8dd37a4a5a7f4960d1393f156f3db84
[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,\
25 \"min\":%d, \"max\":%d, \"limit\":%d, \"realquota\":%Lu, \"credit\":%Lu, \"dailyquota\":%ld }",
26 ip->name, ip->lmsid, ip->addr, ip->traffic, ip->direct, ip->proxy, ip->upload,
27 ip->min, ip->desired, ip->max, ip->realquota, ip->credit,
28 (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)));
29 jsoncount++;
30 }
31 }
32 fprintf(f, "}\n");
33 fclose(f);
34 puts("done.");
35 }
36 else
37 {
38 perror(json);
39 }
40 }
This page took 0.863691 seconds and 3 git commands to generate.