X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fircd_reply.c;h=256d18c5047c92f2ad5521eabca98ecce2f3b6f0;hb=refs%2Fheads%2Fupstream;hp=5e33b1bf932d926e1a43c41dafd1c8967256105c;hpb=80881d85337d93d70b67a505ae5178199b1b3155;p=ircu2.10.12-pk.git diff --git a/ircd/ircd_reply.c b/ircd/ircd_reply.c index 5e33b1b..256d18c 100644 --- a/ircd/ircd_reply.c +++ b/ircd/ircd_reply.c @@ -19,106 +19,72 @@ * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ */ +/** @file + * @brief Implementation of functions to send common replies to users. + * @version $Id$ + */ +#include "config.h" + #include "ircd_reply.h" #include "client.h" #include "ircd.h" +#include "ircd_log.h" #include "ircd_snprintf.h" -#include "numeric.h" #include "msg.h" +#include "msgq.h" +#include "numeric.h" #include "s_conf.h" #include "s_debug.h" #include "send.h" -#include +/* #include -- Now using assert in ircd_log.h */ #include -/* Report a protocol violation warning to anyone listening. This can be - * easily used to cleanup the last couple of parts of the code up. +/** Report a protocol violation warning to anyone listening. This can + * be easily used to clean up the last couple of parts of the code. + * @param[in] cptr Client that violated the protocol. + * @param[in] pattern Description of how the protocol was violated. + * @return Zero. */ - int protocol_violation(struct Client* cptr, const char* pattern, ...) { - va_list vl; - char buffer[512]; - assert(pattern); - assert(cptr); - va_start(vl,pattern); - ircd_snprintf(0,buffer,sizeof(buffer)-2, - "Protocol Violation from %C: %v",vl); - sendcmdto_flag_butone(&me, CMD_DESYNCH, NULL, FLAGS_DEBUG, - ":%s", cptr, buffer); - va_end(vl); - return 0; -} + struct VarData vd; + char message[BUFSIZE]; -int need_more_params(struct Client* cptr, const char* cmd) -{ - if (!MyUser(cptr)) - protocol_violation(cptr,"Not enough parameters for %s",cmd); - send_reply(cptr, ERR_NEEDMOREPARAMS, cmd); + assert(pattern); + assert(cptr); + + vd.vd_format = pattern; + va_start(vd.vd_args, pattern); + ircd_snprintf(NULL, message, sizeof(message), + "Protocol Violation from %s: %v", cli_name(cptr), &vd); + va_end(vd.vd_args); + + sendwallto_group_butone(&me, WALL_DESYNCH, NULL, "%s", message); return 0; } -/* - * send_error_to_client - send an error message to a client - * I don't know if this function is any faster than the other version - * but it is a bit easier to use. It's reentrant until it hits vsendto_one - * at least :) --Bleep +/** Inform a client that they need to provide more parameters. + * @param[in] cptr Taciturn client. + * @param[in] cmd Command name. + * @return Zero. */ -int send_error_to_client(struct Client* cptr, int error, ...) +int need_more_params(struct Client* cptr, const char* cmd) { - va_list vl; - char buf[BUFSIZE]; - char* dest = buf; - const char* src = me.name; - const struct Numeric* num = get_error_numeric(error); - - assert(0 != cptr); - assert(0 != num); - /* - * prefix - */ - *dest++ = ':'; - while ((*dest = *src++)) - ++dest; - *dest++ = ' '; - /* - * numeric - */ - src = num->str; - while ((*dest = *src++)) - ++dest; - *dest++ = ' '; - /* - * client name (nick) - */ - src = cptr->name; - while ((*dest = *src++)) - ++dest; - *dest++ = ' '; - /* - * reply format - */ - strcpy(dest, num->format); - -#if 0 - Debug((DEBUG_INFO, "send_error_to_client: format: ->%s<-", buf)); -#endif - - va_start(vl, error); - vsendto_one(cptr, buf, vl); - va_end(vl); + send_reply(cptr, ERR_NEEDMOREPARAMS, cmd); return 0; } - +/** Send a generic reply to a user. + * @param[in] to Client that wants a reply. + * @param[in] reply Numeric of message to send. + * @return Zero. + */ int send_reply(struct Client *to, int reply, ...) { struct VarData vd; - char sndbuf[IRC_BUFSIZE]; + struct MsgBuf *mb; const struct Numeric *num; assert(0 != to); @@ -136,27 +102,17 @@ int send_reply(struct Client *to, int reply, ...) assert(0 != vd.vd_format); /* build buffer */ - ircd_snprintf(to->from, sndbuf, sizeof(sndbuf) - 2, "%:#C %s %C %v", &me, - num->str, to, &vd); + mb = msgq_make(cli_from(to), "%:#C %s %C %v", &me, num->str, to, &vd); va_end(vd.vd_args); /* send it to the user */ - send_buffer(to, sndbuf); + send_buffer(to, mb, 0); + + msgq_clean(mb); return 0; /* convenience return */ } -int send_admin_info(struct Client* sptr) -{ - const struct LocalConf* admin = conf_get_local(); - assert(0 != sptr); - - send_reply(sptr, RPL_ADMINME, me.name); - send_reply(sptr, RPL_ADMINLOC1, admin->location1); - send_reply(sptr, RPL_ADMINLOC2, admin->location2); - send_reply(sptr, RPL_ADMINEMAIL, admin->contact); - return 0; -}