unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

batch.c (2964B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/batch.c
      3  *   (C) 2019 Syzop & The UnrealIRCd Team
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers.
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 #include "unrealircd.h"
     24 
     25 ModuleHeader MOD_HEADER
     26   = {
     27 	"batch",
     28 	"5.0",
     29 	"Batch CAP", 
     30 	"UnrealIRCd Team",
     31 	"unrealircd-6",
     32 	};
     33 
     34 /* Forward declarations */
     35 CMD_FUNC(cmd_batch);
     36 
     37 /* Variables */
     38 long CAP_BATCH = 0L;
     39 
     40 int batch_mtag_is_ok(Client *client, const char *name, const char *value);
     41 
     42 MOD_INIT()
     43 {
     44 	ClientCapabilityInfo cap;
     45 	ClientCapability *c;
     46 	MessageTagHandlerInfo mtag;
     47 
     48 	MARK_AS_OFFICIAL_MODULE(modinfo);
     49 
     50 	memset(&cap, 0, sizeof(cap));
     51 	cap.name = "batch";
     52 	c = ClientCapabilityAdd(modinfo->handle, &cap, &CAP_BATCH);
     53 
     54 	memset(&mtag, 0, sizeof(mtag));
     55 	mtag.name = "batch";
     56 	mtag.is_ok = batch_mtag_is_ok;
     57 	mtag.clicap_handler = c;
     58 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     59 
     60 	CommandAdd(modinfo->handle, "BATCH", cmd_batch, MAXPARA, CMD_USER|CMD_SERVER);
     61 	return MOD_SUCCESS;
     62 }
     63 
     64 MOD_LOAD()
     65 {
     66 	return MOD_SUCCESS;
     67 }
     68 
     69 MOD_UNLOAD()
     70 {
     71 	return MOD_SUCCESS;
     72 }
     73 
     74 /* BATCH:
     75  * As an intra-server command:
     76  * :sender BATCH target +xxxxx [etc etc etc]
     77  */
     78 CMD_FUNC(cmd_batch)
     79 {
     80 	Client *target;
     81 	char buf[512];
     82 
     83 	if (MyUser(client) || (parc < 3))
     84 		return;
     85 
     86 	target = find_client(parv[1], NULL);
     87 	if (!target)
     88 		return; /* race condition */
     89 
     90 	/* If the recipient does not support message tags or
     91 	 * does not support batch, then don't do anything.
     92 	 */
     93 	if (MyConnect(target) && !IsServer(target) && !HasCapability(target, "batch"))
     94 		return;
     95 
     96 	if (MyUser(target))
     97 	{
     98 		/* Send the batch message to the client */
     99 		parv[1] = "BATCH";
    100 		concat_params(buf, sizeof(buf), parc, parv);
    101 		sendto_prefix_one(target, client, recv_mtags, ":%s %s", client->name, buf);
    102 	} else {
    103 		/* Relay the batch message to the server */
    104 		concat_params(buf, sizeof(buf), parc, parv);
    105 		sendto_prefix_one(target, client, recv_mtags, ":%s BATCH %s", client->name, buf);
    106 	}
    107 }
    108 
    109 /** This function verifies if the client sending
    110  * 'batch' is permitted to do so and uses a permitted
    111  * syntax.
    112  * We simply allow batch ONLY from servers and with any syntax.
    113  */
    114 int batch_mtag_is_ok(Client *client, const char *name, const char *value)
    115 {
    116 	if (IsServer(client))
    117 		return 1;
    118 
    119 	return 0;
    120 }