Commit f30b97dc authored by Jan Köster's avatar Jan Köster
Browse files

test

parent f0d4a009
Loading
Loading
Loading
Loading
+1 −6
Changes for plugins/content/content.cpp: 1 added line, 6 removed lines.
Original line number Diff line number Diff line
@@ -825,13 +825,8 @@ namespace blogi {

                try {
                    auto now = std::chrono::system_clock::now();
#if defined(FreeBSD) || defined(__APPLE__)
                    auto local_now = date::zoned_time{date::current_zone(), now};
#elif !defined(_LIBCPP_VERSION)
                    auto local_now = std::chrono::zoned_time{std::chrono::current_zone(), now};
#endif
                    try {
                        time_str = std::format("{:%a %b %d %H:%M:%S %Y %z}", now);
                        time_str = std::format("{:%Y-%m-%d}", now);
                    } catch (...) {
                        throw excep[libhttppp::HTTPException::Error] << "Cannot get Time (std::format/put_time failed)!";
                    }
+22 −7
Changes for src/session.cpp: 22 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ blogi::Session::~Session(){
void blogi::Session::_initSession(){
    dbpp::SQL sessionSql;
    dbpp::SQL sessionDataSql;
    dbpp::SQL alterSql;
    dbpp::DBResult res;
    dbpp::SQL uuidTypeSql;
    const dbpp::SQL uuidType = _sessiondb.getUUIDType(uuidTypeSql);
@@ -55,7 +56,7 @@ void blogi::Session::_initSession(){
    sessionSql << "CREATE TABLE IF NOT EXISTS session("
    <<   "id " << uuidType << ","
    <<   "useragent text,"
    <<   "created date NOT NULL,"
    <<   "created timestamp NOT NULL,"
    <<   "PRIMARY KEY (id)"
    << ");";

@@ -68,6 +69,12 @@ void blogi::Session::_initSession(){

    _sessiondb.exec(sessionSql,res);
    _sessiondb.exec(sessionDataSql,res);

    // Keep existing installations compatible by upgrading DATE to TIMESTAMP where needed.
    dbpp::modifyColumn(alterSql, _sessiondb, "session", "created", "timestamp", "NOT NULL");
    try {
        _sessiondb.exec(alterSql, res);
    } catch (...) {}
}


@@ -80,15 +87,23 @@ const std::string &blogi::Session::createSession(std::string &buf,const std::str

    dbpp::SQL sql;
    dbpp::DBResult res;
    std::vector<char> sbuf;

    auto now = std::chrono::system_clock::now();
    // Use std::format to directly format the time point
    // The format string can be customized
    std::string ttmp = std::format("{:%a %b %d %T %Y}", now);
    // Use an explicit UTC timestamp literal to keep behavior deterministic across DB engines and replication setups.
    const auto now = std::chrono::system_clock::now();
    const std::time_t now_tt = std::chrono::system_clock::to_time_t(now);
    std::tm utc_tm{};
#ifdef _WIN32
    gmtime_s(&utc_tm, &now_tt);
#else
    gmtime_r(&now_tt, &utc_tm);
#endif
    char date_buf[20] = {0};
    std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &utc_tm);

    sql << "INSERT INTO session (id,useragent,created) VALUES ('"
          << sessionid.c_str() << "','" << useragent.c_str() << "','"
          << ttmp.c_str() << "');";
        << sessionid.c_str() << "','" << sql.escaped(sbuf, useragent.c_str()) << "','"
        << date_buf << "');";
    try{
        _sessiondb.exec(sql, res);
    }catch(char *err){