ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/misc.c
Revision: 1592
Committed: Sat Oct 27 21:02:32 2012 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/s_misc.c
File size: 3340 byte(s)
Log Message:
- Second time's the charm? Moving svnroot/ircd-hybrid-8 to
  svnroot/ircd-hybrid/trunk

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 "client.h"
28     #include "irc_string.h"
29     #include "sprintf_irc.h"
30     #include "ircd.h"
31     #include "numeric.h"
32     #include "irc_res.h"
33     #include "fdlist.h"
34     #include "s_bsd.h"
35 michael 1309 #include "conf.h"
36 adx 30 #include "s_serv.h"
37     #include "send.h"
38     #include "memory.h"
39    
40    
41     static const char *months[] =
42     {
43     "January", "February", "March", "April",
44     "May", "June", "July", "August",
45     "September", "October", "November","December"
46     };
47    
48     static const char *weekdays[] =
49     {
50     "Sunday", "Monday", "Tuesday", "Wednesday",
51     "Thursday", "Friday", "Saturday"
52     };
53    
54     char *
55     date(time_t lclock)
56     {
57     static char buf[80], plus;
58     struct tm *lt, *gm;
59     struct tm gmbuf;
60     int minswest;
61    
62     if (!lclock)
63     lclock = CurrentTime;
64     gm = gmtime(&lclock);
65     memcpy(&gmbuf, gm, sizeof(gmbuf));
66     gm = &gmbuf;
67     lt = localtime(&lclock);
68    
69     /*
70     * There is unfortunately no clean portable way to extract time zone
71     * offset information, so do ugly things.
72     */
73     minswest = (gm->tm_hour - lt->tm_hour) * 60 + (gm->tm_min - lt->tm_min);
74    
75     if (lt->tm_yday != gm->tm_yday)
76     {
77     if ((lt->tm_yday > gm->tm_yday && lt->tm_year == gm->tm_year) ||
78     (lt->tm_yday < gm->tm_yday && lt->tm_year != gm->tm_year))
79     minswest -= 24 * 60;
80     else
81     minswest += 24 * 60;
82     }
83    
84     plus = (minswest > 0) ? '-' : '+';
85     if (minswest < 0)
86     minswest = -minswest;
87    
88 michael 1233 snprintf(buf, sizeof(buf), "%s %s %d %d -- %02u:%02u:%02u %c%02u:%02u",
89     weekdays[lt->tm_wday], months[lt->tm_mon],lt->tm_mday,
90     lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec,
91     plus, minswest/60, minswest%60);
92 adx 30 return buf;
93     }
94    
95     const char *
96     smalldate(time_t lclock)
97     {
98     static char buf[MAX_DATE_STRING];
99     struct tm *lt, *gm;
100     struct tm gmbuf;
101    
102     if (!lclock)
103     lclock = CurrentTime;
104    
105     gm = gmtime(&lclock);
106     memcpy(&gmbuf, gm, sizeof(gmbuf));
107     gm = &gmbuf;
108     lt = localtime(&lclock);
109    
110 michael 1233 snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
111     lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
112     lt->tm_hour, lt->tm_min);
113 adx 30
114     return buf;
115     }
116    
117     #ifdef HAVE_LIBCRYPTO
118     char *
119 michael 967 ssl_get_cipher(const SSL *ssl)
120 adx 30 {
121 michael 967 static char buffer[IRCD_BUFSIZE / 4];
122     int bits = 0;
123 adx 30
124     SSL_CIPHER_get_bits(SSL_get_current_cipher(ssl), &bits);
125    
126 michael 967 snprintf(buffer, sizeof(buffer), "%s %s-%d", SSL_get_version(ssl),
127     SSL_get_cipher(ssl), bits);
128 adx 30
129     return buffer;
130     }
131     #endif

Properties

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