diff --git a/src/plugin_api/command_api.h b/src/plugin_api/command_api.h new file mode 100644 index 0000000..5f713a0 --- /dev/null +++ b/src/plugin_api/command_api.h @@ -0,0 +1,80 @@ +/* + * uhub - A tiny ADC p2p connection hub + * Copyright (C) 2007-2010, Jan Vidar Krey + * + * This program 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 + * (at your option) any later version. + * + * This program 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 this program. If not, see . + * + */ + +#ifndef HAVE_UHUB_PLUGIN_API_H +#define HAVE_UHUB_PLUGIN_API_H + +/** + * This file describes the interface a plugin implementation may use from + * uhub. + */ + +#include "system.h" +#include "plugin_api/types.h" + +struct plugin_command +{ + const char* message; + char* prefix; + size_t prefix_len; + struct linked_list* args; +}; + +typedef int (*plugin_command_handler)(struct plugin_handle*, struct plugin_user* to, struct plugin_command*); + +struct plugin_command_handle +{ + void* internal_handle; /**<<< "Internal used by the hub only" */ + struct plugin_handle* handle; /**<<< "The plugin handle this is associated with" */ + const char* prefix; /**<<< "Command prefix, for instance 'help' would be the prefix for the !help command." */ + size_t length; /**<<< "Length of the prefix" */ + const char* args; /**<<< "Argument codes" */ + enum auth_credentials cred; /**<<< "Minimum access level for the command" */ + plugin_command_handler handler; /**<<< "Function pointer for the command" */ + const char* description; /**<<< "Description for the command" */ + const char* origin; /**<<< "Name of plugin where the command originated." */ +}; + +#define PLUGIN_COMMAND_INITIALIZE(PTR, HANDLE, PREFIX, ARGS, CRED, CALLBACK, DESC) \ + do { \ + PTR->internal_handle = 0; \ + PTR->handle = HANDLE; \ + PTR->prefix = PREFIX; \ + PTR->length = strlen(PREFIX); \ + PTR->args = ARGS; \ + PTR->cred = CRED; \ + PTR->handler = CALLBACK; \ + PTR->description = DESC; \ + } while (0) + +extern int plugin_command_add(struct plugin_handle*, struct plugin_command_handle*); +extern int plugin_command_del(struct plugin_handle*, struct plugin_command_handle*); + +/** + * Send a message to a user. + * From the user's perspective the message will originate from the hub. + */ +extern int plugin_command_send_message(struct plugin_handle*, struct plugin_user* to, const char* message); + +/** + * Send a reply to a command. + */ +extern int plugin_command_send_reply(struct plugin_handle*, struct plugin_user* user, struct plugin_command* command, const char* message); + +#endif /* HAVE_UHUB_PLUGIN_API_H */ diff --git a/src/plugin_api/message_api.h b/src/plugin_api/message_api.h new file mode 100644 index 0000000..628805c --- /dev/null +++ b/src/plugin_api/message_api.h @@ -0,0 +1,29 @@ +/* + * uhub - A tiny ADC p2p connection hub + * Copyright (C) 2007-2010, Jan Vidar Krey + * + * This program 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 + * (at your option) any later version. + * + * This program 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 this program. If not, see . + * + */ + +#ifndef HAVE_UHUB_PLUGIN_MESSAGE_API_H +#define HAVE_UHUB_PLUGIN_MESSAGE_API_H + +/** + * Send an informal message to a user. + * The user will see the message as if the hub sent it. + */ +extern int plugin_send_message(struct plugin_handle*, struct plugin_user* to, const char* message); + +#endif /* HAVE_UHUB_PLUGIN_API_H */ diff --git a/src/plugin_api/types.h b/src/plugin_api/types.h new file mode 100644 index 0000000..c377c60 --- /dev/null +++ b/src/plugin_api/types.h @@ -0,0 +1,96 @@ +/* + * uhub - A tiny ADC p2p connection hub + * Copyright (C) 2007-2010, Jan Vidar Krey + * + * This program 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 + * (at your option) any later version. + * + * This program 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 this program. If not, see . + * + */ + +#ifndef HAVE_UHUB_PLUGIN_TYPES_H +#define HAVE_UHUB_PLUGIN_TYPES_H + +#define PLUGIN_API_VERSION 1 + +#ifndef MAX_NICK_LEN +#define MAX_NICK_LEN 64 +#endif + +#ifndef MAX_PASS_LEN +#define MAX_PASS_LEN 64 +#endif + +#ifndef MAX_CID_LEN +#define MAX_CID_LEN 39 +#endif + +#ifndef MAX_UA_LEN +#define MAX_UA_LEN 32 +#endif + +#ifndef SID_T_DEFINED +typedef uint32_t sid_t; +#define SID_T_DEFINED +#endif + +struct plugin_handle; + +struct plugin_user +{ + sid_t sid; + char nick[MAX_NICK_LEN+1]; + char cid[MAX_CID_LEN+1]; + char user_agent[MAX_UA_LEN+1]; + struct ip_addr_encap addr; + enum auth_credentials credentials; +}; + +struct plugin_hub_info +{ + const char* description; +}; + +enum plugin_status +{ + st_default = 0, /* Use default */ + st_allow = 1, /* Allow action */ + st_deny = -1, /* Deny action */ +}; + +typedef enum plugin_status plugin_st; + +struct auth_info +{ + char nickname[MAX_NICK_LEN+1]; + char password[MAX_PASS_LEN+1]; + enum auth_credentials credentials; +}; + +enum ban_flags +{ + ban_nickname = 0x01, /* Nickname is banned */ + ban_cid = 0x02, /* CID is banned */ + ban_ip = 0x04, /* IP address (range) is banned */ +}; + +struct ban_info +{ + unsigned int flags; /* See enum ban_flags. */ + char nickname[MAX_NICK_LEN+1]; /* Nickname - only defined if (ban_nickname & flags). */ + char cid[MAX_CID_LEN+1]; /* CID - only defined if (ban_cid & flags). */ + struct ip_addr_encap ip_addr_lo; /* Low IP address of an IP range */ + struct ip_addr_encap ip_addr_hi; /* High IP address of an IP range */ + time_t expiry; /* Time when the ban record expires */ +}; + +#endif /* HAVE_UHUB_PLUGIN_TYPES_H */