*/
#include "stdinc.h"
-#include "tools.h"
#include "send.h"
#include "channel.h"
#include "class.h"
#include "client.h"
#include "common.h"
-#include "irc_string.h"
+#include "match.h"
#include "ircd.h"
#include "numeric.h"
-#include "commio.h"
#include "s_serv.h"
-#include "sprintf_irc.h"
#include "s_conf.h"
#include "s_newconf.h"
-#include "linebuf.h"
-#include "s_log.h"
-#include "memory.h"
+#include "logger.h"
#include "hook.h"
#include "monitor.h"
unsigned long current_serial = 0L;
+struct Client *remote_rehash_oper_p;
+
/* send_linebuf()
*
* inputs - client to send to, linebuf to attach
{
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Max SendQ limit exceeded for %s: %u > %lu",
- get_server_name(to, HIDE_IP),
- rb_linebuf_len(&to->localClient->buf_sendq),
+ 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),
+ rb_linebuf_len(&to->localClient->buf_sendq),
get_sendq(to));
}
- if(IsClient(to))
- to->flags |= FLAGS_SENDQEX;
-
- dead_link(to);
+ dead_link(to, 1);
return -1;
}
else
if(IsIOError(to))
return;
+ /* Something wants us to not send anything currently */
+ /* if(IsCork(to))
+ return; */
+
+ /* try to flush later when the write event resets this */
+ if(IsFlush(to))
+ return;
+
#ifdef USE_IODEBUG_HOOKS
hd.client = to;
if(to->localClient->buf_sendq.list.head)
((buf_line_t *) to->localClient->buf_sendq.list.head->
data)->buf + to->localClient->buf_sendq.writeofs;
#endif
-
+
+
+ ClearFlush(to);
to->localClient->sendB += retlen;
me.localClient->sendB += retlen;
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
{
- dead_link(to);
+ dead_link(to, 0);
return;
}
}
+
if(rb_linebuf_len(&to->localClient->buf_sendq))
- rb_setselect(to->localClient->F, RB_SELECT_WRITE,
+ {
+ SetFlush(to);
+ rb_setselect(to->localClient->F, RB_SELECT_WRITE,
send_queued_write, to);
+ }
+ else
+ ClearFlush(to);
+}
+
+void
+send_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()
send_queued_write(rb_fde_t *F, void *data)
{
struct Client *to = data;
- /*ClearFlush(to);*/
+ ClearFlush(to);
send_queued(to);
}
-/* send_queued_slink_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
- */
-void
-send_queued_slink_write(int fd, void *data)
-{
- struct Client *to = data;
- int retlen;
-
- /*
- ** Once socket is marked dead, we cannot start writing to it,
- ** even if the error is removed...
- */
- if(IsIOError(to))
- return;
-
- /* Next, lets try to write some data */
- if(to->localClient->slinkq)
- {
- retlen = write(to->localClient->ctrlfd,
- to->localClient->slinkq + to->localClient->slinkq_ofs,
- to->localClient->slinkq_len);
-
- if(retlen < 0)
- {
- /* If we have a fatal error */
- if(!rb_ignore_errno(errno))
- {
- dead_link(to);
- return;
- }
- }
- /* 0 bytes is an EOF .. */
- else if(retlen == 0)
- {
- dead_link(to);
- return;
- }
- else
- {
- to->localClient->slinkq_len -= retlen;
-
- s_assert(to->localClient->slinkq_len >= 0);
- if(to->localClient->slinkq_len)
- to->localClient->slinkq_ofs += retlen;
- else
- {
- to->localClient->slinkq_ofs = 0;
- MyFree(to->localClient->slinkq);
- to->localClient->slinkq = NULL;
- }
- }
- }
-
- /* if we have any more data, reschedule a write */
- if(to->localClient->slinkq_len)
- rb_setselect(to->localClient->ctrlfd,
- RB_SELECT_WRITE, send_queued_slink_write, to);
-}
-
/* sendto_one()
*
* inputs - client to send to, va_args
* outputs - client has message put into its queue
- * side effects -
+ * side effects -
*/
void
sendto_one(struct Client *target_p, const char *pattern, ...)
/*
* 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
* 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
static char buf[BUFSIZE];
va_list args;
buf_head_t rb_linebuf_local;
- buf_head_t rb_linebuf_name;
buf_head_t rb_linebuf_id;
struct Client *target_p;
struct membership *msptr;
rb_dlink_node *next_ptr;
rb_linebuf_newbuf(&rb_linebuf_local);
- rb_linebuf_newbuf(&rb_linebuf_name);
rb_linebuf_newbuf(&rb_linebuf_id);
current_serial++;
else
rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
":%s!%s@%s %s",
- source_p->name, source_p->username,
+ source_p->name, source_p->username,
source_p->host, buf);
- rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, ":%s %s", source_p->name, buf);
rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
if(target_p->from->serial != current_serial)
{
- if(has_id(target_p->from))
- send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
- else
- send_linebuf_remote(target_p, source_p, &rb_linebuf_name);
-
+ send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
target_p->from->serial = current_serial;
}
}
}
rb_linebuf_donebuf(&rb_linebuf_local);
- rb_linebuf_donebuf(&rb_linebuf_name);
rb_linebuf_donebuf(&rb_linebuf_id);
}
+/* sendto_channel_flags()
+ *
+ * inputs - server not to send to, flags needed, source, channel, va_args
+ * outputs - message is sent to channel members
+ * side effects -
+ */
+void
+sendto_channel_opmod(struct Client *one, struct Client *source_p,
+ struct Channel *chptr, const char *command,
+ const char *text)
+{
+ buf_head_t rb_linebuf_local;
+ buf_head_t rb_linebuf_old;
+ buf_head_t rb_linebuf_new;
+ struct Client *target_p;
+ struct membership *msptr;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
+
+ rb_linebuf_newbuf(&rb_linebuf_local);
+ rb_linebuf_newbuf(&rb_linebuf_old);
+ rb_linebuf_newbuf(&rb_linebuf_new);
+
+ current_serial++;
+
+ if(IsServer(source_p))
+ rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
+ ":%s %s %s :%s",
+ source_p->name, command, chptr->chname, text);
+ else
+ rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
+ ":%s!%s@%s %s %s :%s",
+ source_p->name, source_p->username,
+ source_p->host, command, chptr->chname, text);
+
+ if (chptr->mode.mode & MODE_MODERATED)
+ rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
+ ":%s %s %s :%s",
+ use_id(source_p), command, chptr->chname, text);
+ else
+ rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
+ ":%s NOTICE @%s :<%s:%s> %s",
+ use_id(source_p->servptr), chptr->chname,
+ source_p->name, chptr->chname, text);
+ rb_linebuf_putmsg(&rb_linebuf_new, NULL, NULL,
+ ":%s %s =%s :%s",
+ use_id(source_p), command, chptr->chname, text);
+
+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
+ {
+ msptr = ptr->data;
+ target_p = msptr->client_p;
+
+ if(IsIOError(target_p->from) || target_p->from == one)
+ continue;
+
+ if((msptr->flags & CHFL_CHANOP) == 0)
+ continue;
+
+ if(IsDeaf(target_p))
+ continue;
+
+ if(!MyClient(target_p))
+ {
+ /* if we've got a specific type, target must support
+ * CHW.. --fl
+ */
+ if(NotCapable(target_p->from, CAP_CHW))
+ continue;
+
+ if(target_p->from->serial != current_serial)
+ {
+ if (IsCapable(target_p->from, CAP_EOPMOD))
+ send_linebuf_remote(target_p, source_p, &rb_linebuf_new);
+ else
+ send_linebuf_remote(target_p, source_p, &rb_linebuf_old);
+ target_p->from->serial = current_serial;
+ }
+ }
+ else
+ _send_linebuf(target_p, &rb_linebuf_local);
+ }
+
+ rb_linebuf_donebuf(&rb_linebuf_local);
+ rb_linebuf_donebuf(&rb_linebuf_old);
+ rb_linebuf_donebuf(&rb_linebuf_new);
+}
/* sendto_channel_local()
*
struct Client *target_p;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
-
- rb_linebuf_newbuf(&linebuf);
-
+
+ rb_linebuf_newbuf(&linebuf);
+
va_start(args, pattern);
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
va_end(args);
rb_linebuf_donebuf(&linebuf);
}
+/*
+ * _sendto_channel_local_with_capability_butone()
+ *
+ * Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
+ */
+static void
+_sendto_channel_local_with_capability_butone(struct Client *one, int type, int caps, int negcaps, struct Channel *chptr,
+ const char *pattern, va_list * args)
+{
+ buf_head_t linebuf;
+ struct membership *msptr;
+ struct Client *target_p;
+ rb_dlink_node *ptr;
+ rb_dlink_node *next_ptr;
+
+ rb_linebuf_newbuf(&linebuf);
+ rb_linebuf_putmsg(&linebuf, pattern, args, 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) ||
+ !IsCapable(target_p, caps) ||
+ !NotCapable(target_p, negcaps))
+ continue;
+
+ if(type && ((msptr->flags & type) == 0))
+ continue;
+
+ _send_linebuf(target_p, &linebuf);
+ }
+
+ rb_linebuf_donebuf(&linebuf);
+}
+
+/* sendto_channel_local_with_capability()
+ *
+ * inputs - flags to send to, caps, negate caps, channel to send to, va_args
+ * outputs - message to local channel members
+ * side effects -
+ */
+void
+sendto_channel_local_with_capability(int type, int caps, int negcaps, struct Channel *chptr, const char *pattern, ...)
+{
+ va_list args;
+
+ va_start(args, pattern);
+ _sendto_channel_local_with_capability_butone(NULL, type, caps, negcaps, chptr, pattern, &args);
+ va_end(args);
+}
+
+
+/* sendto_channel_local_with_capability()
+ *
+ * inputs - flags to send to, caps, negate caps, channel to send to, va_args
+ * outputs - message to local channel members
+ * side effects -
+ */
+void
+sendto_channel_local_with_capability_butone(struct Client *one, int type, int caps, int negcaps, struct Channel *chptr,
+ const char *pattern, ...)
+{
+ va_list args;
+
+ va_start(args, pattern);
+ _sendto_channel_local_with_capability_butone(one, type, caps, negcaps, chptr, pattern, &args);
+ va_end(args);
+}
+
+
/* sendto_channel_local_butone()
*
* inputs - flags to send to, channel to send to, va_args
struct Client *target_p;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
-
- rb_linebuf_newbuf(&linebuf);
-
+
+ rb_linebuf_newbuf(&linebuf);
+
va_start(args, pattern);
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
va_end(args);
* sendto_common_channels_local()
*
* inputs - pointer to client
+ * - 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.
+ * in same channel with user.
* used by m_nick.c and exit_one_client.
*/
void
-sendto_common_channels_local(struct Client *user, const char *pattern, ...)
+sendto_common_channels_local(struct Client *user, int cap, const char *pattern, ...)
{
va_list args;
rb_dlink_node *ptr;
target_p = msptr->client_p;
if(IsIOError(target_p) ||
- target_p->serial == current_serial)
+ target_p->serial == current_serial ||
+ !IsCapable(target_p, cap))
continue;
target_p->serial = current_serial;
* sendto_common_channels_local_butone()
*
* inputs - pointer to client
+ * - 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.
*/
void
-sendto_common_channels_local_butone(struct Client *user, const char *pattern, ...)
+sendto_common_channels_local_butone(struct Client *user, int cap, const char *pattern, ...)
{
va_list args;
rb_dlink_node *ptr;
target_p = msptr->client_p;
if(IsIOError(target_p) ||
- target_p->serial == current_serial)
+ target_p->serial == current_serial ||
+ !IsCapable(target_p, cap))
continue;
target_p->serial = current_serial;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
buf_head_t rb_linebuf_local;
- buf_head_t rb_linebuf_name;
buf_head_t rb_linebuf_id;
rb_linebuf_newbuf(&rb_linebuf_local);
- rb_linebuf_newbuf(&rb_linebuf_name);
rb_linebuf_newbuf(&rb_linebuf_id);
va_start(args, pattern);
else
rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
":%s!%s@%s %s",
- source_p->name, source_p->username,
+ source_p->name, source_p->username,
source_p->host, buf);
- rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, ":%s %s", source_p->name, buf);
rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
if(what == MATCH_HOST)
if(target_p == one)
continue;
- if(has_id(target_p))
- send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
- else
- send_linebuf_remote(target_p, source_p, &rb_linebuf_name);
+ send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
}
rb_linebuf_donebuf(&rb_linebuf_local);
rb_linebuf_donebuf(&rb_linebuf_id);
- rb_linebuf_donebuf(&rb_linebuf_name);
}
/* sendto_match_servs()
*
* inputs - source, mask to send to, caps needed, va_args
- * outputs -
+ * outputs -
* side effects - message is sent to matching servers with caps.
*/
void
-sendto_match_servs(struct Client *source_p, const char *mask, int cap,
+sendto_match_servs(struct Client *source_p, const char *mask, int cap,
int nocap, const char *pattern, ...)
{
static char buf[BUFSIZE];
rb_dlink_node *ptr;
struct Client *target_p;
buf_head_t rb_linebuf_id;
- buf_head_t rb_linebuf_name;
if(EmptyString(mask))
return;
rb_linebuf_newbuf(&rb_linebuf_id);
- rb_linebuf_newbuf(&rb_linebuf_name);
va_start(args, pattern);
rb_vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
- rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
+ rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
":%s %s", use_id(source_p), buf);
- rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL,
- ":%s %s", source_p->name, buf);
current_serial++;
if(nocap && !NotCapable(target_p->from, nocap))
continue;
- if(has_id(target_p->from))
- _send_linebuf(target_p->from, &rb_linebuf_id);
- else
- _send_linebuf(target_p->from, &rb_linebuf_name);
+ _send_linebuf(target_p->from, &rb_linebuf_id);
}
}
rb_linebuf_donebuf(&rb_linebuf_id);
- rb_linebuf_donebuf(&rb_linebuf_name);
+}
+
+/* sendto_local_clients_with_capability()
+ *
+ * inputs - caps needed, pattern, va_args
+ * outputs -
+ * side effects - message is sent to matching local clients with caps.
+ */
+void
+sendto_local_clients_with_capability(int cap, const char *pattern, ...)
+{
+ va_list args;
+ rb_dlink_node *ptr;
+ struct Client *target_p;
+ buf_head_t linebuf;
+
+ rb_linebuf_newbuf(&linebuf);
+
+ va_start(args, pattern);
+ rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+ va_end(args);
+
+ RB_DLINK_FOREACH(ptr, lclient_list.head)
+ {
+ target_p = ptr->data;
+
+ if(IsIOError(target_p) || !IsCapable(target_p, cap))
+ continue;
+
+ send_linebuf(target_p, &linebuf);
+ }
+
+ rb_linebuf_donebuf(&linebuf);
}
/* sendto_monitor()
struct Client *target_p;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
-
- rb_linebuf_newbuf(&linebuf);
-
+
+ rb_linebuf_newbuf(&linebuf);
+
va_start(args, pattern);
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
va_end(args);
* side effects - client is sent message with correct prefix.
*/
void
-sendto_anywhere(struct Client *target_p, struct Client *source_p,
+sendto_anywhere(struct Client *target_p, struct Client *source_p,
const char *command, const char *pattern, ...)
{
va_list args;
{
if(IsServer(source_p))
rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
- source_p->name, command,
+ source_p->name, command,
target_p->name);
else
- rb_linebuf_putmsg(&linebuf, pattern, &args,
- ":%s!%s@%s %s %s ",
+ rb_linebuf_putmsg(&linebuf, pattern, &args,
+ ":%s!%s@%s %s %s ",
source_p->name, source_p->username,
source_p->host, command,
target_p->name);
rb_linebuf_donebuf(&linebuf);
}
-/* sendto_realops_flags()
- *
- * inputs - umode needed, level (opers/admin), va_args
- * output -
- * side effects - message is sent to opers with matching umodes
- */
-void
-sendto_realops_flags(int flags, int level, const char *pattern, ...)
-{
- struct Client *client_p;
- rb_dlink_node *ptr;
- rb_dlink_node *next_ptr;
- va_list args;
- buf_head_t linebuf;
-
- rb_linebuf_newbuf(&linebuf);
-
- va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
- ":%s NOTICE * :*** Notice -- ", me.name);
- va_end(args);
-
- RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
- {
- client_p = ptr->data;
-
- /* If we're sending it to opers and theyre an admin, skip.
- * If we're sending it to admins, and theyre not, skip.
- */
- if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
- ((level == L_OPER) && IsOperAdmin(client_p)))
- continue;
-
- if(client_p->umodes & flags)
- _send_linebuf(client_p, &linebuf);
- }
-
- rb_linebuf_donebuf(&linebuf);
-}
-
/* sendto_realops_snomask()
*
* inputs - snomask needed, level (opers/admin), va_args
va_start(args, pattern);
rb_vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
- rb_linebuf_putmsg(&linebuf, pattern, NULL,
+ rb_linebuf_putmsg(&linebuf, pattern, NULL,
":%s NOTICE * :*** Notice -- %s", me.name, buf);
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);
- sendto_server(NULL, NULL, CAP_ENCAP, CAP_TS6,
- ":%s ENCAP * SNOTE %c :%s",
- me.name, snobuf[1], buf);
- }
+ }
+ else if (remote_rehash_oper_p != NULL)
+ {
+ /* rather a lot of copying around, oh well -- jilles */
+ va_start(args, pattern);
+ rb_vsnprintf(buf, sizeof(buf), pattern, args);
+ va_end(args);
+ rb_linebuf_putmsg(&linebuf, pattern, NULL,
+ ":%s NOTICE * :*** Notice -- %s", me.name, buf);
+ sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf);
}
else
{
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_putmsg(&linebuf, pattern, &args,
":%s NOTICE * :*** Notice -- ", me.name);
va_end(args);
}
rb_linebuf_newbuf(&linebuf);
va_start(args, pattern);
- rb_linebuf_putmsg(&linebuf, pattern, &args,
+ rb_linebuf_putmsg(&linebuf, pattern, &args,
":%s NOTICE * :*** Notice -- ", source_p->name);
va_end(args);
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
buf_head_t rb_linebuf_id;
- buf_head_t rb_linebuf_name;
- rb_linebuf_newbuf(&rb_linebuf_name);
rb_linebuf_newbuf(&rb_linebuf_id);
-
+
va_start(args, pattern);
rb_vsnprintf(buf, sizeof(buf), pattern, args);
va_end(args);
- rb_linebuf_putmsg(&rb_linebuf_name, NULL, NULL, ":%s KILL %s :%s",
- me.name, target_p->name, buf);
rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
use_id(&me), use_id(target_p), buf);
(!has_id(client_p) || !has_id(target_p)))
continue;
- if(has_id(client_p))
- _send_linebuf(client_p, &rb_linebuf_id);
- else
- _send_linebuf(client_p, &rb_linebuf_name);
+ _send_linebuf(client_p, &rb_linebuf_id);
}
rb_linebuf_donebuf(&rb_linebuf_id);
- rb_linebuf_donebuf(&rb_linebuf_name);
}