1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
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 |
|
54 |
if (!lclock) |
55 |
lclock = CurrentTime; |
56 |
|
57 |
gm = gmtime(&lclock); |
58 |
memcpy(&gmbuf, gm, sizeof(gmbuf)); |
59 |
gm = &gmbuf; |
60 |
lt = localtime(&lclock); |
61 |
|
62 |
/* |
63 |
* There is unfortunately no clean portable way to extract time zone |
64 |
* offset information, so do ugly things. |
65 |
*/ |
66 |
minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min); |
67 |
|
68 |
if (lt->tm_yday != gm->tm_yday) |
69 |
{ |
70 |
if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) || |
71 |
(lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year)) |
72 |
minswest -= 24 * 60; |
73 |
else |
74 |
minswest += 24 * 60; |
75 |
} |
76 |
|
77 |
plus = (minswest > 0) ? '-' : '+'; |
78 |
if (minswest < 0) |
79 |
minswest = -minswest; |
80 |
|
81 |
snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u", |
82 |
weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday, |
83 |
lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec, |
84 |
plus, minswest/60, minswest%60); |
85 |
return buf; |
86 |
} |
87 |
|
88 |
const char * |
89 |
smalldate(time_t lclock) |
90 |
{ |
91 |
static char buf[MAX_DATE_STRING]; |
92 |
struct tm *lt, *gm; |
93 |
struct tm gmbuf; |
94 |
|
95 |
if (!lclock) |
96 |
lclock = CurrentTime; |
97 |
|
98 |
gm = gmtime(&lclock); |
99 |
memcpy(&gmbuf, gm, sizeof(gmbuf)); |
100 |
gm = &gmbuf; |
101 |
lt = localtime(&lclock); |
102 |
|
103 |
snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d", |
104 |
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, |
105 |
lt->tm_hour, lt->tm_min); |
106 |
|
107 |
return buf; |
108 |
} |
109 |
|
110 |
/* |
111 |
* myctime - This is like standard ctime()-function, but it zaps away |
112 |
* the newline from the end of that string. Also, it takes |
113 |
* the time value as parameter, instead of pointer to it. |
114 |
* Note that it is necessary to copy the string to alternate |
115 |
* buffer (who knows how ctime() implements it, maybe it statically |
116 |
* has newline there and never 'refreshes' it -- zapping that |
117 |
* might break things in other places...) |
118 |
* |
119 |
* |
120 |
* Thu Nov 24 18:22:48 1986 |
121 |
*/ |
122 |
const char * |
123 |
myctime(time_t value) |
124 |
{ |
125 |
static char buf[32]; |
126 |
char *p; |
127 |
|
128 |
strlcpy(buf, ctime(&value), sizeof(buf)); |
129 |
|
130 |
if ((p = strchr(buf, '\n'))) |
131 |
*p = '\0'; |
132 |
return buf; |
133 |
} |
134 |
|
135 |
#ifdef HAVE_LIBCRYPTO |
136 |
const char * |
137 |
ssl_get_cipher(const SSL *ssl) |
138 |
{ |
139 |
static char buffer[IRCD_BUFSIZE]; |
140 |
int bits = 0; |
141 |
|
142 |
SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits); |
143 |
|
144 |
snprintf(buffer, sizeof(buffer), "%s %s-%d", SSL_get_version(ssl), |
145 |
SSL_get_cipher(ssl), bits); |
146 |
return buffer; |
147 |
} |
148 |
#endif |