/[svn]/ircd-hybrid/trunk/src/misc.c
ViewVC logotype

Annotation of /ircd-hybrid/trunk/src/misc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3455 - (hide annotations)
Thu May 1 19:39:12 2014 UTC (6 years, 6 months ago) by michael
File MIME type: text/x-chdr
File size: 3825 byte(s)
- misc.c:ssl_get_ciper(): get rid of this magic IRCD_BUFSIZE/4.
  Use IRCD_BUFSIZE instead.

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 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     "January", "February", "March", "April",
36     "May", "June", "July", "August",
37     "September", "October", "November","December"
38     };
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     struct tm *lt, *gm;
51     struct tm gmbuf;
52     int minswest;
53    
54 michael 2916 if (!lclock)
55 adx 30 lclock = CurrentTime;
56 michael 3244
57 adx 30 gm = gmtime(&lclock);
58     memcpy(&gmbuf, gm, sizeof(gmbuf));
59     gm = &gmbuf;
60     lt = localtime(&lclock);
61    
62     /*
63     * There is unfortunately no clean portable way to extract time zone
64     * offset information, so do ugly things.
65     */
66     minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
67    
68     if (lt->tm_yday != gm->tm_yday)
69     {
70     if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
71     (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
72     minswest -= 24 * 60;
73     else
74     minswest += 24 * 60;
75     }
76    
77     plus = (minswest > 0) ? '-' : '+';
78     if (minswest < 0)
79     minswest = -minswest;
80    
81 michael 1233 snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
82     weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday,
83     lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
84     plus, minswest/60, minswest%60);
85 adx 30 return buf;
86     }
87    
88     const char *
89     smalldate(time_t lclock)
90     {
91     static char buf[MAX_DATE_STRING];
92     struct tm *lt, *gm;
93     struct tm gmbuf;
94    
95     if (!lclock)
96     lclock = CurrentTime;
97    
98     gm = gmtime(&lclock);
99     memcpy(&gmbuf, gm, sizeof(gmbuf));
100 michael 2916 gm = &gmbuf;
101 adx 30 lt = localtime(&lclock);
102 michael 2916
103 michael 1233 snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
104     lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
105     lt->tm_hour, lt->tm_min);
106 adx 30
107     return buf;
108     }
109    
110 michael 2970 /*
111     * myctime - This is like standard ctime()-function, but it zaps away
112     * the newline from the end of that string. Also, it takes
113     * the time value as parameter, instead of pointer to it.
114     * Note that it is necessary to copy the string to alternate
115     * buffer (who knows how ctime() implements it, maybe it statically
116     * has newline there and never 'refreshes' it -- zapping that
117     * might break things in other places...)
118     *
119     *
120     * Thu Nov 24 18:22:48 1986
121     */
122     const char *
123     myctime(time_t value)
124     {
125     static char buf[32];
126     char *p;
127    
128     strlcpy(buf, ctime(&value), sizeof(buf));
129    
130 michael 3244 if ((p = strchr(buf, '\n')))
131 michael 2970 *p = '\0';
132     return buf;
133     }
134    
135 adx 30 #ifdef HAVE_LIBCRYPTO
136 michael 1847 const char *
137 michael 967 ssl_get_cipher(const SSL *ssl)
138 adx 30 {
139 michael 3455 static char buffer[IRCD_BUFSIZE];
140 michael 967 int bits = 0;
141 adx 30
142     SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
143    
144 michael 967 snprintf(buffer, sizeof(buffer), "%s %s-%d", SSL_get_version(ssl),
145     SSL_get_cipher(ssl), bits);
146 adx 30 return buffer;
147     }
148     #endif

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28