/* * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) * Copyright (c) 2019, 2020 Alex-David Denes * * uIRC 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. * * uIRC 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 uIRC. If not, see . */ #include "misc.h" const char* const IRC_Cmds[] = { [ADMIN] = "ADMIN", [AWAY] = "AWAY", [CONNECT] = "CONNECT", [DIE] = "DIE", [ERROR] = "ERROR", [INFO] = "INFO", [INVITE] = "INVITE", [ISON] = "ISON", [JOIN] = "JOIN", [KICK] = "KICK", [KILL] = "KILL", [LINKS] = "LINKS", [LIST] = "LIST", [LUSERS] = "LUSERS", [MODE] = "MODE", [MOTD] = "MOTD", [NAMES] = "NAMES", [NICK] = "NICK", [NOTICE] = "NOTICE", [OPER] = "OPER", [PART] = "PART", [PASS] = "PASS", [PING] = "PING", [PONG] = "PONG", [PRIVMSG] = "PRIVMSG", [QUIT] = "QUIT", [REHASH] = "REHASH", [RESTART] = "RESTART", [SERVER] = "SERVER", [SERVICE] = "SERVICE", [SERVLIST] = "SERVLIST", [SQUERY] = "SQUERY", [SQUIT] = "SQUIT", [STATS] = "STATS", [SUMMON] = "SUMMON", [TIME] = "TIME", [TOPIC] = "TOPIC", [TRACE] = "TRACE", [USERHOST] = "USERHOST", [USERS] = "USERS", [USER] = "USER", [VERSION] = "VERSION", [WALLOPS] = "WALLOPS", [WHOIS] = "WHOIS", [WHOWAS] = "WHOWAS", [WHO] = "WHO", #ifdef UIRC_IRCV3 [ACCOUNT] = "ACCOUNT", [ACC] = "ACC", [ACK] = "ACK", [AUTHENTICATE] = "AUTHENTICATE", [BATCH] = "BATCH", [CAP] = "CAP", [CHGHOST] = "CHGHOST", [FAIL] = "FAIL", [MONITOR] = "MONITOR", [NOTE] = "NOTE", [RENAME] = "RENAME", [RESUME] = "RESUME", [SETNAME] = "SETNAME", [WARN] = "WARN", [WEBIRC] = "WEBIRC" #endif }; signed short Ircmd_stoi(char* str) { if (str == NULL) return ERR_UIRC_NULL_ARGS; for (signed short i = UIRC_FCMD; i <= (signed short) UIRC_LCMD; i++) { if (IRC_Cmds[i] != NULL && strcmp(IRC_Cmds[i], str) == 0) return i; } return ERR_UIRC_UNKNOWN_TOKEN; } size_t safe_strcpy(char** dest, const char* src, size_t lef) { size_t cnt; if (lef > (cnt = strlen(src)) + 1) { strcpy(*dest, src); *dest += cnt; return cnt; } else return 0; } bool safe_charcpy(char** dest, const char c, size_t lef) { if (lef > 1) { *(*dest)++ = c; **dest = '\0'; return 1; } else return 0; } void skip_spaces(char** addr) { for (; **addr == ' '; (*addr)++) ; } char* strtok_mr(char** addr, const char* tokens) { if (addr == NULL || *addr == NULL || !**addr || tokens == NULL) return NULL; char* save = *addr; const char* tok = NULL; do { if (!**addr) return save; for (tok = tokens; *tok; tok++) { if (**addr == *tok) { **addr = '\0'; break; } } } while (*(*addr)++); return save; }