Fix logging and add few IRCv3 features (WIP)
This commit is contained in:
parent
5bcbfe640b
commit
7329529bca
|
@ -20,6 +20,7 @@ add_executable(uircd
|
|||
src/net.c
|
||||
src/filesystem.c
|
||||
src/misc.c
|
||||
src/log.c
|
||||
)
|
||||
|
||||
find_library(UIRC_PATH NAMES uirc libuirc REQUIRED)
|
||||
|
|
|
@ -123,17 +123,22 @@ signed int prepare_log_path(IRC_Message* message, PathBuf* pathbuffer, Connectio
|
|||
bool isdir;
|
||||
} elements[] = {{reused_strings[0], true}, {NULL, true}, {"out", false}};
|
||||
char temp[MAXLINE];
|
||||
if (ISCMD(JOIN) || ISCMD(PART) || ISCMD(QUIT) || ISCMD(MOTD) || ISCMD(RPL_MOTD) || ISCMD(RPL_MOTDSTART) || ISCMD(RPL_ENDOFMOTD)
|
||||
|| ISCMD(ERR_NOMOTD) || ISCMD(PING) || ISCMD(PONG) || ISCMD(RPL_LIST) || ISCMD(RPL_LISTEND)) {
|
||||
if (ISCMD(JOIN) || ISCMD(PART) || ISCMD(QUIT) || ISCMD(RPL_USERSSTART) || ISCMD(RPL_USERS) || ISCMD(RPL_NOUSERS) || ISCMD(RPL_ENDOFUSERS)
|
||||
|| ISCMD(RPL_NAMREPLY) || ISCMD(RPL_ENDOFNAMES)) {
|
||||
elements[0].name = reused_strings[2];
|
||||
if (ISCMD(JOIN) || ISCMD(PART) || ISCMD(QUIT))
|
||||
elements[1].name = "events";
|
||||
else if (ISCMD(MOTD) || ISCMD(RPL_MOTD) || ISCMD(RPL_MOTDSTART) || ISCMD(RPL_ENDOFMOTD) || ISCMD(ERR_NOMOTD))
|
||||
elements[1].name = "motd";
|
||||
else if (ISCMD(PING) || ISCMD(PONG))
|
||||
elements[1].name = "pings";
|
||||
else if (ISCMD(RPL_LIST) || ISCMD(RPL_LISTEND))
|
||||
elements[1].name = "channels";
|
||||
elements[1].name = "events";
|
||||
elements[1].isdir = false;
|
||||
} else if (ISCMD(MOTD) || ISCMD(RPL_MOTD) || ISCMD(RPL_MOTDSTART) || ISCMD(RPL_ENDOFMOTD) || ISCMD(ERR_NOMOTD)) {
|
||||
elements[0].name = reused_strings[2];
|
||||
elements[1].name = "motd";
|
||||
elements[1].isdir = false;
|
||||
} else if (ISCMD(PING) || ISCMD(PONG)) {
|
||||
elements[0].name = reused_strings[2];
|
||||
elements[1].name = "pings";
|
||||
elements[1].isdir = false;
|
||||
} else if (ISCMD(RPL_LIST) || ISCMD(RPL_LISTEND)) {
|
||||
elements[0].name = reused_strings[2];
|
||||
elements[1].name = "channels";
|
||||
elements[1].isdir = false;
|
||||
} else if (ISCMD(PRIVMSG) || ISCMD(NOTICE)) {
|
||||
if (message->args[0] == NULL) return -2;
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of uIRCd. (https://git.redxen.eu/caskd/uIRCd)
|
||||
* Copyright (c) 2019, 2020 Alex-David Denes
|
||||
*
|
||||
* uIRCd is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* uIRCd is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with uIRCd. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
char logchars[] = {[LOG_DEBUG] = 'D', [LOG_VERBOSE] = 'V', [LOG_INFO] = 'I', [LOG_WARN] = 'W', [LOG_ERROR] = 'E', [LOG_FATAL] = 'F'};
|
||||
|
19
src/log.h
19
src/log.h
|
@ -27,23 +27,10 @@
|
|||
#define LOG_INFO 3
|
||||
#define LOG_VERBOSE 4
|
||||
#define LOG_DEBUG 5
|
||||
extern char logchars[];
|
||||
|
||||
#define LOG(LEVEL, ...) \
|
||||
if (LEVEL <= loglevel) { \
|
||||
char* logchar = "?"; \
|
||||
switch (LEVEL) { \
|
||||
case (LOG_DEBUG): logchar = "D"; break; \
|
||||
case (LOG_VERBOSE): logchar = "V"; break; \
|
||||
case (LOG_INFO): logchar = "I"; break; \
|
||||
case (LOG_WARN): logchar = "W"; break; \
|
||||
case (LOG_ERROR): logchar = "E"; break; \
|
||||
case (LOG_FATAL): logchar = "F"; break; \
|
||||
} \
|
||||
fprintf(stderr, "[%s] ", logchar); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
if (loglevel == LOG_DEBUG) fprintf(stderr, " --> LINE: %i -- FILE: %s", __LINE__, __FILE__); \
|
||||
putc('\n', stderr); \
|
||||
}
|
||||
#define LOG(LEVEL, FORMAT, ...) \
|
||||
if (LEVEL <= loglevel) fprintf(stderr, "[%c:L%i] " FORMAT "\n", logchars[LEVEL], __LINE__, __VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
26
src/main.c
26
src/main.c
|
@ -23,7 +23,7 @@ int loglevel = LOG_FATAL;
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
int c;
|
||||
char *quitmsg = "uIRC indev beta", *pos = NULL;
|
||||
char *quitmsg = "uIRCd " VERSION, *pos = NULL;
|
||||
unsigned int totcon = 0, timeout = 30;
|
||||
Connection cons[MAXCONN] = {0};
|
||||
setvbuf(stderr, NULL, _IOLBF, 0); /* Threads may want to print incomplete messages to the log at the same that, avoid that. */
|
||||
|
@ -50,8 +50,8 @@ int main(int argc, char* argv[])
|
|||
} else
|
||||
cons[totcon].data.port = "6667";
|
||||
cons[totcon].data.addr = ((pos = point_after(optarg, '@')) == NULL) ? "localhost" : pos;
|
||||
cons[totcon].names.real = ((pos = point_after(optarg, ':')) == NULL) ? "uIRC user" : pos;
|
||||
cons[totcon].names.user = ((pos = point_after(optarg, '!')) == NULL) ? "uIRC-user" : pos;
|
||||
cons[totcon].names.real = ((pos = point_after(optarg, ':')) == NULL) ? "uIRCd user" : pos;
|
||||
cons[totcon].names.user = ((pos = point_after(optarg, '!')) == NULL) ? "uIRCd-user" : pos;
|
||||
cons[totcon++].names.nick = optarg;
|
||||
break;
|
||||
}
|
||||
|
@ -68,14 +68,14 @@ int main(int argc, char* argv[])
|
|||
case 'C': break; // TODO: Reserved for config file path
|
||||
case 'V': loglevel = atoi(optarg); break;
|
||||
case 'v': {
|
||||
printf("uIRCd version %s\n", VERSION);
|
||||
printf("uIRCd version " VERSION "\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
case 'h': print_help(); return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
if (totcon < 1) {
|
||||
LOG(LOG_FATAL, "No connection was provided.");
|
||||
LOG(LOG_FATAL, "%s", "No connection was provided.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ int main(int argc, char* argv[])
|
|||
wpid = 1;
|
||||
}
|
||||
}
|
||||
LOG(LOG_VERBOSE, "Exiting gracefully.");
|
||||
LOG(LOG_VERBOSE, "%s", "Exiting gracefully.");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -191,6 +191,18 @@ int run_main(Connection* conn, char* quitmsg, unsigned int timeout)
|
|||
/* Send NICK and USER registration */
|
||||
// TODO: PASS
|
||||
signed long temp;
|
||||
/*
|
||||
if ((temp = Assm_mesg(sendbuf.buffer, Assm_cmd_CAP_LS("302"), sizeof(sendbuf.buffer))) > 0) {
|
||||
sendbuf.append_pos = (size_t)temp;
|
||||
LOG(LOG_VERBOSE, "Sending a CAP LS to " ADDRFMT ".", conn->data.addr, conn->data.port);
|
||||
if (flush_buffer(sendbuf.buffer, sendbuf.append_pos, sendbuf.fd) == -1) {
|
||||
LOG(LOG_WARN, "Couldn't send CAP LS to " ADDRFMT ". " ERRNOFMT, conn->data.addr, conn->data.port,
|
||||
strerror(errno), errno);
|
||||
conn->state = CONN_RECONNECTING;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if ((temp = Assm_mesg(sendbuf.buffer, Assm_cmd_NICK(conn->names.nick), sizeof(sendbuf.buffer))) > 0) {
|
||||
sendbuf.append_pos = (size_t)temp;
|
||||
LOG(LOG_VERBOSE, "Sending a NICK registration to " ADDRFMT " containing \"%s\".", conn->data.addr,
|
||||
|
@ -301,7 +313,7 @@ int run_main(Connection* conn, char* quitmsg, unsigned int timeout)
|
|||
|
||||
memset((void*)&buffer, '\0', sizeof(IRC_Message));
|
||||
if ((len = get_buffer_line(fifobuf.buffer, &buffer)) > 0) {
|
||||
LOG(LOG_DEBUG, "Tokenized FIFO message successfully.");
|
||||
LOG(LOG_DEBUG, "%s", "Tokenized FIFO message successfully.");
|
||||
signed long temp;
|
||||
if ((temp = Assm_mesg(fifobuf.buffer, &buffer, sizeof(fifobuf.buffer))) > 0) {
|
||||
if (flush_buffer(fifobuf.buffer, (size_t)temp, sendbuf.fd) == -1) {
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#ifndef UIRCD_INCLUDED_MAIN
|
||||
#define UIRCD_INCLUDED_MAIN
|
||||
#define VERSION "indev - testing"
|
||||
#define VERSION "2020.10.30.1-beta"
|
||||
|
||||
void stop_loop(void);
|
||||
int run_main(Connection* conn, char* quitmsg, unsigned int timeout);
|
||||
|
|
29
src/misc.c
29
src/misc.c
|
@ -45,7 +45,7 @@ ssize_t get_buffer_line(char* buf, IRC_Message* parsed)
|
|||
if (ppoi > buf && *(ppoi - 1) == '\r') *(ppoi - 1) = '\0';
|
||||
LOG(LOG_DEBUG, "Got message %s", buf);
|
||||
if (Tok_mesg(buf, parsed) == 1) return ++ppoi - buf;
|
||||
LOG(LOG_WARN, "Received invalid IRC message (see RFC2812).");
|
||||
LOG(LOG_WARN, "%s", "Received invalid IRC message (see RFC2812).");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -95,6 +95,33 @@ int auto_msg_actions(IRC_Message* message, Connection* conn, Buffer_Info* buf)
|
|||
}
|
||||
break;
|
||||
}
|
||||
/*
|
||||
case (CAP): {
|
||||
if (message->args[1] != NULL && strcmp(message->args[1], "LS") == 0) {
|
||||
LOG(LOG_VERBOSE, "Requesting capabilities \"%s\" on " ADDRFMT ".", message->args[2], conn->data.addr,
|
||||
conn->data.port);
|
||||
if ((len = Assm_mesg(buf->buffer, Assm_cmd_CAP_REQ(message->args[2]), sizeof(buf->buffer))) > 0) {
|
||||
if (flush_buffer(buf->buffer, (size_t)len, buf->fd) == -1) {
|
||||
LOG(LOG_WARN, "Couldn't request capabilities \"%s\" on " ADDRFMT ". " ERRNOFMT, message->args[2],
|
||||
conn->data.addr, conn->data.port, strerror(errno), errno);
|
||||
conn->state = CONN_RECONNECTING;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if (message->args[1] != NULL && strcmp(message->args[1], "ACK") == 0) {
|
||||
LOG(LOG_VERBOSE, "Ending capability negotiation on " ADDRFMT ".", conn->data.addr, conn->data.port);
|
||||
if ((len = Assm_mesg(buf->buffer, Assm_cmd_CAP_END(), sizeof(buf->buffer))) > 0) {
|
||||
if (flush_buffer(buf->buffer, (size_t)len, buf->fd) == -1) {
|
||||
LOG(LOG_WARN, "Couldn't end capability negotiation on " ADDRFMT ". " ERRNOFMT, conn->data.addr,
|
||||
conn->data.port, strerror(errno), errno);
|
||||
conn->state = CONN_RECONNECTING;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
*/
|
||||
case (ERROR): {
|
||||
LOG(LOG_ERROR, "Received error on connection " ADDRFMT " with the message \"%s\".", conn->data.addr, conn->data.port,
|
||||
message->args[0]);
|
||||
|
|
Reference in New Issue