ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/misc.c
Revision: 2301
Committed: Wed Jun 19 12:21:28 2013 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/s_misc.c
File size: 3339 byte(s)
Log Message:
- s_misc.c: constify weekdays[], months[]

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * s_misc.c: Yet another miscellaneous functions file.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "s_misc.h"
27 #include "client.h"
28 #include "irc_string.h"
29 #include "ircd.h"
30 #include "numeric.h"
31 #include "irc_res.h"
32 #include "fdlist.h"
33 #include "s_bsd.h"
34 #include "conf.h"
35 #include "s_serv.h"
36 #include "send.h"
37 #include "memory.h"
38
39
40 static const char *const months[] =
41 {
42 "January", "February", "March", "April",
43 "May", "June", "July", "August",
44 "September", "October", "November","December"
45 };
46
47 static const char *const weekdays[] =
48 {
49 "Sunday", "Monday", "Tuesday", "Wednesday",
50 "Thursday", "Friday", "Saturday"
51 };
52
53 const char *
54 date(time_t lclock)
55 {
56 static char buf[80], plus;
57 struct tm *lt, *gm;
58 struct tm gmbuf;
59 int minswest;
60
61 if (!lclock)
62 lclock = CurrentTime;
63 gm = gmtime(&lclock);
64 memcpy(&gmbuf, gm, sizeof(gmbuf));
65 gm = &gmbuf;
66 lt = localtime(&lclock);
67
68 /*
69 * There is unfortunately no clean portable way to extract time zone
70 * offset information, so do ugly things.
71 */
72 minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
73
74 if (lt->tm_yday != gm->tm_yday)
75 {
76 if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
77 (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
78 minswest -= 24 * 60;
79 else
80 minswest += 24 * 60;
81 }
82
83 plus = (minswest > 0) ? '-' : '+';
84 if (minswest < 0)
85 minswest = -minswest;
86
87 snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
88 weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday,
89 lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
90 plus, minswest/60, minswest%60);
91 return buf;
92 }
93
94 const char *
95 smalldate(time_t lclock)
96 {
97 static char buf[MAX_DATE_STRING];
98 struct tm *lt, *gm;
99 struct tm gmbuf;
100
101 if (!lclock)
102 lclock = CurrentTime;
103
104 gm = gmtime(&lclock);
105 memcpy(&gmbuf, gm, sizeof(gmbuf));
106 gm = &gmbuf;
107 lt = localtime(&lclock);
108
109 snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
110 lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
111 lt->tm_hour, lt->tm_min);
112
113 return buf;
114 }
115
116 #ifdef HAVE_LIBCRYPTO
117 const char *
118 ssl_get_cipher(const SSL *ssl)
119 {
120 static char buffer[IRCD_BUFSIZE / 4];
121 int bits = 0;
122
123 SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
124
125 snprintf(buffer, sizeof(buffer), "%s %s-%d", SSL_get_version(ssl),
126 SSL_get_cipher(ssl), bits);
127
128 return buffer;
129 }
130 #endif

Properties

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