Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File Path of downloaded dafsa.bin in firefox stable - Ubuntu:
- // file:///home/arpit/.cache/mozilla/firefox/843zsjle.default/settings/main/public-suffix-list/dafsa.bin
- // File Path of downloaded dafsa.bin in firefox nightly - Ubuntu:
- // file:///home/arpit/Development/moz/mozilla-central/obj-x86_64-pc-linux-gnu/tmp/profile-default/settings/main/public-suffix-list/dafsa.bin
- // File Path of downloaded dafsa.bin in firefox stable - Windows:
- // file://C:/Users/rpitt/AppData/Local/Mozilla/Firefox/Profiles/6fm1js29.default-1564744451242/settings/main/public-suffix-list/dafsa.bin
- I considered using IFstream instead of fopen.
- - IFstream handles char16_t* natively, fopen does not.
- Current Method:
- #include "mozilla/FStream.h"
- NS_IMETHODIMP nsEffectiveTLDService::Observe(nsISupports* aSubject,
- const char* aTopic,
- const char16_t* aData) {
- // aData is like one of the examples mentioned above
- if (nsCRT::strcmp(aTopic, "public-suffix-list-updated") == 0) {
- const char16_t* fileURI = (char16_t*)((char*)aData + 7); // cut "file://" from aData
- IFstream dafsaFile;
- dafsaFile.open(fileName, ifstream::binary | ifstream::ate);
- if (dafsaFile.is_open()) {
- unsigned int length = dafsaFile.tellg();
- dafsaFile.seekg(ifstream::beg);
- unsigned char kDafsaRemote[length];
- dafsaFile.read((char*)kDafsaRemote, length);
- mGraph = mozilla::Dafsa(kDafsaRemote);
- }
- dafsaFile.close();
- return NS_OK;
- }
- Previous Method:
- NS_IMETHODIMP nsEffectiveTLDService::Observe(nsISupports* aSubject,
- const char* aTopic,
- const char16_t* aData) {
- if (nsCRT::strcmp(aTopic, "public-suffix-list-updated") == 0) {
- const char* fileURI = (char*) aData +7; // cut "file://" from aData
- FILE* fp = fopen(fileURI, "rb");
- if(fp){
- fseek(fp, 0, SEEK_END);
- unsigned int size = ftell(fp);
- rewind(fp);
- // Initialise kDafsaRemote with the data read from dafsa.bin
- unsigned char kDafsaRemote[size];
- fread(kDafsaRemote, size, 1, fp);
- nsEffectiveTLDService:: mGraph = mozilla::Dafsa(kDafsaRemote);
- }
- fclose(fp);
- return NS_OK;
- }
Add Comment
Please, Sign In to add comment