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 |
const char * |
34 |
date(time_t lclock) |
35 |
{ |
36 |
static char buf[80]; |
37 |
static time_t lclock_last; |
38 |
|
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 |
const char * |
52 |
date_iso8601(time_t lclock) |
53 |
{ |
54 |
static char buf[MAX_DATE_STRING]; |
55 |
static time_t lclock_last; |
56 |
|
57 |
if (!lclock) |
58 |
lclock = CurrentTime; |
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 |
myctime(time_t lclock) |
83 |
{ |
84 |
static char buf[MAX_DATE_STRING]; |
85 |
static time_t lclock_last; |
86 |
char *p; |
87 |
|
88 |
if (!lclock) |
89 |
lclock = CurrentTime; |
90 |
|
91 |
if (lclock_last == lclock) |
92 |
return buf; |
93 |
|
94 |
lclock_last = lclock; |
95 |
strlcpy(buf, ctime(&lclock), sizeof(buf)); |
96 |
|
97 |
if ((p = strchr(buf, '\n'))) |
98 |
*p = '\0'; |
99 |
return buf; |
100 |
} |
101 |
|
102 |
#ifdef HAVE_LIBCRYPTO |
103 |
const char * |
104 |
ssl_get_cipher(const SSL *ssl) |
105 |
{ |
106 |
static char buffer[IRCD_BUFSIZE]; |
107 |
int bits = 0; |
108 |
|
109 |
SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits); |
110 |
|
111 |
snprintf(buffer, sizeof(buffer), "%s-%s-%d", SSL_get_version(ssl), |
112 |
SSL_get_cipher(ssl), bits); |
113 |
return buffer; |
114 |
} |
115 |
#endif |