6 static inline char *token(char **foo
, char sep
)
8 char *line
= *foo
, *ret
;
12 while (*line
&& *line
!= sep
)
18 *foo
= *line
? line
: NULL
;
24 static inline unsigned getrand(void)
27 if (RAND_pseudo_bytes((unsigned char*)&r
, sizeof(r
)) >= 0)
29 fprintf(stderr
, "random number generator error: %s", ERR_error_string(ERR_peek_last_error(), NULL
));
30 while (ERR_get_error());
37 void (*cmd
)(struct bio
*b
, const char *nick
, const char *host
, const char *target
, char *args
);
40 int64_t disabled_until
;
41 char failed_command
[];
42 } __attribute__((aligned(256)));
44 static unsigned strhash(const char *h
)
46 TDB_DATA in
= { .dptr
= (char*)h
, .dsize
= strlen(h
) };
47 return tdb_jenkins_hash(&in
);
50 static void __attribute__ ((__format__(__printf__
, 3, 4))) privmsg(struct bio
*b
, const char *who
, const char *fmt
, ...)
56 vasprintf(&buffer
, fmt
, va
);
59 b
->writeline(b
, "PRIVMSG %s :%s", who
, buffer
);
63 static void __attribute__ ((__format__(__printf__
, 3, 4))) action(struct bio
*b
, const char *who
, const char *fmt
, ...)
69 vasprintf(&buffer
, fmt
, va
);
72 b
->writeline(b
, "PRIVMSG %s :\001ACTION %s\001", who
, buffer
);
76 static int64_t get_time(struct bio
*b
, const char *target
)
79 if (gettimeofday(&tv
, NULL
) < 0) {
80 static int complain_time
;
81 if (target
&& !complain_time
++)
82 privmsg(b
, target
, "Could not get time: %m");