ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/misc.c
Revision: 3244
Committed: Sun Mar 30 16:56:13 2014 UTC (10 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/s_misc.c
File size: 4008 byte(s)
Log Message:
- s_misc.c: mostly style cleanups

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 2916 * Copyright (c) 1997-2014 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     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * 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     #include "s_misc.h"
29     #include "client.h"
30     #include "irc_string.h"
31     #include "ircd.h"
32     #include "numeric.h"
33     #include "irc_res.h"
34     #include "fdlist.h"
35     #include "s_bsd.h"
36 michael 1309 #include "conf.h"
37 adx 30 #include "s_serv.h"
38     #include "send.h"
39     #include "memory.h"
40    
41    
42 michael 2301 static const char *const months[] =
43 adx 30 {
44     "January", "February", "March", "April",
45     "May", "June", "July", "August",
46     "September", "October", "November","December"
47     };
48    
49 michael 2301 static const char *const weekdays[] =
50 adx 30 {
51     "Sunday", "Monday", "Tuesday", "Wednesday",
52     "Thursday", "Friday", "Saturday"
53     };
54    
55 michael 1847 const char *
56 michael 2916 date(time_t lclock)
57 adx 30 {
58     static char buf[80], plus;
59     struct tm *lt, *gm;
60     struct tm gmbuf;
61     int minswest;
62    
63 michael 2916 if (!lclock)
64 adx 30 lclock = CurrentTime;
65 michael 3244
66 adx 30 gm = gmtime(&lclock);
67     memcpy(&gmbuf, gm, sizeof(gmbuf));
68     gm = &gmbuf;
69     lt = localtime(&lclock);
70    
71     /*
72     * There is unfortunately no clean portable way to extract time zone
73     * offset information, so do ugly things.
74     */
75     minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
76    
77     if (lt->tm_yday != gm->tm_yday)
78     {
79     if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
80     (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
81     minswest -= 24 * 60;
82     else
83     minswest += 24 * 60;
84     }
85    
86     plus = (minswest > 0) ? '-' : '+';
87     if (minswest < 0)
88     minswest = -minswest;
89    
90 michael 1233 snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
91     weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday,
92     lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
93     plus, minswest/60, minswest%60);
94 adx 30 return buf;
95     }
96    
97     const char *
98     smalldate(time_t lclock)
99     {
100     static char buf[MAX_DATE_STRING];
101     struct tm *lt, *gm;
102     struct tm gmbuf;
103    
104     if (!lclock)
105     lclock = CurrentTime;
106    
107     gm = gmtime(&lclock);
108     memcpy(&gmbuf, gm, sizeof(gmbuf));
109 michael 2916 gm = &gmbuf;
110 adx 30 lt = localtime(&lclock);
111 michael 2916
112 michael 1233 snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
113     lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
114     lt->tm_hour, lt->tm_min);
115 adx 30
116     return buf;
117     }
118    
119 michael 2970 /*
120     * myctime - This is like standard ctime()-function, but it zaps away
121     * the newline from the end of that string. Also, it takes
122     * the time value as parameter, instead of pointer to it.
123     * Note that it is necessary to copy the string to alternate
124     * buffer (who knows how ctime() implements it, maybe it statically
125     * has newline there and never 'refreshes' it -- zapping that
126     * might break things in other places...)
127     *
128     *
129     * Thu Nov 24 18:22:48 1986
130     */
131     const char *
132     myctime(time_t value)
133     {
134     static char buf[32];
135     char *p;
136    
137     strlcpy(buf, ctime(&value), 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 967 static char buffer[IRCD_BUFSIZE / 4];
149     int bits = 0;
150 adx 30
151     SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
152    
153 michael 967 snprintf(buffer, sizeof(buffer), "%s %s-%d", SSL_get_version(ssl),
154     SSL_get_cipher(ssl), bits);
155 adx 30 return buffer;
156     }
157     #endif

Properties

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