gcontini
2019-12-14 7c2489cc3dc798484e11a449fd0e305210de901b
fix codacy warnings
7个文件已修改
71 ■■■■■ 已修改文件
CONTRIBUTING.md 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
README.md 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/StringUtils.cpp 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/StringUtils.h 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/licensecc.cpp 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/limits/license_verifier.cpp 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/windows/signature_verifier.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CONTRIBUTING.md
@@ -79,9 +79,8 @@
*  In the pull request comment reference the issue you want to fix.
##### Don't
*  Don't reformat the code following your personal likes, it introduce a lot of "noise" and makes very hard to merge. Use the clang-format style provided at the base of the project.
*  Very large pull requests with few comments, no corresponding issue explaining what's it about will probably be rejected.
   *  We understand that the project is still in beta stage, however we would like to discuss it with you before we take project changing decision. Please contact the project maintainer at `contini.mailing[AT]gmail.com` if you have time and plan to do a large contribution.
   *  Even it it's in beta stage it's used ( _by some really courageous people!_ ) in production. We can't break current functionality, user established habits without documenting the change.
-   Don't reformat the code following your personal likes, it introduce a lot of "noise" and makes very hard to merge. Use the clang-format style provided at the base of the project.
-   Very large pull requests with few comments, no corresponding issue explaining what's it about will probably be rejected.
    -  We understand that the project is still in beta stage, however we would like to discuss it with you before we take project changing decision. Please contact the project maintainer at `contini.mailing[AT]gmail.com` if you have time and plan to do a large contribution.
    -  Even it it's in beta stage it's used ( _by some really courageous people!_ ) in production. We can't break current functionality, user established habits without documenting the change.
  
README.md
@@ -47,7 +47,7 @@
cd build
```
## on Linux
## build on Linux
```console
cmake .. -DCMAKE_INSTALL_PREFIX=../install
@@ -55,7 +55,7 @@
make install
```
## on Windows (with MSVC 2015)
## build on Windows (with MSVC 2015)
```console
cmake .. -G "Visual Studio 14 2015 Win64" -DBOOST_ROOT="{Folder where boost is}" -DCMAKE_INSTALL_PREFIX=../install
@@ -87,7 +87,6 @@
## How to use
The [examples](https://github.com/open-license-manager/examples) repository that shows various ways to integrate `open-licence-manager` into your project.
## How to contribute
The project is not dead but we take our time to answer. The best interaction you can have with us is through the issue system. Have a look to the [contribution guidelines](CONTRIBUTING.md)
src/library/base/StringUtils.cpp
@@ -40,26 +40,24 @@
    return cp;
}
time_t seconds_from_epoch(const char *timeString) {
time_t seconds_from_epoch(const string &timeString) {
    int year, month, day;
    tm tm;
    if (strlen(timeString) == 8) {
        const int nfield = sscanf(timeString, "%4d%2d%2d", &year, &month, &day);
    if (timeString.size() == 8) {
        const int nfield = sscanf(timeString.c_str(), "%4d%2d%2d", &year, &month, &day);
        if (nfield != 3) {
            throw invalid_argument("Date not recognized");
        }
    } else if (strlen(timeString) == 10) {
        const int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month,
                &day);
    } else if (timeString.size() == 10) {
        const int nfield = sscanf(timeString.c_str(), "%4d-%2d-%2d", &year, &month, &day);
        if (nfield != 3) {
            const int nfield = sscanf(timeString, "%4d/%2d/%2d", &year, &month,
                    &day);
            const int nfield = sscanf(timeString.c_str(), "%4d/%2d/%2d", &year, &month, &day);
            if (nfield != 3) {
                throw invalid_argument("Date not recognized");
                throw invalid_argument("Date [" + timeString + "] not recognized");
            }
        }
    } else {
        throw invalid_argument("Date not recognized");
        throw invalid_argument("Date [" + timeString + "] not recognized");
    }
    tm.tm_isdst = -1;
    tm.tm_year = year - 1900;
@@ -73,8 +71,7 @@
    return mktime(&tm);
}
const vector<string> split_string(const string &licensePositions,
        char splitchar) {
const vector<string> split_string(const string &licensePositions, char splitchar) {
    std::stringstream streamToSplit(licensePositions);
    std::string segment;
    std::vector<string> seglist;
@@ -86,8 +83,7 @@
}
const static regex iniSection("\\[.*?\\]");
const static regex b64(
        "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$");
const static regex b64("^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$");
FILE_FORMAT identify_format(const string &license) {
    FILE_FORMAT result = UNKNOWN;
@@ -99,4 +95,16 @@
    return result;
}
// strnln_s is not well supported and strlen is marked unsafe..
size_t mstrnlen_s(const char *szptr, size_t maxsize) {
    if (szptr == nullptr) {
        return 0;
    }
    size_t count = 0;
    while (*szptr++ && maxsize--) {
        count++;
    }
    return count;
}
} /* namespace license */
src/library/base/StringUtils.h
@@ -23,13 +23,16 @@
std::string toupper_copy(const std::string& lowercase);
time_t seconds_from_epoch(const char* s);
time_t seconds_from_epoch(const std::string& timeString);
/**
 * Split a string on a given character
 */
const std::vector<std::string> split_string(const std::string& stringToBeSplit, const char splitchar);
// strnln_s is not well supported and strlen is marked unsafe..
size_t mstrnlen_s(const char* szptr, size_t maxsize);
typedef enum {
    INI, BASE64, UNKNOWN
} FILE_FORMAT;
src/library/licensecc.cpp
@@ -5,8 +5,10 @@
// Copyright   : BSD
//============================================================================
#define __STDC_WANT_LIB_EXT1__ 1
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstring>
#include <iostream>
@@ -16,6 +18,7 @@
#include <licensecc_properties.h>
#include "limits/license_verifier.hpp"
#include "base/StringUtils.h"
#include "LicenseReader.hpp"
#include "pc-identifiers.h"
@@ -53,8 +56,10 @@
    const license::LicenseReader lr = license::LicenseReader(licenseLocation);
    vector<license::FullLicenseInfo> licenses;
    string project;
    if (callerInformation != nullptr && strlen(callerInformation->project_name) > 0) {
        project = string(callerInformation->project_name);
    size_t str_size;
    if (callerInformation != nullptr &&
        (str_size = license::mstrnlen_s(callerInformation->project_name, sizeof callerInformation->project_name)) > 0) {
        project = string(callerInformation->project_name, str_size);
    } else {
        project = string(LCC_PROJECT_NAME);
    }
src/library/limits/license_verifier.cpp
@@ -38,7 +38,7 @@
    const time_t now = time(nullptr);
    auto expiry = licInfo.m_limits.find(PARAM_EXPIRY_DATE);
    if (expiry != licInfo.m_limits.end()) {
        if (seconds_from_epoch(expiry->second.c_str()) < now) {
        if (seconds_from_epoch(expiry->second) < now) {
            /*
                        eventRegistryOut.addEvent(PRODUCT_EXPIRED, source.c_str(),
                                string("Expired on: " + this->to_date).c_str());*/
@@ -48,7 +48,7 @@
    }
    auto start_date = licInfo.m_limits.find(PARAM_BEGIN_DATE);
    if (is_valid && start_date != licInfo.m_limits.end()) {
        if (seconds_from_epoch(start_date->second.c_str()) > now) {
        if (seconds_from_epoch(start_date->second) > now) {
            /*eventRegistryOut.addEvent(PRODUCT_EXPIRED, source.c_str(),
                    string("Valid from " + this->from_date).c_str());*/
            m_event_registry.addEvent(PRODUCT_EXPIRED, licInfo.source.c_str(),
@@ -75,7 +75,7 @@
    if (expiry != fullLicInfo.m_limits.end()) {
        strncpy(info.expiry_date, expiry->second.c_str(), sizeof(info.expiry_date));
        info.has_expiry = true;
        const double secs = difftime(seconds_from_epoch(expiry->second.c_str()), time(nullptr));
        const double secs = difftime(seconds_from_epoch(expiry->second), time(nullptr));
        info.days_left = max((int)round(secs / (60 * 60 * 24)), 0);
    } else {
        info.has_expiry = false;
src/library/os/windows/signature_verifier.cpp
@@ -54,7 +54,6 @@
static DWORD hashData(BCRYPT_HASH_HANDLE& hHash, const string& data, PBYTE pbHash, DWORD hashDataLenght) {
    DWORD status;
    bool success = false;
    if (NT_SUCCESS(status = BCryptHashData(hHash, (BYTE*)data.c_str(), (ULONG)data.length(), 0))) {
        status = BCryptFinishHash(hHash, pbHash, hashDataLenght, 0);
    }