ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/misc.c
Revision: 6423
Committed: Wed Aug 26 18:55:59 2015 UTC (11 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 3959 byte(s)
Log Message:
- misc.c: style corrections

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 5347 * Copyright (c) 1997-2015 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file s_misc.c
23     * \brief Yet another miscellaneous functions file.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 3347 #include "misc.h"
29 adx 30 #include "irc_string.h"
30     #include "ircd.h"
31    
32    
33 michael 2301 static const char *const months[] =
34 adx 30 {
35 michael 6423 "January", "February", "March", "April",
36     "May", "June", "July", "August",
37     "September", "October", "November", "December"
38 adx 30 };
39    
40 michael 2301 static const char *const weekdays[] =
41 adx 30 {
42     "Sunday", "Monday", "Tuesday", "Wednesday",
43     "Thursday", "Friday", "Saturday"
44     };
45    
46 michael 1847 const char *
47 michael 2916 date(time_t lclock)
48 adx 30 {
49     static char buf[80], plus;
50 michael 6423 static time_t lclock_last;
51 adx 30 struct tm *lt, *gm;
52     struct tm gmbuf;
53     int minswest;
54    
55 michael 2916 if (!lclock)
56 adx 30 lclock = CurrentTime;
57 michael 3244
58 michael 6413 if (lclock_last == lclock)
59     return buf;
60    
61     lclock_last = lclock;
62 adx 30 gm = gmtime(&lclock);
63     memcpy(&gmbuf, gm, sizeof(gmbuf));
64     gm = &gmbuf;
65     lt = localtime(&lclock);
66    
67     /*
68     * There is unfortunately no clean portable way to extract time zone
69     * offset information, so do ugly things.
70     */
71     minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
72    
73     if (lt->tm_yday != gm->tm_yday)
74     {
75     if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
76     (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
77     minswest -= 24 * 60;
78     else
79     minswest += 24 * 60;
80     }
81    
82     plus = (minswest > 0) ? '-' : '+';
83     if (minswest < 0)
84     minswest = -minswest;
85    
86 michael 1233 snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
87 michael 6423 weekdays[lt->tm_wday], months[lt->tm_mon], lt->tm_mday,
88 michael 1233 lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
89     plus, minswest/60, minswest%60);
90 adx 30 return buf;
91     }
92    
93     const char *
94 michael 6415 date_iso8601(time_t lclock)
95     {
96     static char buf[MAX_DATE_STRING];
97     static time_t lclock_last;
98    
99     if (!lclock)
100     lclock = CurrentTime;
101    
102     if (lclock_last != lclock)
103     {
104     lclock_last = lclock;
105     strftime(buf, sizeof(buf), "%FT%H:%M:%S%z", localtime(&lclock));
106     }
107    
108     return buf;
109     }
110    
111 michael 2970 /*
112     * myctime - This is like standard ctime()-function, but it zaps away
113     * the newline from the end of that string. Also, it takes
114     * the time value as parameter, instead of pointer to it.
115     * Note that it is necessary to copy the string to alternate
116     * buffer (who knows how ctime() implements it, maybe it statically
117     * has newline there and never 'refreshes' it -- zapping that
118     * might break things in other places...)
119     *
120     *
121     * Thu Nov 24 18:22:48 1986
122     */
123     const char *
124 michael 6413 myctime(time_t lclock)
125 michael 2970 {
126 michael 6423 static char buf[MAX_DATE_STRING];
127     static time_t lclock_last;
128 michael 2970 char *p;
129    
130 michael 6419 if (!lclock)
131     lclock = CurrentTime;
132    
133 michael 6413 if (lclock_last == lclock)
134     return buf;
135 michael 2970
136 michael 6413 lclock_last = lclock;
137     strlcpy(buf, ctime(&lclock), sizeof(buf));
138    
139 michael 3244 if ((p = strchr(buf, '\n')))
140 michael 2970 *p = '\0';
141     return buf;
142     }
143    
144 adx 30 #ifdef HAVE_LIBCRYPTO
145 michael 1847 const char *
146 michael 967 ssl_get_cipher(const SSL *ssl)
147 adx 30 {
148 michael 3455 static char buffer[IRCD_BUFSIZE];
149 michael 967 int bits = 0;
150 adx 30
151     SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
152    
153 michael 4914 snprintf(buffer, sizeof(buffer), "%s-%s-%d", SSL_get_version(ssl),
154 michael 967 SSL_get_cipher(ssl), bits);
155 adx 30 return buffer;
156     }
157     #endif

Properties

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