while (ret >= 0 &&
hash_table_iterate(iter, limit->session_hash, &session, &value)) T_BEGIN {
str_truncate(str, 0);
+ str_printfa(str, "%ld\t%u\t", (long)session->pid,
+ session->refcount);
+ str_append_tabescaped(str, session->userip->username);
+ str_append_c(str, '\t');
str_append_tabescaped(str, session->userip->service);
- if (session->userip->ip.family != 0) {
- str_append_c(str, '/');
+ str_append_c(str, '\t');
+ if (session->userip->ip.family != 0)
str_append(str, net_ip2addr(&session->userip->ip));
- }
- str_append_c(str, '/');
- str_append_tabescaped(str, session->userip->username);
- str_printfa(str, "\t%ld\t%u\n", (long)session->pid,
- session->refcount);
+ str_append_c(str, '\n');
ret = o_stream_send(output, str_data(str), str_len(str));
} T_END;
hash_table_iterate_deinit(&iter);
static int who_parse_line(const char *line, struct who_line *line_r)
{
const char *const *args = t_strsplit_tabescaped(line);
- const char *ident = args[0];
- const char *pid_str = args[1];
- const char *refcount_str = args[2];
- const char *p, *ip_str;
-
i_zero(line_r);
- /* ident = service/ip/username (imap, pop3)
- or service/username (lmtp) */
- p = strchr(ident, '/');
- if (p == NULL)
+ /* <pid> <refcount> <username> <service> <ip> */
+ if (str_array_length(args) < 5)
return -1;
- if (str_to_pid(pid_str, &line_r->pid) < 0)
+
+ if (str_to_pid(args[0], &line_r->pid) < 0)
return -1;
- line_r->service = t_strdup_until(ident, p++);
- line_r->username = strchr(p, '/');
- if (line_r->username == NULL) {
- /* no IP */
- line_r->username = p;
- } else {
- ip_str = t_strdup_until(p, line_r->username++);
- (void)net_addr2ip(ip_str, &line_r->ip);
- }
- if (str_to_uint(refcount_str, &line_r->refcount) < 0)
+ if (str_to_uint(args[1], &line_r->refcount) < 0)
return -1;
+ line_r->username = args[2];
+ line_r->service = args[3];
+ if (args[4][0] != '\0') {
+ if (net_addr2ip(args[4], &line_r->ip) < 0)
+ return -1;
+ }
return 0;
}