ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/libio/misc/misc.c
Revision: 65
Committed: Mon Oct 3 23:33:16 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 3784 byte(s)
Log Message:
- removed external references from libio/misc
- imported s_misc.c to libio, moved CurrentTime there

File Contents

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

Properties

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