ArpitB

Observe

Aug 7th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. NS_IMETHODIMP nsEffectiveTLDService::Observe(nsISupports* aSubject,
  2.                                              const char* aTopic,
  3.                                              const char16_t* aData) {
  4.  
  5.   if (nsCRT::strcmp(aTopic, "public-suffix-list-updated") == 0) {
  6.  
  7.     nsCOMPtr<nsIFile> mDAFSABinFile;
  8.     nsresult rv;
  9.     mDAFSABinFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
  10.     if (mDAFSABinFile) {
  11.       rv = mDAFSABinFile->InitWithPath(nsDependentString(aData));
  12.  
  13.       nsCOMPtr<nsIInputStream> inputStream;
  14.       rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream),
  15.                                       mDAFSABinFile);
  16.  
  17.       if (rv != NS_ERROR_FILE_NOT_FOUND) {
  18.         uint64_t length = 0;
  19.         rv = inputStream->Available(&length);
  20.         std::cout << length << "\n\n";  // For debugging, to be removed
  21.  
  22.         unsigned char kDafsaRemote[length];
  23.         while (1) {
  24.           uint32_t count;
  25.           rv = inputStream->Read((char*)kDafsaRemote, length, &count);
  26.           NS_ENSURE_SUCCESS(rv, rv);
  27.  
  28.           // We reached the end of the file.
  29.           if (count == 0) {
  30.             break;
  31.           }
  32.         }
  33.         inputStream->Close();
  34.         for (auto k : kDafsaRemote) {
  35.           std::cout << (int)k << "\n";  // For debugging, to be removed
  36.         }
  37.  
  38.         nsEffectiveTLDService::mGraph = mozilla::Dafsa(kDafsaRemote);
  39.       }
  40.     }
  41.   }
  42.   return NS_OK;
  43. }
Add Comment
Please, Sign In to add comment