ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/src/s_misc.c
Revision: 34
Committed: Sun Oct 2 21:05:51 2005 UTC (18 years, 5 months ago) by lusky
Content type: text/x-csrc
File size: 3954 byte(s)
Log Message:
create 7.2 branch, we can move/rename it as needed.


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 "common.h"
29 #include "irc_string.h"
30 #include "sprintf_irc.h"
31 #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"
40
41
42 static const char *months[] =
43 {
44 "January", "February", "March", "April",
45 "May", "June", "July", "August",
46 "September", "October", "November","December"
47 };
48
49 static const char *weekdays[] =
50 {
51 "Sunday", "Monday", "Tuesday", "Wednesday",
52 "Thursday", "Friday", "Saturday"
53 };
54
55 char *
56 date(time_t lclock)
57 {
58 static char buf[80], plus;
59 struct tm *lt, *gm;
60 struct tm gmbuf;
61 int minswest;
62
63 if (!lclock)
64 lclock = CurrentTime;
65 gm = gmtime(&lclock);
66 memcpy(&gmbuf, gm, sizeof(gmbuf));
67 gm = &gmbuf;
68 lt = localtime(&lclock);
69
70 /*
71 * There is unfortunately no clean portable way to extract time zone
72 * offset information, so do ugly things.
73 */
74 minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
75
76 if (lt->tm_yday != gm->tm_yday)
77 {
78 if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
79 (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
80 minswest -= 24 * 60;
81 else
82 minswest += 24 * 60;
83 }
84
85 plus = (minswest > 0) ? '-' : '+';
86 if (minswest < 0)
87 minswest = -minswest;
88
89 ircsprintf(buf, "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
90 weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday,
91 lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
92 plus, minswest/60, minswest%60);
93 return buf;
94 }
95
96 const char *
97 smalldate(time_t lclock)
98 {
99 static char buf[MAX_DATE_STRING];
100 struct tm *lt, *gm;
101 struct tm gmbuf;
102
103 if (!lclock)
104 lclock = CurrentTime;
105
106 gm = gmtime(&lclock);
107 memcpy(&gmbuf, gm, sizeof(gmbuf));
108 gm = &gmbuf;
109 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);
114
115 return buf;
116 }
117
118 /* small_file_date()
119 * Make a small YYYYMMDD formatted string suitable for a
120 * dated file stamp.
121 */
122 char *
123 small_file_date(time_t lclock)
124 {
125 static char timebuffer[MAX_DATE_STRING];
126 struct tm *tmptr;
127
128 if (!lclock)
129 time(&lclock);
130
131 tmptr = localtime(&lclock);
132 strftime(timebuffer, MAX_DATE_STRING, "%Y%m%d", tmptr);
133
134 return timebuffer;
135 }
136
137 #ifdef HAVE_LIBCRYPTO
138 char *
139 ssl_get_cipher(SSL *ssl)
140 {
141 static char buffer[128];
142 const char *name = NULL;
143 int bits;
144
145 switch (ssl->session->ssl_version)
146 {
147 case SSL2_VERSION:
148 name = "SSLv2";
149 break;
150
151 case SSL3_VERSION:
152 name = "SSLv3";
153 break;
154
155 case TLS1_VERSION:
156 name = "TLSv1";
157 break;
158
159 default:
160 name = "UNKNOWN";
161 }
162
163 SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
164
165 snprintf(buffer, sizeof(buffer), "%s %s-%d",
166 name, SSL_get_cipher(ssl), bits);
167
168 return buffer;
169 }
170 #endif

Properties

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