Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/VibeDevelopers/Comet.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036/* * ircd-ratbox: A slightly useful ircd. * send.c: Functions for sending messages. * * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center * Copyright (C) 1996-2002 Hybrid Development Team * Copyright (C) 2002-2005 ircd-ratbox development team * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */
#include "stdinc.h"#include "send.h"#include "channel.h"#include "class.h"#include "client.h"#include "hash.h"#include "match.h"#include "ircd.h"#include "numeric.h"#include "s_assert.h"#include "s_serv.h"#include "s_conf.h"#include "s_newconf.h"#include "logger.h"#include "hook.h"#include "monitor.h"#include "msgbuf.h"
#define CLIENT_CAP_MASK(x) ((x)->from->localClient->client_caps | (IsServerCapable((x)->from, CAP_STAG) ? serv_clicapmask : 0))
static void send_queued_write(rb_fde_t *F, void *data);
unsigned long current_serial = 0L;
struct Client *remote_rehash_oper_p;
/* send_linebuf() * * inputs - client to send to, linebuf to attach * outputs - * side effects - linebuf is attached to client */static intsend_linebuf(struct Client *to, buf_head_t *linebuf){ if(IsMe(to)) { sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send message to myself!"); return 0; }
if(!MyConnect(to) || IsIOError(to)) return 0;
if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to)) { dead_link(to, 1);
if(IsServer(to)) { sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Max SendQ limit exceeded for %s: %u > %lu", to->name, rb_linebuf_len(&to->localClient->buf_sendq), get_sendq(to));
ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu", log_client_name(to, SHOW_IP), rb_linebuf_len(&to->localClient->buf_sendq), get_sendq(to)); }
return -1; } else { /* just attach the linebuf to the sendq instead of * generating a new one */ rb_linebuf_attach(&to->localClient->buf_sendq, linebuf); }
/* ** Update statistics. The following is slightly incorrect ** because it counts messages even if queued, but bytes ** only really sent. Queued bytes get updated in SendQueued. */ to->localClient->sendM += 1; me.localClient->sendM += 1; if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) send_queued(to); return 0;}
/* send_msgbuf() * * inputs - client to send to, msgbuf * outputs - 0 on success, -1 on failure * side effects - linebuf representing msgbuf is attached to client */static intsend_msgbuf(struct Client *target_p, struct MsgBuf *msgbuf){ buf_head_t linebuf; struct MsgBuf_str_data data = { .msgbuf = msgbuf, .caps = CLIENT_CAP_MASK(target_p) }; rb_strf_t strings = { .func = msgbuf_unparse_linebuf, .func_args = &data, .next = NULL };
rb_linebuf_newbuf(&linebuf); rb_linebuf_put(&linebuf, &strings); int val = send_linebuf(MyClient(target_p) ? target_p : target_p->from, &linebuf); rb_linebuf_donebuf(&linebuf);
return val;}
/* send_queued_write() * * inputs - fd to have queue sent, client we're sending to * outputs - contents of queue * side effects - write is rescheduled if queue isnt emptied */voidsend_queued(struct Client *to){ int retlen;
rb_fde_t *F = to->localClient->F; if (!F) return;
/* cant write anything to a dead socket. */ if(IsIOError(to)) return;
/* try to flush later when the write event resets this */ if(IsFlush(to)) return;
if(rb_linebuf_len(&to->localClient->buf_sendq)) { while ((retlen = rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0) { /* We have some data written .. update counters */ ClearFlush(to);
to->localClient->sendB += retlen; me.localClient->sendB += retlen; if(to->localClient->sendB > 1023) { to->localClient->sendK += (to->localClient->sendB >> 10); to->localClient->sendB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ } else if(me.localClient->sendB > 1023) { me.localClient->sendK += (me.localClient->sendB >> 10); me.localClient->sendB &= 0x03ff; } }
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) { dead_link(to, 0); return; } }
if(rb_linebuf_len(&to->localClient->buf_sendq)) { SetFlush(to); rb_setselect(to->localClient->F, RB_SELECT_WRITE, send_queued_write, to); } else ClearFlush(to);}
voidsend_pop_queue(struct Client *to){ if(to->from != NULL) to = to->from; if(!MyConnect(to) || IsIOError(to)) return; if(rb_linebuf_len(&to->localClient->buf_sendq) > 0) send_queued(to);}
/* send_queued_write() * * inputs - fd to have queue sent, client we're sending to * outputs - contents of queue * side effects - write is scheduled if queue isnt emptied */static voidsend_queued_write(rb_fde_t *F, void *data){ struct Client *to = data; ClearFlush(to); send_queued(to);}
/* * linebuf_put_* * * inputs - msgbuf header, linebuf object, capability mask, pattern, arguments * outputs - none * side effects - the linebuf object is cleared, then populated */static voidlinebuf_put_tags(buf_head_t *linebuf, const struct MsgBuf *msgbuf, const struct Client *target_p, rb_strf_t *message){ struct MsgBuf_str_data msgbuf_str_data = { .msgbuf = msgbuf, .caps = CLIENT_CAP_MASK(target_p) }; rb_strf_t strings = { .func = msgbuf_unparse_linebuf_tags, .func_args = &msgbuf_str_data, .length = TAGSLEN + 1, .next = message };
message->length = DATALEN + 1; rb_linebuf_put(linebuf, &strings);}
static voidlinebuf_put_tagsf(buf_head_t *linebuf, const struct MsgBuf *msgbuf, const struct Client *target_p, const rb_strf_t *message, const char *format, ...){ va_list va; rb_strf_t strings = { .format = format, .format_args = &va, .next = message };
va_start(va, format); linebuf_put_tags(linebuf, msgbuf, target_p, &strings); va_end(va);}
static voidlinebuf_put_msg(buf_head_t *linebuf, rb_strf_t *message){ message->length = DATALEN + 1; rb_linebuf_put(linebuf, message);}
static voidlinebuf_put_msgf(buf_head_t *linebuf, const rb_strf_t *message, const char *format, ...){ va_list va; rb_strf_t strings = { .format = format, .format_args = &va, .next = message };
va_start(va, format); linebuf_put_msg(linebuf, &strings); va_end(va);}
/* build_msgbuf * * inputs - msgbuf object, client the message is from, target (NULL if multi-target), line (excluding tags), tags to include * outputs - none * side effects - a msgbuf object is populated with the full command and relevant tags */static voidbuild_msgbuf(struct MsgBuf *msgbuf, struct Client *from, struct Client *target, struct Channel *chptr, bool source_sees_message, char *line, size_t n_tags, const struct MsgTag tags[]){ hook_data_outbound_msgbuf hdata;
msgbuf_init(msgbuf); msgbuf_partial_parse(msgbuf, line);
for (size_t i = 0; i < n_tags; i++) { if (tags[i].key != NULL) msgbuf_append_tag(msgbuf, tags[i].key, tags[i].value, tags[i].capmask); }
hdata.source = from; hdata.msgbuf = msgbuf; hdata.target = target; hdata.chptr = chptr; hdata.source_sees_message = source_sees_message;
call_hook(h_outbound_msgbuf, &hdata);
/* avoid duplicating params when unparsing */ msgbuf->cmd = NULL; msgbuf->target = NULL;}
/* sendto_one() * * inputs - client to send to, va_args * outputs - client has message put into its queue * side effects - */voidsendto_one(struct Client *target_p, const char *pattern, ...){ va_list args; struct Client *dest_p = target_p->from; struct MsgBuf msgbuf; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
if (IsIOError(dest_p)) return;
va_start(args, pattern); rb_fsnprint(buf, sizeof(buf), &strings); va_end(args);
build_msgbuf(&msgbuf, &me, target_p, NULL, false, buf, 0, NULL); send_msgbuf(target_p, &msgbuf);}
/* sendto_one_prefix() * * inputs - client to send to, va_args * outputs - client has message put into its queue * side effects - source(us)/target is chosen based on TS6 capability */voidsendto_one_prefix(struct Client *target_p, struct Client *source_p, const char *command, const char *pattern, ...){ struct Client *dest_p = target_p->from; va_list args; struct MsgBuf msgbuf; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
if (IsIOError(dest_p)) return;
if (IsMe(dest_p)) { sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); return; }
int used = snprintf(buf, sizeof(buf), ":%s %s %s ", get_id(source_p, target_p), command, get_id(target_p, target_p));
va_start(args, pattern); rb_fsnprint(buf + used, sizeof(buf) - used, &strings); va_end(args);
bool receives_message = MyClient(source_p) && source_p == target_p; build_msgbuf(&msgbuf, source_p, target_p, NULL, receives_message, buf, 0, NULL); send_msgbuf(target_p, &msgbuf);}
/* sendto_one_notice() * * inputs - client to send to, va_args * outputs - client has a NOTICE put into its queue * side effects - source(us)/target is chosen based on TS6 capability */voidsendto_one_notice(struct Client *target_p, const char *pattern, ...){ struct Client *dest_p = target_p->from; va_list args; struct MsgBuf msgbuf; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL }; const char *to = get_id(target_p, target_p);
if (EmptyString(to)) to = "*";
if (IsIOError(dest_p)) return;
if (IsMe(dest_p)) { sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); return; }
int used = snprintf(buf, sizeof(buf), ":%s NOTICE %s ", get_id(&me, target_p), to);
va_start(args, pattern); rb_fsnprint(buf + used, sizeof(buf) - used, &strings); va_end(args);
build_msgbuf(&msgbuf, &me, target_p, NULL, false, buf, 0, NULL); send_msgbuf(target_p, &msgbuf);}
/* sendto_one_numeric() * * inputs - client to send to, va_args * outputs - client has message put into its queue * side effects - source/target is chosen based on TS6 capability */voidsendto_one_numeric(struct Client *target_p, int numeric, const char *pattern, ...){ struct Client *dest_p = target_p->from; va_list args; struct MsgBuf msgbuf; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL }; const char *to = get_id(target_p, target_p);
if (EmptyString(to)) to = "*";
if (IsIOError(dest_p)) return;
if (IsMe(dest_p)) { sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!"); return; }
int used = snprintf(buf, sizeof(buf), ":%s %03d %s ", get_id(&me, target_p), numeric, to);
va_start(args, pattern); rb_fsnprint(buf + used, sizeof(buf) - used, &strings); va_end(args);
build_msgbuf(&msgbuf, &me, target_p, NULL, false, buf, 0, NULL); send_msgbuf(target_p, &msgbuf);}
/* sendto_one() * * inputs - client to send to, tags, va_args * outputs - client has message put into its queue * side effects - */voidsendto_one_tags(struct Client *target_p, uint64_t serv_cap, uint64_t serv_negcap, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args; struct Client *dest_p = target_p->from; struct MsgBuf msgbuf; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
if (IsIOError(dest_p)) return;
if (!IsServerCapable(dest_p, serv_cap) || !NotServerCapable(dest_p, serv_negcap)) return;
va_start(args, pattern); rb_fsnprint(buf, sizeof(buf), &strings); va_end(args);
build_msgbuf(&msgbuf, &me, target_p, NULL, false, buf, n_tags, tags); send_msgbuf(target_p, &msgbuf);}
/* * sendto_server_internal * * inputs - pointer to client to NOT send to * - caps or'd together which must ALL be present * - caps or'd together which must ALL NOT be present * - printf style format string * - args to format string * - message tags * output - NONE * side effects - Send a message to all connected servers, except the * client 'one' (if non-NULL), as long as the servers * support ALL capabs in 'caps', and NO capabs in 'nocaps'. */static voidsendto_server_internal(struct Client *one, struct Channel *chptr, uint64_t caps, uint64_t nocaps, const char *format, va_list *args, size_t n_tags, const struct MsgTag tags[]){ struct Client *target_p; rb_dlink_node *ptr; rb_dlink_node *next_ptr; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = format, .format_args = args, .next = NULL };
/* noone to send to... */ if(rb_dlink_list_length(&serv_list) == 0) return;
if(chptr != NULL && *chptr->chname != '#') return;
rb_fsnprint(buf, sizeof(buf), &strings); build_msgbuf(&msgbuf, &me, NULL, chptr, false, buf, n_tags, tags); /* source is already provided as part of format; don't overwrite it with anything else */ msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) { target_p = ptr->data;
/* check against 'one' */ if (one != NULL && (target_p == one->from)) continue;
/* check we have required capabs */ if (!IsServerCapable(target_p, caps)) continue;
/* check we don't have any forbidden capabs */ if (!NotServerCapable(target_p, nocaps)) continue;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); }
msgbuf_cache_free(&msgbuf_cache);}
/* * sendto_server * * inputs - pointer to client to NOT send to * - caps or'd together which must ALL be present * - caps or'd together which must ALL NOT be present * - printf style format string * - args to format string * output - NONE * side effects - Send a message to all connected servers, except the * client 'one' (if non-NULL), as long as the servers * support ALL capabs in 'caps', and NO capabs in 'nocaps'. * * This function was written in an attempt to merge together the other * billion sendto_*serv*() functions, which sprung up with capabs, uids etc * -davidt */voidsendto_server(struct Client *one, struct Channel *chptr, uint64_t caps, uint64_t nocaps, const char *format, ...){ va_list args; va_start(args, format); sendto_server_internal(one, chptr, caps, nocaps, format, &args, 0, NULL); va_end(args);}
/* * sendto_server_tags * * inputs - pointer to client to NOT send to * - caps or'd together which must ALL be present * - caps or'd together which must ALL NOT be present * - message tags * - printf style format string * - args to format string * output - NONE * side effects - Send a message to all connected servers, except the * client 'one' (if non-NULL), as long as the servers * support ALL capabs in 'caps', and NO capabs in 'nocaps'. */voidsendto_server_tags(struct Client *one, struct Channel *chptr, uint64_t caps, uint64_t nocaps, size_t n_tags, const struct MsgTag tags[], const char *format, ...){ va_list args; va_start(args, format); sendto_server_internal(one, chptr, caps, nocaps, format, &args, n_tags, tags); va_end(args);}
/* sendto_channel_flags_internal() * * inputs - server not to send to * - channel flags needed * - source * - channel * - client caps * - client priv needed * - server caps * - message text * - tags * outputs - message is sent to channel members * side effects - */static voidsendto_channel_flags_internal(struct Client *one, int type, struct Client *source_p, struct Channel *chptr, uint64_t cli_cap, uint64_t cli_negcap, const char *priv, uint64_t serv_cap, uint64_t serv_negcap, const rb_strf_t *strings, size_t n_tags, const struct MsgTag tags[]){ char buf[DATALEN + 1]; char local_source[USERHOST_REPLYLEN]; struct Client *target_p; struct membership *msptr; rb_dlink_node *ptr; rb_dlink_node *next_ptr; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache;
current_serial++;
snprintf(local_source, sizeof(local_source), IsPerson(source_p) ? "%s!%s@%s" : "%s", source_p->name, source_p->username, source_p->host);
rb_fsnprint(buf, sizeof(buf), strings);
bool receives_message = false; if (MyClient(source_p)) { receives_message = IsClientCapable(source_p, CLICAP_ECHO_MESSAGE); if (!receives_message && (msptr = find_channel_membership(chptr, source_p)) != NULL) { receives_message = source_p != one && (!type || (msptr->flags & type) != 0) && !IsDeaf(source_p) && IsClientCapable(source_p, cli_cap) && NotClientCapable(source_p, cli_negcap) && (priv == NULL || HasPrivilege(source_p, priv)); } }
build_msgbuf(&msgbuf, source_p, NULL, chptr, receives_message, buf, n_tags, tags);
msgbuf_cache_init(&msgbuf_cache, &msgbuf, local_source, use_id(source_p));
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) { msptr = ptr->data; target_p = msptr->client_p;
if (!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one)) continue;
if (MyClient(source_p) && (IsIOError(target_p) || target_p == one)) continue;
if (type && (msptr->flags & type) == 0) continue;
if (IsDeaf(target_p)) continue;
if (!MyClient(target_p)) { /* if we've got a specific type, target must support * CHW.. --fl */ if(type && NotServerCapable(target_p->from, CAP_CHW)) continue;
if (!IsServerCapable(target_p->from, serv_cap) || !NotServerCapable(target_p->from, serv_negcap)) continue;
if (target_p->from->serial != current_serial) { send_linebuf(target_p->from, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), true)); target_p->from->serial = current_serial; } } else if (IsClientCapable(target_p, cli_cap) && NotClientCapable(target_p, cli_negcap) && (priv == NULL || HasPrivilege(target_p, priv))) { send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); } }
/* source client may not be on the channel, send echo separately */ if (MyClient(source_p) && IsClientCapable(source_p, CLICAP_ECHO_MESSAGE)) { target_p = one == NULL ? source_p : one;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); }
msgbuf_cache_free(&msgbuf_cache);}
/* sendto_channel_flags() * * inputs - server not to send to, flags needed, source, channel, va_args * outputs - message is sent to channel members * side effects - */voidsendto_channel_flags(struct Client *one, int type, struct Client *source_p, struct Channel *chptr, const char *pattern, ...){ va_list args; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
va_start(args, pattern); sendto_channel_flags_internal(one, type, source_p, chptr, NOCAPS, NOCAPS, NULL, NOCAPS, NOCAPS, &strings, 0, NULL); va_end(args);}
/* sendto_channel_flags_tags() * * inputs - server not to send to, flags needed, source, channel, caps, tags, va_args * outputs - message is sent to channel members * side effects - */voidsendto_channel_flags_tags(struct Client *one, int type, struct Client *source_p, struct Channel *chptr, uint64_t cli_cap, uint64_t cli_negcap, uint64_t serv_cap, uint64_t serv_negcap, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
va_start(args, pattern); sendto_channel_flags_internal(one, type, source_p, chptr, cli_cap, cli_negcap, NULL, serv_cap, serv_negcap, &strings, n_tags, tags); va_end(args);}
/* sendto_channel_opmod_internal() * * inputs - server not to send to, flags needed, source, channel, caps, message, tags * outputs - message is sent to channel members * side effects - */static voidsendto_channel_opmod_internal(struct Client *one, struct Client *source_p, struct Channel *chptr, uint64_t cli_cap, uint64_t cli_negcap, uint64_t serv_cap, uint64_t serv_negcap, const char *command, const char *text, size_t n_tags, const struct MsgTag tags[]){ char buf[DATALEN + 1]; char local_source[USERHOST_REPLYLEN]; char chbuf[CHANNELLEN + 2]; struct Client *target_p; struct membership *msptr; rb_dlink_node *ptr; rb_dlink_node *next_ptr; struct MsgBuf msgbuf_statusmsg; struct MsgBuf msgbuf_eopmod; struct MsgBuf msgbuf_old; struct MsgBuf_cache msgbuf_cache_statusmsg; struct MsgBuf_cache msgbuf_cache_eopmod; struct MsgBuf_cache msgbuf_cache_old; const char *fmt = !strcmp("TAGMSG", command) ? "%s %s%s" : "%s %s%s :%s"; const char *statusmsg_prefix = ConfigChannel.opmod_send_statusmsg ? "@" : "";
/* remote targets must support CHW */ serv_cap |= CAP_CHW;
snprintf(local_source, sizeof(local_source), IsPerson(source_p) ? "%s!%s@%s" : "%s", source_p->name, source_p->username, source_p->host);
snprintf(buf, sizeof(buf), fmt, command, statusmsg_prefix, chptr->chname, text);
bool receives_message = false; if (MyClient(source_p)) { receives_message = IsClientCapable(source_p, CLICAP_ECHO_MESSAGE); if (!receives_message && (msptr = find_channel_membership(chptr, source_p)) != NULL) { receives_message = source_p != one && (msptr->flags & CHFL_CHANOP) != 0 && !IsDeaf(source_p) && IsClientCapable(source_p, cli_cap) && NotClientCapable(source_p, cli_negcap); } }
build_msgbuf(&msgbuf_statusmsg, source_p, NULL, chptr, receives_message, buf, n_tags, tags); msgbuf_cache_init(&msgbuf_cache_statusmsg, &msgbuf_statusmsg, local_source, use_id(source_p));
memcpy(&msgbuf_eopmod, &msgbuf_statusmsg, sizeof(struct MsgBuf)); snprintf(chbuf, sizeof(chbuf), "=%s", chptr->chname); msgbuf_eopmod.para[1] = chbuf; msgbuf_cache_init(&msgbuf_cache_eopmod, &msgbuf_eopmod, local_source, use_id(source_p));
snprintf(buf, sizeof(buf), ":%s NOTICE @%s :<%s:%s> %s", use_id(source_p->servptr), chptr->chname, source_p->name, chptr->chname, text); memcpy(&msgbuf_old, &msgbuf_statusmsg, sizeof(struct MsgBuf)); msgbuf_partial_parse(&msgbuf_old, buf); msgbuf_cache_init(&msgbuf_cache_old, &msgbuf_old, NULL, NULL);
current_serial++;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head) { msptr = ptr->data; target_p = msptr->client_p;
if (!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one)) continue;
if (MyClient(source_p) && target_p == one) continue;
if ((msptr->flags & CHFL_CHANOP) == 0) continue;
if (IsDeaf(target_p)) continue;
if (!MyClient(target_p)) { if (!IsServerCapable(target_p->from, serv_cap) || !NotServerCapable(target_p->from, serv_negcap)) continue;
if(target_p->from->serial != current_serial) { if (IsServerCapable(target_p->from, CAP_EOPMOD)) send_linebuf(target_p->from, msgbuf_cache_get(&msgbuf_cache_eopmod, CLIENT_CAP_MASK(target_p), true)); else if (chptr->mode.mode & MODE_MODERATED) send_linebuf(target_p->from, msgbuf_cache_get(&msgbuf_cache_statusmsg, CLIENT_CAP_MASK(target_p), true)); else send_linebuf(target_p->from, msgbuf_cache_get(&msgbuf_cache_old, CLIENT_CAP_MASK(target_p), true)); target_p->from->serial = current_serial; } } else if (IsClientCapable(target_p, cli_cap) && NotClientCapable(target_p, cli_negcap)) { send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache_statusmsg, CLIENT_CAP_MASK(target_p), false)); } }
/* source client may not be on the channel, send echo separately */ if (MyClient(source_p) && IsClientCapable(source_p, CLICAP_ECHO_MESSAGE)) { target_p = one;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache_statusmsg, CLIENT_CAP_MASK(target_p), false)); }
msgbuf_cache_free(&msgbuf_cache_statusmsg); msgbuf_cache_free(&msgbuf_cache_eopmod); msgbuf_cache_free(&msgbuf_cache_old);}
/* sendto_channel_opmod() * * inputs - server not to send to, flags needed, source, channel, message * outputs - message is sent to channel members * side effects - */voidsendto_channel_opmod(struct Client *one, struct Client *source_p, struct Channel *chptr, const char *command, const char *text){ sendto_channel_opmod_internal(one, source_p, chptr, NOCAPS, NOCAPS, NOCAPS, NOCAPS, command, text, 0, NULL);}
/* sendto_channel_opmod_tags() * * inputs - server not to send to, flags needed, source, channel, caps, message, tags * outputs - message is sent to channel members * side effects - */voidsendto_channel_opmod_tags(struct Client *one, struct Client *source_p, struct Channel *chptr, uint64_t cli_cap, uint64_t cli_negcap, uint64_t serv_cap, uint64_t serv_negcap, const char *command, const char *text, size_t n_tags, const struct MsgTag tags[]){ sendto_channel_opmod_internal(one, source_p, chptr, cli_cap, cli_negcap, serv_cap, serv_negcap, command, text, n_tags, tags);}
/* sendto_channel_local_internal() * * inputs - source, flags to send to, privs to send to, channel to send to, va_args * outputs - message to local channel members * side effects - */static voidsendto_channel_local_internal(struct Client *one, int type, struct Client *source_p, struct Channel *chptr, uint64_t caps, uint64_t negcaps, const char *priv, const char *pattern, va_list *args, size_t n_tags, const struct MsgTag tags[]){ char buf[DATALEN + 1]; struct membership *msptr; struct Client *target_p; rb_dlink_node *ptr; rb_dlink_node *next_ptr; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
rb_fsnprint(buf, sizeof(buf), &strings);
/* source_p == NULL in some tests; in real code this would indicate a server-sent message, so use &me if NULL */ if (source_p == NULL) source_p = &me;
bool receives_message = false; if (MyClient(source_p) && (msptr = find_channel_membership(chptr, source_p)) != NULL) { receives_message = source_p != one && (!type || (msptr->flags & type) != 0) && IsClientCapable(source_p, caps) && NotClientCapable(source_p, negcaps) && (priv == NULL || HasPrivilege(source_p, priv)); }
build_msgbuf(&msgbuf, source_p, NULL, chptr, receives_message, buf, n_tags, tags);
/* source is already provided as part of pattern; don't overwrite it with anything else */ msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) { msptr = ptr->data; target_p = msptr->client_p;
if (target_p == one) continue;
if (IsIOError(target_p)) continue;
if (type && (msptr->flags & type) == 0) continue;
if (!IsClientCapable(target_p, caps) || !NotClientCapable(target_p, negcaps)) continue;
if (priv != NULL && !HasPrivilege(target_p, priv)) continue;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); }
msgbuf_cache_free(&msgbuf_cache);}
/* sendto_channel_local_priv() * * inputs - source, flags to send to, privs to send to, channel to send to, va_args * outputs - message to local channel members * side effects - */voidsendto_channel_local_priv(struct Client *source_p, int type, const char *priv, struct Channel *chptr, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(NULL, type, source_p, chptr, NOCAPS, NOCAPS, priv, pattern, &args, 0, NULL); va_end(args);}
/* sendto_channel_local() * * inputs - source, flags to send to, channel to send to, va_args * outputs - message to local channel members * side effects - */voidsendto_channel_local(struct Client *source_p, int type, struct Channel *chptr, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(NULL, type, source_p, chptr, NOCAPS, NOCAPS, NULL, pattern, &args, 0, NULL); va_end(args);}
/* sendto_channel_local_tags() * * inputs - source, flags to send to, privs to send to, channel to send to, tags, va_args * outputs - message to local channel members * side effects - */voidsendto_channel_local_tags(struct Client *source_p, int type, const char *priv, struct Channel *chptr, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(NULL, type, source_p, chptr, NOCAPS, NOCAPS, priv, pattern, &args, n_tags, tags); va_end(args);}
/* sendto_channel_local_with_capability() * * inputs - source, flags to send to, caps, negate caps, channel to send to, va_args * outputs - message to local channel members * side effects - */voidsendto_channel_local_with_capability(struct Client *source_p, int type, uint64_t caps, uint64_t negcaps, struct Channel *chptr, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(NULL, type, source_p, chptr, caps, negcaps, NULL, pattern, &args, 0, NULL); va_end(args);}
/* sendto_channel_local_with_capability_tags() * * inputs - source, flags to send to, caps, negate caps, channel to send to, tags, va_args * outputs - message to local channel members * side effects - */voidsendto_channel_local_with_capability_tags(struct Client *source_p, int type, uint64_t caps, uint64_t negcaps, struct Channel *chptr, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(NULL, type, source_p, chptr, caps, negcaps, NULL, pattern, &args, n_tags, tags); va_end(args);}
/* sendto_channel_local_with_capability_butone() * * inputs - source, flags to send to, caps, negate caps, channel to send to, va_args * outputs - message to local channel members * side effects - */voidsendto_channel_local_with_capability_butone(struct Client *one, int type, uint64_t caps, uint64_t negcaps, struct Channel *chptr, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(one, type, one, chptr, caps, negcaps, NULL, pattern, &args, 0, NULL); va_end(args);}
/* sendto_channel_local_with_capability_butone_tags() * * inputs - source, flags to send to, caps, negate caps, channel to send to, tags, va_args * outputs - message to local channel members * side effects - */voidsendto_channel_local_with_capability_butone_tags(struct Client *one, int type, uint64_t caps, uint64_t negcaps, struct Channel *chptr, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(one, type, one, chptr, caps, negcaps, NULL, pattern, &args, n_tags, tags); va_end(args);}
/* sendto_channel_local_butone() * * inputs - flags to send to, channel to send to, va_args * - user to ignore when sending * outputs - message to local channel members * side effects - */voidsendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_channel_local_internal(one, type, one, chptr, NOCAPS, NOCAPS, NULL, pattern, &args, 0, NULL); va_end(args);}
/* sendto_common_channels_local_internal() * * inputs - client to exclude, user to check, caps, message, tags * outputs - NONE * side effects - Sends a message to all people on local server who are in the same channel with user */static voidsendto_common_channels_local_internal(struct Client *one, struct Client *user, uint64_t caps, uint64_t negcaps, const char *pattern, va_list *args, size_t n_tags, const struct MsgTag tags[]){ rb_dlink_node *ptr; rb_dlink_node *next_ptr; rb_dlink_node *uptr; rb_dlink_node *next_uptr; struct Channel *chptr; struct Client *target_p; struct membership *msptr; struct membership *mscptr; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL }; rb_fsnprint(buf, sizeof(buf), &strings);
bool receives_message = MyClient(user) && user != one && IsClientCapable(user, caps) && NotClientCapable(user, negcaps);
build_msgbuf(&msgbuf, user, NULL, NULL, receives_message, buf, n_tags, tags); /* source is already provided as part of pattern; don't overwrite it with anything else */ msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
++current_serial;
/* skip the excluded user, if specified */ if (one != NULL) one->serial = current_serial;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head) { mscptr = ptr->data; chptr = mscptr->chptr;
RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head) { msptr = uptr->data; target_p = msptr->client_p;
if(IsIOError(target_p) || target_p->serial == current_serial || !IsClientCapable(target_p, caps) || !NotClientCapable(target_p, negcaps)) continue;
target_p->serial = current_serial; send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); } }
/* this can happen when the user isn't in any channels, but we still * need to send them the data, ie a nick change */ if (MyConnect(user) && (user->serial != current_serial) && IsClientCapable(user, caps) && NotClientCapable(user, negcaps)) { send_linebuf(user, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(user), false)); }
msgbuf_cache_free(&msgbuf_cache);}
/* * sendto_common_channels_local() * * inputs - pointer to client * - capability mask * - negated capability mask * - pattern to send * output - NONE * side effects - Sends a message to all people on local server who are * in same channel with user. * used by m_nick.c and exit_one_client. */voidsendto_common_channels_local(struct Client *user, uint64_t caps, uint64_t negcaps, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_common_channels_local_internal(NULL, user, caps, negcaps, pattern, &args, 0, NULL); va_end(args);}
/* * sendto_common_channels_local_tags() * * inputs - pointer to client * - capability mask * - negated capability mask * - message tags * - pattern to send * output - NONE * side effects - Sends a message to all people on local server who are * in same channel with user. * used by m_nick.c and exit_one_client. */voidsendto_common_channels_local_tags(struct Client *user, uint64_t caps, uint64_t negcaps, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_common_channels_local_internal(NULL, user, caps, negcaps, pattern, &args, n_tags, tags); va_end(args);}
/* * sendto_common_channels_local_butone() * * inputs - pointer to client * - capability mask * - negated capability mask * - pattern to send * output - NONE * side effects - Sends a message to all people on local server who are * in same channel with user, except for user itself. */voidsendto_common_channels_local_butone(struct Client *user, uint64_t caps, uint64_t negcaps, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_common_channels_local_internal(user, user, caps, negcaps, pattern, &args, 0, NULL); va_end(args);}
/* * sendto_common_channels_local_butone_tags() * * inputs - pointer to client * - capability mask * - negated capability mask * - message tags * - pattern to send * output - NONE * side effects - Sends a message to all people on local server who are * in same channel with user, except for user itself. */voidsendto_common_channels_local_butone_tags(struct Client *user, uint64_t caps, uint64_t negcaps, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_common_channels_local_internal(user, user, caps, negcaps, pattern, &args, n_tags, tags); va_end(args);}
/* sendto_match_internal() * * inputs - server not to send to, source, mask, type of mask, capabilities, va_args, tags * output - * side effects - message is sent to matching clients */static voidsendto_match_internal(struct Client *one, struct Client *source_p, const char *mask, int what, uint64_t cli_cap, uint64_t cli_negcap, uint64_t serv_cap, uint64_t serv_negcap, const char *pattern, va_list *args, size_t n_tags, const struct MsgTag tags[]){ struct Client *target_p; rb_dlink_node *ptr; rb_dlink_node *next_ptr; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; char local_source[USERHOST_REPLYLEN]; rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
rb_fsnprint(buf, sizeof(buf), &strings); snprintf(local_source, sizeof(local_source), IsPerson(source_p) ? "%s!%s@%s" : "%s", source_p->name, source_p->username, source_p->host);
bool receives_message = false; if (MyClient(source_p) && IsClientCapable(source_p, cli_cap) && NotClientCapable(source_p, cli_negcap)) { receives_message = (what == MATCH_HOST && match(mask, source_p->host)) || (what == MATCH_SERVER && match(mask, me.name)); }
build_msgbuf(&msgbuf, source_p, NULL, NULL, receives_message, buf, n_tags, tags); msgbuf_cache_init(&msgbuf_cache, &msgbuf, local_source, use_id(source_p));
if (what == MATCH_HOST) { RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) { target_p = ptr->data;
if (match(mask, target_p->host) && IsClientCapable(target_p, cli_cap) && NotClientCapable(target_p, cli_negcap)) send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); } } /* what = MATCH_SERVER, if it doesnt match us, just send remote */ else if (match(mask, me.name)) { RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) { target_p = ptr->data;
if (IsClientCapable(target_p, cli_cap) && NotClientCapable(target_p, cli_negcap)) send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); } }
RB_DLINK_FOREACH(ptr, serv_list.head) { target_p = ptr->data;
if (target_p == one) continue;
if (!IsServerCapable(target_p->from, serv_cap) || !NotServerCapable(target_p->from, serv_negcap)) continue;
send_linebuf(target_p->from, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), true)); }
msgbuf_cache_free(&msgbuf_cache);}
/* sendto_match_butone() * * inputs - server not to send to, source, mask, type of mask, va_args * output - * side effects - message is sent to matching clients */voidsendto_match_butone(struct Client *one, struct Client *source_p, const char *mask, int what, const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_match_internal(one, source_p, mask, what, 0, 0, 0, 0, pattern, &args, 0, NULL); va_end(args);}
/* sendto_match_with_capability_butone_tags() * * inputs - server not to send to, source, mask, type of mask, capabilities, tags, va_args * output - * side effects - message is sent to matching clients */voidsendto_match_butone_tags(struct Client *one, struct Client *source_p, const char *mask, int what, uint64_t cli_cap, uint64_t cli_negcap, uint64_t serv_cap, uint64_t serv_negcap, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_match_internal(one, source_p, mask, what, cli_cap, cli_negcap, serv_cap, serv_negcap, pattern, &args, n_tags, tags); va_end(args);}
/* sendto_match_servs() * * inputs - source, mask to send to, caps needed, va_args, tags * outputs - * side effects - message is sent to matching servers with caps. */static voidsendto_match_servs_internal(struct Client *source_p, const char *mask, uint64_t cap, uint64_t negcap, const char *pattern, va_list *args, size_t n_tags, const struct MsgTag tags[]){ rb_dlink_node *ptr; struct Client *target_p; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
if (EmptyString(mask)) return;
int used = snprintf(buf, sizeof(buf), ":%s ", use_id(source_p)); rb_fsnprint(buf + used, sizeof(buf) - used, &strings);
build_msgbuf(&msgbuf, source_p, NULL, NULL, false, buf, n_tags, tags); msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
current_serial++;
RB_DLINK_FOREACH(ptr, global_serv_list.head) { target_p = ptr->data;
/* don't send to ourselves, or back to where it came from... */ if (IsMe(target_p) || target_p->from == source_p->from) continue;
if (target_p->from->serial == current_serial) continue;
if (match(mask, target_p->name)) { /* if we set the serial here, then we'll never do * a match() again if !IsCapable() */ target_p->from->serial = current_serial;
if (cap && !IsServerCapable(target_p->from, cap)) continue;
if (negcap && !NotServerCapable(target_p->from, negcap)) continue;
send_linebuf(target_p->from, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), true)); } }
msgbuf_cache_free(&msgbuf_cache);}
/* sendto_match_servs() * * inputs - source, mask to send to, caps needed, va_args * outputs - * side effects - message is sent to matching servers with caps. */voidsendto_match_servs(struct Client *source_p, const char *mask, uint64_t cap, uint64_t negcap, const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_match_servs_internal(source_p, mask, cap, negcap, pattern, &args, 0, NULL); va_end(args);}
/* sendto_match_servs_tags() * * inputs - source, mask to send to, caps needed, tags, va_args * outputs - * side effects - message is sent to matching servers with caps. */voidsendto_match_servs_tags(struct Client *source_p, const char *mask, uint64_t cap, uint64_t negcap, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_match_servs_internal(source_p, mask, cap, negcap, pattern, &args, n_tags, tags); va_end(args);}
/* sendto_local_clients_with_capability() * * inputs - caps needed, pattern, va_args * outputs - * side effects - message is sent to matching local clients with caps. */voidsendto_local_clients_with_capability(uint64_t cap, const char *pattern, ...){ va_list args; rb_dlink_node *ptr; struct Client *target_p; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
va_start(args, pattern); rb_fsnprint(buf, sizeof(buf), &strings); va_end(args);
build_msgbuf(&msgbuf, &me, NULL, NULL, false, buf, 0, NULL); msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
RB_DLINK_FOREACH(ptr, lclient_list.head) { target_p = ptr->data;
if (IsIOError(target_p) || !IsClientCapable(target_p, cap)) continue;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); }
msgbuf_cache_free(&msgbuf_cache);}
static voidsendto_list_internal(struct Client *one, struct Client *source_p, rb_dlink_list *list, uint64_t caps, uint64_t negcaps, bool (*filter)(struct Client *, void *), void *filter_data, const char *pattern, va_list *args, size_t n_tags, const struct MsgTag tags[]){ struct Client *target_p; rb_dlink_node *ptr; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
rb_fsnprint(buf, sizeof(buf), &strings);
build_msgbuf(&msgbuf, source_p, NULL, NULL, false, buf, n_tags, tags); msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
RB_DLINK_FOREACH(ptr, list->head) { target_p = ptr->data; if (target_p == one) continue;
if (caps != NOCAPS && !IsClientCapable(target_p, caps)) continue;
if (negcaps != NOCAPS && !NotClientCapable(target_p, negcaps)) continue;
if (filter != NULL && !filter(target_p, filter_data)) continue;
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(target_p), false)); }
msgbuf_cache_free(&msgbuf_cache);}
/* sendto_list_local_butone() * * inputs - target to exclude, list of targets to send to, filters, format, va_args * outputs - message to local users on the list who match the filters * side effects - */voidsendto_list_local_butone(struct Client *one, struct Client *source_p, rb_dlink_list *list, uint64_t caps, uint64_t negcaps, bool (*filter)(struct Client *, void *), void *filter_data, const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_list_internal(one, source_p, list, caps, negcaps, filter, filter_data, pattern, &args, 0, NULL); va_end(args);}
voidsendto_list_local_tags_butone(struct Client *one, struct Client *source_p, rb_dlink_list *list, uint64_t caps, uint64_t negcaps, bool (*filter)(struct Client *, void *), void *filter_data, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_list_internal(one, source_p, list, caps, negcaps, filter, filter_data, pattern, &args, n_tags, tags); va_end(args);}
voidsendto_monitor(struct Client *source_p, struct monitor *monptr, const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_list_internal(NULL, source_p, &monptr->users, NOCAPS, NOCAPS, NULL, NULL, pattern, &args, 0, NULL); va_end(args);}
voidsendto_monitor_with_capability(struct Client *source_p, struct monitor *monptr, uint64_t caps, uint64_t negcaps, const char *pattern, ...){ va_list args; va_start(args, pattern); sendto_list_internal(NULL, source_p, &monptr->users, caps, negcaps, NULL, NULL, pattern, &args, 0, NULL); va_end(args);}
/* _sendto_anywhere() * * inputs - real_target, target, source, va_args, tags * outputs - * side effects - client is sent message/own message with correct prefix. */static voidsendto_anywhere_internal(struct Client *dest_p, struct Client *target_p, struct Client *source_p, const char *command, uint64_t serv_cap, uint64_t serv_negcap, const char *pattern, va_list *args, size_t n_tags, const struct MsgTag tags[]){ struct MsgBuf msgbuf; char buf[DATALEN + 1]; int used; rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
if (!MyClient(dest_p) && (!IsServerCapable(target_p->from, serv_cap) || !NotServerCapable(target_p->from, serv_negcap))) return;
if (MyClient(dest_p)) used = snprintf(buf, sizeof(buf), IsPerson(source_p) ? ":%1$s!%4$s@%5$s %2$s %3$s " : ":%1$s %2$s %3$s ", source_p->name, command, target_p->name, source_p->username, source_p->host); else used = snprintf(buf, sizeof(buf), ":%s %s %s ", get_id(source_p, target_p), command, get_id(target_p, target_p));
rb_fsnprint(buf + used, sizeof(buf) - used, &strings); bool receives_message = MyClient(source_p) && source_p == dest_p; build_msgbuf(&msgbuf, source_p, dest_p, NULL, receives_message, buf, n_tags, tags); send_msgbuf(dest_p, &msgbuf);}
/* sendto_anywhere() * * inputs - target, source, va_args * outputs - * side effects - client is sent message with correct prefix. */voidsendto_anywhere(struct Client *target_p, struct Client *source_p, const char *command, const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_anywhere_internal(target_p, target_p, source_p, command, 0, 0, pattern, &args, 0, NULL); va_end(args);}
/* sendto_anywhere_echo() * * inputs - target, source, va_args * outputs - * side effects - client is sent own message with correct prefix. */voidsendto_anywhere_echo(struct Client *target_p, struct Client *source_p, const char *command, const char *pattern, ...){ va_list args;
s_assert(MyClient(source_p)); s_assert(!IsServer(source_p));
va_start(args, pattern); sendto_anywhere_internal(source_p, target_p, source_p, command, 0, 0, pattern, &args, 0, NULL); va_end(args);}
/* sendto_anywhere_tags() * * inputs - target, source, caps, tags, va_args * outputs - * side effects - client is sent message with correct prefix. */voidsendto_anywhere_tags(struct Client *target_p, struct Client *source_p, const char *command, uint64_t serv_cap, uint64_t serv_negcap, size_t n_tags, const struct MsgTag tags[], const char *pattern, ...){ va_list args;
va_start(args, pattern); sendto_anywhere_internal(target_p, target_p, source_p, command, serv_cap, serv_negcap, pattern, &args, n_tags, tags); va_end(args);}
/* sendto_realops_snomask() * * inputs - snomask needed, level (opers/admin), va_args * output - * side effects - message is sent to opers with matching snomasks */voidsendto_realops_snomask(int flags, int level, const char *pattern, ...){ char *snobuf; struct Client *client_p; rb_dlink_node *ptr; rb_dlink_node *next_ptr; va_list args; struct MsgBuf msgbuf; struct MsgBuf remote_rehash_msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
/* rather a lot of copying around, oh well -- jilles */ va_start(args, pattern); size_t used = snprintf(buf, sizeof(buf), ":%s NOTICE * :*** Notice -- ", me.name); rb_fsnprint(buf + used, sizeof(buf) - used, &strings); va_end(args);
build_msgbuf(&msgbuf, &me, NULL, NULL, false, buf, 0, NULL); msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
/* Be very sure not to do things like "Trying to send to myself" * L_NETWIDE, otherwise infinite recursion may result! -- jilles */ if (level & L_NETWIDE && ConfigFileEntry.global_snotices) { snobuf = construct_snobuf(flags); if (snobuf[1] != '\0') sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS, ":%s ENCAP * SNOTE %c :%s", me.id, snobuf[1], buf + used); } else if (remote_rehash_oper_p != NULL) { memcpy(&remote_rehash_msgbuf, &msgbuf, sizeof(struct MsgBuf)); remote_rehash_msgbuf.origin = get_id(&me, remote_rehash_oper_p); remote_rehash_msgbuf.para[1] = get_id(remote_rehash_oper_p, remote_rehash_oper_p); send_msgbuf(remote_rehash_oper_p, &remote_rehash_msgbuf); } level &= ~L_NETWIDE;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) { client_p = ptr->data;
/* If we're sending it to opers and they're an admin, skip. * If we're sending it to admins, and they're not, skip. */ if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || ((level == L_OPER) && IsOperAdmin(client_p))) continue;
if (client_p->snomask & flags) { send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(client_p), false)); } }
msgbuf_cache_free(&msgbuf_cache);}/* sendto_realops_snomask_from() * * inputs - snomask needed, level (opers/admin), source server, va_args * output - * side effects - message is sent to opers with matching snomask */voidsendto_realops_snomask_from(int flags, int level, struct Client *source_p, const char *pattern, ...){ struct Client *client_p; rb_dlink_node *ptr; rb_dlink_node *next_ptr; va_list args; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
va_start(args, pattern); int used = snprintf(buf, sizeof(buf), ":%s NOTICE * :*** Notice -- ", source_p->name); rb_fsnprint(buf + used, sizeof(buf) - used, &strings); va_end(args);
bool receives_message = false; if (MyClient(source_p) && (source_p->snomask & flags) != 0) { receives_message = (level == L_ADMIN && IsOperAdmin(source_p)) || (level == L_OPER && !IsOperAdmin(source_p)) || (level != L_OPER && level != L_ADMIN); }
build_msgbuf(&msgbuf, source_p, NULL, NULL, receives_message, buf, 0, NULL); msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head) { client_p = ptr->data;
/* If we're sending it to opers and they're an admin, skip. * If we're sending it to admins, and they're not, skip. */ if(((level == L_ADMIN) && !IsOperAdmin(client_p)) || ((level == L_OPER) && IsOperAdmin(client_p))) continue;
if (client_p->snomask & flags) { send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(client_p), false)); } }
msgbuf_cache_free(&msgbuf_cache);}
/* * sendto_wallops_flags * * inputs - flag types of messages to show to real opers * - client sending request * - var args input message * output - NONE * side effects - Send a wallops to local opers */voidsendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...){ struct Client *client_p; rb_dlink_node *ptr; rb_dlink_node *next_ptr; va_list args; struct MsgBuf msgbuf; struct MsgBuf_cache msgbuf_cache; char buf[DATALEN + 1]; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL }; const char *fmt = IsPerson(source_p) ? ":%s!%s@%s WALLOPS :" : ":%s WALLOPS :";
va_start(args, pattern); int used = snprintf(buf, sizeof(buf), fmt, source_p->name, source_p->username, source_p->host); rb_fsnprint(buf + used, sizeof(buf) - used, &strings); va_end(args);
bool receives_message = MyClient(source_p) && (source_p->umodes & flags) != 0; build_msgbuf(&msgbuf, source_p, NULL, NULL, receives_message, buf, 0, NULL); msgbuf_cache_init(&msgbuf_cache, &msgbuf, NULL, NULL);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head) { client_p = ptr->data;
if (client_p->umodes & flags) { send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAP_MASK(client_p), false)); } }
msgbuf_cache_free(&msgbuf_cache);}
/* kill_client() * * input - client to send kill to, client to kill, va_args * output - * side effects - we issue a kill for the client */voidkill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...){ va_list args; buf_head_t linebuf; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern); linebuf_put_msgf(&linebuf, &strings, ":%s KILL %s :", get_id(&me, target_p), get_id(diedie, target_p)); va_end(args);
send_linebuf(target_p, &linebuf); rb_linebuf_donebuf(&linebuf);}
/* * kill_client_serv_butone * * inputs - pointer to client to not send to * - pointer to client to kill * output - NONE * side effects - Send a KILL for the given client * message to all connected servers * except the client 'one'. Also deal with * client being unknown to leaf, as in lazylink... */voidkill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...){ static char buf[BUFSIZE]; va_list args; struct Client *client_p; rb_dlink_node *ptr; rb_dlink_node *next_ptr; buf_head_t rb_linebuf_id; rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
rb_linebuf_newbuf(&rb_linebuf_id);
va_start(args, pattern); linebuf_put_msgf(&rb_linebuf_id, &strings, ":%s KILL %s :%s", use_id(&me), use_id(target_p), buf); va_end(args);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head) { client_p = ptr->data;
/* ok, if the client we're supposed to not send to has an * ID, then we still want to issue the kill there.. */ if(one != NULL && (client_p == one->from) && (!has_id(client_p) || !has_id(target_p))) continue;
send_linebuf(client_p, &rb_linebuf_id); }
rb_linebuf_donebuf(&rb_linebuf_id);}
static struct Client *multiline_stashed_target_p;static char multiline_prefix[DATALEN+1]; /* allow for null termination */static int multiline_prefix_len;static char multiline_separator[2];static int multiline_separator_len;static char *multiline_item_start;static char *multiline_cur;static int multiline_cur_len;static int multiline_remote_pad;
boolsend_multiline_init(struct Client *target_p, const char *separator, const char *format, ...){ va_list args;
s_assert(multiline_stashed_target_p == NULL && "Multiline: didn't cleanup after last usage!");
va_start(args, format); multiline_prefix_len = vsnprintf(multiline_prefix, sizeof multiline_prefix, format, args); va_end(args);
if (multiline_prefix_len <= 0 || multiline_prefix_len >= DATALEN) { s_assert(false && "Multiline: failure preparing prefix!"); return false; }
multiline_separator_len = rb_strlcpy(multiline_separator, separator, sizeof multiline_separator); if (multiline_separator_len >= sizeof multiline_separator) { s_assert(false && "Multiline: separator too long"); return false; }
multiline_stashed_target_p = target_p; multiline_item_start = multiline_prefix + multiline_prefix_len; multiline_cur = multiline_item_start; multiline_cur_len = multiline_prefix_len; multiline_remote_pad = 0; return true;}
boolsend_multiline_remote_pad(struct Client *target_p, struct Client *client_p){ ssize_t remote_pad;
if (target_p != multiline_stashed_target_p) { s_assert(false && "Multiline: missed init call!"); multiline_stashed_target_p = NULL; return false; }
if (MyConnect(target_p)) return true;
remote_pad = strlen(client_p->name) - strlen(client_p->id);
if (remote_pad > 0) { multiline_remote_pad += remote_pad; }
return true;}
enum multiline_item_resultsend_multiline_item(struct Client *target_p, const char *format, ...){ va_list args; char item[DATALEN]; int item_len, res; enum multiline_item_result ret = MULTILINE_SUCCESS;
if (target_p != multiline_stashed_target_p) { s_assert(false && "Multiline: missed init call!"); multiline_stashed_target_p = NULL; return MULTILINE_FAILURE; }
va_start(args, format); item_len = vsnprintf(item, sizeof item, format, args); va_end(args);
if (item_len < 0 || multiline_prefix_len + multiline_remote_pad + item_len > DATALEN) { s_assert(false && "Multiline: failure preparing item!"); multiline_stashed_target_p = NULL; return MULTILINE_FAILURE; }
if (multiline_cur_len + ((*multiline_item_start != '\0') ? multiline_separator_len : 0) + item_len > DATALEN - multiline_remote_pad) { sendto_one(target_p, "%s", multiline_prefix); *multiline_item_start = '\0'; multiline_cur_len = multiline_prefix_len; multiline_cur = multiline_item_start; ret = MULTILINE_WRAPPED; }
res = snprintf(multiline_cur, sizeof multiline_prefix - multiline_cur_len, "%s%s", (*multiline_item_start != '\0') ? multiline_separator : "", item);
if (res < 0) { s_assert(false && "Multiline: failure appending item!"); multiline_stashed_target_p = NULL; return MULTILINE_FAILURE; }
multiline_cur_len += res; multiline_cur += res; return ret;}
boolsend_multiline_fini(struct Client *target_p, const char *format, ...){ va_list args; char final[DATALEN]; int final_len;
if (target_p != multiline_stashed_target_p) { s_assert(false && "Multiline: missed init call!"); multiline_stashed_target_p = NULL; return false; }
if (multiline_cur_len == multiline_prefix_len) { multiline_stashed_target_p = NULL; return true; }
if (format) { va_start(args, format); final_len = vsnprintf(final, sizeof final, format, args); va_end(args);
if (final_len <= 0 || final_len > multiline_prefix_len) { s_assert(false && "Multiline: failure preparing final prefix!"); multiline_stashed_target_p = NULL; return false; } } else { rb_strlcpy(final, multiline_prefix, multiline_prefix_len + 1); }
sendto_one(target_p, "%s%s", final, multiline_item_start);
multiline_stashed_target_p = NULL; return true;}
voidsend_multiline_reset(void){ multiline_stashed_target_p = NULL;}