]> jfr.im git - irc/freenode/syn.git/blame - util.c
masks.c: add help files
[irc/freenode/syn.git] / util.c
CommitLineData
345beb92
SB
1#include "atheme.h"
2
345beb92
SB
3const char *decode_hex_ip(const char *hex)
4{
5 static char buf[16];
6 unsigned int ip = 0;
7
8 buf[0] = '\0';
9
a7578b74
SB
10 if (strlen(hex) != 8)
11 return NULL;
345beb92 12
a7578b74
SB
13 char *endptr;
14 ip = strtoul(hex, &endptr, 16);
15 if (*endptr)
345beb92
SB
16 return NULL;
17
18 sprintf(buf, "%hhu.%hhu.%hhu.%hhu", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
19 return buf;
20}
21
22const char *get_random_host_part()
23{
24 static char buf[19];
25
26 strcpy(buf, "x-");
27
28 for (int i=2; i < 18; ++i)
29 {
30 buf[i] = 'a' + rand() % 26;
31 }
32 buf[18] = 0;
33 return buf;
34}
35
b45a5ca4
SB
36time_t syn_parse_duration(const char *s)
37{
38 time_t duration = atol(s);
39 while (isdigit(*s))
40 s++;
41 switch (*s)
42 {
43 case 'H':
44 case 'h':
45 duration *= 60;
46 break;
47 case 'D':
48 case 'd':
49 duration *= 1440;
50 break;
51 case 'W':
52 case 'w':
53 duration *= 10080;
54 break;
55 }
56 return duration;
57}
58
59const char *syn_format_expiry(time_t t)
60{
61 static char expirybuf[BUFSIZE];
62 if (t > 0)
63 {
64 strftime(expirybuf, BUFSIZE, "%d/%m/%Y %H:%M:%S", gmtime(&t));
65 }
66 else
67 {
68 strcpy(expirybuf, "never");
69 }
70
71 return expirybuf;
72}
345beb92 73
492a4dc0
JK
74DECLARE_MODULE_V1
75(
76 "syn/util", false, NULL, NULL,
77 "$Revision$",
78 "Stephen Bennett <stephen -at- freenode.net>"
79);