#include <algorithm>
#include <deque>
#include <iterator>
+#include <string_view>
#include <utility>
#include <vector>
+using namespace std::string_view_literals;
/* libraries */
#ifdef HAVE_LIBTLS
args[argc] = NULL;
}
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) {
+ std::string_view commandsv = command;
+ if (commandsv != "PASS"sv != 0 && commandsv != "OPER"sv && commandsv != "NEWACC"sv &&
+ commandsv != "AUTHENTICATE"sv && commandsv != "WEBIRC"sv) {
for (int i = 0; i < argc; i++){
fprintf(stderr, " %d:%s", i, args[i]);
}
}
fprintf(stderr, "\n");
- return irc_process_line(client, source, command, argc, args);
+ return irc_process_line(client, source, commandsv, argc, args);
}
static void cont_webirc(Client *client, int res) {
if (!(client->umode & UMODE_SECURE) || res != 0) {
newUser(client);
}
}
-#define MATCH_COMMAND(s) else if(strcmp(command, s) == 0)
-int irc_process_line(Client *client, char *source, char *command, int argc, char *args[]) {
+#define MATCH_COMMAND(s) else if (command == s##sv)
+int irc_process_line(Client *client, char *source, std::string_view command, int argc, char *args[]) {
(void)source;
databuf.clear();
- if (command[0] == '\0') {
+ if (command.empty()) {
return 0;
} MATCH_COMMAND("PING") {
if (!args[0])
case '-': is_plus = 0; break;
default:
if (client)
- err_unknowncommand(client, "MODE"), sendbuf(client);
+ err_unknowncommand(client, "MODE"sv), sendbuf(client);
return;
}
stringset *list;
void sendbuf_monitor(const char *nick, int cookie, int positive, int negative);
const char *format_umodes(Client *cl);
int irc_parse_line(Client *client, char *p, char *end);
-int irc_process_line(Client *client, char *source, char *command, int argc, char *args[]);
+int irc_process_line(Client *client, char *source, std::string_view command, int argc, char *args[]);
void newUser(Client *client);
void sendLUSERS(Client *client);
void sendMOTD(Client *client);
copy_strf(&databuf, ":%s 417 %s :Input line was too long\r\n", hostname, client->nick);
}
#endif
-void err_unknowncommand(Client *client, const char *command) // 421
+void err_unknowncommand(Client *client, std::string_view command) // 421
{
- copy_strf(&databuf, ":%s 421 %s %s :Unknown command\r\n", hostname, client->nick ? client->nick : "*", command);
+ copy_strf(&databuf, ":%s 421 %s %.*s :Unknown command\r\n", hostname, client->nick ? client->nick : "*", (int)command.size(), command.data());
}
void err_nomotd(Client *client) // 422
{
(void)client;
copy_strf(&databuf, ":%s 451 * :You have not registered\r\n", hostname);
}
-void err_needmoreparams(Client *client, const char *command) // 461
+void err_needmoreparams(Client *client, std::string_view command) // 461
{
- copy_strf(&databuf, ":%s 461 %s %s :Not enough parameters\r\n", hostname, client->nick ? client->nick : "*", command);
+ copy_strf(&databuf, ":%s 461 %s %.*s :Not enough parameters\r\n", hostname, client->nick ? client->nick : "*", (int)command.size(), command.data());
}
void err_alreadyregistered(Client *client) // 462
{
void err_wasnosuchnick(Client *client); // 406
void err_noorigin(Client *client); // 409
void err_inputtoolong(Client *client); // 417
-void err_unknowncommand(Client *client, const char *command); // 421
+void err_unknowncommand(Client *client, std::string_view command); // 421
void err_nomotd(Client *client); // 422
void err_erroneusnickname(Client *client, const char *nick); // 432
void err_nicknameinuse(Client *client, const char *nick); // 433
void err_notonchannel(Client *client, Channel *chan); // 442
void err_useronchannel(Client *client, const char *nick, Channel *chan); // 443
void err_notregistered(Client *client); // 451
-void err_needmoreparams(Client *client, const char *command); // 461
+void err_needmoreparams(Client *client, std::string_view command); // 461
void err_alreadyregistered(Client *client); // 462
void err_passwdmismatch(Client *client); // 464
void err_yourebannedcreep(Client *client); // 465
}
break;
}
- if (end[1] == 's') { // %s
+ if (end[1] == '.' && end[2] == '*' && end[3] == 's') { // %.*s
+ append_strn(v, s, end-s);
+ int n = va_arg(ap, int);
+ const char *c = va_arg(ap, const char *);
+ append_strn(v, c, n);
+ s = end + 4;
+ } else if (end[1] == 's') { // %s
append_strn(v, s, end-s);
const char *c = va_arg(ap, const char *);
append_str(v, c ? c : "(null)");