-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathjson.c
More file actions
43 lines (39 loc) · 1.12 KB
/
json.c
File metadata and controls
43 lines (39 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* 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->code[0] > 0
and (ip->traffic or ip->direct or ip->proxy or ip->upload))
{
if(jsoncount)
{
fprintf(f, ",\n");
}
fprintf(f,
" \"%s\":{ \"code\": %s, \"ip\":\"%s\", \"total\":%Lu, \"down\":%Lu, \
\"proxy\":%Lu, \"up\":%Lu, \"min\":%d, \"max\":%d, \"limit\":%d, \
\"pktsup\":%Lu, \"pktsdown\":%Lu, \"realquota\":%Lu, \"credit\":%Lu, \"dailyquota\":%ld }",
ip->name, ip->code, ip->addr, ip->traffic, ip->direct, ip->proxy,
ip->upload, ip->min, ip->desired, ip->max, ip->pktsup, ip->pktsdown,
ip->realquota, ip->credit, (ip->min*ip->keyword->data_limit+(ip->keyword->fixed_limit<<20)));
jsoncount++;
}
}
fprintf(f, "}\n");
fclose(f);
puts("done.");
}
else
{
perror(json);
}
}