I am writing an application (C program) in which I would like to do a text search (similar to 'grep') on text documents in the disk cache. While I can easily search the files in the cache diretory, I need to find their original URLs. Once I can match the key (URL) to the file on disk, I'll be all set. I was hoping to be able to look at the cache source code and determine how to read the cache entries, but have found this a daunting task.
From netwerk/protocol/about/src/nsAboutCacheEntry.cpp it looks like I need to do something like this:
388 rv = descriptor->GetKey(getter_Copies(str));
and then
474 rv = descriptor->GetFile(getter_AddRefs(cacheFile)); 475 if (NS_SUCCEEDED(rv)) { 476 nsAutoString filePath; 477 cacheFile->GetPath(filePath); 478 APPEND_ROW("file on disk", NS_ConvertUCS2toUTF8(filePath)); 479 }
However, even after scouring the header files, I can't figure out how nsICacheEntryDescriptor structure is formatted. Once I know this, can I simply read the cache entry files (_CACHE_001_ etc.) and parse the information I need?
Thanks much for the assistance!
Josiah Dykstra
i'd recommend that you try to use the instance of libnecko.so/necko.dll that is included in a release build of mozilla. if you link your application against libxpcom.so/xpcom.dll (or if you use the xpcom glue layer to dynamically load libxpcom.so/xpcom.dll), you can then access the cache XPCOM components just as nsAboutCacheEntry.cpp does.
of course embedding portions of mozilla like this in your application is not necessarily a trivial task (yet). the GRE (gecko runtime environment) is meant to make this easier. you might want to read up on how you can use the GRE.
darin