2021-01-03 23:34:57 +00:00
|
|
|
/*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#ifndef UIRC_GUARD_TOKENIZERS
|
|
|
|
#define UIRC_GUARD_TOKENIZERS
|
|
|
|
|
|
|
|
#ifdef UIRC_IRCV3
|
|
|
|
/*!
|
|
|
|
* \brief Tokenize IRCv3 tags
|
|
|
|
*
|
|
|
|
* This function parses IRCv3 tags according to the specification at
|
|
|
|
* \param[in] str String containing a IRC source with or without the ':' prefix
|
|
|
|
* \param[out] out Allocated IRC_User structure
|
|
|
|
* \param[in] useorig If '\%orig' should be considered in the parsing
|
|
|
|
*/
|
|
|
|
signed int Tok_tags(char* str, IRC_Tags* out);
|
|
|
|
#endif /* UIRC_IRCV3 */
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Tokenize a IRC message source.
|
|
|
|
*
|
|
|
|
* This function takes the source part of a message, pointing struct elements to parts of it.
|
|
|
|
* \param[in] str String containing a IRC source with or without the ':' prefix
|
|
|
|
* \param[out] out Allocated IRC_User structure
|
|
|
|
* \param[in] useorig If '\%orig' should be considered in the parsing
|
|
|
|
*/
|
|
|
|
signed int Tok_user(char* str, IRC_User* out, bool useorig);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Tokenize a IRC message string.
|
|
|
|
*
|
|
|
|
* This function takes a IRC Message and attempts to tokenize/parse it, pointing every element found to it's respective struct element
|
|
|
|
* \param[in] str String containing a IRC message without the ending '\\r\\n'
|
|
|
|
* \param[out] out Allocated IRC_Message structure
|
|
|
|
*/
|
|
|
|
signed int Tok_mesg(char* str, IRC_Message* out);
|
|
|
|
|
|
|
|
#ifdef UIRC_HELPERS
|
|
|
|
/*!
|
|
|
|
* \brief A PING tokenizer/parser
|
|
|
|
*
|
|
|
|
* This function is a simple helper to get the source and target of a PING since the RFC has a "interesting" implementation
|
|
|
|
* \param[in] mesg IRC_Message struct containing the PING message
|
|
|
|
* \param[out] source Source of the PING (server)
|
|
|
|
* \param[out] target Target of the PING (server or client)
|
|
|
|
*/
|
2021-01-04 17:21:18 +00:00
|
|
|
void Tok_cmd_PING(const IRC_Message* mesg, char** source, char** target);
|
2021-01-03 23:34:57 +00:00
|
|
|
/*!
|
|
|
|
* \brief Tokenizer for cases where the first argument is optional
|
|
|
|
*
|
|
|
|
* This function is a private helper for cases where the first argument might be missing but the second isn't
|
|
|
|
* \param[in] mesg IRC_Message struct
|
2021-01-04 17:21:18 +00:00
|
|
|
* \param[out] optarg Optional argument if found or NULL
|
2021-01-03 23:34:57 +00:00
|
|
|
* \param[out] target Required argument
|
|
|
|
*/
|
2021-01-04 17:21:18 +00:00
|
|
|
void Tok_FArgOpt(const IRC_Message* mesg, char** optarg, char** reqarg);
|
2021-01-03 23:34:57 +00:00
|
|
|
#endif /* UIRC_HELPERS */
|
|
|
|
|
|
|
|
#endif /* UIRC_GUARD_TOKENIZERS */
|
|
|
|
|