Exemplo n.º 1
0
int TestURLChars(void)
{
  // Number of tests
  int errors = 2; 

  CString urlString("http://" MARLIN_HOST "/Marlin Test all/URL?first=abc&second=באהגיטכךםלןמףעצפתש��‎�חסץד");
  CString mustBeUrl("http://" MARLIN_HOST "/Marlin%20Test%20all/URL?first=abc&second=%C3%A1%C3%A0%C3%A4%C3%A2%C3%A9%C3%A8%C3%AB%C3%AA%C3%AD%C3%AC%C3%AF%C3%AE%C3%B3%C3%B2%C3%B6%C3%B4%C3%BA%C3%B9%C3%BC%C3%BB%C3%BD%C3%BF%C3%A7%C3%B1%C3%B5%C3%A3");
  CrackedURL url1(urlString);
  CString encoded = url1.URL();

  // Test if success
  if(encoded == mustBeUrl)
  {
    --errors;
  }

  // Encoding of higher order UTF-8 like the euro signs
  urlString = "http://" MARLIN_HOST "/Een%20Twee%20drie?een=waarde=%3Crequest%3E%3Cpage%3Eklantenkaart%3C%2Fpage%3E%3Crequesttype%3Econtactmemoaanmaken%3C%2Frequesttype%3E%3Ccallback%3EdesktopCallback%3C%2Fcallback%3E%3Cparameters%3E%3Cparameter%3E%3Cname%3Econtactmemogegevens%3C%2Fname%3E%3Cvalue%3E%7B%22contact_id%22:151714,%22eerste_contact_id%22:151714,%22werknemer_id%22:2942,%22werknemer_naam%22:%22N.N.+Bhoera%22,%22beheerorgnaam%22:%22Edwin%22,%22richting%22:%22uit%22,%22onderwerp%22:%22H%C3%AF%C3%ABr+st%C3%A4%C3%A4n+%E2%82%AC+test%22%7D%3C%2Fvalue%3E%3C%2Fparameter%3E%3C%2Fparameters%3E%3C%2Frequest%3E";
  CrackedURL url2(urlString);
  encoded = url2.URL();

  // Test if success
  if(urlString == encoded)
  {
    --errors;
  }

  // SUMMARY OF THE TEST
  // --- "---------------------------------------------- - ------
  printf("Testing URL %% encoding and Unicode chars       : %s\n",errors ? "ERROR" : "OK");

  return errors;
}
Exemplo n.º 2
0
TEST_F(TestURIUtils, IsInternetStream)
{
  CURL url1("http://path/to/file");
  CURL url2("https://path/to/file");
  EXPECT_TRUE(URIUtils::IsInternetStream(url1));
  EXPECT_TRUE(URIUtils::IsInternetStream(url2));
}
Exemplo n.º 3
0
 void serialize()
 {
     // create a small test file
     int mode = saga::filesystem::Create | saga::filesystem::ReadWrite;
     saga::filesystem::file f1 (saga::url("test.txt"), mode);
     std::string data("This is a test file!");
     f1.write(saga::buffer(data));
     std::string url1(f1.get_url().get_string());
     
     // serialize file
     std::string data1(saga::adaptors::serialize(f1));
     f1.close();
     
     // re-create a saga::file 
     saga::filesystem::file f2 (saga::adaptors::deserialize(data1));
     BOOST_CHECK_EQUAL(url1, f2.get_url());
     
     // check if position has been re-created correctly
     saga::off_t offset = f2.seek(0, saga::filesystem::Current);
     BOOST_CHECK_EQUAL(offset, (saga::off_t)data.size());
     
     std::string data2(saga::adaptors::serialize(f2));
     BOOST_CHECK_EQUAL(data1, data2);
     f2.close();
     
     boost::filesystem::remove("test.txt");
 }
Exemplo n.º 4
0
TEST(KURLTest, PathAfterLastSlash)
{
    KURL url1(ParsedURLString, "http://host/path/to/file.txt");
    EXPECT_EQ(20u, url1.pathAfterLastSlash());

    KURL invalidUTF8(ParsedURLString, "http://a@9%aa%:/path/to/file.txt");
    EXPECT_EQ(0u, invalidUTF8.pathAfterLastSlash());
}
Exemplo n.º 5
0
TEST(KURLTest, IsHierarchical)
{
    KURL url1(ParsedURLString, "http://host/path/to/file.txt");
    EXPECT_TRUE(url1.isHierarchical());

    KURL invalidUTF8(ParsedURLString, "http://a@9%aa%:/path/to/file.txt");
    EXPECT_FALSE(invalidUTF8.isHierarchical());
}
Exemplo n.º 6
0
TEST(KURLTest, LastPathComponent)
{
    KURL url1(ParsedURLString, "http://host/path/to/file.txt");
    EXPECT_EQ("file.txt", url1.lastPathComponent());

    KURL invalidUTF8(ParsedURLString, "http://a@9%aa%:/path/to/file.txt");
    EXPECT_EQ(String(), invalidUTF8.lastPathComponent());
}
Exemplo n.º 7
0
TEST(KURLTest, ProtocolIsInHTTPFamily)
{
    KURL url1(ParsedURLString, "http://host/path/to/file.txt");
    EXPECT_TRUE(url1.protocolIsInHTTPFamily());

    KURL invalidUTF8(ParsedURLString, "http://a@9%aa%:/path/to/file.txt");
    EXPECT_FALSE(invalidUTF8.protocolIsInHTTPFamily());
}
Exemplo n.º 8
0
bool autobots_toutiao::RequestForRenren()
{
	QString str_url1 = QString("http://isub.snssdk.com/2/auth/login/v2/?platform=renren_sns&version_code=5.8.3&uid_type=14&app_name=news_article&vid=%1&device_id=%2&channel=App Store&resolution=750*1334&aid=13&ab_version=83098,79288,87751,87331,85045,86854,86884,87032,86738,31650,87244,82679,87835,87830,87494,87036,87629&ab_feature=z2&ab_group=z2&openudid=0d919477efbefb99dfe7a02a2df34d9127ecc947&live_sdk_version=1.3.0&idfv=%3&ac=WIFI&os_version=9.3.5&ssmix=a&device_platform=iphone&iid=6088961915&ab_client=a1,f2,f7,e1&device_type=%4&idfa=86E011D2-C2DA-40CB-AB9D-DB1E1F9D668A")
		.arg(m_devices_list[m_device_order]._uuid).arg(m_devices_list[m_device_order]._did).arg(m_devices_list[m_device_order]._uuid).arg(m_devices_list[m_device_order]._device_type);

	QUrl url1(str_url1);

	HttpParamList header_list;
	header_list.push_back(HttpParamItem("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"));
	header_list.push_back(HttpParamItem("Connection", "Keep-Alive"));
	header_list.push_back(HttpParamItem("Accept-Encoding", "gzip, deflate"));
	header_list.push_back(HttpParamItem("Accept-Language", "zh-CN"));
	header_list.push_back(HttpParamItem("Host", "isub.snssdk.com"));
	header_list.push_back(HttpParamItem("User-Agent", m_devices_list[m_device_order]._useragent));

	QNetworkReply* reply = network.GetRequest(url1, header_list);

	QTime _t;
	_t.start();

	bool _timeout = false;

	while (reply && !reply->isFinished())
	{
		QCoreApplication::processEvents();

		if (_t.elapsed() >= TIMEOUT) {
			_timeout = true;
			break;
		}
	}

	if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
	{
		return false;
	}

	QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);

	int n = statusCodeV.toInt();

	if (n == 302 || n == 301)
	{
		// 重定向
		QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

		QUrl red_url = redirectionTarget.toUrl();

		QString str = red_url.toString();

		return ProcessRedirectSSL(str);
	}
	else
	{
		return false;
	}

}
Exemplo n.º 9
0
bool autobots_toutiao::RequestForRenren()
{
  QString str_url1 = "http://toutiao.com/auth/connect/?type=toutiao&platform=renren_sns";

  QUrl url1(str_url1);

  HttpParamList header_list;
  //header_list.push_back(HttpParamItem("(Request-Line)",	"GET /auth/connect/?type=toutiao&platform=renren_sns HTTP/1.1"));
  header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
//  header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list.push_back(HttpParamItem("Host", "toutiao.com"));
  header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

  QNetworkReply* reply = network.GetRequest(url1, header_list);

  QTime _t;
  _t.start();

  bool _timeout = false;

  while(reply && !reply->isFinished())
  {
    QCoreApplication::processEvents();

    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
  {
    return false;
  }

  QVariant statusCodeV =  reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);  

  int n = statusCodeV.toInt();

  if (n == 302 || n == 301)
  {
    // 重定向
    QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

    QUrl red_url = redirectionTarget.toUrl();

    QString str = red_url.toString();

    return ProcessRedirectSSL(str);
  }
  else
  {
    return false;
  }

}
Exemplo n.º 10
0
TEST(WebKit2, DISABLED_DOMWindowExtensionBasic)
{
    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionBasicPageGroup")));

    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DOMWindowExtensionBasic", pageGroup.get()));

    WKContextInjectedBundleClientV0 injectedBundleClient;
    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));

    injectedBundleClient.base.version = 0;
    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;

    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base);

    // The default cache model has a capacity of 0, so it is necessary to switch to a cache
    // model that actually allows for a page cache.
    WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser);

    PlatformWebView webView(context.get(), pageGroup.get());

    // Make sure the extensions for each frame are installed in each world.
    WKRetainPtr<WKURLRef> url1(AdoptWK, Util::createURLForResource("simple-iframe", "html"));
    WKPageLoadURL(webView.page(), url1.get());

    Util::run(&finished);
    finished = false;

    // Make sure those first 4 extensions are disconnected, and 2 new ones are installed.
    WKRetainPtr<WKURLRef> url2(AdoptWK, Util::createURLForResource("simple", "html"));
    WKPageLoadURL(webView.page(), url2.get());

    Util::run(&finished);
    finished = false;

    // Make sure those two are disconnected, and the first four are reconnected.
    WKPageGoBack(webView.page());

    Util::run(&finished);
    finished = false;

    // Make sure the 2 disconnected extensions in the page cache and the 4 active extensions are all removed.
    WKPageClose(webView.page());

    Util::run(&finished);

    const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*);
    EXPECT_EQ(expectedSize, messages.size());

    if (messages.size() != expectedSize)
        return;

    for (size_t i = 0; i < messages.size(); ++i)
        EXPECT_WK_STREQ(expectedMessages[i], messages[i].get());
}
TEST(WebKit2, DISABLED_DOMWindowExtensionNoCache)
{
    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionNoCachePageGroup")));

    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DOMWindowExtensionNoCache", pageGroup.get()));

    WKContextInjectedBundleClientV1 injectedBundleClient;
    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));

    injectedBundleClient.base.version = 1;
    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;

    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base);

    // Disable the page cache.
    WKContextSetCacheModel(context.get(), kWKCacheModelDocumentViewer);

    PlatformWebView webView(context.get(), pageGroup.get());

    // Make sure the extensions for each frame are installed in each world.
    WKRetainPtr<WKURLRef> url1(AdoptWK, Util::createURLForResource("simple-iframe", "html"));
    WKPageLoadURL(webView.page(), url1.get());

    Util::run(&finished);
    finished = false;

    // Make sure those first 4 extensions are destroyed, and 2 new ones are installed.
    WKRetainPtr<WKURLRef> url2(AdoptWK, Util::createURLForResource("simple", "html"));
    WKPageLoadURL(webView.page(), url2.get());

    Util::run(&finished);
    finished = false;

    // Make sure those 2 are destroyed, and the first 4 are recreated.
    WKPageGoBack(webView.page());

    Util::run(&finished);
    finished = false;

    WKPageClose(webView.page());

    Util::run(&finished);

    const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*);
    EXPECT_EQ(expectedSize, messages.size());

    if (messages.size() != expectedSize)
      return;

    for (size_t i = 0; i < messages.size(); ++i)
      EXPECT_WK_STREQ(expectedMessages[i], messages[i].get());
}
Exemplo n.º 12
0
bool CAsyncFileCopy::Copy(const CStdString &from, const CStdString &to, const CStdString &heading)
{
  // reset the variables to their appropriate states
  m_from = from;
  m_to = to;
  m_cancelled = false;
  m_succeeded = false;
  m_percent = 0;
  m_speed = 0;
  m_running = true;
  CStdString fromStripped, toStripped;
  CURL url1(from);
  url1.GetURLWithoutUserDetails(fromStripped);
  CURL url2(to);
  url2.GetURLWithoutUserDetails(toStripped);

  // create our thread, which starts the file copy operation
  Create();
  CGUIDialogProgress *dlg = (CGUIDialogProgress *)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
  DWORD time = timeGetTime();
  while (m_running)
  {
    m_event.WaitMSec(1000 / 30);
    if (!m_running)
      break;
    // start the dialog up as needed
    if (dlg && !dlg->IsDialogRunning() && timeGetTime() > time + 500) // wait 0.5 seconds before starting dialog
    {
      dlg->SetHeading(heading);
      dlg->SetLine(0, fromStripped);
      dlg->SetLine(1, toStripped);
      dlg->SetPercentage(0);
      dlg->StartModal();
    }
    // and update the dialog as we go
    if (dlg && dlg->IsDialogRunning())
    {
      CStdString speedString;
      speedString.Format("%2.2f KB/s", m_speed / 1024);
      dlg->SetHeading(heading);
      dlg->SetLine(0, fromStripped);
      dlg->SetLine(1, toStripped);
      dlg->SetLine(2, speedString);
      dlg->SetPercentage(m_percent);
      dlg->Progress();
      m_cancelled = dlg->IsCanceled();
    }
  }
  if (dlg)
    dlg->Close();
  return !m_cancelled && m_succeeded;
}
Exemplo n.º 13
0
int auto_smzdm::smzdm_run()
{
  QNetworkCookieJar* cookie = new QNetworkCookieJar(this);

  network.GetManager().setCookieJar(cookie);

  GetContent();

  foreach(QString str, m_comment_list)
  {

    QString jq = QString("jQuery") + "11100" + GetNumberString(16) +"_" + GetTimeStr();

    QString str_url1 = QString(
      "http://zhiyou.smzdm.com/user/comment/ajax_rating?callback=%1&comment_id=%2&rating=1&_=%3").arg(jq,str,GetTimeStr());

    QUrl url1(str_url1);

    HttpParamList header_list;
    header_list.push_back(HttpParamItem("Referer", m_news_url));
    header_list.push_back(HttpParamItem("Accept", "application/javascript, */*;q=0.8"));
    header_list.push_back(HttpParamItem("Cache-Control","no-cache"));
    header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
    //header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
    header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
    header_list.push_back(HttpParamItem("Host", m_host));
    header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

    QNetworkReply* reply = network.GetRequest(url1, header_list);

#ifdef _DEBUG

       QTime _t;
       _t.start();
   
       bool _timeout = false;
  
       while (reply && !reply->isFinished())
       {
         QCoreApplication::processEvents();
         if (_t.elapsed() >= 10*1000) {
           _timeout = true;
           break;
         }
       }

      QString rt = reply->readAll();
#endif //_DEBUG
      reply->deleteLater();
// 
   }
Exemplo n.º 14
0
TEST(KURLTest, ProtocolIs)
{
    KURL url1(ParsedURLString, "foo://bar");
    EXPECT_TRUE(url1.protocolIs("foo"));
    EXPECT_FALSE(url1.protocolIs("foo-bar"));

    KURL url2(ParsedURLString, "foo-bar:");
    EXPECT_TRUE(url2.protocolIs("foo-bar"));
    EXPECT_FALSE(url2.protocolIs("foo"));

    KURL invalidUTF8(ParsedURLString, "http://a@9%aa%:");
    EXPECT_FALSE(invalidUTF8.protocolIs("http"));
    EXPECT_TRUE(invalidUTF8.protocolIs(""));
}
Exemplo n.º 15
0
bool CAsyncFileCopy::Copy(const std::string &from, const std::string &to, const std::string &heading)
{
  // reset the variables to their appropriate states
  m_from = from;
  m_to = to;
  m_cancelled = false;
  m_succeeded = false;
  m_percent = 0;
  m_speed = 0;
  m_running = true;
  CURL url1(from);
  CURL url2(to);

  // create our thread, which starts the file copy operation
  Create();
  CGUIDialogProgress *dlg = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
  unsigned int time = XbmcThreads::SystemClockMillis();
  while (m_running)
  {
    m_event.WaitMSec(1000 / 30);
    if (!m_running)
      break;
    // start the dialog up as needed
    if (dlg && !dlg->IsDialogRunning() && (XbmcThreads::SystemClockMillis() - time) > 500) // wait 0.5 seconds before starting dialog
    {
      dlg->SetHeading(CVariant{heading});
      dlg->SetLine(0, CVariant{url1.GetWithoutUserDetails()});
      dlg->SetLine(1, CVariant{url2.GetWithoutUserDetails()});
      dlg->SetPercentage(0);
      dlg->StartModal();
    }
    // and update the dialog as we go
    if (dlg && dlg->IsDialogRunning())
    {
      dlg->SetHeading(CVariant{heading});
      dlg->SetLine(0, CVariant{url1.Get()});
      dlg->SetLine(1, CVariant{url2.Get()});
      dlg->SetLine(2, CVariant{ StringUtils::Format("%2.2f KB/s", m_speed / 1024) });
      dlg->SetPercentage(m_percent);
      dlg->Progress();
      m_cancelled = dlg->IsCanceled();
    }
  }
  if (dlg)
    dlg->Close();
  return !m_cancelled && m_succeeded;
}
Exemplo n.º 16
0
bool WatchDog::IsPathAvailable(const CStdString &pathToCheck, bool bDefault)
{
#ifdef WATCHDOG_DONT_TEST_PATH
  return true;
#else
  CStdString strPath = _P(pathToCheck);

  CFileItem item;
  item.m_strPath = strPath;
  if (item.IsApp())
    return true;
  
  if (item.IsInternetStream())
    return g_application.IsConnectedToNet();
  
  CSingleLock lock(m_lock);
  
  CURI url1 (strPath);
  CStdString strUrl1;
  strUrl1 = url1.Get();
  strUrl1 = BOXEE::BXUtils::RemoveSMBCredentials(strUrl1);
  strUrl1.ToLower();
  CUtil::RemoveSlashAtEnd(strUrl1);

  for (std::map<CStdString, PathStatus>::iterator iter=m_mapPaths.begin(); iter != m_mapPaths.end(); iter++)
  {
    CURI url2(iter->first);
    CStdString strUrl2;
    strUrl2 = url2.Get();
    strUrl2 = BOXEE::BXUtils::RemoveSMBCredentials(strUrl2);
    strUrl2.ToLower();
    CUtil::RemoveSlashAtEnd(strUrl2);
    
    if(strUrl1.Find(strUrl2) >= 0)
    { 
      if (iter->second == WD_UNKNOWN)
      {
        return bDefault;
      }
      
      return (iter->second == WD_AVAILABLE);
    }
  }

  return bDefault; // we dont know...
#endif
}
Exemplo n.º 17
0
void URLTestCase::CopyAndAssignment()
{
    wxURL url1("http://www.example.org/");
    wxURL url2;
    wxURI *puri = &url2;        // downcast

    { // Copy constructor
        wxURL url3(url1);
        CPPUNIT_ASSERT(url1 == url3);
    }
    { // Constructor for string
        wxURL url3(url1.GetURL());
        CPPUNIT_ASSERT(url1 == url3);
    }
    { // 'Copy' constructor for uri
        wxURL url3(*puri);
        CPPUNIT_ASSERT(url2 == url3);
    }

    // assignment for uri
    *puri = url1;
    CPPUNIT_ASSERT(url1 == url2);

    // assignment to self through base pointer
    *puri = url2;

    // Assignment of string
    url1 = wxS("http://www.example2.org/index.html");
    *puri = wxS("http://www.example2.org/index.html");
    CPPUNIT_ASSERT(url1 == url2);

    // Assignment
    url1 = wxS("");
    url2 = url1;
    CPPUNIT_ASSERT(url1 == url2);

    // assignment to self
    wxCLANG_WARNING_SUPPRESS(self-assign-overloaded)
    url2 = url2;
    wxCLANG_WARNING_RESTORE(self-assign-overloaded)

    // check for destructor (with base pointer!)
    puri = new wxURL();
    delete puri;
}
Exemplo n.º 18
0
int main(int argc, char **argv) {
    GURL real1("file://localhost/e:/Alex/workspace/demonstrator/Genesis/build/bin/x64/DEBUG/L32f.png");
    std::cout << (real1.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (real1.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(real1);

    GURL url("http://*****:*****@wwww.furious-typing.com:1234/test/main.html?id=12356&mid=carlos#location");
    std::cout << (url.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (url.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(url);

    GURL invalid1("c:\\blubber");
    std::cout << (invalid1.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (invalid1.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(invalid1);

    GURL invalid2("file:/host/path");
    std::cout << (invalid2.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (invalid2.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(invalid2);

    GURL url1("http://*****:*****@wwww.furious-typing.com:1234/test/main file.html?id=12356&mid=carlos#location");
    std::cout << (url1.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (url1.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(url1);

    GURL real2("file://localhost///192.168.0.2/path/to/file.txt");
    std::cout << (real2.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (real2.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(real2);

    GURL real3("file://localhost/e%3A/Alex/workspace/demonstrator/Genesis/build/bin/x64/DEBUG/L%5B32%5Df.pfm");
    std::cout << (real3.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (real3.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(real3);

    GURL real4("file://localhost/e:/Alex/workspace/demonstrator/Genesis/build/bin/x64/DEBUG/L[32]f.pfm");
    std::cout << (real4.is_valid() ? "is valid" : "is invalid") << '\n';
    std::cout << (real4.IsStandard() ? "is standard" : "is not standard") << '\n';
    print_uri(real4);
    return 0;
}
Exemplo n.º 19
0
 void serialize()
 {
     // create a small test file
     int mode = saga::advert::Create | saga::advert::ReadWrite;
     saga::advert::entry adv1 (saga::url("/test.adv"), mode);
     std::string url1(adv1.get_url().get_string());
     
     // serialize logical_file
     std::string data1(saga::adaptors::serialize(adv1));
     adv1.close();
     
     // re-create a saga::logical_file 
     saga::advert::entry adv2 (saga::adaptors::deserialize(data1));
     BOOST_CHECK_EQUAL(url1, adv2.get_url().get_string());
     
     std::string data2(saga::adaptors::serialize(adv2));
     BOOST_CHECK_EQUAL(data1, data2);
     adv2.close();
     
     saga::advert::directory adv(saga::url("/"), mode);
     adv.remove("test.adv");
 }
Exemplo n.º 20
0
// public void addWebAction(QAction* action, QWebPage::WebAction webAction)
void tst_TabWidget::addWebAction()
{
    QFETCH(QWebPage::WebAction, webAction);

    SubTabWidget widget;

    QSignalSpy spy0(&widget, SIGNAL(linkHovered(const QString &)));
    QSignalSpy spy1(&widget, SIGNAL(loadPage(const QString &)));
    QSignalSpy spy2(&widget, SIGNAL(loadProgress(int)));
    QSignalSpy spy3(&widget, SIGNAL(setCurrentTitle(const QString &)));
    QSignalSpy spy4(&widget, SIGNAL(showStatusBarMessage(const QString &)));
    QSignalSpy spy5(&widget, SIGNAL(tabsChanged()));
    QSignalSpy spy6(&widget, SIGNAL(lastTabClosed()));

    QAction *action = new QAction(&widget);
    widget.addWebAction(action, webAction);

    widget.newTab();
    QVERIFY(!action->isEnabled());

    widget.loadUrl(QUrl("about:config"));
    QUrl url1(":/notfound.html"); //QUrl("http://www.google.com/"));
    QUrl url2(":/notfound2.html"); //QUrl("http://www.yahoo.com/"));
    widget.loadUrl(url1);
    widget.loadUrl(url2);

    QTRY_VERIFY(action->isEnabled());
    widget.newTab();
    QVERIFY(!action->isEnabled());

    QCOMPARE(spy0.count(), 0);
    QCOMPARE(spy1.count(), 0);
    QVERIFY(spy2.count() > 0);
    QCOMPARE(spy3.count(), 8);
    QVERIFY(spy4.count() > 0);
    QCOMPARE(spy5.count(), 6);
    QCOMPARE(spy6.count(), 0);
}
Exemplo n.º 21
0
bool autobots_toutiao::LoginBili(const QString& name, const QString& password, const QString& hash_code, const QString& public_key)
{
  QString str_url1 = "https://passport.bilibili.com/ajax/miniLogin/login";

  QUrl url1(str_url1);
    
  QString str_temp = "https://passport.bilibili.com/ajax/miniLogin/minilogin";

  QString en_pwd = pwdEncrypt::GetInstance()->EncryptPassword(password,public_key,hash_code);

  HttpParamList header_list;
  header_list.push_back(HttpParamItem("Accept",	"application/json, text/javascript, */*; q=0.01"));
  header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
  header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list.push_back(HttpParamItem("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"));
  header_list.push_back(HttpParamItem("Host", "passport.bilibili.com"));
  header_list.push_back(HttpParamItem("Referer", str_temp));
  header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

  HttpParamList post_data;
  post_data.push_back(HttpParamItem("captcha",""));
  post_data.push_back(HttpParamItem("keep","1"));
  post_data.push_back(HttpParamItem("pwd",en_pwd));
  post_data.push_back(HttpParamItem("userid",name));

  QNetworkReply* reply = network.GetRequest_ssl(url1, header_list);

  QTime _t;
  _t.start();

  bool _timeout = false;

  while (reply && !reply->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
  {
    reply->deleteLater();
    return false;
  }

  QVariant statusCodeV =  reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);  

  int n = statusCodeV.toInt();

  if (n!=200)
  {
    return false;
  }

  QByteArray rp_data = reply->readAll();

  bool res = GetResult(rp_data);

  if (reply!=NULL)
  {
    reply->deleteLater();
  }

  return res;
}
Exemplo n.º 22
0
QString AFormatter::formatHyperlinks (const QString& text)
{
	QString result = text;

	QRegExp url1("\\[url\\](.+)\\[/url\\]",        Qt::CaseInsensitive, QRegExp::RegExp);
	QRegExp url2("\\[url=(\\S+)\\](.+)\\[/url\\]", Qt::CaseInsensitive, QRegExp::RegExp);

	url1.setMinimal(true);
	url2.setMinimal(true);

	int index = 0;

	while ((index = url1.indexIn(result, index)) != -1)
	{
		QString html;
		QString lstr = url1.cap(1);
		int     lval = AParser::isURL(lstr);

		if (lval == 1)
			html = QString::fromUtf8("<a href='") + lstr + "'>" + lstr + "</a>";
		else if (lval == 2) // опасная ссылка
			html = "<span class='alert'>" + lstr + "</span>";
		else // невалидная ссылка
			html = lstr;

		result.replace(url1.cap(0), html);

		index += std::min(url1.matchedLength(), html.length());
	}

	index = 0;

	while ((index = url2.indexIn(result, index)) != -1)
	{
		QString html;

		QString lstr = url2.cap(1);
		QString rstr = url2.cap(2);

		int lval = AParser::isURL(lstr);
		int rval = AParser::isURL(rstr);

		if (lval == 1)
			html = "<a href='" + lstr + "'>" + rstr + "</a>";
		else if (rval == 1)
			html = "<a href='" + rstr + "'>" + lstr + "</a>";
		else if (lval == 2)
			html = "<span class='alert'>" + rstr + "</span>";
		else if (rval == 2)
			html = "<span class='alert'>" + lstr + "</span>";
		else // невалидная ссылка
			html = rstr + " (" + lstr + ")";

		result.replace(url2.cap(0), html);

		index += std::min(url2.matchedLength(), html.length());
	}

	// ссылки без тэгов
	QRegExp url3("[^'>]((http://|https://|ftp://|[^/]www\\.)[^<\\s]+)", Qt::CaseInsensitive, QRegExp::RegExp);

	index = 0;

	while ((index = url3.indexIn(result, index)) != -1)
	{
		QString html;
		QString lstr = url3.cap(1);
		int     lval = AParser::isURL(lstr);

		if (lval == 1)
		{
			html = QString::fromUtf8("<a href='") + lstr + "'>" + QUrl::fromPercentEncoding(lstr.toUtf8()) + "</a>";
			result.replace(lstr, html);
			index += std::min(url3.matchedLength(), html.length());
		}
		else // невалидная или опасная ссылка
			index += url3.matchedLength();
	}

	// email url
	QRegExp email("\\[email\\](\\S+)\\[/email\\]", Qt::CaseInsensitive, QRegExp::RegExp);

	email.setMinimal(true);

	index = 0;

	while ((index = email.indexIn(result, index)) != -1)
	{
		QString html;
		QString lstr = email.cap(1);
		int     lval = AParser::isURL(lstr);

		if (lval == 1)
			html = QString::fromUtf8("<a href='mailto:") + lstr + "'>" + lstr + "</a>";
		else if (lval == 2)
			html = lstr;
		else // невалидная ссылка
			html = lstr;

		result.replace(email.cap(0), html);

		index += std::min(email.matchedLength(), html.length());
	}

	// msdn url
	QRegExp msdn("\\[msdn\\](\\S+)\\[/msdn\\]", Qt::CaseInsensitive, QRegExp::RegExp);
	msdn.setMinimal(true);
	result.replace(msdn, "<a href='http://search.msdn.microsoft.com/Default.aspx?brand=Msdn&query=\\1'>\\1</a>");

	return result;
}
Exemplo n.º 23
0
bool autobots_toutiao::AuthorByRenren(const QString& name, const QString& password)
{
  //1.检验验证码
//   QString vcode, code_sign;
//   bool need_code = NeedValidateCode(name, vcode, code_sign);
//   QString str_need_code = need_code ? "true" : "";

  QString str_url1 = "https://passport.bilibili.com/login?act=getkey&_=" + GetTimeStr();;

  QUrl url1(str_url1);
    
  QString str_temp = "https://passport.bilibili.com/ajax/miniLogin/minilogin";

  HttpParamList header_list;
  header_list.push_back(HttpParamItem("Accept",	"application/json, text/javascript, */*; q=0.01"));
  header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
  //header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list.push_back(HttpParamItem("Host", "passport.bilibili.com"));
  header_list.push_back(HttpParamItem("Referer", str_temp));
  header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

  QNetworkReply* reply = network.GetRequest_ssl(url1, header_list);

  QTime _t;
  _t.start();

  bool _timeout = false;

  while (reply && !reply->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
  {
    reply->deleteLater();
    return false;
  }

  QVariant statusCodeV =  reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);  

  int n = statusCodeV.toInt();

  bool res = false;

  if (n!=200)
  {
    return res;
  }

  QByteArray rp_data = reply->readAll();

  QString hash_code, public_key;

  res = GetCode(rp_data, hash_code, public_key);

  if (reply != NULL)
  {
    reply->deleteLater();
  }

  if (!res)
  {
    return res;
  }

  res = LoginBili(name,password,hash_code,public_key);

  return res;
}
Exemplo n.º 24
0
int auto_smzdm::smzdm_run()
{
  QNetworkCookieJar* cookie = new QNetworkCookieJar(this);

  network.GetManager().setCookieJar(cookie);

  QString str_url_1 = "http://digi.tech.qq.com/original/pyp/pro.html";

  QUrl url_1(str_url_1);
  HttpParamList header_list1;
  header_list1.push_back(HttpParamItem("Accept",	"application/json, text/javascript, */*; q=0.01"));
  header_list1.push_back(HttpParamItem("Connection","Keep-Alive"));
  header_list1.push_back(HttpParamItem("Accept-Encoding","deflate"));
  header_list1.push_back(HttpParamItem("Accept-Language","zh-cn"));
  header_list1.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"));

  header_list1.push_back(HttpParamItem("Cache-Control", "no-cache"));
  //header_list.push_back(HttpParamItem("X-CSRFToken", "20c9e1fc22618a31cbfcd42218e96dd0"));
  header_list1.push_back(HttpParamItem("Host", "digi.tech.qq.com"));
  header_list1.push_back(HttpParamItem("Referer", "http://digi.tech.qq.com/original/pyp/pro.html"));
  header_list1.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));
 
  QNetworkReply* rp1 = network.GetRequest(url_1, header_list1);

   QTime _t;
   _t.start();
 
   bool _timeout = false;
 
   while (rp1 &&!rp1->isFinished())
   {
     QCoreApplication::processEvents();
     if (_t.elapsed() >= TIMEOUT) {
       _timeout = true;
       break;
     }
   }

   QString str = rp1->readAll();
   rp1->deleteLater();

  //投票
  QString str_url1 = "http://panshi.qq.com/v2/vote/10615080/submit";

  QUrl url1(str_url1);

  HttpParamList header_list2;
  header_list2.push_back(HttpParamItem("Accept", "text/html, application/xhtml+xml, */*"));
  header_list2.push_back(HttpParamItem("Referer", "http://digi.tech.qq.com/original/pyp/pro.html"));
  header_list2.push_back(HttpParamItem("Cache-Control","no-cache"));
  header_list2.push_back(HttpParamItem("Connection","keep-alive"));
  //header_list2.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list2.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list2.push_back(HttpParamItem("Host", "panshi.qq.com"));
  header_list2.push_back(HttpParamItem("X-Requested-With", "XMLHttpRequest"));
  header_list2.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded"));
  header_list2.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"));

  HttpParamList post_data;
  post_data.push_back(HttpParamItem("answer","{\"673646\":{\"selected\":[1560346]}}"));
  post_data.push_back(HttpParamItem("callback","parent.AppPlatform.Survey.Digg.ReceiveDiggResult"));
  post_data.push_back(HttpParamItem("format","script"));
  post_data.push_back(HttpParamItem("g_tk","2013"));
  post_data.push_back(HttpParamItem("login","1"));
  post_data.push_back(HttpParamItem("source","1"));
  QNetworkReply* rp2 = network.PostRequest(url1, header_list2, post_data);

  _t.restart();

  _timeout = false;

  while (rp2 &&!rp2->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  str = rp2->readAll();
  rp2->deleteLater();

  cookie->deleteLater();

  return 0;
}
Exemplo n.º 25
0
bool autobots_toutiao::Login(const QString& name, const QString& password)
{
  //1.检验验证码
  QString vcode, code_sign;
  bool need_code = NeedValidateCode(name, vcode, code_sign);
  QString str_need_code = need_code ? "true" : "";

  QString str_url1 = "https://sso.toutiao.com/account_login/";

  QUrl url1(str_url1);

  HttpParamList header_list;
  header_list.push_back(HttpParamItem("Referer", "text/javascript, text/html, application/xml, text/xml, */*"));
  header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
  header_list.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded"));
  //header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list.push_back(HttpParamItem("Host", "sso.toutiao.com"));
  header_list.push_back(HttpParamItem("Referer", "https://sso.toutiao.com/login/"));
  header_list.push_back(HttpParamItem("X-CSRFToken", m_csrf_token));
  header_list.push_back(HttpParamItem("X-Requested-With", "XMLHttpRequest"));
  header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));

  HttpParamList post_data;
  post_data.push_back(HttpParamItem("account",name));
  post_data.push_back(HttpParamItem("captcha",vcode));
  post_data.push_back(HttpParamItem("code", ""));
  post_data.push_back(HttpParamItem("is_30_days_no_login","false"));
  post_data.push_back(HttpParamItem("mobile",""));
  post_data.push_back(HttpParamItem("password",password));
  post_data.push_back(HttpParamItem("service","http://www.toutiao.com/"));

  QNetworkReply* reply = network->PostRequest_ssl(url1, header_list,post_data);

  QTime _t;
  _t.start();

  bool _timeout = false;

  while (reply && !reply->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
  {
    return false;
  }

  QVariant statusCodeV =  reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);  

  int n = statusCodeV.toInt();

  if (n!= 200)
  {
	  return false;
  }

  QByteArray data = reply->readAll();

  int res = GetResult(data);

  if (res == 0)
  {
	  return true;
  }
  else if (res == -1)
  {
	  VlidateCodeOnLine* obj = VlidateCodeOnLine::GetInstance();
	  obj->ReportError("bestsalt", code_sign);
	  return false;
  }
  else
  {
	  return false;
  }

  //////////////////////////////////////////////////////////////////////////
  //bool res = false;
  //if (n == 302 || n == 301)
  //{
  //  // 重定向
  //  QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

  //  QUrl red_url = redirectionTarget.toUrl();

  //  QString str = red_url.toString();

  //  int r = ProcessRedirectLoginGet(str);

  //  if (r == 0)
  //  {
  //    res = true;
  //  }
  //  else if (r = -2)
  //  {
  //    // 验证码错误
  //    VlidateCodeOnLine* obj = VlidateCodeOnLine::GetInstance();
  //    obj->ReportError("bestsalt",code_sign);
  //  }
  //}
  //else
  //{
  //  res = false;
  //}

  //if (reply != NULL)
  //{
  //  reply->deleteLater();
  //}

  //return res;
}
Exemplo n.º 26
0
bool autobots_toutiao::NeedValidateCode(const QString& name, QString& vcode, QString& code_sign)
{
  QString str_url1 = "https://sso.toutiao.com/login/";

  QUrl url1(str_url1);
  HttpParamList header_list;
  header_list.push_back(HttpParamItem("Accept", "text/html, application/xhtml+xml, */*"));
  header_list.push_back(HttpParamItem("Connection","Keep-Alive"));
  //header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list.push_back(HttpParamItem("Host", "sso.toutiao.com"));
  header_list.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));
//  header_list.push_back(HttpParamItem("Referer",str_temp));

//   HttpParamList post_data;
//   post_data.push_back(HttpParamItem("authFeed","true"));
//   post_data.push_back(HttpParamItem("authorizeOrigin","00000"));
//   post_data.push_back(HttpParamItem("client_id", m_client_id));
//   post_data.push_back(HttpParamItem("display","page"));
//   post_data.push_back(HttpParamItem("follow","true"));
//   post_data.push_back(HttpParamItem("icode",""));
//   post_data.push_back(HttpParamItem("isNeedIcode",""));
//   post_data.push_back(HttpParamItem("login_type","false"));
//   post_data.push_back(HttpParamItem("password",""));
//   post_data.push_back(HttpParamItem("porigin","80100"));
//   post_data.push_back(HttpParamItem("post_form_id", m_post_id));
//   post_data.push_back(HttpParamItem("redirect_uri","http://api.snssdk.com/auth/login_success/"));
//   post_data.push_back(HttpParamItem("response_type","code"));
//   post_data.push_back(HttpParamItem("scope","status_update photo_upload create_album"));
//   post_data.push_back(HttpParamItem("secure","true"));
//   post_data.push_back(HttpParamItem("state","renren_sns__0____toutiao____2__0__24"));
//   post_data.push_back(HttpParamItem("username",name));

  QNetworkReply* reply = network->GetRequest_ssl(url1, header_list);

  QTime _t;
  _t.start();

  bool _timeout = false;

  while (reply && !reply->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
  {
    return false;
  }

  QVariant statusCodeV =  reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);  

  int n = statusCodeV.toInt();

  if (n != 200)
  {
    return false;
  }

  QByteArray data = reply->readAll();

  bool res = GetValidateCode(data, vcode, code_sign);

  reply->deleteLater();

  return res;

  // 获取验证码
//    QUrl url2("http://icode.renren.com/getcode.do?t=openplatform");
//    HttpParamList header_list2;
//    header_list2.push_back(HttpParamItem("Connection","Keep-Alive"));
//    header_list2.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
//    header_list2.push_back(HttpParamItem("Accept-Language","zh-CN"));
//    header_list2.push_back(HttpParamItem("Host", "icode.renren.com"));
//    header_list2.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));
// //   header_list2.push_back(HttpParamItem("Referer",str_temp));
//  
//    QNetworkReply* reply2 = network->GetRequest(url2, header_list2);
//  
//    _t.restart();
//  
//    _timeout = false;
//  
//    while (reply2 && !reply2->isFinished())
//    {
//      QCoreApplication::processEvents();
//      if (_t.elapsed() >= TIMEOUT) {
//        _timeout = true;
//        break;
//      }
//    }
//  
//    if (reply2 == NULL || (reply2->error() != QNetworkReply::NoError) || _timeout)
//    {
//      return false;
//    }
//  
//    if (n != 200)
//    {
//      return false;
//    }
//  
//    QByteArray data = reply2->readAll();
//  
//    QImage image_ = QImage::fromData(data);//(data.data(),100,40,QImage::Format_RGB32);
// 
//    if (m_code_online)
//    {
//      // 在线验证
//      //bool result = image_.save("e:\\1.jpg");
//      VlidateCodeOnLine* obj = VlidateCodeOnLine::GetInstance();
//      int res = obj->GetRecResults(data, "bestsalt", "hh610520;;", "bestsalt", vcode, code_sign);
//    }
//    else
//    {
//      // 手动验证
//      ValidateDlg dlg(this, image_);
//      if (dlg.exec() == QDialog::Accepted)
//      {
//        vcode = dlg.getCode();
//      }
//    }

/*  return true;*/
}
Exemplo n.º 27
0
QString AFormatter::normalizeBody (const QString& body, const QString& nick)
{
	QString data = body;

	// отбрасываем "[tagline]" и "[moderator]"
	QRegExp tagline("\\[tagline\\](.+)\\[/tagline\\]",       Qt::CaseInsensitive);
	QRegExp moderator("\\[moderator\\](.+)\\[/moderator\\]", Qt::CaseInsensitive);

	tagline.setMinimal(true);
	moderator.setMinimal(true);

	data.replace(tagline,   "");
	data.replace(moderator, "");

	// удаляем img с даными вместо ссылки (например, см. http://www.rsdn.ru/forum/flame.comp/4077971.1.aspx)
	QRegExp img1("\\[img\\]data:(\\S+)\\[/img\\]", Qt::CaseInsensitive);
	img1.setMinimal(true);
	data.replace(img1, "");

	// заменяем [img]...[/img] на ссылку
	QRegExp img2("\\[img\\](\\S+)\\[/img\\]", Qt::CaseInsensitive);
	img2.setMinimal(true);
	data.replace(img2, QString::fromUtf8("[url=\\1]\\1[/url]"));

	// укорачивание длинных ссылок (например, см. http://www.rsdn.ru/forum/web/4086359.1.aspx)
	QRegExp url1("\\[url=data:(\\S+)\\](.+)\\[/url\\]", Qt::CaseInsensitive);
	url1.setMinimal(true);
	data.replace(url1, "[url=bad%20link]\\2[/url]");

	// удаление тэга цитирования
	QRegExp q1("(^|[^\\[])\\[q\\]", Qt::CaseInsensitive);
	q1.setMinimal(true);
	data.replace(q1, "\\1");

	QRegExp q2("(^|[^\\[])\\[/q\\]", Qt::CaseInsensitive);
	q2.setMinimal(true);
	data.replace(q2, "\\1");

	// удаление таблиц из цитирования
	QRegExp table("(^|[^\\[])\\[t\\](.+)\\[/t\\]", Qt::CaseInsensitive);
	table.setMinimal(true);
	data.replace(table, "\\1");

	// удаление тэгов [h1]..[h6] из цитирования
	for (int i = 1; i < 7; i++)
	{
		QRegExp h1("(^|[^\\[])\\[h" + QString::number(i) + "\\]", Qt::CaseInsensitive);
		h1.setMinimal(true);
		data.replace(h1, "\\1");

		QRegExp h2("(^|[^\\[])\\[/h" + QString::number(i) + "\\]", Qt::CaseInsensitive);
		h2.setMinimal(true);
		data.replace(h2, "\\1");
	}

	data = data.trimmed();

	// разбиение
	QStringList source = data.split("\n");

	QString nick_3 = AFormatter::nick3(nick);

	// добавление квотинга к строкам
	for (int i = 0; i < source.size(); i++)
		if (source[i].trimmed().length())
			source[i] = nick_3 + "> " + source[i];

	// удаление дублирующихся пустых строк
	int index = 0;

	// регексп для приветствий в квотинге
	QRegExp hello(QString::fromUtf8(">\\s{0,}Здравствуйте,\\s.+,\\sВы писали:"));

	while (index < source.size() - 1)
	{
		if (source.at(index).trimmed().length() == 0 && source.at(index + 1).trimmed().length() == 0)
		{
			source.removeAt(index);
			continue;
		}
		else if (source.at(index).indexOf(hello) != -1)
		{
			source.removeAt(index);

			if (index > 0)
				index--;

			continue;
		}

		index++;
	}

	// вычисление уровня квотинга
	QList<int> quoting_level;

	int size = source.size();

	for (int i = 0; i < size; i++)
	{
		QString temp = source.at(i).trimmed();

		int level = 0;

		for (int j = 0; j < temp.length() - 3; j++)
		{
			if (temp[j] == ' ' && !(temp[j + 1] == '&' || temp[j + 2] == '&' || temp[j + 3] == '&'))
				break;
			else if (temp[j] == '&' && temp[j + 1] == 'g' && temp[j + 2] == 't' && temp[j + 3] == ';')
			{
				level++;
				j += 3;
			}
			else if (temp[j] == '&' && temp[j + 1] == 'l' && temp[j + 2] == 't' && temp[j + 3] == ';')
				break;
		}

		quoting_level.append(level);

		source[i] = temp;
	}

	// вставка пустых строк между разными уровнями квотинга
	for (int i = 0; i < size - 1; i++)
	{
		if (source[i].length() == 0)
			continue;

		if (quoting_level.at(i) != quoting_level.at(i + 1) && source[i + 1].length() /*&& (quoting_level.at(i) == 0 || quoting_level.at(i + 1) == 0)*/)
			source[i] = source[i] + "\r\n";
	}

	data = source.join("\r\n").trimmed();

	// замена HTML спец-символов
	data.replace("&gt;",  ">");
	data.replace("&lt;",  "<");
	data.replace("&amp;", "&");

	return data;
}
Exemplo n.º 28
0
bool autobots_toutiao::AuthorByRenren(const QString& name, const QString& password)
{
	//1.检验验证码
	QString vcode, code_sign;
	bool need_code = NeedValidateCode(name, vcode, code_sign);
	QString str_need_code = need_code ? "true" : "";

	QString str_url1 = "https://graph.renren.com/oauth/grant";

	QUrl url1(str_url1);

	QString str_temp = "http://graph.renren.com/oauth/grant?client_id=" + m_client_id + "&redirect_uri=http://api.snssdk.com/auth/login_success/&response_type=code&display=page&scope=status_update+photo_upload+create_album&state=renren_sns__0____toutiao____2__0__24&secure=true&origin=00000";

	HttpParamList header_list;
	//header_list.push_back(HttpParamItem("(Request-Line)",	"GET /auth/connect/?type=toutiao&platform=renren_sns HTTP/1.1"));
	header_list.push_back(HttpParamItem("Connection", "Keep-Alive"));
	header_list.push_back(HttpParamItem("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"));
	header_list.push_back(HttpParamItem("Accept-Language", "zh-CN"));
	header_list.push_back(HttpParamItem("Host", "graph.renren.com"));
	header_list.push_back(HttpParamItem("Referer", str_temp));
	//Referer	
	header_list.push_back(HttpParamItem("User-Agent", m_devices_list[m_device_order]._useragent));

	HttpParamList post_data;
	QString t = QString("http://api.snssdk.com/auth/login_success/") + "&client_id=" + m_client_id;
	//post_data.push_back(HttpParamItem("authFeed","true"));
	post_data.push_back(HttpParamItem("authorizeOrigin", "00000"));
	//post_data.push_back(HttpParamItem("client_id", m_client_id));
	post_data.push_back(HttpParamItem("display", "touch"));
	post_data.push_back(HttpParamItem("follow", "true"));
	post_data.push_back(HttpParamItem("icode", vcode));
	post_data.push_back(HttpParamItem("isNeedIcode", str_need_code));
	post_data.push_back(HttpParamItem("login_type", "false"));
	post_data.push_back(HttpParamItem("password", password));
	post_data.push_back(HttpParamItem("porigin", "80103"));
	post_data.push_back(HttpParamItem("post_form_id", m_post_id));
	post_data.push_back(HttpParamItem("redirect_uri", t));
	post_data.push_back(HttpParamItem("response_type", "code"));
	post_data.push_back(HttpParamItem("scope", "status_update photo_upload create_album"));
	post_data.push_back(HttpParamItem("secure", "true"));
	post_data.push_back(HttpParamItem("state", m_state_id));
	post_data.push_back(HttpParamItem("username", name));

	QNetworkReply* reply = network.PostRequest_ssl(url1, header_list, post_data);

	QTime _t;
	_t.start();

	bool _timeout = false;

	while (reply && !reply->isFinished())
	{
		QCoreApplication::processEvents();
		if (_t.elapsed() >= TIMEOUT) {
			_timeout = true;
			break;
		}
	}

	if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
	{
		reply->deleteLater();
		return false;
	}

	QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);

	int n = statusCodeV.toInt();

	bool res = false;
	if (n == 302 || n == 301)
	{
		// 重定向
		QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

		QUrl red_url = redirectionTarget.toUrl();

		QString str = red_url.toString();

		int r = ProcessRedirectLoginGet(str);

		if (r == 0)
		{
			res = true;
		}
		else if (r == -2)
		{
			// 验证码错误
			VlidateCodeOnLine* obj = VlidateCodeOnLine::GetInstance();
			obj->ReportError("bestsalt", code_sign);
		}
	}
	else
	{
		QString msg = reply->readAll();
		res = false;
	}

	if (reply != NULL)
	{
		reply->deleteLater();
	}

	return res;
}
Exemplo n.º 29
0
bool autobots_toutiao::NeedValidateCode(const QString& name, QString& vcode, QString& code_sign)
{
	QString str_url1 = "http://graph.renren.com/icode/check";

	QUrl url1(str_url1);
	QString str_temp = "http://graph.renren.com/oauth/grant?client_id=" + m_client_id + "&redirect_uri=http://api.snssdk.com/auth/login_success/&response_type=code&display=page&scope=status_update+photo_upload+create_album&state=renren_sns__0____toutiao____2__0__24&secure=true&origin=00000";
	HttpParamList header_list;
	header_list.push_back(HttpParamItem("Connection", "Keep-Alive"));
	//  header_list.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
	header_list.push_back(HttpParamItem("Accept-Language", "zh-CN"));
	header_list.push_back(HttpParamItem("Host", "graph.renren.com"));
	header_list.push_back(HttpParamItem("User-Agent", m_devices_list[m_device_order]._useragent));
	header_list.push_back(HttpParamItem("Referer", str_temp));
	//network.GetManager().setCookieJar(new QNetworkCookieJar(this));

	HttpParamList post_data;
	post_data.push_back(HttpParamItem("authFeed", "true"));
	post_data.push_back(HttpParamItem("authorizeOrigin", "00000"));
	post_data.push_back(HttpParamItem("client_id", m_client_id));
	post_data.push_back(HttpParamItem("display", "page"));
	post_data.push_back(HttpParamItem("follow", "true"));
	post_data.push_back(HttpParamItem("icode", ""));
	post_data.push_back(HttpParamItem("isNeedIcode", ""));
	post_data.push_back(HttpParamItem("login_type", "false"));
	post_data.push_back(HttpParamItem("password", ""));
	post_data.push_back(HttpParamItem("porigin", "80100"));
	post_data.push_back(HttpParamItem("post_form_id", m_post_id));
	post_data.push_back(HttpParamItem("redirect_uri", "http://api.snssdk.com/auth/login_success/"));
	post_data.push_back(HttpParamItem("response_type", "code"));
	post_data.push_back(HttpParamItem("scope", "status_update photo_upload create_album"));
	post_data.push_back(HttpParamItem("secure", "true"));
	post_data.push_back(HttpParamItem("state", "renren_sns__0____toutiao____2__0__24"));
	post_data.push_back(HttpParamItem("username", name));

	QNetworkReply* reply = network.PostRequest(url1, header_list, post_data);

	QTime _t;
	_t.start();

	bool _timeout = false;

	while (reply && !reply->isFinished())
	{
		QCoreApplication::processEvents();
		if (_t.elapsed() >= TIMEOUT) {
			_timeout = true;
			break;
		}
	}

	if (reply == NULL || (reply->error() != QNetworkReply::NoError) || _timeout)
	{
		return false;
	}

	QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);

	int n = statusCodeV.toInt();

	if (n != 200)
	{
		return false;
	}

	QString str = reply->readAll();

	reply->deleteLater();

	if (str.toInt() == 0)
	{
		return false;
	}

	// 获取验证码

	QUrl url2("http://icode.renren.com/getcode.do?t=openplatform");
	HttpParamList header_list2;
	header_list2.push_back(HttpParamItem("Connection", "Keep-Alive"));
	//  header_list2.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
	header_list2.push_back(HttpParamItem("Accept-Language", "zh-CN"));
	header_list2.push_back(HttpParamItem("Host", "icode.renren.com"));
	header_list2.push_back(HttpParamItem("User-Agent", m_devices_list[m_device_order]._useragent));
	header_list2.push_back(HttpParamItem("Referer", str_temp));

	QNetworkReply* reply2 = network.GetRequest(url2, header_list2);

	_t.restart();

	_timeout = false;

	while (reply2 && !reply2->isFinished())
	{
		QCoreApplication::processEvents();
		if (_t.elapsed() >= TIMEOUT) {
			_timeout = true;
			break;
		}
	}

	if (reply2 == NULL || (reply2->error() != QNetworkReply::NoError) || _timeout)
	{
		return false;
	}

	statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);

	n = statusCodeV.toInt();

	if (n != 200)
	{
		return false;
	}

	QByteArray data = reply2->readAll();

	QImage image_ = QImage::fromData(data);//(data.data(),100,40,QImage::Format_RGB32);

	if (m_code_online)
	{
		// 在线验证
		//bool result = image_.save("e:\\1.jpg");
		VlidateCodeOnLine* obj = VlidateCodeOnLine::GetInstance();
		int res = obj->GetRecResults(data, "bestsalt", "hh610520;;", "bestsalt", vcode, code_sign);
	}
	else
	{
		// 手动验证
		ValidateDlg dlg(this, image_);
		if (dlg.exec() == QDialog::Accepted)
		{
			vcode = dlg.getCode();
		}
	}

	return true;
}