]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/formats.c
6 #include "../lib/strlfunc.h"
7 #include "../irc/irc.h"
10 char *trusts_timetostr(time_t t
) {
13 strftime(buf
, sizeof(buf
), "%Y-%m-%d %H:%M:%S", localtime(&t
));
18 char *dumpth(trusthost
*th
, int oformat
) {
22 snprintf(buf
, sizeof(buf
), "#%u,%s,%u,%u,%jd", th
->group
->id
, CIDRtostr(th
->ip
, th
->bits
), th
->count
, th
->maxusage
, (intmax_t)th
->lastseen
);
24 snprintf(buf
, sizeof(buf
), "%u,%s,%u,%u,%jd,%jd,%u,%u", th
->group
->id
, CIDRtostr(th
->ip
, th
->bits
), th
->id
, th
->maxusage
, (intmax_t)th
->lastseen
, (intmax_t)th
->created
, th
->maxpernode
, th
->nodebits
);
30 char *dumptg(trustgroup
*tg
, int oformat
) {
34 snprintf(buf
, sizeof(buf
), "#%u,%s,%u,%u,%d,%u,%u,%jd,%jd,%jd,%s,%s,%s", tg
->id
, tg
->name
->content
, tg
->count
, tg
->trustedfor
, tg
->flags
& TRUST_ENFORCE_IDENT
, tg
->maxperident
, tg
->maxusage
, (intmax_t)tg
->expires
, (intmax_t)tg
->lastseen
, (intmax_t)tg
->lastmaxusereset
, tg
->createdby
->content
, tg
->contact
->content
, tg
->comment
->content
);
36 snprintf(buf
, sizeof(buf
), "%u,%s,%u,%d,%u,%u,%jd,%jd,%jd,%s,%s,%s", tg
->id
, tg
->name
->content
, tg
->trustedfor
, tg
->flags
, tg
->maxperident
, tg
->maxusage
, (intmax_t)tg
->expires
, (intmax_t)tg
->lastseen
, (intmax_t)tg
->lastmaxusereset
, tg
->createdby
->content
, tg
->contact
->content
, tg
->comment
->content
);
42 int parsetg(char *buf
, trustgroup
*tg
, int oformat
) {
43 char *line
, *createdby
, *contact
, *comment
, *name
, *id
;
44 unsigned long expires
, lastseen
, lastmaxusereset
;
48 /* #id,ticket35153,14,20,1,1,17,1879854575,1222639249,0,nterfacer,Qwhois&2120764,Non-Commercial Bouncer (Created by: doomie)
54 ,expires ,lastseen ,lastmaxusereset
55 ,createdby,contact ,comment
59 strlcpy(xbuf
, buf
, sizeof(xbuf
));
72 line
= strchr(xbuf
, ',');
77 if(oformat
&& (id
[0] == '#'))
80 tg
->id
= strtoul(id
, NULL
, 10);
85 line
= strchr(line
, ',');
91 r
= sscanf(line
, "%*u,%u,%u,%u,%u,%lu,%lu,%lu,%n",
92 /*current, */ &tg
->trustedfor
, &tg
->flags
, &tg
->maxperident
,
93 &tg
->maxusage
, &expires
, &lastseen
, &lastmaxusereset
, &pos
);
95 if(tg
->maxperident
> 0)
96 tg
->flags
|= TRUST_RELIABLE_USERNAME
;
98 r
= sscanf(line
, "%u,%u,%u,%u,%lu,%lu,%lu,%n",
99 &tg
->trustedfor
, &tg
->flags
, &tg
->maxperident
,
100 &tg
->maxusage
, &expires
, &lastseen
, &lastmaxusereset
, &pos
);
105 tg
->expires
= (time_t)expires
;
106 tg
->lastseen
= (time_t)lastseen
;
107 tg
->lastmaxusereset
= (time_t)lastmaxusereset
;
109 createdby
= &line
[pos
];
110 contact
= strchr(createdby
, ',');
115 comment
= strchr(contact
, ',');
120 tg
->name
= getsstring(name
, TRUSTNAMELEN
);
121 tg
->createdby
= getsstring(createdby
, CREATEDBYLEN
);
122 tg
->comment
= getsstring(comment
, COMMENTLEN
);
123 tg
->contact
= getsstring(contact
, CONTACTLEN
);
124 if(!tg
->name
|| !tg
->createdby
|| !tg
->comment
|| !tg
->contact
) {
125 freesstring(tg
->name
);
126 freesstring(tg
->createdby
);
127 freesstring(tg
->comment
);
128 freesstring(tg
->contact
);
135 int parseth(char *line
, trusthost
*th
, unsigned int *tgid
, int oformat
) {
136 unsigned long lastseen
, created
;
137 int maxpernode
, nodebits
;
138 char *ip
, xbuf
[1024], *id
;
140 /* #id,192.168.2.128/26,20,23,1222732944
141 ip ,cur,max,lastseen */
143 strlcpy(xbuf
, line
, sizeof(xbuf
));
146 line
= strchr(line
, ',');
151 if(oformat
&& (id
[0] == '#'))
154 *tgid
= strtoul(id
, NULL
, 10);
159 line
= strchr(line
, ',');
164 if(!ipmask_parse(ip
, &th
->ip
, &th
->bits
))
168 if(sscanf(line
, "%*u,%u,%lu", /*current, */&th
->maxusage
, &lastseen
) != 2)
170 created
= getnettime();
174 if(sscanf(line
, "%u,%u,%lu,%lu,%d,%d", &th
->id
, &th
->maxusage
, &lastseen
, &created
, &maxpernode
, &nodebits
) != 6)
178 th
->lastseen
= (time_t)lastseen
;
179 th
->created
= (time_t)created
;
180 th
->maxpernode
= maxpernode
;
181 th
->nodebits
= nodebits
;
186 char *rtrim(char *buf
) {
187 static char obuf
[1024];
188 size_t len
= strlcpy(obuf
, buf
, sizeof(obuf
));
190 if((len
< sizeof(obuf
)) && (len
> 0)) {
192 for(i
=len
-1;i
>=0;i
--) {