Skip to content

Commit ec95b29

Browse files
committed
Merge branch 'master' of github.com:gtkevemon/gtkevemon
2 parents 3dae617 + 6e837e6 commit ec95b29

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/api/evetime.cc

+20-8
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,39 @@ EveTime::get_local_time_string (void)
7272
/* ---------------------------------------------------------------- */
7373

7474
std::string
75-
EveTime::get_local_time_string (time_t time, bool slim)
75+
EveTime::get_time_string (struct tm *tm, bool slim)
7676
{
77+
// If we wind up with an invalid time, we don't want to crash,
78+
// so we return a string indicating something has gone wrong.
79+
if (!tm)
80+
{
81+
return "INVALID TIME";
82+
}
83+
7784
static ConfValuePtr lf = Config::conf.get_value("evetime.time_format");
7885
static ConfValuePtr sf = Config::conf.get_value("evetime.time_short_format");
7986

8087
char buffer[128];
81-
strftime(buffer, 128, (slim ? **sf : **lf).c_str(), ::localtime(&time));
88+
strftime(buffer, 128, (slim ? **sf : **lf).c_str(), tm);
8289
return std::string(buffer);
8390
}
8491

8592
/* ---------------------------------------------------------------- */
8693

8794
std::string
88-
EveTime::get_gm_time_string (time_t time, bool slim)
95+
EveTime::get_local_time_string (time_t time, bool slim)
8996
{
90-
static ConfValuePtr lf = Config::conf.get_value("evetime.time_format");
91-
static ConfValuePtr sf = Config::conf.get_value("evetime.time_short_format");
97+
struct tm tm;
98+
return EveTime::get_time_string(::localtime_r(&time, &tm), slim);
99+
}
92100

93-
char buffer[128];
94-
strftime(buffer, 128, (slim ? **sf : **lf).c_str(), ::gmtime(&time));
95-
return std::string(buffer);
101+
/* ---------------------------------------------------------------- */
102+
103+
std::string
104+
EveTime::get_gm_time_string (time_t time, bool slim)
105+
{
106+
struct tm tm;
107+
return EveTime::get_time_string(::gmtime_r(&time, &tm), slim);
96108
}
97109

98110
/* ---------------------------------------------------------------- */

src/api/evetime.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class EveTime
3030
static time_t timediff;
3131
static bool initialized;
3232

33+
static std::string get_time_string (struct tm *tm, bool slim);
34+
3335
public:
3436
/* Calculate the time difference from a string. */
3537
static void init_from_eveapi_string (std::string const& evetime);

src/net/networking.cc

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <iostream>
22
#include <openssl/err.h>
33

4+
#include "util/thread.h"
5+
46
#include "certificates.h"
57
#include "networking.h"
68

@@ -55,6 +57,22 @@ unload (void)
5557

5658
/* ---------------------------------------------------------------- */
5759

60+
static Semaphore *ssl_locks;
61+
62+
static void locking_callback(int mode, int type, const char *file, int line)
63+
{
64+
(void)file; (void)line;
65+
66+
if (mode & CRYPTO_LOCK)
67+
{
68+
ssl_locks[type].wait();
69+
}
70+
else
71+
{
72+
ssl_locks[type].post();
73+
}
74+
}
75+
5876
SSL_CTX*
5977
ssl_context (void)
6078
{
@@ -106,6 +124,11 @@ ssl_context (void)
106124
SSL_CTX_set_verify_depth(ctx, 2);
107125

108126
ssl_ctx = ctx;
127+
128+
/* Set up locks so that openssl is thread safe. */
129+
ssl_locks = new Semaphore[CRYPTO_num_locks()];
130+
CRYPTO_set_locking_callback(locking_callback);
131+
109132
return ssl_ctx;
110133
}
111134

0 commit comments

Comments
 (0)