Esempio n. 1
0
const shared_ptr<LicenseParserResult> LicenseParser::ParsePublishingLicenseInner(const void *pbPublishLicense,
                                                                     size_t cbPublishLicense)
{
    string publishLicense;
    if ((cbPublishLicense > sizeof(BOM_UTF8)) && (memcmp(pbPublishLicense, BOM_UTF8, sizeof(BOM_UTF8)) == 0))
    {
        string utf8NoBOM(reinterpret_cast<const uint8_t *>(pbPublishLicense) + sizeof(BOM_UTF8),
                         reinterpret_cast<const uint8_t *>(pbPublishLicense) +
                         cbPublishLicense);
        publishLicense = utf8NoBOM;
    }
    else if (cbPublishLicense % 2 == 0)
    {
        // Assume UTF16LE (Unicode)
        auto strUnicode = QString::fromUtf16(reinterpret_cast<const uint16_t*>(pbPublishLicense), 
                                                              static_cast<int>(cbPublishLicense) / sizeof(uint16_t));
        auto utf8ByteArray = strUnicode.toUtf8();
        string utfString(utf8ByteArray.constData(), utf8ByteArray.length());
        publishLicense = utfString;
    }
    else 
    {
        throw exceptions::RMSNetworkException("Invalid publishing license encoding",
                                              exceptions::RMSNetworkException::InvalidPL);
    }
    Logger::Hidden("Publishing License in LicenseParser: %s", publishLicense.c_str());
    size_t finalSize = publishLicense.size();

    string publishLicenseWithRoot;
    CXMLUtils::WrapWithRoot(publishLicense.c_str(), finalSize, publishLicenseWithRoot);

    auto document = IDomDocument::create();
    std::string errMsg;
    int errLine   = 0;
    int errColumn = 0;

    auto ok = document->setContent(publishLicenseWithRoot,
                                 errMsg,
                                 errLine,
                                 errColumn);

    if (!ok) 
    {
        throw exceptions::RMSNetworkException("Invalid publishing license",
                                          exceptions::RMSNetworkException::InvalidPL);
    }

    auto extranetDomainNode = document->SelectSingleNode(EXTRANET_XPATH);
    auto intranetDomainNode = document->SelectSingleNode(INTRANET_XPATH);

    auto extranetDomain = (nullptr != extranetDomainNode.get()) ? extranetDomainNode->text() : string();
    RemoveTrailingNewLine(extranetDomain);
    auto intranetDomain = (nullptr != intranetDomainNode.get()) ? intranetDomainNode->text() : string();
    RemoveTrailingNewLine(intranetDomain);
    vector<shared_ptr<Domain> > domains;

    if (!extranetDomain.empty())
    {
        domains.push_back(Domain::CreateFromUrl(extranetDomain));
    }

    if (!intranetDomain.empty())
    {
        // don't add the intranet domain if it's the same as extranet
        if (extranetDomain.empty() ||
           (0 != _stricmp(intranetDomain.data(), extranetDomain.data())))
        {
            domains.push_back(Domain::CreateFromUrl(intranetDomain));
        }
    }
    if (domains.empty()) 
    {
        throw exceptions::RMSNetworkException("Invalid domains publishing license",
                                          exceptions::RMSNetworkException::InvalidPL);
    }

    shared_ptr<LicenseParserResult> result;
    if (rmscore::core::FeatureControl::IsEvoEnabled())
    {
        auto slcNode = document->SelectSingleNode(SLC_XPATH);
        if (nullptr == slcNode.get())
        {
            throw exceptions::RMSNetworkException("Server public certificate",
                                              exceptions::RMSNetworkException::InvalidPL);
        }
        auto publicCertificate = slcNode->text();
        RemoveTrailingNewLine(publicCertificate);

        result = make_shared<LicenseParserResult>(LicenseParserResult(domains,
                                                                      make_shared<string>(publicCertificate)));
    }
    else
    {
        result = make_shared<LicenseParserResult>(domains);
    }
    return result;
}
Esempio n. 2
0
int main()
{
    verbose = (getenv ("PEGASUS_TEST_VERBOSE")) ? true : false;
    // Test one pattern vs string per call
    //  (test #, pattern, stringToBeTested, expected result)
    testPattern(1,__LINE__,"", "", false);
    testPattern(2,__LINE__,"abc", "", false);
    testPattern(3,__LINE__,"", "abc", false);

    testPattern(4,__LINE__,"abc", "abc", true);
    testPattern(5,__LINE__,"abcd", "abc", false);

    testPattern(6,__LINE__,"abc", "abcd", false);

    testPattern(7,__LINE__,"ab.", "ab?", true);
    testPattern(8,__LINE__,".a.b", "aa!b", true);
    testPattern(9,__LINE__,"\\.ab", ".ab", true);
    testPattern(10,__LINE__,"\\.ab", "\\.ab", false);

    testPattern(11,__LINE__,".*", "abcd", true);

    testPattern(12,__LINE__,"\\.*", "......", true);
    testPattern(13,__LINE__,"abcd*", "abcddddd", true);

    testPattern(14,__LINE__,"abcd*", "abcd", false);

    testPattern(15,__LINE__,"ab*cd", "abbbbcd", true);
    testPattern(16,__LINE__,"\\*ab", "*ab", true);
    testPattern(17,__LINE__,".\\*", "****", false);
    testPattern(18,__LINE__,".est", "Test", true);
//// KS_TODO this pattern fails so we are exluding it until we understand
//// the issue
////  testPattern(19,__LINE__,".*est", "Test", true);
    //// KS_TODO not sure what this one should do.
////  testPattern(19,__LINE__,"*est", "Test", true);
    // The following tests use utf16 chars
    {
        Char16 utf16Chars[] = {0xD800,0x78BC, 0xDC01, 0x45A3, 0x00};

        const String utf(utf16Chars);
        testPattern(30,__LINE__,utf, utf, true);
    }

    {
        Char16 utf16CharsP[] = { 0xD800,0x78BC, 0x00};

        String utfPattern(utf16CharsP);
        utfPattern.append("*");
        Char16 utf16[] = {0xD800,0x78BC, 0xD800,0x78BC, 0xD800,0x78BC, 0x00};

        const String utfString(utf16);
        testPattern(31,__LINE__,utfPattern, utfString, true);
    }
    {
        Char16 utf16CharsS[] = {0xD800,0x78BC, 0x00};

        String utfString(utf16CharsS);
        utfString.append("*");
        testPattern(32,__LINE__,".*", utfString, true);
    }

    {
        Char16 utf16CharsP[] = {0xD800,0x78BC, 0x00};

        String utfPattern(utf16CharsP);
        utfPattern.append(".*");

        Char16 utf16CharsS[] = {0xD800,0x78BC, 0x00};

        String utfString(utf16CharsS);
        utfString.append("an3s");
        testPattern(33,__LINE__,utfPattern, utfString, true);
    }
    cout << "+++++ passed all tests" << endl;
    return 0;
}
Esempio n. 3
0
inline std::string handleToStr(const v8::Local<v8::Value> & str)
{
	v8::String::Utf8Value utfString(str->ToString());
	return *utfString;
}