ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/misc.c
(Generate patch)

Comparing:
ircd-hybrid-7.3/src/s_misc.c (file contents), Revision 1029 by michael, Sun Nov 8 13:10:50 2009 UTC vs.
ircd-hybrid/trunk/src/misc.c (file contents), Revision 7006 by michael, Fri Jan 1 00:07:54 2016 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_misc.c: Yet another miscellaneous functions file.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2016 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file s_misc.c
23 > * \brief Yet another miscellaneous functions file.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "s_misc.h"
27 < #include "client.h"
28 < #include "common.h"
28 > #include "misc.h"
29   #include "irc_string.h"
30 #include "sprintf_irc.h"
30   #include "ircd.h"
32 #include "numeric.h"
33 #include "irc_res.h"
34 #include "fdlist.h"
35 #include "s_bsd.h"
36 #include "s_conf.h"
37 #include "s_serv.h"
38 #include "send.h"
39 #include "memory.h"
31  
32  
33 < static const char *months[] =
33 > const char *
34 > date(time_t lclock)
35   {
36 <  "January",   "February", "March",   "April",
37 <  "May",       "June",     "July",    "August",
46 <  "September", "October",  "November","December"
47 < };
36 >  static char buf[80];
37 >  static time_t lclock_last;
38  
39 < static const char *weekdays[] =
40 < {
41 <  "Sunday",   "Monday", "Tuesday", "Wednesday",
42 <  "Thursday", "Friday", "Saturday"
43 < };
39 >  if (!lclock)
40 >    lclock = CurrentTime;
41 >
42 >  if (lclock_last != lclock)
43 >  {
44 >    lclock_last = lclock;
45 >    strftime(buf, sizeof(buf), "%A %B %-e %Y -- %T %z", localtime(&lclock));
46 >  }
47 >
48 >  return buf;
49 > }
50  
51 < char *
52 < date(time_t lclock)
51 > const char *
52 > date_iso8601(time_t lclock)
53   {
54 <  static char buf[80], plus;
55 <  struct tm *lt, *gm;
60 <  struct tm gmbuf;
61 <  int minswest;
54 >  static char buf[MAX_DATE_STRING];
55 >  static time_t lclock_last;
56  
57 <  if (!lclock)
57 >  if (!lclock)
58      lclock = CurrentTime;
59 <  gm = gmtime(&lclock);
60 <  memcpy(&gmbuf, gm, sizeof(gmbuf));
61 <  gm = &gmbuf;
62 <  lt = localtime(&lclock);
63 <
64 <  /*
65 <   * There is unfortunately no clean portable way to extract time zone
72 <   * offset information, so do ugly things.
73 <   */
74 <  minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
75 <
76 <  if (lt->tm_yday != gm->tm_yday)
77 <  {
78 <    if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
79 <        (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
80 <      minswest -= 24 * 60;
81 <    else
82 <      minswest += 24 * 60;
83 <  }
84 <
85 <  plus = (minswest > 0) ? '-' : '+';
86 <  if (minswest < 0)
87 <    minswest = -minswest;
88 <
89 <  ircsprintf(buf, "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
90 <             weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday,
91 <             lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
92 <             plus, minswest/60, minswest%60);
59 >
60 >  if (lclock_last != lclock)
61 >  {
62 >    lclock_last = lclock;
63 >    strftime(buf, sizeof(buf), "%FT%T%z", localtime(&lclock));
64 >  }
65 >
66    return buf;
67   }
68  
69 + /*
70 + * myctime - This is like standard ctime()-function, but it zaps away
71 + *   the newline from the end of that string. Also, it takes
72 + *   the time value as parameter, instead of pointer to it.
73 + *   Note that it is necessary to copy the string to alternate
74 + *   buffer (who knows how ctime() implements it, maybe it statically
75 + *   has newline there and never 'refreshes' it -- zapping that
76 + *   might break things in other places...)
77 + *
78 + *
79 + * Thu Nov 24 18:22:48 1986
80 + */
81   const char *
82 < smalldate(time_t lclock)
82 > date_ctime(time_t lclock)
83   {
84    static char buf[MAX_DATE_STRING];
85 <  struct tm *lt, *gm;
101 <  struct tm gmbuf;
85 >  static time_t lclock_last;
86  
87    if (!lclock)
88      lclock = CurrentTime;
89  
90 <  gm = gmtime(&lclock);
91 <  memcpy(&gmbuf, gm, sizeof(gmbuf));
92 <  gm = &gmbuf;
93 <  lt = localtime(&lclock);
94 <  
111 <  ircsprintf(buf, "%d/%d/%d %02d.%02d",
112 <             lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
113 <             lt->tm_hour, lt->tm_min);
90 >  if (lclock_last != lclock)
91 >  {
92 >    lclock_last = lclock;
93 >    strftime(buf, sizeof(buf), "%a %b %-e %T %Y", localtime(&lclock));
94 >  }
95  
96    return buf;
97   }
98  
99 + const char *
100 + time_dissect(time_t duration)
101 + {
102 +  static char buf[32];  /* 32 = sizeof("9999999999999999 days, 23:59:59") */
103 +  unsigned int days = 0, hours = 0, minutes = 0, seconds = 0;
104 +
105 +  while (duration >= 60 * 60 * 24)
106 +  {
107 +    duration -= 60 * 60 * 24;
108 +    ++days;
109 +  }
110 +
111 +  while (duration >= 60 * 60)
112 +  {
113 +    duration -= 60 * 60;
114 +    ++hours;
115 +  }
116 +
117 +  while (duration >= 60)
118 +  {
119 +    duration -= 60;
120 +    ++minutes;
121 +  }
122 +
123 +  seconds = duration;
124 +
125 +  snprintf(buf, sizeof(buf), "%u day%s, %02u:%02u:%02u",
126 +           days, days == 1 ? "" : "s", hours, minutes, seconds);
127 +  return buf;
128 + }
129 +
130   #ifdef HAVE_LIBCRYPTO
131 < char *
131 > const char *
132   ssl_get_cipher(const SSL *ssl)
133   {
134 <  static char buffer[IRCD_BUFSIZE / 4];
134 >  static char buffer[IRCD_BUFSIZE];
135    int bits = 0;
136  
137    SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
138  
139 <  snprintf(buffer, sizeof(buffer), "%s %s-%d", SSL_get_version(ssl),
139 >  snprintf(buffer, sizeof(buffer), "%s-%s-%d", SSL_get_version(ssl),
140             SSL_get_cipher(ssl), bits);
129  
141    return buffer;
142   }
143   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)