ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/misc.c
Revision: 6422
Committed: Wed Aug 26 18:12:52 2015 UTC (10 years ago) by michael
Content type: text/x-csrc
File size: 3942 byte(s)
Log Message:
- Get rid of smalldate() and replace all instances of it with date_iso8601()

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 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
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
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 "misc.h"
29 #include "irc_string.h"
30 #include "ircd.h"
31
32
33 static const char *const months[] =
34 {
35 "January", "February", "March", "April",
36 "May", "June", "July", "August",
37 "September", "October", "November","December"
38 };
39
40 static const char *const weekdays[] =
41 {
42 "Sunday", "Monday", "Tuesday", "Wednesday",
43 "Thursday", "Friday", "Saturday"
44 };
45
46 const char *
47 date(time_t lclock)
48 {
49 static char buf[80], plus;
50 struct tm *lt, *gm;
51 struct tm gmbuf;
52 int minswest;
53 static time_t lclock_last;
54
55 if (!lclock)
56 lclock = CurrentTime;
57
58 if (lclock_last == lclock)
59 return buf;
60
61 lclock_last = lclock;
62 gm = gmtime(&lclock);
63 memcpy(&gmbuf, gm, sizeof(gmbuf));
64 gm = &gmbuf;
65 lt = localtime(&lclock);
66
67 /*
68 * There is unfortunately no clean portable way to extract time zone
69 * offset information, so do ugly things.
70 */
71 minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
72
73 if (lt->tm_yday != gm->tm_yday)
74 {
75 if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
76 (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
77 minswest -= 24 * 60;
78 else
79 minswest += 24 * 60;
80 }
81
82 plus = (minswest > 0) ? '-' : '+';
83 if (minswest < 0)
84 minswest = -minswest;
85
86 snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
87 weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday,
88 lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
89 plus, minswest/60, minswest%60);
90 return buf;
91 }
92
93 const char *
94 date_iso8601(time_t lclock)
95 {
96 static char buf[MAX_DATE_STRING];
97 static time_t lclock_last;
98
99 if (!lclock)
100 lclock = CurrentTime;
101
102 if (lclock_last != lclock)
103 {
104 lclock_last = lclock;
105 strftime(buf, sizeof(buf), "%FT%H:%M:%S%z", localtime(&lclock));
106 }
107
108 return buf;
109 }
110
111 /*
112 * myctime - This is like standard ctime()-function, but it zaps away
113 * the newline from the end of that string. Also, it takes
114 * the time value as parameter, instead of pointer to it.
115 * Note that it is necessary to copy the string to alternate
116 * buffer (who knows how ctime() implements it, maybe it statically
117 * has newline there and never 'refreshes' it -- zapping that
118 * might break things in other places...)
119 *
120 *
121 * Thu Nov 24 18:22:48 1986
122 */
123 const char *
124 myctime(time_t lclock)
125 {
126 static char buf[32];
127 char *p;
128 static time_t lclock_last;
129
130 if (!lclock)
131 lclock = CurrentTime;
132
133 if (lclock_last == lclock)
134 return buf;
135
136 lclock_last = lclock;
137 strlcpy(buf, ctime(&lclock), sizeof(buf));
138
139 if ((p = strchr(buf, '\n')))
140 *p = '\0';
141 return buf;
142 }
143
144 #ifdef HAVE_LIBCRYPTO
145 const char *
146 ssl_get_cipher(const SSL *ssl)
147 {
148 static char buffer[IRCD_BUFSIZE];
149 int bits = 0;
150
151 SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
152
153 snprintf(buffer, sizeof(buffer), "%s-%s-%d", SSL_get_version(ssl),
154 SSL_get_cipher(ssl), bits);
155 return buffer;
156 }
157 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision