This repository has been archived on 2021-04-17. You can view files and clone it, but cannot push or open issues or pull requests.
uIRC/include/uirc/type.h

146 lines
5.2 KiB
C

/*
* This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC)
* Copyright (c) 2019-2021 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/>.
*/
/*! \file */
#include "uirc/mode.h"
#include <corelibs/llist.h> // llist_t
#include <inttypes.h> // uintmax_t
#include <stdbool.h> // bool
#ifndef UIRC_GUARD_PUBLIC_TYPES
#define UIRC_GUARD_PUBLIC_TYPES
typedef uintmax_t IRC_Counter;
#ifdef UIRC_FEATURE_IRCV3
/*!
* \brief Capability status structure
*/
typedef struct {
char *key, /*!< Name of the tag */
*value; /*!< Value of the tag
* \warning may be NULL
*/
bool clientbound; /*!< true if the tag is sent by the client */
} IRC_Tag;
/*!
* \brief Capability status structure
*/
typedef struct {
char* name; /*!< Name of the capability */
bool active; /*!< Status of the capability */
} IRC_Capability;
#endif /* UIRC_FEATURE_IRCV3 */
/*!
* \brief User information structure
*/
typedef struct {
char *nick, /*!< Nickname of the user */
*user, /*!< Username of the user */
*host, /*!< Hostname of the user */
*real; /*!< Real name of the user
* \note It is only used in USER registrations
*/
IRC_Modes modes; /*!< Modes that the user has active on the network */
bool is_service; /*!< Whether the user is a service or not */
} IRC_User;
/*!
* \brief The maximum amount of arguments in a message (including trailing)
*
* See *params* at \ref https://tools.ietf.org/html/rfc2812#section-2.3.1
* \warning This should remain as it is unless you deal with a special implementation that can handle more
*/
#define IRC_MAXARGS 15
/*!
* \brief Message information structure
*/
typedef struct {
IRC_User* source; /*!< Where the message originates from */
char* command; /*!< Command of the message */
char* args[IRC_MAXARGS]; /*!< Array of arguments up to \ref IRC_MAXARGS, ended early by a NULL */
bool trailing; /*!< Tells if the last argument is trailing */
#ifdef UIRC_FEATURE_IRCV3
llist_t* tag_list; /*!< Linked list of \ref IRC_Tag for the message */
#endif /* UIRC_FEATURE_IRCV3 */
} IRC_Message;
/*!
* \brief List of possible buffer types
*/
typedef enum {
IRC_DIRECT, /*!< Private buffer (direct messages) */
IRC_CHANNEL, /*!< Channel buffer (group of people) */
IRC_GLOBAL /*!< Anything else that doesn't fit in the other categories */
} IRC_Buffer_Type;
/*!
* \brief Buffer information structure
*
* This structure contains lists and information about a buffer
*/
typedef struct {
IRC_Buffer_Type type; /*!< Type of the buffer */
char * name, /*!< Name of the buffer, usually channel name or nickname */
*topic, /*!< Topic of the buffer (only applies to channels) */
*key; /*!< Password required to subscribe to the buffer (to be used with PASS) */
bool subscribed; /*!< Subscription status (eg. being part of a channel) */
IRC_Modes modes; /*!< Modes for the buffer (not to be confused to modes of a user) */
llist_t * user_list, /*!< Linked list of \ref IRC_User participating in a buffer (channel usually) */
*message_list; /*!< Linked list of \ref IRC_Message received on that buffer */
} IRC_Buffer;
/*!
* \brief Network information structure
*
* This structure contains all the information related to a network and inherits all the other structures directly or indirectly
*/
typedef struct {
char *addr, /*!< Address of the server (usually IP address for TCP) */
*svc, /*!< Service description (port for TCP) */
*pass; /*!< Password for the service */
IRC_User* user; /*!< User that registers on the network (self) */
llist_t* buf_list; /*!< Linked list of \ref IRC_Buffer open to this network */
#ifdef UIRC_FEATURE_IRCV3
llist_t* cap_list; /*!< Linked list of \ref IRC_Capability for this network */
#endif /* UIRC_FEATURE_IRCV3 */
} IRC_Network;
/*!
* \brief List of structure types available
*
* This is used to signal what kind of structure was passed to a function which accepts multiple types or is a void pointer
*/
typedef enum {
#ifdef UIRC_FEATURE_IRCV3
IRC_STRUCT_TAG, /*!< \ref IRC_Tag */
IRC_STRUCT_CAPABILITY, /*!< \ref IRC_Capability */
#endif /* UIRC_FEATURE_IRCV3 */
IRC_STRUCT_USER, /*!< \ref IRC_User */
IRC_STRUCT_MESSAGE, /*!< \ref IRC_Message */
IRC_STRUCT_BUFFER, /*!< \ref IRC_Buffer */
IRC_STRUCT_NETWORK /*!< \ref IRC_Network */
} IRC_Struct_Type;
#endif /* UIRC_GUARD_PUBLIC_TYPES */