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-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 |
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 |
< |
* $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 |
> |
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 *weekdays[] = |
40 |
> |
static const char *const weekdays[] = |
41 |
|
{ |
42 |
|
"Sunday", "Monday", "Tuesday", "Wednesday", |
43 |
|
"Thursday", "Friday", "Saturday" |
44 |
|
}; |
45 |
|
|
46 |
< |
char * |
47 |
< |
date(time_t lclock) |
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) |
54 |
> |
if (!lclock) |
55 |
|
lclock = CurrentTime; |
56 |
+ |
|
57 |
|
gm = gmtime(&lclock); |
58 |
|
memcpy(&gmbuf, gm, sizeof(gmbuf)); |
59 |
|
gm = &gmbuf; |
78 |
|
if (minswest < 0) |
79 |
|
minswest = -minswest; |
80 |
|
|
81 |
< |
ircsprintf(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); |
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 |
|
|
97 |
|
|
98 |
|
gm = gmtime(&lclock); |
99 |
|
memcpy(&gmbuf, gm, sizeof(gmbuf)); |
100 |
< |
gm = &gmbuf; |
100 |
> |
gm = &gmbuf; |
101 |
|
lt = localtime(&lclock); |
110 |
– |
|
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); |
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 |
< |
char * |
136 |
> |
const char * |
137 |
|
ssl_get_cipher(const SSL *ssl) |
138 |
|
{ |
139 |
< |
static char buffer[IRCD_BUFSIZE / 4]; |
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); |
129 |
– |
|
146 |
|
return buffer; |
147 |
|
} |
148 |
|
#endif |