X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fopercmds.c;h=f208f94d3eeb8f32d128340066e422915a6f2ed4;hb=refs%2Fheads%2Fupstream;hp=bbc4cec48bbb1afc94371d93868b4ee08aa2d53f;hpb=19cd4740e84080d52a5231c4714ba3dae375bff1;p=ircu2.10.12-pk.git diff --git a/ircd/opercmds.c b/ircd/opercmds.c index bbc4cec..f208f94 100644 --- a/ircd/opercmds.c +++ b/ircd/opercmds.c @@ -19,13 +19,16 @@ * 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 AsLL ping helper commands. + * @version $Id$ + */ +#include "config.h" + #include "opercmds.h" #include "class.h" #include "client.h" -#include "crule.h" #include "ircd.h" #include "ircd_chattr.h" #include "ircd_reply.h" @@ -41,86 +44,24 @@ #include #include +#include #include -/* - * m_stats/stats_conf +/** Calculate current time or elapsed time. * - * Report N/C-configuration lines from this server. This could - * report other configuration lines too, but converting the - * status back to "char" is a bit akward--not worth the code - * it needs... + * If neither \a sec nor \a usec are NULL, calculate milliseconds + * elapsed since that time, and return a string containing that + * number. * - * Note: The info is reported in the order the server uses - * it--not reversed as in ircd.conf! + * If either \a sec or \a usec are NULL, format a timestamp containing + * Unix timestamp and microseconds since that second (separated by + * spaces), and return a string containing that timestamp. + * + * @todo This should be made into two functions. + * @param[in] sec Either NULL or a Unix timestamp in seconds. + * @param[in] usec Either NULL or an offset to \a sec in microseconds. + * @return A static buffer with contents as described above. */ - -static unsigned int report_array[17][3] = { - {CONF_SERVER, RPL_STATSCLINE, 'C'}, - {CONF_CLIENT, RPL_STATSILINE, 'I'}, - {CONF_KILL, RPL_STATSKLINE, 'K'}, - {CONF_IPKILL, RPL_STATSKLINE, 'k'}, - {CONF_LEAF, RPL_STATSLLINE, 'L'}, - {CONF_OPERATOR, RPL_STATSOLINE, 'O'}, - {CONF_HUB, RPL_STATSHLINE, 'H'}, - {CONF_LOCOP, RPL_STATSOLINE, 'o'}, - {CONF_CRULEALL, RPL_STATSDLINE, 'D'}, - {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'}, - {CONF_UWORLD, RPL_STATSULINE, 'U'}, - {CONF_TLINES, RPL_STATSTLINE, 'T'}, - {0, 0} -}; - -void report_configured_links(struct Client *sptr, int mask) -{ - static char null[] = ""; - struct ConfItem *tmp; - unsigned int *p; - unsigned short int port; - char c, *host, *pass, *name; - - for (tmp = GlobalConfList; tmp; tmp = tmp->next) { - if ((tmp->status & mask)) - { - for (p = &report_array[0][0]; *p; p += 3) - if (*p == tmp->status) - break; - if (!*p) - continue; - c = (char)*(p + 2); - host = BadPtr(tmp->host) ? null : tmp->host; - pass = BadPtr(tmp->passwd) ? null : tmp->passwd; - name = BadPtr(tmp->name) ? null : tmp->name; - port = tmp->port; - /* - * On K line the passwd contents can be - * displayed on STATS reply. -Vesa - */ - /* Special-case 'k' or 'K' lines as appropriate... -Kev */ - if ((tmp->status & CONF_KLINE)) - sendto_one(sptr, rpl_str(p[1]), me.name, - sptr->name, c, host, pass, name, port, get_conf_class(tmp)); - /* - * connect rules are classless - */ - else if ((tmp->status & CONF_CRULE)) - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name); - else if ((tmp->status & CONF_TLINES)) - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, pass); - else if ((tmp->status & CONF_UWORLD)) - sendto_one(sptr, rpl_str(p[1]), - me.name, sptr->name, c, host, pass, name, port, - get_conf_class(tmp)); - else if ((tmp->status & (CONF_SERVER | CONF_HUB))) - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, "*", name, - port, get_conf_class(tmp)); - else - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name, - port, get_conf_class(tmp)); - } - } -} - char *militime(char* sec, char* usec) { struct timeval tv; @@ -135,3 +76,43 @@ char *militime(char* sec, char* usec) return timebuf; } +/** Calculate current time or elapsed time. + * + * If \a start is NULL, create a timestamp containing Unix timestamp + * and microseconds since that second (separated by a period), and + * return a string containing that timestamp. + * + * Otherwise, if \a start does not contain a period, return a string + * equal to "0". + * + * Otherwise, calculate milliseconds elapsed since the Unix time + * described in \a start (in the format described above), and return a + * string containing that number. + * + * @todo This should be made into two functions. + * @param[in] start Either NULL or a Unix timestamp in + * pseudo-floating-point format. + * @return A static buffer with contents as described above. + */ +char *militime_float(char* start) +{ + struct timeval tv; + static char timebuf[18]; + char *p; + + gettimeofday(&tv, NULL); + if (start) + { + if ((p = strchr(start, '.'))) + { + p++; + sprintf(timebuf, "%ld", + (tv.tv_sec - atoi(start)) * 1000 + (tv.tv_usec - atoi(p)) / 1000); + } + else + strcpy(timebuf, "0"); + } + else + sprintf(timebuf, "%ld.%ld", tv.tv_sec, tv.tv_usec); + return timebuf; +}