const char *hostname = 0;
void sendbuf(struct client_data *client) {
- fprintf(stderr, "SERVER %" PRISocket ": %.*s", client->fd, (int)databuf.len, (char*)databuf.buf);
+ log_client(client, "SERVER: %.*s", (int)databuf.len, (char*)databuf.buf);
sendClient(client, databuf.buf, databuf.len);
}
static void chanlog_time(time_t timestamp) {
if (end > p && end[-1] == '\r')
*--end = '\n';
if (memchr(p, '\0', end-p)) {
- fprintf(stderr, "Client %" PRISocket " sent a NULL\n", client->fd);
+ log_client(client, "sent a NULL\n");
killConnection(client, 0);
return 1; // null detected
}
if (memchr(p, '\r', end-p)) {
- fprintf(stderr, "Client %" PRISocket " sent an extra CR\n", client->fd);
+ log_client(client, "sent an extra CR\n");
killConnection(client, 0);
return 1; // internal \r detected
}
}
args[argc] = NULL;
}
- fprintf(stderr, "parsed %" PRISocket ": %s", client->fd, command);
+ log_client(client, "parsed: %s", command);
if (strcmp(command, "PASS") != 0 && strcmp(command, "OPER") != 0 && strcmp(command, "NEWACC") != 0
&& strcmp(command, "AUTHENTICATE") != 0 && strcmp(command, "WEBIRC") != 0) {
for (int i = 0; i < argc; i++){
#ifdef HAVE_LIBTLS
// TODO: move this when we add sasl
if (client->cctx && tls_peer_cert_provided(client->cctx))
- fprintf(stderr, "CertFP %" PRISocket ": %s\n", client->fd, tls_peer_cert_hash(client->cctx));
+ log_client(client, "CertFP: %s\n", tls_peer_cert_hash(client->cctx));
#endif
rpl_welcome(client), sendbuf(client);
rpl_yourhost(client), sendbuf(client);
strcpy_lit(client_addr, "?");
port = 0;
}
- fprintf(stderr, "Connection accepted from Socket: %" PRISocket ", IP: %s PORT: %d\n", fd,
- client_addr, port);
struct tls *cctx = NULL;
if (listener->ctx) {
#ifdef HAVE_LIBTLS
if (tls_accept_socket(listener->ctx, &cctx, fd) == -1) {
close(fd);
- fprintf(stderr, "tls_accept_socket: %s\n", tls_error(listener->ctx));
+ fprintf(stderr, "tls_accept_socket: %s (ip %s port %d)\n", tls_error(listener->ctx), client_addr, port);
continue;
}
#endif
}
if (!cl->hostname)
abortf("strdup fail (hostname)\n");
+ log_client(cl, "accepted (ip %s port %d)\n", client_addr, port);
netpoll::add(cl->fd, SOCKTYPE_CLIENT, cl);
update_poll_reg(cl);
copy_strf(&databuf, ":%s NOTICE * :Hello welcome to PatchyIRCD!\r\n", hostname);
// Copyright (c) 2022 Sam Smith
// Copyright (c) 2022-2025 Egor
// SPDX-License-Identifier: GPL-2.0-or-later
+#include <stdarg.h>
#include "net.h"
#include "irc.h"
#include "ircfmt.h"
}
}
+void log_client(struct client_data *cl, const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ fprintf(stderr, "C:%d ", cl->fd);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+}
+
void killConnection(struct client_data *cl, int byChoice)
{
if (!cl)
cl->dying = 1;
job_kill(cl);
if (cl->peername)
- fprintf(stderr, "Client disconnected from Socket: %" PRISocket ", IP: %s PORT: %d\n", cl->fd, cl->peername, cl->peerport);
+ log_client(cl, "disconnected (ip %s port %d)\n", cl->peername, cl->peerport);
if (!byChoice && cl->nick && cl->username) {
msg_quit(cl, "", "Has left the building (Forced)");
sendbuf_visible(cl);
update_poll_reg(cl);
return;
}
- if (rv == -1) {
- fprintf(stderr, "tls_close (%" PRISocket "): %s\n", cl->fd, tls_error(cl->cctx));
- }
+ if (rv == -1)
+ log_client(cl, "tls_close: %s\n", tls_error(cl->cctx));
tls_free(cl->cctx);
cl->cctx = NULL;
}
// Copyright (c) 2022 Sam Smith
-// Copyright (c) 2022-2024 Egor
+// Copyright (c) 2022-2025 Egor
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef NET_H_
#define NET_H_
void sendbuf_visible(struct client_data *client);
struct client_data *allocClient(void);
void update_poll_reg(struct client_data *cl);
+void log_client(struct client_data *cl, const char *format, ...);
void killConnection(struct client_data *client, int byChoice);
void killConnectionPart2(struct client_data *cl);
void recvProc(struct client_data *cl);
#include <netdb.h>
#include <fcntl.h>
#include <signal.h>
-#define PRISocket "d"
#define net_wouldblock() (errno == EAGAIN || errno == EWOULDBLOCK)
#endif