X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Firc-info.c;h=ad585fe236151dc68f013ad22a81896512de767a;hp=806ab274d28493d7c90ec043209f82c6e7c603e7;hb=056de78e315a79edc1166649514bf8dfeb18abb1;hpb=cc336b75580d012c1caee58a252d1ad14b2cee23 diff --git a/src/ngircd/irc-info.c b/src/ngircd/irc-info.c index 806ab274..ad585fe2 100644 --- a/src/ngircd/irc-info.c +++ b/src/ngircd/irc-info.c @@ -25,7 +25,6 @@ #include "ngircd.h" #include "conn-func.h" #include "conn-zip.h" -#include "client.h" #include "channel.h" #include "conf.h" #include "defines.h" @@ -1232,45 +1231,30 @@ static inline bool Show_MOTD_SSLInfo(UNUSED CLIENT *c) { return true; } GLOBAL bool IRC_Show_MOTD( CLIENT *Client ) { - char line[127]; - FILE *fd; + const char *line; + size_t len_tot, len_str; assert( Client != NULL ); - if (Conf_MotdPhrase[0]) { - if (!Show_MOTD_Start(Client)) - return DISCONNECTED; - if (!Show_MOTD_Sendline(Client, Conf_MotdPhrase)) - return DISCONNECTED; - goto out; - } + len_tot = array_bytes(&Conf_Motd); + if (len_tot == 0 && !Conn_UsesSSL(Client_Conn(Client))) + return IRC_WriteStrClient(Client, ERR_NOMOTD_MSG, Client_ID(Client)); - fd = fopen( Conf_MotdFile, "r" ); - if( ! fd ) { - Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno )); - if (Conn_UsesSSL(Client_Conn(Client))) { - if (!Show_MOTD_Start(Client)) - return DISCONNECTED; - goto out; - } - return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) ); - } + if (!Show_MOTD_Start(Client)) + return DISCONNECTED; - if (!Show_MOTD_Start( Client )) { - fclose(fd); - return false; - } + line = array_start(&Conf_Motd); + while (len_tot > 0) { + len_str = strlen(line) + 1; - while (fgets( line, (int)sizeof line, fd )) { - ngt_TrimLastChr( line, '\n'); + assert(len_tot >= len_str); + len_tot -= len_str; - if( ! Show_MOTD_Sendline( Client, line)) { - fclose( fd ); - return false; - } + if (!Show_MOTD_Sendline(Client, line)) + return DISCONNECTED; + line += len_str; } - fclose(fd); -out: + if (!Show_MOTD_SSLInfo(Client)) return DISCONNECTED; return Show_MOTD_End(Client);