authd: add stats reporting API

This commit is contained in:
Elizabeth Myers 2016-03-27 17:04:14 -05:00
parent eccc44ed7b
commit 02e141f7a3
3 changed files with 53 additions and 9 deletions

View file

@ -20,6 +20,7 @@
#include "authd.h"
#include "dns.h"
#include "notice.h"
#include "res.h"
static void handle_lookup_ip_reply(void *data, struct DNSReply *reply);
@ -255,35 +256,39 @@ enumerate_nameservers(const char *rid, const char letter)
{
char buf[(HOSTIPLEN + 1) * IRCD_MAXNS];
char *c = buf;
int i;
size_t s = 0;
uint32_t i_rid = (uint32_t)strtol(rid, NULL, 16);
if (!irc_nscount)
{
/* Shouldn't happen */
rb_helper_write(authd_helper, "X %s %c NONAMESERVERS", rid, letter);
stats_error(i_rid, letter, "NONAMESERVERS");
return;
}
for(i = 0; i < irc_nscount; i++)
for(int i = 0; i < irc_nscount; i++)
{
char addr[HOSTIPLEN];
size_t addrlen;
rb_inet_ntop_sock((struct sockaddr *)&irc_nsaddr_list[i], addr, sizeof(addr));
if (!addr[0])
{
/* Shouldn't happen */
rb_helper_write(authd_helper, "X %s %c INVALIDNAMESERVER", rid, letter);
stats_error(i_rid, letter, "INVALIDNAMESERVER");
return;
}
(void)snprintf(c, HOSTIPLEN + 1, "%s ", addr);
c += strlen(addr) + 1;
addrlen = strlen(addr) + 1;
(void)snprintf(c, sizeof(buf) - s, "%s ", addr);
c += addrlen;
s += addrlen;
}
*(--c) = '\0';
rb_helper_write(authd_helper, "Y %s %c %s", rid, letter, buf);
stats_result(i_rid, letter, "%s", buf);
}
void

View file

@ -22,7 +22,8 @@
#include "notice.h"
/* Send a notice to a client */
void notice_client(uint32_t cid, const char *fmt, ...)
void
notice_client(uint32_t cid, const char *fmt, ...)
{
char buf[BUFSIZE];
va_list args;
@ -35,7 +36,8 @@ void notice_client(uint32_t cid, const char *fmt, ...)
}
/* Send a warning to the IRC daemon for logging, etc. */
void warn_opers(notice_level_t level, const char *fmt, ...)
void
warn_opers(notice_level_t level, const char *fmt, ...)
{
char buf[BUFSIZE];
va_list args;
@ -46,3 +48,37 @@ void warn_opers(notice_level_t level, const char *fmt, ...)
rb_helper_write(authd_helper, "W %c :%s", level, buf);
}
/* Send a stats result */
void
stats_result(uint32_t cid, char letter, const char *fmt, ...)
{
char buf[BUFSIZE];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
rb_helper_write(authd_helper, "Y %x %c %s", cid, letter, buf);
}
/* Send a stats error */
void
stats_error(uint32_t cid, char letter, const char *fmt, ...)
{
char buf[BUFSIZE];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
rb_helper_write(authd_helper, "X %x %c %s", cid, letter, buf);
}
void
stats_done(uint32_t cid, char letter)
{
rb_helper_write(authd_helper, "Z %x %c", cid, letter);
}

View file

@ -31,5 +31,8 @@ typedef enum
void notice_client(uint32_t cid, const char *fmt, ...);
void warn_opers(notice_level_t level, const char *fmt, ...);
void stats_result(uint32_t cid, char letter, const char *fmt, ...);
void stats_error(uint32_t cid, char letter, const char *fmt, ...);
void stats_done(uint32_t cid, char letter);
#endif /* __CHARYBDIS_AUTHD_NOTICE_H__ */